and ran it through a for loop to make a 30x30 plane with selectable planes as each shape was another mesh added to the scene.
And of course building 6 sides with each side consisting of 900 pieces which makes a total of 5400 pieces for just 1 cube would hurt the FPS
Of course being a lazy programmer decide to skip it for a few days… then decided that no shortcuts i needed to do it better…
So now im at a regular new THREE.BoxGeometry(30,30,30,30,30,30)
I already know how to select an side of a cube
and wondering how to select individual segments
theres 2 ways i COULD do this…
Find the cursor’s position and the cube’s position, rotation and zoom and do the math of whats being selected
use raycaster somehow to select segments
so after some googling i havent found out if i even can select segments…
is it possible?
If not is there another/better way of finding out where on the 30x30 cube my mouse is selecting?
Thanks for bearing w/ me i just started on ThreeJS a couple weeks ago and am a noob
Each square (or “segment”) consists of two faces.
Using THREE.Raycaster() you can get the index of a face. Having that index, you can find its neighbour.
The rest is just to change colours of faces. There are many options, actually, of how you can change faces’ colours. The main thing is to find those faces
Rather than selecting a segment (2 faces) is it possible to select multiple faces that are adjacent to the selected face. Like selecting 3 faces since a face has 3 edge. Because when I increment faceIndex by one last faces occurs on meaningless parts of the model. Guess an algorithm is required for that. Do u have any suggestion for that?
As long as it gives what desired it works for me actually. This is a great example!!. However I noticed that it uses BufferGeometry but I converted my model to Geometry to use faces and faceIndexes to paint my faces. Does this approach works on my code or should i convert it to buffergeometry?
You would just look for triangles that use the same vertex index numbers on one of the 3 edges with the 3 edges of the selected face. 1 edge, so 2 index numbers must match 2 index numbers of the triangle you test with, but regardless which in order as the test edge of the test triangle might share the same 2 vertex numbers (edge) but not in the same order.
By using a tiny radius you can also use Paul’s suggestion which will basically give the adjacent faces as well, but comparing just the vertex id’s would be quite faster.