How does or could one obtain specializations from a scene graph?
I currently use a TransformNode that looks something like this:
__declspec(align(16)) struct TransformNode final
: public AlignedData< TransformNode > {
private:
friend class Node;
SharedPtr< Transform > m_transform;
Node *m_parent;
vector< SharedPtr< Node > > m_childs;
mutable XMMATRIX m_object_to_world;
mutable XMMATRIX m_world_to_object;
mutable bool m_dirty_object_to_world;
mutable bool m_dirty_world_to_object;
};
The TransformNode encapsulates a local Transform (parent <> object) as well as its positioning in a scene graph (parent and child Nodes). A Node itself is some proxy on top of a TransformNode, allowing to do node->getTransform()->SetTranslation() via an indirection instead of directly calling and polluting the node itself (e.g. node->SetTranslation()). The Node class forms the root of a hierarchy containing abstract models, lights, sprites, cameras which all have their own specializations.
Given some Node, how does one normally convert it to its specialization?
- Each node has a name, so I can search for a specific node and perform a dynamic_cast based on a template type provided by the user. Though this requires names to be globally unique or at least unique in every subtree of the scene graph.
- If all the specializations are known in advance, then a static_cast can be used instead of a dynamic_cast if some enum member specifies the specialized type.
- If all the specializations are known in advance, I can use specialized collections instead of one general collection in TransformNode.
- The scene graph can support general visitors, but this requires an expensive double dispatch as well as lots of boilerplate code for a single implementation of the visitor.
For rendering purposes, I also have some flattened collections of the scene graph: models, specialized lights, cameras and sprites. But I do not have the need to have a collection for each specialization. For the lights, I explicitly want to know the most specialized types, but for cameras I do not really care for rendering and can just work with the abstract camera interface.