Maybe a bug with frozen Model3Ds
I'm loading a Model3D via Task.Run (it's very large) and then freezing it so I can use it in the main UI thread where I manually add it to a ModelVisual3D.  That works great, no problems.  I am also allowing the user to toggle visibility of the ModelVisual3D (I also have wireframe and other display options that can still be visible) and to do this I'm removing/adding it to viewport children list.  

Here's where the (maybe) bug comes in: if the model is frozen the first add works, the remove works and then when the model is re-added, I get no visual of the model.  If I clone the model in the main UI thread (so it's not frozen) that same exact code works fine.  

So, it appears that once a frozen model is removed from the viewport children list it cannot be added back in and get visuals.

Since I'm now just cloning the Model3D after load, it's no concern to me but I thought you might want to look at it.
I cannot reproduce this problem. I have a frozen Model3DGroup with a ModelVisual3D and then I tried to add/remove it from Viewport3D.Childer, from parent ModelVisual3D and I have also tried to set ModelVisual3D.Content to null and then back to frozen Model3DGroup. In all cases this worked for me. I will send you an email and ask you to provide some additional information.

Note that with Ab3d.DXEngine there is a more efficient way to show / hide 3D objects then adding / removing it to a Children collection. Instead, you can use ContentVisual3D and change its IsVisible property.  An advantage of this approach is that in this case the DirectX resources that are created from the models are preserved and only rendering of the objects is skipped. In case when you remove the object from the parent's tree (and not add it back in the same frame), then the DirectX resources are disposed. So when adding the model back the resources will need to be generated again.

Therefore it is usually better to use ContentModel3D instead of ModelVisual3D as a parent Visual3D object. See "Other Ab3d.PowerToys samples / ContentVisual3D sample" in the Ab3d.DXEninge samples for more info.
Andrej Benedik
After checking the sample code of the mjtrainor it turned out that the problem was caused because the object that rendered the WireframeVisual3D in DXEngine (WpfWireframeVisual3DNode) can change the rendering effect of the object it is rendering.

In case of mjtrainor the object was rendered twice - once within WireframeVisual3D and once on its own. When the WireframeVisual3D.WireframeType is set to Wireframe, then this also changes the rendering type of the object to wireframe rendering. This renders the object twice as wireframe object.

The recommended way to solve this is to render the object only once and set the WireframeVisual3D.WireframeType to one of the following:
  • WireframeWithOriginalSolidModel
  • Wireframe
  • OriginalSolidModel
  • None
Then the WpfWireframeVisual3DNode will correctly render the wireframe and the solid object.

If you want to still render the meshModel separately then please create the new instances of GeometryModel3D (and Model3DGroup) objects - you can preserve the MeshGeometry3D.
Andrej Benedik

Forum Jump:

Users browsing this thread:
1 Guest(s)