function scaleOneAxisOnMove() { point.applyMatrix4(tempMatrix.getInverse(worldRotationMatrix)); if (scope.axis === 'X') { scope.object.scale.x = oldScale.x * (1 + point.x / oldScale.x); } if (scope.axis === 'Y') { scope.object.scale.y = oldScale.y * (1 + point.y / oldScale.y); } if (scope.axis === 'Z') { scope.object.scale.z = oldScale.z * (1 + point.z / oldScale.z); } }
function scaleOnMove() { scale = endTouchData.distance / startTouchData.distance; scope.object.scale.x = oldScale.x * scale; scope.object.scale.y = oldScale.y * scale; scope.object.scale.z = oldScale.z * scale; }
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 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 }; }
/** This renders text via canvas and projects it as a sprite */ function Text({ children, size = 1, letterSpacing = 0.01, color = '#000000' }) { const [font] = useState(() => new THREE.FontLoader().parse(fontFile)) const [shapes, [x, y]] = useMemo(() => { let x = 0, y = 0 let letters = [...children] let mat = new THREE.MeshBasicMaterial({ color, opacity: 1, transparent: true }) return [ letters.map(letter => { const geom = new THREE.ShapeGeometry(font.generateShapes(letter, size, 1)) geom.computeBoundingBox() const mesh = new THREE.Mesh(geom, mat) mesh.position.x = x x += geom.boundingBox.max.x + letterSpacing y = Math.max(y, geom.boundingBox.max.y) return mesh }), [x, y], ] }, [children]) return ( <group position={[-x / 2, -y / 2, 0]}> {shapes.map((shape, index) => ( <primitive key={index} object={shape} /> ))} </group> ) }
function rotateEAxis() { point.applyMatrix4(tempMatrix.getInverse(lookAtMatrix)); tempVector.applyMatrix4(tempMatrix.getInverse(lookAtMatrix)); rotation.set( Math.atan2(point.z, point.y), Math.atan2(point.x, point.z), Math.atan2(point.y, point.x) ); offsetRotation.set( Math.atan2(tempVector.z, tempVector.y), Math.atan2(tempVector.x, tempVector.z), Math.atan2(tempVector.y, tempVector.x) ); tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse(parentRotationMatrix) ); quaternionE.setFromAxisAngle(eye, offsetRotation.z - rotation.z); quaternionXYZ.setFromRotationMatrix(worldRotationMatrix); tempQuaternion.multiplyQuaternions(tempQuaternion, quaternionE); tempQuaternion.multiplyQuaternions(tempQuaternion, quaternionXYZ); scope.object.quaternion.copy(tempQuaternion); }
function rotateWorldSpace() { rotation.set( Math.atan2(point.z, point.y), Math.atan2(point.x, point.z), Math.atan2(point.y, point.x) ); offsetRotation.set( Math.atan2(tempVector.z, tempVector.y), Math.atan2(tempVector.x, tempVector.z), Math.atan2(tempVector.y, tempVector.x) ); unitX, Math.round( (rotation.x - offsetRotation.x) / scope.rotationSnap ) * scope.rotationSnap ); ); } else { quaternionX.setFromAxisAngle(unitX, rotation.x - offsetRotation.x); quaternionY.setFromAxisAngle(unitY, rotation.y - offsetRotation.y); quaternionZ.setFromAxisAngle(unitZ, rotation.z - offsetRotation.z);
Math.atan2(point.x, point.z), Math.atan2(point.y, point.x) ); offsetRotation.set( Math.atan2(tempVector.z, tempVector.y), Math.atan2(tempVector.x, tempVector.z), Math.atan2(tempVector.y, tempVector.x) ); unitX, Math.round( (rotation.x - offsetRotation.x) / scope.rotationSnap ) * scope.rotationSnap ); ); } else { quaternionX.setFromAxisAngle(unitX, rotation.x - offsetRotation.x); quaternionY.setFromAxisAngle(unitY, rotation.y - offsetRotation.y); quaternionZ.setFromAxisAngle(unitZ, rotation.z - offsetRotation.z);