When i build a mesh with triangles is it possible to select each triangle separately?

hello everyone

I have build a mesh with the help of triangles, I want to know is it possible to select each triangle separately?
this is my PG for 6 triangles :
https://www.babylonjs-playground.com/#VKBJN#874

and below screenshot is my final model with about 100,000 triangles.

You should be able to access all the required info from the ray cast functionnalities:

https://doc.babylonjs.com/babylon101/picking_collisions#advanced-picking-features

and Raycasts - Babylon.js Documentation

1 Like

Thank you so much :pray:t2: :pray:t2:

Is it possible to select each triangles separately when I use triangle to build mesh?
this is my PG but when I wanted to selected each triangle the problem is whole of the triangles is selected.
https://www.babylonjs-playground.com/#VKBJN#876

pickedMesh is not the only property returned see PickingInfo | Babylon.js Documentation you can also get faceId.

Thank you so much.
I used faceId but how can I use bv and bu to get the coordinate?
i use faceId in my PG in this way : https://www.babylonjs-playground.com/#VKBJN#878

Each triangle requires three indices not just one see Create Custom Meshes - Babylon.js Documentation

One triangle (sometimes called a facet or face) has a faceId which links to three positions.

thanks, so if wanted to show three indices of each triangles what should I do?

https://www.babylonjs-playground.com/#VKBJN#879

from the three indices you can find the three positions for each of the triangle vertices.

x = myPositions(3 * index);
y = myPositions(3 * index + 1);
z = myPositions(3 * index + 2);

From the positions you can find the min and max values for x, y, and z, create two vector3s minVec and maxVec and use this to create a new bounding box BoundingBox - Babylon.js Documentation

thank you so much , its great. and is it possible to change the color of 3 indices when I selected them ?

https://doc.babylonjs.com/how_to/updating_vertices#adding-to-the-data

It is always worth checking Further Reading on any docs page you are using to learn.

sorry for my questions, But I didn’t understand how can I access to position with faceId. should I use bu and bv?

As I have shown use faceId to access the three indices for the triangle. From each of these indices access the x, y and z values from the vertex.positions array which you put equal to myPositions.

1 Like

thank you so much. should i use vertexData.positions[index0] ?

No!

replace x, y, z in turn by x0, y0, z0, x1, y1, z1, x2, y2, z2 and index in turn by index0, index1, index2 to get pos0, pos1, pos2

1 Like

I try to get the position in this way but when I use myPositions(3*index) I got this error:

Sorry my mistake - myPositions is an array

x = myPositions[3 * index];
y = myPositions[3 * index + 1];
z = myPositions[3 * index + 2];

1 Like

thank you so much. :pray:t2: :pray:t2:

sorry to be bothering you again, but is it possible to help me know how can I define BoundingBox correctly?

    x0 = myPositions[3 * index0];
    y0 = myPositions[3 * index0 + 1];
    z0 = myPositions[3 * index0 + 2];

    x1 = myPositions[3 * index1];
    y1 = myPositions[3 * index1 + 1];
    z1 = myPositions[3 * index1 + 2];

    x2 = myPositions[3 * index2];
    y2 = myPositions[3 * index2 + 1];
    z2 = myPositions[3 * index2 + 2];

    var minX = Math.min(x0, x1, x2);
    var minY = Math.min(y0, y1, y2);
    var minZ = Math.min(z0, z1, z2);

    var maxX = Math.max(x0, x1, x2);
    var maxY = Math.max(y0, y1, y2);
    var maxZ = Math.max(z0, z1, z2);

    var minVec = new BABYLON.Vector3(minX, minY, minZ);
    var maxVec = new BABYLON.Vector3(maxX, maxY, maxZ);

    var BoundingBox = new BoundingBox(minVec, maxVec);

BoundingBox, like Vector3, is in the BABYLON name space so new BABYLON.BoundingBox(minVec, maxVec);

1 Like