Skip to content

Instantly share code, notes, and snippets.

@EvanBacon
Last active October 18, 2017 18:31
Show Gist options
  • Save EvanBacon/3bd0eab626ab4ff1d7744d75fb519cf5 to your computer and use it in GitHub Desktop.
Save EvanBacon/3bd0eab626ab4ff1d7744d75fb519cf5 to your computer and use it in GitHub Desktop.
Three.js helper function for scaling the longest side of a mesh to a certain size. This is a debug method for AR development.
const scaleLongestSideToSize = (mesh, size) => {
const { x: width, y: height, z: depth } = new THREE.Box3().setFromObject(mesh).getSize();
const longest = Math.max(width, Math.max(height, depth));
const scale = size / longest;
mesh.scale.set(scale, scale, scale);
}
export default scaleLongestSideToSize;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment