Optimized | |
public class OptimizedGroupNode : GroupNode, IInstancedNode
The OptimizedGroupNode type exposes the following members.
| Name | Description | |
|---|---|---|
| OptimizedGroupNode(String) | Constructor | |
| OptimizedGroupNode(GroupNode, String) | Constructor | |
| OptimizedGroupNode(IEnumerableSceneNode, String) | Constructor |
| Name | Description | |
|---|---|---|
| IsInitializingInBackground | When true, then the background initialization is still executing (started by calling InitializeAsync method). In this case it is not allowed to change the child nodes. | |
| IsTwoSided | Gets or sets a Boolean that specifies if all child models are rendered on both front and back side. Default value is false. | |
| WriteLogWarningForUnsupportedChildNodes | When true (by default), a warning is written to the log when a child node is not supported by the OptimizedGroupNode. |
| Name | Description | |
|---|---|---|
| BeginInitialize(Action, CancellationToken) | BeginInitialize method (without Scene as a parameter) can be called after the OptimizedGroupNode was added to the Scene's RootNode and after child SceneNodes have been added to this OptimizedGroupNode. It initializes all the data and GpuBuffers in the background thread. When this is done, the specified initializeCompletedAction is called. While background initialization is not finished (IsInitializingInBackground is true), it is not allowed to change the child nodes. | |
| BeginInitialize(Scene, ActionOptimizedGroupNode, Exception, CancellationToken) | BeginInitialize method can be called after child SceneNodes have been added to this OptimizedGroupNode. It initializes all the data and GpuBuffers in the background thread. When this is done, the specified initializeCompletedAction is called. While background initialization is not finished (IsInitializingInBackground is true), it is not allowed to change the child nodes. | |
| CollectRenderingItems | (Overrides GroupNodeCollectRenderingItems(RenderingContext)) | |
| Dispose | (Overrides GroupNodeDispose(Boolean)) | |
| DisposeRenderingItems |
DisposeRenderingItems
(Overrides SceneNodeDisposeRenderingItems) | |
| InitializeAsync(CancellationToken) | InitializeAsync method (without Scene as a parameter) can be called after the OptimizedGroupNode was added to the Scene's RootNode and after child SceneNodes have been added to this OptimizedGroupNode. It initializes all the data and GpuBuffers in the background thread. While background initialization is not finished (IsInitializingInBackground is true), it is not allowed to change the child nodes. | |
| InitializeAsync(Scene, CancellationToken) | InitializeAsync method can be called after the child SceneNodes have been added to this OptimizedGroupNode. It initializes all the data and GpuBuffers in the background thread. While background initialization is not finished (IsInitializingInBackground is true), it is not allowed to change the child nodes. | |
| OnInitializeSceneResources | (Overrides GroupNodeOnInitializeSceneResources(Scene, VulkanDevice)) | |
| OnTransformChanged | (Overrides SceneNodeOnTransformChanged) | |
| OnUpdate | (Overrides SceneNodeOnUpdate) | |
| SetIsInOptimizedGroupNode | (Overrides GroupNodeSetIsInOptimizedGroupNode(Boolean)) | |
| UpdateLocalBoundingBox | (Overrides GroupNodeUpdateLocalBoundingBox) |
| Name | Description | |
|---|---|---|
| DumpHierarchy |
Writes the hierarchy of the GroupNode and its children into the Visual Studio Output window.
(Defined by Extensions) |
OptimizedGroupNode is a special GroupNode that optimizes rendering its child nodes by using DrawIndexedIndirect so all child nodes can be rendered in one draw call (or two in case of using opaque and transparent objects).
OptimizedGroupNode first combines all the vertices of all child nodes into a single vertex buffer and a single index buffer. Then all transformation and model color data is an instance buffer. After that a draw indirect buffer is created to specify where to get the vertices in indices data for each model. Finally, the models can be rendered by calling a single vkCmdDrawIndexedIndirect command (when rendering opaque and transparent models, then two vkCmdDrawIndexedIndirect commands are called).
Supported child nodes:
- Only StandardMaterial without a texture and specular color is supported.
- Only the Material property is used (not BackMaterial).
- It is possible to enable two-sided materials for all child models by setting IsTwoSided property to true.
- Transparent materials (Opacity < 1) are rendered by its own draw call. But in this case the transparency sorting of child objects is not supported - the transparent models are rendered in the same order as they are added to the OptimizedGroupNode.
- Only meshes of type StandardMesh and GeometryMesh are supported (PositionsMesh and TriangleMesh with other vertex layout are not supported; also SolidColorMaterial is not supported).
After the child node in the OptimizedGroupNode are shown, then the following operations are supported:
- Change material's color (change the DiffuseColor property) or change material object (assign a new StandardMaterial to ModelNode.Material property).
- Change visibility of child ModelNode or GroupNode.
- Change transformation value or Transform object of child node.
- Add a child node (can be also a GroupNode with many child nodes).
- Remove a child node.
- Move a child node from OptimizedGroupNode to Scene.RootNode (or any of its child GroupNodes).
- Move a SceneNode from Scene.RootNode (or any of its child GroupNodes) to OptimizedGroupNode.
Changing a material, transformation or visibility are fast operations because this only updates a GpuBuffer that defines the color or world matrix. Adding or removing child nodes is a slow operation because it requires a full regeneration of the data and all GpuBuffers.
Not supported child node operations:
- Change mesh or individual positions or triangle indices of child MeshModelNode.
- Change properties on ModelNode objects that result in updating the mesh or MeshTransform. For example, changing Size on BoxModelNode or PyramidModelNode.
After the child nodes are added to OptimizedGroupNode, it is possible to call InitializeAsync method to generate all the data and GpuBuffers on the background thread. While the objects are initializing in the background, it is not allowed to change the child nodes (InvalidOperationException is thrown). It is possible to check the value of IsInitializingInBackground to see if background initialization is still executing.