Hi,
I have a custom procedural geometry that is generated based on several
parameters. Since the generation is fairly expensive, I do not want to
perform it more often than necessary. Therefore, I have chosen the
following approach:
class MyGeode: public osg::Geode
{
public:
// Constructors omitted...
int getParameter1() const { return _parameter1; }
void setParameter1(int parameter1) { _parameter1 = parameter1; dirty(); }
int getParameter2() const { return _parameter2; }
void setParameter2(int parameter2) { _parameter2 = parameter2; dirty(); }
// ...
inline void dirty() { _dirty = true; }
virtual void traverse(osg::NodeVisitor&) override
{
if (_dirty)
{
update(); // Update geometry...
_dirty = false;
}
osg::Geode::traverse(nv);
}
private:
void update();
osg::ref_ptr<osg::Geometry> _geometry;
bool _dirty;
int _parameter1;
int _parameter2;
};
As you can see, I have added a dirty flag to the geode, which gets set
whenever a parameter changes. Is this the right way to go in OSG? Are there
any pitfalls that I should look out for? I have tried to only use the
update traversal like this:
if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
{
// update
}
However, the node never got visited by an UpdateVisitor. Do I somehow need
to signal that a node needs updating? Can it be dangerous to update the
geometry during other traversals? (It seems to work fine...)
Cheers,
Peter
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org