thank you mugen
at first i’m confused
can i have two instancedMesh with 50 object on each with same location and size?
Is it correct to create two Instancedmesh with just one for loop?
const mesh1 = instancedmesh(geometry,material,50)
const mesh2 = instancedmesh(geometry,material,50)
for (var i = 1; i < 50; ++i) {
mesh1.setMatrixAt(i,…
mesh2.setMatrixAt(i,…
I want these objects to be placed in exactly the same place, given that the location of the first object is random
My problem is that I want to use the x and z position of mesh1 for mesh2 but not works
mesh1.setMatrixAt(
i,
new THREE.Matrix4()
.makeTranslation(2, 0 ,1)
.multiply(new THREE.Matrix4().makeScale(0, 0.1, 0))
);
//-----------------
mesh2.setMatrixAt(
i,
new THREE.Matrix4()
.makeTranslation(mesh1.position.x, 0, mesh1.position.z)
.multiply(new THREE.Matrix4().makeScale(0, 0.05, 0))
);
//------
mesh1.position.x and z dont work in mesh2 traslation
Instanced mesh has two positions: mesh.position that affects all of its instances and individual per instance positions set in setMatrixAt.
In you code you apply “global” position of mesh1 to all instances of mesh2, so it doesn’t work like you want it to. You should match individual per instance positions.
In your case it should be:
mesh2.setMatrixAt(
i,
new THREE.Matrix4()
.makeTranslation(2, 0, 1)
.multiply(new THREE.Matrix4().makeScale(0, 0.05, 0))
);
I’m not sure what you mean by “merge”, when you merge two normal geometries, you combine their vertex related data arrays into one. When you say you want two instanced meshes to be at the same position, that’s not merge. Maybe if you provide a visual example of what you want then it’ll be easier to help you.
I have three type of geometries (box,plane,…), each of which consists of 50 objects and located in different places, that is, in total, 150 geometries are produced, which form 50 geometries.
I did this with Instansad Mesh
Now I want to merge these 50 objects in place so that when the scene is loaded they will be one frame.
with BufferGeometryUtils.mergeBufferGeometries