updateWindForce(delta) { const time = Date.now(); this.windStrength = Math.cos(time / 700000) * 500 + 1600; this.windForce.set( Math.sin(time / 2000), Math.cos(time / 3000), Math.sin(time / 1000) ); this.windForce.normalize().multiplyScalar(this.windStrength); }
function handleVertex(v) { n.fromArray(normals, v * 3); n2.copy(n); t = tan1[v]; // Gram-Schmidt orthogonalize tmp.copy(t); tmp.sub(n.multiplyScalar(n.dot(t))).normalize(); // Calculate handedness tmp2.crossVectors(n2, t); test = tmp2.dot(tan2[v]); w = test < 0.0 ? -1.0 : 1.0; tangents[v * 4] = tmp.x; tangents[v * 4 + 1] = tmp.y; tangents[v * 4 + 2] = tmp.z; tangents[v * 4 + 3] = w; }
function rotateXYZEAxis() { let euler = new THREE.Euler(); euler.setFromVector3( point .clone() .cross(tempVector) .normalize() ); quaternionE.setFromEuler(euler); // rotation axis tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse(parentRotationMatrix) ); quaternionX.setFromAxisAngle( quaternionE, -point.clone().angleTo(tempVector) ); quaternionXYZ.setFromRotationMatrix(worldRotationMatrix); tempQuaternion.multiplyQuaternions(tempQuaternion, quaternionX); tempQuaternion.multiplyQuaternions(tempQuaternion, quaternionXYZ); scope.object.quaternion.copy(tempQuaternion); }
applyAerodynamics(delta, geometry) { if (this.windEnabled) { geometry.faces.forEach((face) => { this.tmpForce .copy(face.normal) .normalize() .multiplyScalar(face.normal.dot(this.windForce)); this.particles[face.a].addForce(this.tmpForce); this.particles[face.b].addForce(this.tmpForce); this.particles[face.c].addForce(this.tmpForce); }); } this.particles.forEach((particle) => { particle.addForce(this.gravityForce); particle.integrate(delta); }); }
function getTouchData(event, gestureState) { const touches = event.nativeEvent.touches; const point0 = new THREE.Vector3( touches[0].locationX, touches[0].locationY ); const point1 = new THREE.Vector3( touches[1].locationX, touches[1].locationY ); const angleRadians = Math.atan2( point1.y - point0.y, point1.x - point0.x ); const vector = new THREE.Vector3(); vector.subVectors(point1, point0).normalize(); const distance = point1.distanceTo(point0); return { point0, point1, angleRadians, vector, distance }; }
directionalLight.position.set( 0, 1, 1 ).normalize(); this.scene.add( directionalLight );