I get center of mesh from gltf scene and use result to set position for my tree object. I don’t understand why my position is wrong with original file?
Here is my code get center of mesh:
mesh.geometry.computeBoundingBox();
var boundingBox = mesh.geometry.boundingBox;
var position = new THREE.Vector3();
position.subVectors( boundingBox.max, boundingBox.min );
position.multiplyScalar( 0.5 );
position.add( boundingBox.min );
position.applyMatrix4( mesh.matrixWorld );
Oh no, it isn’t my problem.
My original model is white model. I get position of mesh from white model and set it for tree gltf model and result as image. I need my tree has same position with white model. Sorry because my English is bad.
Each tree is a separate model and you are trying to place one tree on each of the white cubes? If so the problem here is that the tree model itself is offset, so you are giving them the position of the cubes and then they are offsetting themselves. You need to counter the offset by subtracting this vector. Its a similar thing to my first example, but rather than positioning to the center of the world you are setting the tree’s local center.