Custom Node with Inherit<> #990
-
Hello, i'm making a project with VSG and encouneterd with some situation. vsgExchange reading 3D model as MatrixTransform node. I wanted to make this node have some bool value to switch on\off this node (let forget about StateSwitch for a moment). class vsgSceneModel : public vsg::Inherit<vsg::MatrixTransform, vsgSceneModel>{
vsgSceneModel() {}
bool isEnabled = true;
void read(vsg::Input& input) {
vsg::MatrixTransform::read(input);
}
void write(vsg::Output& output) const {
if (!isEnabled) return;
vsg::MatrixTransform::write(output);
}
}
// ***
auto node = vsg::read_cast<vsg::vsgSceneModel>(filename, VARS->GetLoadOptions());
I short, how can i create custom behavior and be able to cast parent node to child? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The read and write methods are just for reading and writing members to Input/Output, they are aren't for runtime behaviors. The vsg::Switch node is now I would use to toggle on/off the traversal of a subgraph, so I wouldn't use custom node, it's just easier to decorate your subgraph with a vsg::Switch node and then use it's functionality to toggle on/off traversal. If you really want to make a transform node that also acts as a switch then you could do the above but just read/write the isEnabled flag so that you have the support for reading/writing .vsgt/.vsgb files, then to implement isEnabled I'd override the virtual void accept(ConstVisitor&), virtual void accept(Visitor&) and virtual void accept(RecordTraversal&) methods. You may be just fine overriding the accept(RecordTraversal&) one. However, this subclassing approach isn't very flexible as it forces you start subclassing all sorts of standard scene graph nodes just to add the toggle, it's much more flexible to just decorate the nodes you want to toggle with a vsg::Switch node. |
Beta Was this translation helpful? Give feedback.
The read and write methods are just for reading and writing members to Input/Output, they are aren't for runtime behaviors.
The vsg::Switch node is now I would use to toggle on/off the traversal of a subgraph, so I wouldn't use custom node, it's just easier to decorate your subgraph with a vsg::Switch node and then use it's functionality to toggle on/off traversal.
If you really want to make a transform node that also acts as a switch then you could do the above but just read/write the isEnabled flag so that you have the support for reading/writing .vsgt/.vsgb files, then to implement isEnabled I'd override the virtual void accept(ConstVisitor&), virtual void accept(Visitor&) and virtual …