Last active
October 18, 2017 18:31
-
-
Save EvanBacon/5e18a49260cbdc4bde2287a823866d99 to your computer and use it in GitHub Desktop.
Three.js helper function for aligning a mesh.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const alignMesh = (mesh, axis = { x: 0.5, y: 0.5, z: 0.5 }) => { | |
axis = axis || {}; | |
const box = new THREE.Box3().setFromObject(mesh); | |
const size = box.getSize(); | |
const { max } = box; | |
const min = { x: -box.min.x, y: -box.min.y, z: -box.min.z }; | |
Object.keys(axis).map(key => { | |
const scale = axis[key]; | |
mesh.position[key] = (min[key] - size[key]) + (size[key] * scale); | |
}); | |
} | |
export default alignMesh; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment