Help Needed: Three.js Instanced Meshes - Instances Not Retaining Positions

Hi everyone,

I’m working on a Three.js project where I need to place multiple instances of 3D models in a scene using instanced meshes. However, I’m encountering an issue where the instances are not retaining their positions correctly. The instances either all move to a new position or do not retain their intended positions. (there’s also some shading issues, but ill tackle that later).

I have attached all relevant files along a video showing the issue as well as some logs i used for debugging.

Any help is greatly appreciated. If the task is too complex I can offer some incentive. I don’t have much, but i am willing to discuss.

bitbox.js:193 Intersect at: -26.720457220391516, 0, -251.59985348890086
bitbox.js:97 Selected asset: big_tree_foliage_single_LOD0_jungle_mat_0.glb
bitbox.js:193 Intersect at: -91.35863718332138, 0, 297.2136667639786
bitbox.js:130 Added new instanced mesh for big_tree_foliage_single_LOD0_jungle_mat_0.glb with count 100
bitbox.js:146 Placing at position: -90, 0, 300
bitbox.js:151 Instanced mesh count after placing: 101
bitbox.js:152 Matrix for new instance: 1,0,0,0,0,1,0,0,0,0,1,0,-90,0,300,1
bitbox.js:157 InstancedMesh position: -90,0,300
bitbox.js:158 InstancedMesh matrix: 1,0,0,0,0,1,0,0,0,0,1,0,-90,0,300,1
bitbox.js:193 Intersect at: -280.85688927512615, 0, -304.43468858906783
bitbox.js:146 Placing at position: -280, 0, -300
bitbox.js:151 Instanced mesh count after placing: 102
bitbox.js:152 Matrix for new instance: 1,0,0,0,0,1,0,0,0,0,1,0,-280,0,-300,1
bitbox.js:157 InstancedMesh position: -280,0,-300
bitbox.js:158 InstancedMesh matrix: 1,0,0,0,0,1,0,0,0,0,1,0,-280,0,-300,1


server.js (5.2 KB)
client.js (7.8 KB)
bitbox.js (7.9 KB)

:bangbang:Edit: Found the solution here Every instances in InstancedMesh go to same position? - #3 by RemiTurcotte

Most likely you set the position property, which affects the whole group of all instances. Individual instances have their position in an array of matrices – one for each instance. Here is a short demo:

https://codepen.io/boytchev/pen/yLxpGBX

Hi, I found the solution at Every instances in InstancedMesh go to same position? - #3 by RemiTurcotte but this is also helpful so ill need an array to sync in their position to all connected clients. Thank you so much for sharing this!

1 Like