Ab3d.DXEngine Users Guide
Tips and tricks
Use object instancing
When rendering many instances of the same 3D models use InstancedMeshGeometryVisual3D or InstancedModelGroupVisual3D.
This gives you the best performance for rendering 3D objects.
Freeze 3D objects
When the 3D model will not be changed, it is highly recommended to freeze it (call Freeze method on Model3DGroup or GeometryModel3D).
Freezing a group of models (Model3DGroup) can greatly improve performance - DXEngine can combine mesh geometry data into a single vertex buffer and draw models that have the same material with a single draw call.
Do not forget to dispose the DXViewportView or DXSceneView when it is not used any more.
DXEngine allocates a lot of unmanaged resources that need to be manually disposed by calling Dispose method.
Usually this can be done in the Unload event handler for the control that hosts DXViewportView.
But please be careful with Unload event. For example in the control that is inside TabControl is unloaded when the user changes tab and gets loaded back when the user selected the tab again.
Get rendering statistics
To get na overview on how many triangles are rendered and how long each rendering step takes, you can enable collecting rendering statistics.
This can be done with setting the Ab3d.DirectX.DXDiagnostics.IsCollectingStatistics property to true.
After that you can get the rendering statistics from the DXSceneView.DXScene.Statistics property.
The best way to read the statistics is in the SceneRendered event on DXView object.
To get a graphical display of the statistics, you can also use the Ab3d.DirectX.Client.Diagnostics project and its DiagnosticsWindow.
First you need to reference the Ab3d.DirectX.Client.Diagnostics assembly in your project (the Ab3d.DirectX.Client.Diagnostics is avaiable with full source code in the samples folder).
Then create a new DiagnosticsWindow object, sets its DXView property to DXViewportView and show the window.
Manually update the DXViewportView
When your scene contains many (thousands) objects, it can take some time to check all objects for any changed.
This check is done in the Update method. By default Update method is called on every WPF's rendering event and before any DXEngine's rendering.
Because automatic checking can consume some CPU cycles, it is possible to disable it with setting the IsAutomaticallyUpdatingDXScene property on DXView (or DXViewportView) to false.
After that you need to manually update the scene by calling the Update method.
If you disable automatic updating, you will need to call Update every time you change the 3D models (if you do more changed at once then call Update only once at the end of the changes).
You do not need to call Update method after only the camera is changed.
To further optimize updating of the changed objects, you can pass a SceneNode to the Update method.
This will update only the specified SceneNode and all of its children instead of updating all the SceneNodes in DXViewportView (occurs when Update is called without any parameter - in this case the RootNode is passed to the Update method).
This is useful when you have many objects in the scene and you frequently change some of the objects while most of the objects are not changed.
In this case group the objects that are frequently changed in one Model3DGroup or ModelVisual3D. Then get the SceneNode that is created for this Model3DGroup or ModelVisual3D and call Update on it.
The following code snippet shows how to do that (not that the DXViewportView must already be initialized):
var group1SceneNode = dxSceneViewBase.GetSceneNodeForWpfObject(modelGroup1);
if (group1SceneNode != null)
Do not use png files with transparency when the image does not have any transparent pixels
Usually the png files are written in 24 bit format with included transparency channel.
Because of included transparency channel, the DXEngine considers the material with such texture as transparent (event if it does not contain and transparent pixels).
This means that the material is rendered in a less efficient way.
Therefore it is recommended to save images that do not contain transparent pixels in jpg format or in png without included transparency.
Use DXEngineSnoop tool
The DXEngineSnoop tool is a DXEngine performance analysis and diagnostics tool. It is installed in the Ab3d.DXEngine\Tools directory.
The DXEngineSnoop can inject into a running WPF application, find a DXViewportView and show various statistics and diagnostics about the rendered 3D scene.