Selecting a Face of Cube

New to 3D development and trying to figure things out. Lets say I have a cube in my scene. I can pick the cube and detect which facet was hit using a ray. If each face on a cube is made up of 2 facets, when I pick, I only get 1 of the facets, not the entire face. My main goal is to color an entire face of an object that gets selected by a user. How do i know what other facet(s) are on the same face that was selected? I’d like to get all the facets on a selected face, and color it.

Also, why can I apply material (color) to an entire face of a cube using an index, but I can’t pick an entire face?

I would advice to create your cube with 6 planes in this case. It will simplify everything.

1 Like

Thanks Sebavan. My problem is the shape will not always be a cube. There will be custom shapes. Like an “L” or “U” shape. Is there a way I can get the facet that the ray picks, then find all of the facets that are connected to it in that plane.

You will need to find all the facet with similar normals.

I have been struggling with this as well and it is an absolute under documented pain in the butt. And i haven’t been able to come up with a simple playground solution like picking a facet and making it red.
As far as i know Babylon doesn’t work with faces so if you change a color you color the vertices of a submesh.
@sebavan , do you know of a simple playground example that takes the pickinfo and changes the color of the clicked face?

Simple. I believe not. May be have a look at this recent similar topic.
I guess the easiest in your case (since you are creating the meshes, if I understand correctly?) would be to access them either through submeshes or material settings.

Mind Yoga in the morning…

Provided you have the coordinates of a facet and set a plane at this point. You cut the object at this point in the z axis, so to speak. Now you need all points that lie above this cutting plane towards the camera.

Face Select Problem

Nice trick (but incomplete for this use case ). May be your yoga sessions (and your famous coding skills) can teach how to 1) generate the plane at picked meshed position, 2) rotate/face the picked point normals and 3) size to fit the picked mesh only or include the picked mesh only? Nah, Don’t think I’m challenging you …Or may be just a little, but then for the ‘good’ only

Why is it so hard to access this mesh / facet?

I tried with ray as well but it’s the same pickInfo

It’s hard because there is no concept of poly-selection (groups) in BJS. As exposed in the other topic/link I shared. So all the approaches and methods we are trying are just go-arounds working with what is available. On the other hand, the versatility of BJS allows us to imagine all these methods. May be one day we’ll find the one that’s good enough to be implemented as a helper. The above one from @CodingCrusader looks promising to me. Just on a first thought after my morning coffee (and without a yoga session )

It may be me but i did not see a solution in the teapot example

There are multiple (pseudo) solutions, but there is no ‘one fits all’… At least, not just yet.
But having people continueously revive the topic as you do, and having other people better at manipulating than coding (like myself ) trying to push the genious and gurus to invent one should certainly provide a result one of these days. Let’s just keep faith (and keep pushing

1 Like

I’m so with you on that

You challenge a crusader? A daring enterprise! :o)

I dare you. I double dare you Let’s see what comes out of it

Another solution I just thought of: why don’t you shoot several rays on a circular area in the direction of the target object and collect all the facets hit?

Honestly, I don’t know how this would work. Where would you cast the ray from? In my opinion (my opinion only) the solution would likely be around using the facet data and faceID. If somehow we would be able to make a multiple selection of facets and be able to assign them an identical faceID (like we can do with materials or meshes), then we could use faceID to act on this group. My two cents only.

The main code was completely written by chatGPT!

select face problem

Although it hardly solves the problem i REALLY like the visual effect! It’s more or less like a palette knife It gets a lil messy if you hit the same spot a couple of times, but it makes me want to automate this and use it as a texturing option.