Posts: 12
Threads: 8
Joined: Apr 2024
Reputation:
0
06-26-2024, 05:24 PM
Hello
I am in the need of highlighting the face of a mesh under the pointer
Is this even possible?
Thanks
Posts: 738
Threads: 8
Joined: Sep 2009
Reputation:
41
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.
Andrej Benedik