Any Idea on how to Raycast two of the same geometries but in different groups?

I have a program that gets many different geometries and materials from a backserver and then positions them on the screen. Each of these geometries can have multiple groups so that they can use different materials, but share geometries. I put each group of geometries into its own mesh. Because of this, if a geometry has two or more groups, the distance to each group will be the same (because they share the same geometries), and therefore, won’t necessarily highlight the mesh closest to the camera. Is there any way to fix this?

I know my description may be a little confusing so I would be happy to clarify if anyone has any questions.

Hi!

That’s why it’s better to provide a live code example :slight_smile:

1 Like

I guess the code can boil down to something as simple as this:

var bufferGeometry = new THREE.BufferGeometry();

bufferGeometry.addAttribute("position", (3000 vertices));
bufferGeometry.addAttribute("normal", (3000 normals));
bufferGeometry.setIndex(arrayOfIndices);
bufferGeometry.addGroup(0,1500,material1);
bufferGeometry.addGroup(1500,1500,material2);

Basically I would have a single buffergeometry with two groups that I would like to raycast on individually.

How about a fiddle? And possibly use the code formatting option so code is easier to read (it doesn’t EXACTLY the same as the other text in the post).

1 Like

I know it isn’t exactly the same, but that is the simplified general idea in which I think it might be easier for people to help me.

40%20AM

Ok thanks, fixed. Also, maybe this will help. Imagine a cube which is composed of a single geometry, but each face on the cube is a different group with a different material. Is it possible to highlight those faces individually?

You underestimate the laziness of people :slight_smile:
Providing a minimal, complete and verifiable example will reduce the time of an answer.

But we risk turning this into Stack Overflow and then people will stop having fun. The only goal of three.js is for people to have fun.

2 Likes

@pailhead
True!
But I’m too lazy to reproduce the problem myself :slight_smile: (I’m saying exclusively about me)

I agree, same here. Maybe there’s someone who is not.

You may have to .clone() the geometry. So each geometry have a different ID.
And if you raycast it, it wont change all the object that have that ID.

hi . i got same problem like you .

so could you tell me the sloution if you find it out