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); } }
satisfyConstraints() { this.constraints.forEach(([p1, p2, distance]) => { this.diff.subVectors(p2.position, p1.position); const currentDist = this.diff.length(); if (currentDist === 0) return; const correction = this.diff.multiplyScalar(1 - distance / currentDist); const correctionHalf = correction.multiplyScalar(0.5); p1.position.add(correctionHalf); p2.position.sub(correctionHalf); }); }
const getCameraPosition = camera => { // not sure why i should do this, copied from somewhere camera.position.setFromMatrixPosition(camera.matrixWorld); // get camera position const cameraPos = new THREE.Vector3(0, 0, 0); cameraPos.applyMatrix4(camera.matrixWorld); return cameraPos; }
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() { var v = new THREE.Vector3(); return function panUp(distance, objectMatrix) { v.setFromMatrixColumn(objectMatrix, 1); // get Y column of objectMatrix v.multiplyScalar(distance); panOffset.add(v); }; })()
constructor(props) { super(props); this.state = {}; this.animate = this.animate.bind(this); this.scene = new THREE.Scene(); this.camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 ); this.camera.position.set( 0, 0, 60 ); this.renderer = new THREE.WebGLRenderer(); this.renderer.setSize( window.innerWidth, window.innerHeight ); }
// HELPERS _getCameraPosition() { if (!this.viewProjectionMatrix) { return new THREE.Vector3(); } const cam = new THREE.Camera(); const rootInverse = new THREE.Matrix4().getInverse(this.rootTransform); cam.projectionMatrix.elements = this.viewProjectionMatrix; cam.projectionMatrixInverse = new THREE.Matrix4().getInverse(cam.projectionMatrix); // add since three@0.103.0 const campos = new THREE.Vector3(0, 0, 0).unproject(cam).applyMatrix4(rootInverse); return campos; }
constructor(renderer) { const width = renderer.domElement.width; const height = renderer.domElement.height; // Create and position a Perspective Camera this.threeCamera = new THREE.PerspectiveCamera(Config.camera.fov, width / height, Config.camera.near, Config.camera.far); this.threeCamera.position.set(Config.camera.posX, Config.camera.posY, Config.camera.posZ); // Initial sizing this.updateSize(renderer); // Listeners window.addEventListener('resize', () => this.updateSize(renderer), false); }
place(position, rotation) { const material = new Material(0xeeeeee).standard; const mesh = new THREE.Mesh(this.geo, material); // Use ES6 spread to set position and rotation from passed in array mesh.position.set(...position); mesh.rotation.set(...rotation); if(Config.shadow.enabled) { mesh.receiveShadow = true; } this.scene.add(mesh); }
function update(time) { const angle = time*speed; group.rotation.y = angle; subjectMaterial.alphaMap.offset.y = 0.55 + time * textureOffsetSpeed; subjectWireframe.material.color.setHSL( Math.sin(angle*2), 0.5, 0.5 ); const scale = (Math.sin(angle*8)+6.4)/5; subjectWireframe.scale.set(scale, scale, scale) }
integrate(delta) { const newPos = this.tmp.subVectors(this.position, this.previous); newPos.multiplyScalar(this.drag).add(this.position); newPos.add(this.acceleration.multiplyScalar(delta * delta)); this.tmp = this.previous; this.previous = this.position; this.position = newPos; this.acceleration.set(0, 0, 0); }
(function() { var v = new THREE.Vector3(); return function panLeft(distance, objectMatrix) { v.setFromMatrixColumn(objectMatrix, 0); // get X column of objectMatrix v.multiplyScalar(-distance); panOffset.add(v); }; })()