InstancedMesh is not working

Hello EveryOne,

I am using instance buffer geometry + mesh basic material like this

const mesh = new THREE.InstancedMesh(geometry. material,count)

but i am not getting anything in the scene.

I am attaching my instance buffer geometry

instance_geometry.txt (1.9 MB)

Here my question is
i am using instance buffer geometry with shader material but i am not able to pick the instances
So i walk through the article and found that it is going to work with instancemesh is that right or is there any other way to pick objects


If you really do it this way and this is not a typo, then there’s no surprise that you get nothing.
It has to be geometry, material.

@prisoner849 its a typo here not in my code but my instance buffer geometry is not working with the instancedMesh

InstancedMesh takes a BufferGeometry, not InstancedBufferGeometry as your file indicates you are using. Other than that you’ll have to provide more information on what you’re doing / trying to do in order for us to help.

Can you make a jsfiddle that demonstrates your issue?

This is not true , it is working now but i am not able to pick any objects from my instanced mesh. Means raycasting is not working , i am using this example to achieve my goal.

if we look at my intancebuffergeometry so i am using some attributes like elevation and orientation and shader material so according to that these attribute values my object is following the terrain. So here my question is can we achieve this affect with shader material also.

Main things here why raycasting is not working due to instanceBufferGeometry

This is not true , it is working now but i am not able to pick any objects from my instanced mesh.

Again without an example demonstrating the issue it’s hard to pin down exactly what’s happening. I was simply pointing out what the documentation states you should use – there should be no reason to use InstancedBufferGeometry even if it works.

Regarding your raycasting issue you’ll need to make a jsfiddle. It entirely depends on what you’re doing in the shader and it’s not productive for us to guess.

I appreciate your help and i know if you use instanceBufferGeometry so we are not able to pick the objects.

Here is my fiddle that is not working i dont know why

But you can walk through the code so here i have a shader program that is running for an instanceBufferGeometry is it possible to pick the individual instances if not so i have such a same shader program for each instance i will share that instance data also to you but first let me know the possbility.


It looks like you’ve accidentally posted the original, unedited fiddle.

Oh sorry my bad, updated one

The fiddle you’ve posted doe not run for me. I get the following error:

three.module.js:41367 Uncaught TypeError: Cannot read property 'type' of undefined

That aside it looks like you are doing custom calculations to set gl_Position in the shader which means that three.js cannot know where the triangles wind up being transformed to – so you’ll have to implement a custom raycast function. And it looks like you aren’t using instanceMatrix, either, which means there’s no point to using InstancedMesh here, either. I recommend using a regular ShaderMaterial rather than RawShaderMaterial and regular Mesh in that case.

Ok , one last question is there any way possible to debug this shader program or webgl program (like we use in the normal js debugger )

Unfortunately not – shaders can be notoriously difficult to debug. I often output intermediate variables as color so I can more easily see what’s going on.