Click or drag to resize
Ab4d.SharpEngine logo

OptimizedGroupNode Class

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). It can render only ModelGroup objects with diffuse color StandardMaterial (no specular color or texture). See remarks for more info.
Inheritance Hierarchy

Namespace: Ab4d.SharpEngine.SceneNodes
Assembly: Ab4d.SharpEngine (in Ab4d.SharpEngine.dll) Version: 5.0.1075+bc537c8d217949260b11f66ee86aefa6456ac517
Syntax
C#
public class OptimizedGroupNode : GroupNode, 
	IInstancedNode

The OptimizedGroupNode type exposes the following members.

Constructors
Properties
 NameDescription
Public propertyIsInitializingInBackground 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.
Public propertyIsTwoSided Gets or sets a Boolean that specifies if all child models are rendered on both front and back side. Default value is false.
Public propertyWriteLogWarningForUnsupportedChildNodes When true (by default), a warning is written to the log when a child node is not supported by the OptimizedGroupNode.
Top
Methods
 NameDescription
Public methodBeginInitialize(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.
Public methodBeginInitialize(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.
Public methodCollectRenderingItems
(Overrides GroupNodeCollectRenderingItems(RenderingContext))
Protected methodDispose
(Overrides GroupNodeDispose(Boolean))
Public methodDisposeRenderingItems DisposeRenderingItems
(Overrides SceneNodeDisposeRenderingItems)
Public methodInitializeAsync(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.
Public methodInitializeAsync(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.
Protected methodOnInitializeSceneResources
(Overrides GroupNodeOnInitializeSceneResources(Scene, VulkanDevice))
Protected methodOnTransformChanged
(Overrides SceneNodeOnTransformChanged)
Protected methodOnUpdate
(Overrides SceneNodeOnUpdate)
Protected methodSetIsInOptimizedGroupNode
(Overrides GroupNodeSetIsInOptimizedGroupNode(Boolean))
Protected methodUpdateLocalBoundingBox
(Overrides GroupNodeUpdateLocalBoundingBox)
Top
Extension Methods
 NameDescription
Public Extension MethodDumpHierarchy Writes the hierarchy of the GroupNode and its children into the Visual Studio Output window.
(Defined by Extensions)
Top
Remarks

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).

If child node is not supported by the OptimizedGroupNode, then a warning is written to the log. This can be disabled by setting WriteLogWarningForUnsupportedChildNodes property to false.

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.

See Also