-
I'm using a few different GLTF models and they're all very different sizes. Is there a way to scale the geometry, and then 'apply' the scaling so it's effectively [1.0,1.0,1.0] relative to the world? This is the component I'm using right now; function Forest() {
const { nodes, materials } = useGLTF('/tree/tree01.gltf', true)
const treeGeometry = nodes['node-0'].geometry;
const treeMaterial = nodes['node-0'].geometry;
const ref = useRef()
useFrame(state => {
const time = state.clock.getElapsedTime()
let i = 0
for (let x = 0; x < 6; x++) {
for (let z = 0; z < 6; z++) {
const id = i++
tempTrees.position.set(x * 300, 300, 3 - z); // Large world numbers
tempTrees.scale.set( 1, 1, 1 );
tempTrees.updateMatrix()
ref.current.setMatrixAt(id, tempTrees.matrix)
}
}
ref.current.instanceMatrix.needsUpdate = true
})
// need to scale down because the model is huge
return (
<instancedMesh ref={ref} args={[treeGeometry, treeMaterial, 36]} scale={[0.007, 0.007, 0.007]} />
)
} I could just scale the models down in Blender but the idea is for a user to be able to use their own model eventually so it'd be good to apply a fix for it in code. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
check the threejs docs for geometry, it has helper functions for that: https://threejs.org/docs/index.html#api/en/core/BufferGeometry.scale |
Beta Was this translation helpful? Give feedback.
check the threejs docs for geometry, it has helper functions for that: https://threejs.org/docs/index.html#api/en/core/BufferGeometry.scale