Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In a WPF scene, I have 2 Model3D in a GroupModel3D: one Model3D is a tool, the other is a workpiece and I want to test when they touch. To test when they touch, I need to inspect every coordinate of Model 1 to determine if they intersect the triangles of Model 2. The problem is to get the positions - i.e. the coordinates - of the triangles of Model 1 and Model 2. The meshes are easily extracted from a GeometryModel3D. But I need to convert a Model3D to a GeometryModel3D to get to the meshes, or else, directly convert a Model3D to MeshGeometry3D.

For example, the code shown below is not accepted since the children of MyGlobalGroup3D are Model3D elements which cannot be converted to GeometryModel3D.


Would anybody have a suggestion ?

What I have tried:

VB
Dim imodel1 As GeometryModel3D = TryCast(MyGlobalGroup3D.Children.Item(indexWork), GeometryModel3D)
Dim imodel2 As GeometryModel3D = TryCast MyGlobalGroup3D.Children.Item(indexTool), GeometryModel3D)
Posted
Updated 17-Oct-21 22:50pm
v2
Comments
[no name] 17-Oct-21 17:20pm    
Model3D is an abstract base class. That says about as much as saying you're working with fruit.
Member 14335464 17-Oct-21 17:41pm    
Hi Gerry: you can guess from my question that I am not very fluent with all this which is why I am asking knowledgeable people. If the Model3D is not the correct place where to extract the mesh, where should I look then ?
Thanks.
[no name] 18-Oct-21 15:42pm    
You haven't shown any usable code. All one can do is "search".

https://stackoverflow.com/questions/16712798/modelvisual3d-intersection-with-the-another-modelvisual3d-object-wpf
Member 14335464 18-Oct-21 15:59pm    
Thank you Gerry. I had already "searched', and quite a bit at that. What you point to is one approach which I had already looked at.
The issue I was having - and I believe it is well stated in the opening paragraph of my question - is rather "how to get to the mesh from a GeometryModel3D". Turns out that each GeometryModel3D is made of several Geometry3D components, for each of which I can access the mesh. So I found that I have to loop through the GeometryModel3D.Items one by one, extract the mesh, positions, normals, and inspect for intersection. This is now working.

As for Bounds, it is nice for sure, but it describes a box aligned with XYZ and this is often not in the orientation required to correctly detect an intersection.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900