AB4D Forum
Highlight tringle in mesh - Printable Version

+- AB4D Forum (https://forum.ab4d.com)
+-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4)
+--- Forum: Ab4d.SharpEngine (https://forum.ab4d.com/forumdisplay.php?fid=12)
+--- Thread: Highlight tringle in mesh (/showthread.php?tid=4451)



Highlight tringle in mesh - BiMMate - 06-26-2024

Hello

I am in the need of highlighting the face of a mesh under the pointer

Is this even possible?

Thanks


RE: Highlight tringle in mesh - abenedik - 06-27-2024

You can do that with the following:
- do a mouse hit test by calling SceneView.GetClosestHitObject method (pass mouse x and y coordinate to the method)
- if a 3D object is hit, you get a RayHitTestResult object. It has TriangleIndex property - the index of the hit triangle.
- use a new MultiMaterialModelNode (introduced in v2.0) to show a single mesh (you can get the mesh from the hit ModelNode by calling GetMesh method) with multiple materials. The materials are defined by SubMeshes - each submesh specifies the material, StartIndexLocation and IndexCount (to get the StartIndexLocation from the TriangleIndex, multiply TriangleIndex by 3; set IndexCount to 3 to show a single triangle). For example if hit TriangleIndex is 10, then set the frist SubMesh to StartIndexLocation = 0, IndexCount = 3 * 10, the second SubMesh to StartIndexLocation = 3 * 10, IndexCount = 3 and the third SubMesh to StartIndexLocation = 3 * 11, IndexCount = (total triangle indices count - 3 * 11)

See the "Advanced 3D objects / MultiMaterialModelNode" sample for more info.