Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (model.elements[i].rotation !== undefined) {
- var tempOffsetMesh = new THREE.Mesh(new THREE.BoxGeometry(0.1, 0.1, 0.1), new THREE.MeshBasicMaterial({color: 0x9933ff}));
- curSeg.add(tempOffsetMesh);
- var originLocWithoutRot = new THREE.Vector3();
- originLocWithoutRot.x = ((model.elements[i].rotation.origin[0] / 16) - 0.5) - curSeg.position.x;
- originLocWithoutRot.y = ((model.elements[i].rotation.origin[1] / 16) - 0.5) - curSeg.position.y;
- originLocWithoutRot.z = ((model.elements[i].rotation.origin[2] / 16) - 0.5) - curSeg.position.z;
- tempOffsetMesh.position.set(originLocWithoutRot.x, originLocWithoutRot.y, originLocWithoutRot.z);
- // Set the withoutrot to be the matrix world, so that it is easier to compare the difference afterwards
- tempOffsetMesh.updateMatrixWorld();
- tempOffsetMesh.parent.updateMatrixWorld();
- originLocWithoutRot.setFromMatrixPosition(tempOffsetMesh.matrixWorld);
- // Now the tempOffsetMesh is at the correct location of the origin, and is a child of the segment
- // Permanently rotate the segment
- curSeg.rotation[model.elements[i].rotation.axis] = model.elements[i].rotation.angle * (pi / 180);
- // Calculate the offset from the locWithoutRot to the new LocWithRot
- tempOffsetMesh.updateMatrixWorld();
- tempOffsetMesh.parent.updateMatrixWorld();
- var originLocWithRot = new THREE.Vector3();
- originLocWithRot.setFromMatrixPosition(tempOffsetMesh.matrixWorld);
- // Find difference from withoutRot and WithRot
- var tempDifference = new THREE.Vector3();
- tempDifference.x = originLocWithRot.x - originLocWithoutRot.x;
- tempDifference.y = originLocWithRot.y - originLocWithoutRot.y;
- tempDifference.z = originLocWithRot.z - originLocWithoutRot.z;
- // Now, move the object in the negated form of that difference
- curSeg.position.x -= tempDifference.x;
- curSeg.position.y -= tempDifference.y;
- curSeg.position.z -= tempDifference.z;
- curSeg.remove(tempOffsetMesh)
- }
Advertisement
Add Comment
Please, Sign In to add comment