06-26-2024, 05:24 PM
06-27-2024, 01:35 PM
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.
- 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.