Refactored Callback system in osg::Node, osg::Drawable, osg::StateSet and osg::StateAttribute to use a new osg::Callback base class.
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14244 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
parent
35d6cb812f
commit
977ec20751
@ -23,7 +23,6 @@
|
||||
#include <osg/Geometry>
|
||||
#include <osg/GLExtensions>
|
||||
#include <osg/Node>
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/Notify>
|
||||
#include <osg/observer_ptr>
|
||||
#include <osg/Projection>
|
||||
|
@ -37,7 +37,8 @@ public:
|
||||
virtual void apply( osg::PagedLOD& node );
|
||||
|
||||
protected:
|
||||
bool hasCullCallback( osg::NodeCallback* nc, osg::NodeCallback* target )
|
||||
|
||||
bool hasCullCallback( osg::Callback* nc, osg::Callback* target )
|
||||
{
|
||||
if ( nc==target ) return true;
|
||||
else if ( !nc ) return false;
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include <osg/Geode>
|
||||
#include <osg/Transform>
|
||||
#include <osg/Material>
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/Depth>
|
||||
#include <osg/CullFace>
|
||||
#include <osg/TexMat>
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include <osg/Matrixf>
|
||||
#include <osg/Matrixd>
|
||||
#include <osg/Quat>
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/Callback>
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
202
include/osg/Callback
Normal file
202
include/osg/Callback
Normal file
@ -0,0 +1,202 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSG_CALLBACK
|
||||
#define OSG_CALLBACK 1
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/UserDataContainer>
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
||||
class Callback : public virtual Object {
|
||||
|
||||
public :
|
||||
|
||||
Callback(){}
|
||||
|
||||
Callback(const Callback& cb,const CopyOp&):
|
||||
_nestedCallback(cb._nestedCallback) {}
|
||||
|
||||
META_Object(osg, Callback);
|
||||
|
||||
/** Invoke the callback, first parameter is the Object that the callback is attached to,
|
||||
* the second parameter, the data, is typically the NodeVisitor that is invoking the callback.
|
||||
* The run(..) method may be overriden by users directly, or if the user is using one of the old
|
||||
* style callbacks such as NodeCallback or Drawable::UpdateCallback then you can just override
|
||||
* the appropriate callback method on those callback subclasses.
|
||||
* If you are implementing your own callback then one should call traverse() to make sure nested callbacks
|
||||
* and visitor traversal() is completed. */
|
||||
virtual bool run(osg::Object* object, osg::Object* data)
|
||||
{
|
||||
return traverse(object, data);
|
||||
}
|
||||
|
||||
/** traverse the nested callbacks or call NodeVisitor::traverse() if the object is Node, and data is NodeVisitor.*/
|
||||
bool traverse(osg::Object* object, osg::Object* data);
|
||||
|
||||
void setNestedCallback(osg::Callback* cb) { _nestedCallback = cb; }
|
||||
osg::Callback* getNestedCallback() { return _nestedCallback.get(); }
|
||||
const osg::Callback* getNestedCallback() const { return _nestedCallback.get(); }
|
||||
|
||||
inline void addNestedCallback(osg::Callback* nc)
|
||||
{
|
||||
if (nc)
|
||||
{
|
||||
if (_nestedCallback.valid())
|
||||
{
|
||||
_nestedCallback->addNestedCallback(nc);
|
||||
}
|
||||
else
|
||||
{
|
||||
_nestedCallback = nc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void removeNestedCallback(osg::Callback* nc)
|
||||
{
|
||||
if (nc)
|
||||
{
|
||||
if (_nestedCallback==nc)
|
||||
{
|
||||
ref_ptr<osg::Callback> new_nested_callback = _nestedCallback->getNestedCallback();
|
||||
_nestedCallback->setNestedCallback(0);
|
||||
_nestedCallback = new_nested_callback;
|
||||
}
|
||||
else if (_nestedCallback.valid())
|
||||
{
|
||||
_nestedCallback->removeNestedCallback(nc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Callback() {}
|
||||
ref_ptr<Callback> _nestedCallback;
|
||||
};
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osg::Object> > Parameters;
|
||||
|
||||
/** Callback for attaching a script to a Node's via there UserDataContainer for the purpose of overriding class methods within scripts.*/
|
||||
class OSG_EXPORT CallbackObject : public virtual osg::Callback
|
||||
{
|
||||
public:
|
||||
CallbackObject() {}
|
||||
CallbackObject(const std::string& name) { setName(name); }
|
||||
CallbackObject(const CallbackObject& rhs, const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY):osg::Callback(rhs,copyop) {}
|
||||
META_Object(osg, CallbackObject);
|
||||
|
||||
virtual CallbackObject* asCallbackObject() { return this; }
|
||||
virtual const CallbackObject* asCallbackObject() const { return this; }
|
||||
|
||||
/** override Callback::run() entry point to adapt to CallbackObject::run(..) method.*/
|
||||
bool run(osg::Object* object, osg::Object* data);
|
||||
|
||||
inline bool run(osg::Object* object) const
|
||||
{
|
||||
osg::Parameters inputParameters;
|
||||
osg::Parameters outputParameters;
|
||||
return run(object, inputParameters, outputParameters);
|
||||
}
|
||||
|
||||
virtual bool run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const;
|
||||
|
||||
};
|
||||
|
||||
/** Convinience function for getting the CallbackObject associated with specificed name from an Object's UserDataContainer.*/
|
||||
inline CallbackObject* getCallbackObject(osg::Object* object, const std::string& name)
|
||||
{
|
||||
osg::UserDataContainer* udc = object->getUserDataContainer();
|
||||
return udc ? dynamic_cast<osg::CallbackObject*>(udc->getUserObject(name)) : 0;
|
||||
}
|
||||
|
||||
/** Call run(..) on named CallbackObjects attached to specified Object. Return true if at least one CallbackObject has been successfully invoked.*/
|
||||
inline bool runNamedCallbackObjects(osg::Object* object, const std::string& name, osg::Parameters& inputParameters, osg::Parameters& outputParameters)
|
||||
{
|
||||
bool result = false;
|
||||
osg::UserDataContainer* udc = object->getUserDataContainer();
|
||||
if (udc)
|
||||
{
|
||||
for(unsigned int i = 0; i<udc->getNumUserObjects(); ++i)
|
||||
{
|
||||
osg::Object* obj = udc->getUserObject(i);
|
||||
if (obj && obj->getName()==name)
|
||||
{
|
||||
osg::CallbackObject* co = dynamic_cast<osg::CallbackObject*>(obj);
|
||||
if (co) result = co->run(object, inputParameters, outputParameters) | result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// forward declare
|
||||
class Node;
|
||||
class NodeVisitor;
|
||||
|
||||
|
||||
/** Deprecated. */
|
||||
class OSG_EXPORT NodeCallback : public virtual Callback {
|
||||
|
||||
public :
|
||||
|
||||
|
||||
NodeCallback(){}
|
||||
|
||||
NodeCallback(const NodeCallback& nc,const CopyOp& copyop):
|
||||
Callback(nc,copyop) {}
|
||||
|
||||
META_Object(osg,NodeCallback);
|
||||
|
||||
/** NodeCallback overrides the Callback::run() method to adapt it the old style NodeCallback::operator()(Node* node, NodeVisitor* nv) method.*/
|
||||
virtual bool run(osg::Object* object, osg::Object* data);
|
||||
|
||||
/** Callback method called by the NodeVisitor when visiting a node.*/
|
||||
virtual void operator()(Node* node, NodeVisitor* nv);
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~NodeCallback() {}
|
||||
};
|
||||
|
||||
// forward declare
|
||||
class StateAttribute;
|
||||
|
||||
/** Deprecated. */
|
||||
class OSG_EXPORT StateAttributeCallback : public virtual osg::Callback
|
||||
{
|
||||
public:
|
||||
StateAttributeCallback() {}
|
||||
|
||||
StateAttributeCallback(const StateAttributeCallback&,const CopyOp&) {}
|
||||
|
||||
META_Object(osg,StateAttributeCallback);
|
||||
|
||||
/** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/
|
||||
virtual bool run(osg::Object* object, osg::Object* data);
|
||||
|
||||
/** do customized update code.*/
|
||||
virtual void operator () (StateAttribute*, NodeVisitor*) {}
|
||||
};
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
|
@ -15,7 +15,7 @@
|
||||
#define OSG_CLUSTERCULLINGCALLBACK 1
|
||||
|
||||
#include <osg/Drawable>
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/Callback>
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
@ -31,7 +31,7 @@ class Drawable;
|
||||
class Array;
|
||||
class PrimitiveSet;
|
||||
class Shape;
|
||||
class NodeCallback;
|
||||
class Callback;
|
||||
|
||||
|
||||
/** Copy Op(erator) used to control whether shallow or deep copy is used
|
||||
@ -80,7 +80,7 @@ class OSG_EXPORT CopyOp
|
||||
virtual PrimitiveSet* operator() (const PrimitiveSet* primitives) const;
|
||||
virtual Shape* operator() (const Shape* shape) const;
|
||||
virtual Uniform* operator() (const Uniform* shape) const;
|
||||
virtual NodeCallback* operator() (const NodeCallback* nodecallback) const;
|
||||
virtual Callback* operator() (const Callback* nodecallback) const;
|
||||
virtual StateAttributeCallback* operator() (const StateAttributeCallback* stateattributecallback) const;
|
||||
|
||||
protected:
|
||||
|
@ -268,7 +268,7 @@ class OSG_EXPORT Drawable : public Node
|
||||
* for all graphics contexts. */
|
||||
virtual void releaseGLObjects(State* state=0) const;
|
||||
|
||||
struct UpdateCallback : public virtual osg::Object
|
||||
struct OSG_EXPORT UpdateCallback : public virtual Callback
|
||||
{
|
||||
UpdateCallback() {}
|
||||
|
||||
@ -276,24 +276,15 @@ class OSG_EXPORT Drawable : public Node
|
||||
|
||||
META_Object(osg,UpdateCallback);
|
||||
|
||||
/** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/
|
||||
virtual bool run(osg::Object* object, osg::Object* data);
|
||||
|
||||
/** do customized update code.*/
|
||||
virtual void update(osg::NodeVisitor*, osg::Drawable*) {}
|
||||
};
|
||||
|
||||
/** Set the UpdateCallback which allows users to attach customize the updating of an object during the update traversal. */
|
||||
virtual void setUpdateCallback(UpdateCallback* ac);
|
||||
|
||||
/** Get the non const UpdateCallback.*/
|
||||
UpdateCallback* getUpdateCallback() { return _drawableUpdateCallback.get(); }
|
||||
|
||||
/** Get the const UpdateCallback.*/
|
||||
const UpdateCallback* getUpdateCallback() const { return _drawableUpdateCallback.get(); }
|
||||
|
||||
/** Return whether this Drawable has update callbacks associated with it, and therefore must be traversed.*/
|
||||
bool requiresUpdateTraversal() const { return _drawableUpdateCallback.valid() || (_stateset.valid() && _stateset->requiresUpdateTraversal()); }
|
||||
|
||||
|
||||
struct EventCallback : public virtual osg::Object
|
||||
struct OSG_EXPORT EventCallback : public virtual Callback
|
||||
{
|
||||
EventCallback() {}
|
||||
|
||||
@ -301,24 +292,14 @@ class OSG_EXPORT Drawable : public Node
|
||||
|
||||
META_Object(osg,EventCallback);
|
||||
|
||||
/** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/
|
||||
virtual bool run(osg::Object* object, osg::Object* data);
|
||||
|
||||
/** do customized Event code. */
|
||||
virtual void event(osg::NodeVisitor*, osg::Drawable*) {}
|
||||
};
|
||||
|
||||
/** Set the EventCallback which allows users to attach customize the updating of an object during the Event traversal.*/
|
||||
virtual void setEventCallback(EventCallback* ac);
|
||||
|
||||
/** Get the non const EventCallback.*/
|
||||
EventCallback* getEventCallback() { return _drawableEventCallback.get(); }
|
||||
|
||||
/** Get the const EventCallback.*/
|
||||
const EventCallback* getEventCallback() const { return _drawableEventCallback.get(); }
|
||||
|
||||
/** Return whether this Drawable has event callbacks associated with it, and therefore must be traversed.*/
|
||||
bool requiresEventTraversal() const { return _drawableEventCallback.valid() || (_stateset.valid() && _stateset->requiresEventTraversal()); }
|
||||
|
||||
|
||||
struct CullCallback : public virtual osg::Object
|
||||
struct CullCallback : public virtual Callback
|
||||
{
|
||||
CullCallback() {}
|
||||
|
||||
@ -333,17 +314,6 @@ class OSG_EXPORT Drawable : public Node
|
||||
virtual bool cull(osg::NodeVisitor* nv, osg::Drawable* drawable, osg::RenderInfo* renderInfo) const { return cull(nv, drawable, renderInfo? renderInfo->getState():0); }
|
||||
};
|
||||
|
||||
/** Set the CullCallback which allows users to customize the culling of Drawable during the cull traversal.*/
|
||||
virtual void setCullCallback(CullCallback* cc) { _drawableCullCallback=cc; }
|
||||
|
||||
/** Get the non const CullCallback.*/
|
||||
CullCallback* getCullCallback() { return _drawableCullCallback.get(); }
|
||||
|
||||
/** Get the const CullCallback.*/
|
||||
const CullCallback* getCullCallback() const { return _drawableCullCallback.get(); }
|
||||
|
||||
|
||||
|
||||
|
||||
/** Callback attached to an Drawable which allows the users to customize the drawing of an exist Drawable object.
|
||||
* The draw callback is implement as a replacement to the Drawable's own drawImplementation() method, if the
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include <osg/StateSet>
|
||||
#include <osg/BoundingSphere>
|
||||
#include <osg/BoundingBox>
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/Callback>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -202,16 +202,16 @@ class OSG_EXPORT Node : public Object
|
||||
|
||||
|
||||
/** Set update node callback, called during update traversal. */
|
||||
void setUpdateCallback(NodeCallback* nc);
|
||||
void setUpdateCallback(Callback* nc);
|
||||
|
||||
/** Get update node callback, called during update traversal. */
|
||||
inline NodeCallback* getUpdateCallback() { return _updateCallback.get(); }
|
||||
inline Callback* getUpdateCallback() { return _updateCallback.get(); }
|
||||
|
||||
/** Get const update node callback, called during update traversal. */
|
||||
inline const NodeCallback* getUpdateCallback() const { return _updateCallback.get(); }
|
||||
inline const Callback* getUpdateCallback() const { return _updateCallback.get(); }
|
||||
|
||||
/** Convenience method that sets the update callback of the node if it doesn't exist, or nest it into the existing one. */
|
||||
inline void addUpdateCallback(NodeCallback* nc) {
|
||||
inline void addUpdateCallback(Callback* nc) {
|
||||
if (nc != NULL) {
|
||||
if (_updateCallback.valid()) _updateCallback->addNestedCallback(nc);
|
||||
else setUpdateCallback(nc);
|
||||
@ -219,7 +219,7 @@ class OSG_EXPORT Node : public Object
|
||||
}
|
||||
|
||||
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
|
||||
inline void removeUpdateCallback(NodeCallback* nc) {
|
||||
inline void removeUpdateCallback(Callback* nc) {
|
||||
if (nc != NULL && _updateCallback.valid()) {
|
||||
if (_updateCallback == nc)
|
||||
{
|
||||
@ -236,16 +236,16 @@ class OSG_EXPORT Node : public Object
|
||||
|
||||
|
||||
/** Set event node callback, called during event traversal. */
|
||||
void setEventCallback(NodeCallback* nc);
|
||||
void setEventCallback(Callback* nc);
|
||||
|
||||
/** Get event node callback, called during event traversal. */
|
||||
inline NodeCallback* getEventCallback() { return _eventCallback.get(); }
|
||||
inline Callback* getEventCallback() { return _eventCallback.get(); }
|
||||
|
||||
/** Get const event node callback, called during event traversal. */
|
||||
inline const NodeCallback* getEventCallback() const { return _eventCallback.get(); }
|
||||
inline const Callback* getEventCallback() const { return _eventCallback.get(); }
|
||||
|
||||
/** Convenience method that sets the event callback of the node if it doesn't exist, or nest it into the existing one. */
|
||||
inline void addEventCallback(NodeCallback* nc) {
|
||||
inline void addEventCallback(Callback* nc) {
|
||||
if (nc != NULL) {
|
||||
if (_eventCallback.valid()) _eventCallback->addNestedCallback(nc);
|
||||
else setEventCallback(nc);
|
||||
@ -253,7 +253,7 @@ class OSG_EXPORT Node : public Object
|
||||
}
|
||||
|
||||
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
|
||||
inline void removeEventCallback(NodeCallback* nc) {
|
||||
inline void removeEventCallback(Callback* nc) {
|
||||
if (nc != NULL && _eventCallback.valid()) {
|
||||
if (_eventCallback == nc)
|
||||
{
|
||||
@ -270,16 +270,16 @@ class OSG_EXPORT Node : public Object
|
||||
|
||||
|
||||
/** Set cull node callback, called during cull traversal. */
|
||||
void setCullCallback(NodeCallback* nc) { _cullCallback = nc; }
|
||||
void setCullCallback(Callback* nc) { _cullCallback = nc; }
|
||||
|
||||
/** Get cull node callback, called during cull traversal. */
|
||||
inline NodeCallback* getCullCallback() { return _cullCallback.get(); }
|
||||
inline Callback* getCullCallback() { return _cullCallback.get(); }
|
||||
|
||||
/** Get const cull node callback, called during cull traversal. */
|
||||
inline const NodeCallback* getCullCallback() const { return _cullCallback.get(); }
|
||||
inline const Callback* getCullCallback() const { return _cullCallback.get(); }
|
||||
|
||||
/** Convenience method that sets the cull callback of the node if it doesn't exist, or nest it into the existing one. */
|
||||
inline void addCullCallback(NodeCallback* nc) {
|
||||
inline void addCullCallback(Callback* nc) {
|
||||
if (nc != NULL) {
|
||||
if (_cullCallback.valid()) _cullCallback->addNestedCallback(nc);
|
||||
else setCullCallback(nc);
|
||||
@ -287,7 +287,7 @@ class OSG_EXPORT Node : public Object
|
||||
}
|
||||
|
||||
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
|
||||
inline void removeCullCallback(NodeCallback* nc) {
|
||||
inline void removeCullCallback(Callback* nc) {
|
||||
if (nc != NULL && _cullCallback.valid()) {
|
||||
if (_cullCallback == nc)
|
||||
{
|
||||
@ -477,15 +477,15 @@ class OSG_EXPORT Node : public Object
|
||||
friend class osg::Drawable;
|
||||
friend class osg::StateSet;
|
||||
|
||||
ref_ptr<NodeCallback> _updateCallback;
|
||||
ref_ptr<Callback> _updateCallback;
|
||||
unsigned int _numChildrenRequiringUpdateTraversal;
|
||||
void setNumChildrenRequiringUpdateTraversal(unsigned int num);
|
||||
|
||||
ref_ptr<NodeCallback> _eventCallback;
|
||||
ref_ptr<Callback> _eventCallback;
|
||||
unsigned int _numChildrenRequiringEventTraversal;
|
||||
void setNumChildrenRequiringEventTraversal(unsigned int num);
|
||||
|
||||
ref_ptr<NodeCallback> _cullCallback;
|
||||
ref_ptr<Callback> _cullCallback;
|
||||
|
||||
bool _cullingActive;
|
||||
unsigned int _numChildrenWithCullingDisabled;
|
||||
|
@ -14,86 +14,7 @@
|
||||
#ifndef OSG_NODECALLBACK
|
||||
#define OSG_NODECALLBACK 1
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
namespace osg {
|
||||
|
||||
class Node;
|
||||
class NodeVisitor;
|
||||
|
||||
class OSG_EXPORT NodeCallback : public virtual Object {
|
||||
|
||||
public :
|
||||
|
||||
|
||||
NodeCallback(){}
|
||||
|
||||
NodeCallback(const NodeCallback& nc,const CopyOp&):
|
||||
_nestedCallback(nc._nestedCallback) {}
|
||||
|
||||
|
||||
META_Object(osg,NodeCallback);
|
||||
|
||||
|
||||
/** Callback method called by the NodeVisitor when visiting a node.*/
|
||||
virtual void operator()(Node* node, NodeVisitor* nv)
|
||||
{
|
||||
// note, callback is responsible for scenegraph traversal so
|
||||
// they must call traverse(node,nv) to ensure that the
|
||||
// scene graph subtree (and associated callbacks) are traversed.
|
||||
traverse(node,nv);
|
||||
}
|
||||
|
||||
/** Call any nested callbacks and then traverse the scene graph. */
|
||||
void traverse(Node* node,NodeVisitor* nv);
|
||||
|
||||
void setNestedCallback(NodeCallback* nc) { _nestedCallback = nc; }
|
||||
NodeCallback* getNestedCallback() { return _nestedCallback.get(); }
|
||||
const NodeCallback* getNestedCallback() const { return _nestedCallback.get(); }
|
||||
|
||||
inline void addNestedCallback(NodeCallback* nc)
|
||||
{
|
||||
if (nc)
|
||||
{
|
||||
if (_nestedCallback.valid())
|
||||
{
|
||||
_nestedCallback->addNestedCallback(nc);
|
||||
}
|
||||
else
|
||||
{
|
||||
_nestedCallback = nc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void removeNestedCallback(NodeCallback* nc)
|
||||
{
|
||||
if (nc)
|
||||
{
|
||||
if (_nestedCallback==nc)
|
||||
{
|
||||
ref_ptr<NodeCallback> new_nested_callback = _nestedCallback->getNestedCallback();
|
||||
_nestedCallback->setNestedCallback(0);
|
||||
_nestedCallback = new_nested_callback;
|
||||
}
|
||||
else if (_nestedCallback.valid())
|
||||
{
|
||||
_nestedCallback->removeNestedCallback(nc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
ref_ptr<NodeCallback> _nestedCallback;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~NodeCallback() {}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
#include <osg/Callback>
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include <iterator>
|
||||
|
||||
#include <osg/Node>
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/ObserverNodePath>
|
||||
|
||||
namespace osg
|
||||
|
@ -15,20 +15,16 @@
|
||||
#define OSG_SCRIPTENGINE 1
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/Callback>
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osg/UserDataContainer>
|
||||
|
||||
namespace osg
|
||||
{
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osg::Object> > Parameters;
|
||||
|
||||
|
||||
// forward declare
|
||||
class ScriptEngine;
|
||||
|
||||
|
||||
/* Script class for wrapping a script and the language used in the script.*/
|
||||
class Script : public osg::Object
|
||||
{
|
||||
@ -57,53 +53,6 @@ class Script : public osg::Object
|
||||
unsigned int _modifiedCount;
|
||||
};
|
||||
|
||||
/** Callback for attaching a script to a Node's via there UserDataContainer for the purpose of overriding class methods within scripts.*/
|
||||
class OSG_EXPORT CallbackObject : public osg::Object
|
||||
{
|
||||
public:
|
||||
CallbackObject() {}
|
||||
CallbackObject(const std::string& name) { setName(name); }
|
||||
CallbackObject(const CallbackObject& rhs, const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY):osg::Object(rhs,copyop) {}
|
||||
META_Object(osg, CallbackObject);
|
||||
|
||||
inline bool run(osg::Object* object) const
|
||||
{
|
||||
osg::Parameters inputParameters;
|
||||
osg::Parameters outputParameters;
|
||||
return run(object, inputParameters, outputParameters);
|
||||
}
|
||||
|
||||
virtual bool run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const;
|
||||
|
||||
};
|
||||
|
||||
/** Convinience function for getting the CallbackObject associated with specificed name from an Object's UserDataContainer.*/
|
||||
inline CallbackObject* getCallbackObject(osg::Object* object, const std::string& name)
|
||||
{
|
||||
osg::UserDataContainer* udc = object->getUserDataContainer();
|
||||
return udc ? dynamic_cast<osg::CallbackObject*>(udc->getUserObject(name)) : 0;
|
||||
}
|
||||
|
||||
/** Call run(..) on named CallbackObjects attached to specified Object. Return true if at least one CallbackObject has been successfully invoked.*/
|
||||
inline bool runNamedCallbackObjects(osg::Object* object, const std::string& name, osg::Parameters& inputParameters, osg::Parameters& outputParameters)
|
||||
{
|
||||
bool result = false;
|
||||
osg::UserDataContainer* udc = object->getUserDataContainer();
|
||||
if (udc)
|
||||
{
|
||||
for(unsigned int i = 0; i<udc->getNumUserObjects(); ++i)
|
||||
{
|
||||
osg::Object* obj = udc->getUserObject(i);
|
||||
if (obj && obj->getName()==name)
|
||||
{
|
||||
osg::CallbackObject* co = dynamic_cast<osg::CallbackObject*>(obj);
|
||||
if (co) result = co->run(object, inputParameters, outputParameters) | result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/** NodeCallback for attaching a script to a NodeCallback so that it can be called as an update or event callback.*/
|
||||
class OSG_EXPORT ScriptNodeCallback : public osg::NodeCallback
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
#include <osg/Export>
|
||||
#include <osg/Object>
|
||||
#include <osg/StateAttributeCallback>
|
||||
#include <osg/Callback>
|
||||
#include <osg/Shader>
|
||||
#include <osg/GL>
|
||||
|
||||
|
@ -13,27 +13,6 @@
|
||||
#ifndef OSG_STATEATTRIBUTECALLBACK
|
||||
#define OSG_STATEATTRIBUTECALLBACK 1
|
||||
|
||||
#include <osg/Export>
|
||||
#include <osg/Object>
|
||||
|
||||
namespace osg {
|
||||
|
||||
class StateAttribute;
|
||||
class NodeVisitor;
|
||||
|
||||
class OSG_EXPORT StateAttributeCallback : public virtual osg::Object
|
||||
{
|
||||
public:
|
||||
StateAttributeCallback() {}
|
||||
|
||||
StateAttributeCallback(const StateAttributeCallback&,const CopyOp&) {}
|
||||
|
||||
META_Object(osg,StateAttributeCallback);
|
||||
|
||||
/** do customized update code.*/
|
||||
virtual void operator () (StateAttribute*, NodeVisitor*) {}
|
||||
};
|
||||
|
||||
}
|
||||
#include <osg/Callback>
|
||||
|
||||
#endif
|
||||
|
@ -378,7 +378,7 @@ class OSG_EXPORT StateSet : public Object
|
||||
inline bool getNestRenderBins() const { return _nestRenderBins; }
|
||||
|
||||
|
||||
struct Callback : public virtual osg::Object
|
||||
struct Callback : public virtual osg::Callback
|
||||
{
|
||||
Callback() {}
|
||||
|
||||
@ -386,6 +386,9 @@ class OSG_EXPORT StateSet : public Object
|
||||
|
||||
META_Object(osg,Callback);
|
||||
|
||||
/** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/
|
||||
virtual bool run(osg::Object* object, osg::Object* data);
|
||||
|
||||
/** do customized callback code.*/
|
||||
virtual void operator() (StateSet*, NodeVisitor*) {}
|
||||
};
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/Callback>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
@ -16,10 +16,10 @@
|
||||
#ifndef OSGANIMATION_UPDATE_MATRIX_TRANSFORM
|
||||
#define OSGANIMATION_UPDATE_MATRIX_TRANSFORM 1
|
||||
|
||||
#include <osg/Callback>
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/AnimationUpdateCallback>
|
||||
#include <osgAnimation/StackedTransform>
|
||||
#include <osg/NodeCallback>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/Drawable>
|
||||
#include <osg/ApplicationUsage>
|
||||
|
||||
@ -37,12 +36,20 @@ public:
|
||||
|
||||
EventHandler() {}
|
||||
EventHandler(const EventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
osg::Object(eh,copyop),
|
||||
osg::Callback(eh,copyop),
|
||||
osg::NodeCallback(eh, copyop),
|
||||
osg::Drawable::EventCallback(eh, copyop) {}
|
||||
|
||||
META_Object(osgGA, EventHandler);
|
||||
|
||||
virtual bool run(osg::Object* object, osg::Object* data)
|
||||
{
|
||||
osg::Node* node = dynamic_cast<osg::Node*>(object);
|
||||
osg::NodeVisitor* nv = dynamic_cast<osg::NodeVisitor*>(data);
|
||||
operator()(node, nv);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Event traversal node callback method. There is no need to override this method in subclasses of EventHandler as this implementation calls handle(..) for you. */
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <osg/Transform>
|
||||
#include <osg/Projection>
|
||||
#include <osg/OccluderNode>
|
||||
#include <osg/ScriptEngine>
|
||||
|
||||
#include <osgGA/GUIEventAdapter>
|
||||
#include <osgGA/GUIActionAdapter>
|
||||
@ -68,8 +69,27 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
|
||||
/** During traversal each type of node calls its callbacks and its children traversed. */
|
||||
virtual void apply(osg::Node& node) { handle_callbacks_and_traverse(node); }
|
||||
|
||||
virtual void apply(osg::Geode& node) { handle_geode_callbacks(node); }
|
||||
virtual void apply(osg::Billboard& node) { handle_geode_callbacks(node); }
|
||||
|
||||
virtual void apply(osg::Drawable& drawable)
|
||||
{
|
||||
osg::Callback* callback = drawable.getEventCallback();
|
||||
if (callback)
|
||||
{
|
||||
osg::Drawable::UpdateCallback* drawable_callback = dynamic_cast<osg::Drawable::UpdateCallback*>(callback);
|
||||
osg::NodeCallback* node_callback = dynamic_cast<osg::NodeCallback*>(callback);
|
||||
osg::CallbackObject* callback_object = dynamic_cast<osg::CallbackObject*>(callback);
|
||||
|
||||
if (drawable_callback) drawable_callback->update(this,&drawable);
|
||||
if (node_callback) (*node_callback)(&drawable, this);
|
||||
|
||||
if ((!drawable_callback && !node_callback) || callback_object) callback_object->run(&drawable, this);
|
||||
}
|
||||
|
||||
handle_callbacks(drawable.getStateSet());
|
||||
}
|
||||
|
||||
virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); }
|
||||
virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); }
|
||||
|
||||
virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); }
|
||||
|
||||
@ -98,34 +118,11 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
|
||||
{
|
||||
handle_callbacks(node.getStateSet());
|
||||
|
||||
osg::NodeCallback* callback = node.getEventCallback();
|
||||
if (callback) (*callback)(&node,this);
|
||||
else if (node.getNumChildrenRequiringEventTraversal()>0) traverse(node);
|
||||
osg::Callback* callback = node.getEventCallback();
|
||||
if (callback) callback->run(&node,this);
|
||||
else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node);
|
||||
}
|
||||
|
||||
inline void handle_geode_callbacks(osg::Geode& node)
|
||||
{
|
||||
handle_callbacks(node.getStateSet());
|
||||
|
||||
osg::NodeCallback* callback = node.getEventCallback();
|
||||
if (callback) (*callback)(&node,this);
|
||||
/*else if (node.getNumChildrenRequiringEventTraversal()>0)*/
|
||||
traverseGeode(node);
|
||||
}
|
||||
|
||||
inline void traverseGeode(osg::Geode& geode)
|
||||
{
|
||||
traverse((osg::Node&)geode);
|
||||
|
||||
// Call the app callbacks on the drawables.
|
||||
for(unsigned int i=0;i<geode.getNumDrawables();++i)
|
||||
{
|
||||
osg::Drawable::EventCallback* callback = geode.getDrawable(i)->getEventCallback();
|
||||
if (callback) callback->event(this,geode.getDrawable(i));
|
||||
|
||||
handle_callbacks(geode.getDrawable(i)->getStateSet());
|
||||
}
|
||||
}
|
||||
|
||||
osgGA::GUIActionAdapter* _actionAdapter;
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/Drawable>
|
||||
#include <osg/ApplicationUsage>
|
||||
|
||||
@ -54,7 +53,7 @@ public:
|
||||
#if 1
|
||||
GUIEventHandler() {}
|
||||
GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
osg::Object(eh, copyop), EventHandler(eh, copyop) {}
|
||||
osg::Callback(eh, copyop), EventHandler(eh, copyop) {}
|
||||
#else
|
||||
GUIEventHandler() : _ignoreHandledEventsMask(GUIEventAdapter::NONE) {}
|
||||
GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
|
@ -14,7 +14,7 @@
|
||||
#define OSG_ANIMATIONMATERIAL 1
|
||||
|
||||
#include <osg/Material>
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/Callback>
|
||||
|
||||
#include <osgPresentation/Export>
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include <osg/UserDataContainer>
|
||||
#include <osg/ValueObject>
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/ImageSequence>
|
||||
#include <osgGA/GUIEventHandler>
|
||||
|
||||
|
@ -98,28 +98,30 @@ class OSGSHADOW_EXPORT MinimalDrawBoundsShadowMap
|
||||
osg::observer_ptr< ViewData > _vd;
|
||||
};
|
||||
|
||||
struct CameraCullCallback: public osg::NodeCallback {
|
||||
struct CameraCullCallback: public osg::Callback {
|
||||
|
||||
CameraCullCallback(ViewData * vd, osg::NodeCallback * nc): _vd(vd), _nc(nc)
|
||||
CameraCullCallback(ViewData * vd, osg::Callback * nc): _vd(vd), _nc(nc)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
virtual bool run(osg::Object* object, osg::Object* data)
|
||||
{
|
||||
osgUtil::CullVisitor *cv = dynamic_cast< osgUtil::CullVisitor *>( nv );
|
||||
osgUtil::CullVisitor *cv = dynamic_cast< osgUtil::CullVisitor *>( data );
|
||||
|
||||
if( _nc.valid() )
|
||||
_nc->operator()(node,nv);
|
||||
_nc->run(object, data);
|
||||
else
|
||||
traverse(node,nv);
|
||||
traverse(object, data);
|
||||
|
||||
if( cv )
|
||||
_vd->recordShadowMapParams( );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
osg::observer_ptr< ViewData > _vd;
|
||||
osg::ref_ptr< osg::NodeCallback > _nc;
|
||||
osg::ref_ptr< osg::Callback > _nc;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -309,15 +309,15 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
|
||||
|
||||
inline void handle_cull_callbacks_and_traverse(osg::Node& node)
|
||||
{
|
||||
osg::NodeCallback* callback = node.getCullCallback();
|
||||
if (callback) (*callback)(&node,this);
|
||||
osg::Callback* callback = node.getCullCallback();
|
||||
if (callback) callback->run(&node,this);
|
||||
else traverse(node);
|
||||
}
|
||||
|
||||
inline void handle_cull_callbacks_and_accept(osg::Node& node,osg::Node* acceptNode)
|
||||
{
|
||||
osg::NodeCallback* callback = node.getCullCallback();
|
||||
if (callback) (*callback)(&node,this);
|
||||
osg::Callback* callback = node.getCullCallback();
|
||||
if (callback) callback->run(&node,this);
|
||||
else acceptNode->accept(*this);
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#ifndef OSGUTIL_TRANSFORMCALLBACK
|
||||
#define OSGUTIL_TRANSFORMCALLBACK 1
|
||||
|
||||
#include <osg/Node>
|
||||
#include <osg/Callback>
|
||||
#include <osgUtil/Export>
|
||||
|
||||
namespace osgUtil
|
||||
|
@ -15,7 +15,6 @@
|
||||
#define OSGUTIL_UPDATEVISITOR 1
|
||||
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osg/Node>
|
||||
#include <osg/Geode>
|
||||
#include <osg/Billboard>
|
||||
#include <osg/LOD>
|
||||
@ -24,6 +23,7 @@
|
||||
#include <osg/Transform>
|
||||
#include <osg/Projection>
|
||||
#include <osg/OccluderNode>
|
||||
#include <osg/ScriptEngine>
|
||||
|
||||
#include <osgUtil/Export>
|
||||
|
||||
@ -50,17 +50,24 @@ class OSGUTIL_EXPORT UpdateVisitor : public osg::NodeVisitor
|
||||
|
||||
virtual void apply(osg::Drawable& drawable)
|
||||
{
|
||||
osg::Drawable::UpdateCallback* callback = drawable.getUpdateCallback();
|
||||
if (callback) callback->update(this,&drawable);
|
||||
osg::Callback* callback = drawable.getUpdateCallback();
|
||||
if (callback)
|
||||
{
|
||||
osg::Drawable::UpdateCallback* drawable_callback = dynamic_cast<osg::Drawable::UpdateCallback*>(callback);
|
||||
osg::NodeCallback* node_callback = dynamic_cast<osg::NodeCallback*>(callback);
|
||||
osg::CallbackObject* callback_object = dynamic_cast<osg::CallbackObject*>(callback);
|
||||
|
||||
osg::NodeCallback* node_callback = drawable.osg::Node::getUpdateCallback();
|
||||
if (drawable_callback) drawable_callback->update(this,&drawable);
|
||||
if (node_callback) (*node_callback)(&drawable, this);
|
||||
|
||||
if ((!drawable_callback && !node_callback) || callback_object) callback_object->run(&drawable, this);
|
||||
}
|
||||
|
||||
handle_callbacks(drawable.getStateSet());
|
||||
}
|
||||
|
||||
virtual void apply(osg::Geode& node) { handle_geode_callbacks(node); }
|
||||
virtual void apply(osg::Billboard& node) { handle_geode_callbacks(node); }
|
||||
virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); }
|
||||
virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); }
|
||||
|
||||
virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); }
|
||||
|
||||
@ -92,31 +99,10 @@ class OSGUTIL_EXPORT UpdateVisitor : public osg::NodeVisitor
|
||||
{
|
||||
handle_callbacks(node.getStateSet());
|
||||
|
||||
osg::NodeCallback* callback = node.getUpdateCallback();
|
||||
if (callback) (*callback)(&node,this);
|
||||
osg::Callback* callback = node.getUpdateCallback();
|
||||
if (callback) callback->run(&node,this);
|
||||
else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node);
|
||||
}
|
||||
|
||||
inline void handle_geode_callbacks(osg::Geode& geode)
|
||||
{
|
||||
handle_callbacks(geode.getStateSet());
|
||||
|
||||
osg::NodeCallback* callback = geode.getUpdateCallback();
|
||||
if (callback) (*callback)(&geode,this);
|
||||
|
||||
// Call the app callbacks on the drawables.
|
||||
for(unsigned int i=0;i<geode.getNumDrawables();++i)
|
||||
{
|
||||
osg::Drawable::UpdateCallback* callback = geode.getDrawable(i)->getUpdateCallback();
|
||||
if (callback) callback->update(this,geode.getDrawable(i));
|
||||
|
||||
handle_callbacks(geode.getDrawable(i)->getStateSet());
|
||||
}
|
||||
|
||||
// should we traverse just in case a subclass of Geode adds children?? Won't for now as
|
||||
// Geode's arn't designed to have children.
|
||||
// traverse(geode);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -525,7 +525,7 @@ protected:
|
||||
InteractiveImageHandler() {}
|
||||
|
||||
InteractiveImageHandler(const InteractiveImageHandler&,const osg::CopyOp& = osg::CopyOp::SHALLOW_COPY):
|
||||
osg::Object(), osgGA::GUIEventHandler(), osg::Drawable::CullCallback(), _fullscreen(false) {}
|
||||
osg::Callback(), osgGA::GUIEventHandler(), osg::Drawable::CullCallback(), _fullscreen(false) {}
|
||||
|
||||
bool mousePosition(osgViewer::View* view, osg::NodeVisitor* nv, const osgGA::GUIEventAdapter& ea, int& x, int &y) const;
|
||||
|
||||
|
@ -449,6 +449,8 @@ class OSGVOLUME_EXPORT PropertyAdjustmentCallback : public osgGA::GUIEventHandle
|
||||
|
||||
META_Object(osgVolume, PropertyAdjustmentCallback);
|
||||
|
||||
virtual bool run(osg::Object* object, osg::Object* data) { return osgGA::GUIEventHandler::run(object, data); }
|
||||
|
||||
void setKeyEventCycleForward(int key) { _cyleForwardKey = key; }
|
||||
int getKeyEventCycleForward() const { return _cyleForwardKey; }
|
||||
|
||||
|
@ -37,6 +37,7 @@ SET(TARGET_H
|
||||
${HEADER_PATH}/buffered_value
|
||||
${HEADER_PATH}/BufferIndexBinding
|
||||
${HEADER_PATH}/BufferObject
|
||||
${HEADER_PATH}/Callback
|
||||
${HEADER_PATH}/Camera
|
||||
${HEADER_PATH}/CameraView
|
||||
${HEADER_PATH}/ClampColor
|
||||
@ -230,6 +231,7 @@ SET(TARGET_SRC
|
||||
BlendFunc.cpp
|
||||
BufferIndexBinding.cpp
|
||||
BufferObject.cpp
|
||||
Callback.cpp
|
||||
Camera.cpp
|
||||
CameraView.cpp
|
||||
ClampColor.cpp
|
||||
@ -296,7 +298,6 @@ SET(TARGET_SRC
|
||||
# Matrix_implementation.cpp
|
||||
MatrixTransform.cpp
|
||||
Multisample.cpp
|
||||
NodeCallback.cpp
|
||||
Node.cpp
|
||||
NodeTrackerCallback.cpp
|
||||
NodeVisitor.cpp
|
||||
|
109
src/osg/Callback.cpp
Normal file
109
src/osg/Callback.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
#include <osg/Node>
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osg/ScriptEngine>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Callback
|
||||
//
|
||||
bool Callback::traverse(Object* object, Object* data)
|
||||
{
|
||||
if (_nestedCallback.valid()) return run(object, data);
|
||||
else
|
||||
{
|
||||
#if 1
|
||||
osg::Node* node = dynamic_cast<osg::Node*>(object);
|
||||
osg::NodeVisitor* nv = dynamic_cast<osg::NodeVisitor*>(data);
|
||||
#else
|
||||
osg::Node* node = object ? data->asNode() : 0;
|
||||
osg::NodeVisitor* nv = data ? data->asNodeVisitor() : 0;
|
||||
#endif
|
||||
if (node && nv)
|
||||
{
|
||||
nv->traverse(*node);
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// CallbackObject
|
||||
//
|
||||
bool CallbackObject::run(osg::Object* object, osg::Object* data)
|
||||
{
|
||||
osg::Parameters inputParameters, outputParameters;
|
||||
|
||||
if (data && data->referenceCount()>=1)
|
||||
{
|
||||
inputParameters.push_back(data);
|
||||
}
|
||||
|
||||
return run(object,inputParameters, outputParameters);
|
||||
}
|
||||
|
||||
bool CallbackObject::run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
|
||||
{
|
||||
OSG_NOTICE<<"CallbackObject::run(object="<<object<<")"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// NodeCallback
|
||||
//
|
||||
bool NodeCallback::run(osg::Object* object, osg::Object* data)
|
||||
{
|
||||
osg::Node* node = dynamic_cast<osg::Node*>(object);
|
||||
osg::NodeVisitor* nv = dynamic_cast<osg::NodeVisitor*>(data);
|
||||
if (node && nv)
|
||||
{
|
||||
operator()(node, nv);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return traverse(object, data);
|
||||
}
|
||||
}
|
||||
void NodeCallback::operator()(Node* node, NodeVisitor* nv)
|
||||
{
|
||||
// note, callback is responsible for scenegraph traversal so
|
||||
// they must call traverse(node,nv) to ensure that the
|
||||
// scene graph subtree (and associated callbacks) are traversed.
|
||||
traverse(node,nv);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// StateAttributeCallback
|
||||
//
|
||||
bool StateAttributeCallback::run(osg::Object* object, osg::Object* data)
|
||||
{
|
||||
osg::StateAttribute* sa = dynamic_cast<osg::StateAttribute*>(object);
|
||||
osg::NodeVisitor* nv = dynamic_cast<osg::NodeVisitor*>(data);
|
||||
if (sa && nv)
|
||||
{
|
||||
operator()(sa, nv);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return traverse(object, data);
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
#include <osg/PrimitiveSet>
|
||||
#include <osg/Shape>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/Callback>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
@ -66,19 +67,19 @@ StateAttribute* CopyOp::operator() (const StateAttribute* attr) const
|
||||
return const_cast<StateAttribute*>(attr);
|
||||
}
|
||||
|
||||
NodeCallback* CopyOp::operator() (const NodeCallback* nc) const
|
||||
Callback* CopyOp::operator() (const Callback* nc) const
|
||||
{
|
||||
if (nc && _flags&DEEP_COPY_CALLBACKS)
|
||||
{
|
||||
// deep copy the full chain of callback
|
||||
osg::NodeCallback* first = osg::clone(nc, *this);
|
||||
Callback* first = osg::clone(nc, *this);
|
||||
if (!first) return 0;
|
||||
|
||||
first->setNestedCallback(0);
|
||||
nc = nc->getNestedCallback();
|
||||
while (nc)
|
||||
{
|
||||
osg::NodeCallback* ucb = osg::clone(nc, *this);
|
||||
Callback* ucb = osg::clone(nc, *this);
|
||||
if (ucb)
|
||||
{
|
||||
ucb->setNestedCallback(0);
|
||||
@ -89,5 +90,5 @@ NodeCallback* CopyOp::operator() (const NodeCallback* nc) const
|
||||
return first;
|
||||
}
|
||||
else
|
||||
return const_cast<NodeCallback*>(nc);
|
||||
return const_cast<Callback*>(nc);
|
||||
}
|
||||
|
@ -216,6 +216,36 @@ void Drawable::flushDeletedDisplayLists(unsigned int contextID, double& availabl
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Drawable::UpdateCallback::run(osg::Object* object, osg::Object* data)
|
||||
{
|
||||
osg::Drawable* drawable = dynamic_cast<osg::Drawable*>(object);
|
||||
osg::NodeVisitor* nv = dynamic_cast<osg::NodeVisitor*>(data);
|
||||
if (drawable && nv)
|
||||
{
|
||||
update(nv, drawable);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return traverse(object, data);
|
||||
}
|
||||
}
|
||||
|
||||
bool Drawable::EventCallback::run(osg::Object* object, osg::Object* data)
|
||||
{
|
||||
osg::Drawable* drawable = dynamic_cast<osg::Drawable*>(object);
|
||||
osg::NodeVisitor* nv = dynamic_cast<osg::NodeVisitor*>(data);
|
||||
if (drawable && nv)
|
||||
{
|
||||
event(nv, drawable);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return traverse(object, data);
|
||||
}
|
||||
}
|
||||
|
||||
Drawable::Drawable()
|
||||
{
|
||||
_boundingBoxComputed = false;
|
||||
@ -468,48 +498,6 @@ void Drawable::dirtyDisplayList()
|
||||
}
|
||||
|
||||
|
||||
void Drawable::setUpdateCallback(UpdateCallback* ac)
|
||||
{
|
||||
if (_drawableUpdateCallback==ac) return;
|
||||
|
||||
int delta = 0;
|
||||
if (_drawableUpdateCallback.valid()) --delta;
|
||||
if (ac) ++delta;
|
||||
|
||||
_drawableUpdateCallback = ac;
|
||||
|
||||
if (delta!=0 && !(_stateset.valid() && _stateset->requiresUpdateTraversal()))
|
||||
{
|
||||
for(ParentList::iterator itr=_parents.begin();
|
||||
itr!=_parents.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->setNumChildrenRequiringUpdateTraversal((*itr)->getNumChildrenRequiringUpdateTraversal()+delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Drawable::setEventCallback(EventCallback* ac)
|
||||
{
|
||||
if (_drawableEventCallback==ac) return;
|
||||
|
||||
int delta = 0;
|
||||
if (_drawableEventCallback.valid()) --delta;
|
||||
if (ac) ++delta;
|
||||
|
||||
_drawableEventCallback = ac;
|
||||
|
||||
if (delta!=0 && !(_stateset.valid() && _stateset->requiresEventTraversal()))
|
||||
{
|
||||
for(ParentList::iterator itr=_parents.begin();
|
||||
itr!=_parents.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->setNumChildrenRequiringEventTraversal( (*itr)->getNumChildrenRequiringEventTraversal()+delta );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ComputeBound : public PrimitiveFunctor
|
||||
{
|
||||
ComputeBound()
|
||||
|
@ -203,7 +203,7 @@ MatrixList Node::getWorldMatrices(const osg::Node* haltTraversalAtNode) const
|
||||
return matrices;
|
||||
}
|
||||
|
||||
void Node::setUpdateCallback(NodeCallback* nc)
|
||||
void Node::setUpdateCallback(Callback* nc)
|
||||
{
|
||||
// if no changes just return.
|
||||
if (_updateCallback==nc) return;
|
||||
@ -281,7 +281,7 @@ void Node::setNumChildrenRequiringUpdateTraversal(unsigned int num)
|
||||
}
|
||||
|
||||
|
||||
void Node::setEventCallback(NodeCallback* nc)
|
||||
void Node::setEventCallback(Callback* nc)
|
||||
{
|
||||
// if no changes just return.
|
||||
if (_eventCallback==nc) return;
|
||||
|
@ -1,23 +0,0 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
#include <osg/Node>
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/NodeVisitor>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
void NodeCallback::traverse(Node* node,NodeVisitor* nv)
|
||||
{
|
||||
if (_nestedCallback.valid()) (*_nestedCallback)(node,nv);
|
||||
else nv->traverse(*node);
|
||||
}
|
@ -16,13 +16,6 @@
|
||||
|
||||
using namespace osg;
|
||||
|
||||
|
||||
bool CallbackObject::run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
|
||||
{
|
||||
OSG_NOTICE<<"CallbackObject::run(object="<<object<<")"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
ScriptEngine* ScriptNodeCallback::getScriptEngine(osg::NodePath& nodePath)
|
||||
{
|
||||
if (!_script) return 0;
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/State>
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -84,6 +84,26 @@ bool osg::isTextureMode(StateAttribute::GLMode mode)
|
||||
return getTextureGLModeSet().isTextureMode(mode);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// StateAttributeCallback
|
||||
//
|
||||
bool StateSet::Callback::run(osg::Object* object, osg::Object* data)
|
||||
{
|
||||
osg::StateSet* ss = dynamic_cast<osg::StateSet*>(object);
|
||||
osg::NodeVisitor* nv = dynamic_cast<osg::NodeVisitor*>(data);
|
||||
if (ss && nv)
|
||||
{
|
||||
operator()(ss, nv);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return traverse(object, data);
|
||||
}
|
||||
}
|
||||
|
||||
StateSet::StateSet():
|
||||
Object(true),
|
||||
_nestRenderBins(true)
|
||||
|
@ -62,7 +62,7 @@ void AnimationManagerBase::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
}
|
||||
|
||||
|
||||
AnimationManagerBase::AnimationManagerBase(const AnimationManagerBase& b, const osg::CopyOp& copyop) : osg::Object(b, copyop), osg::NodeCallback(b,copyop) // TODO check this
|
||||
AnimationManagerBase::AnimationManagerBase(const AnimationManagerBase& b, const osg::CopyOp& copyop) : osg::Callback(b, copyop), osg::NodeCallback(b,copyop) // TODO check this
|
||||
{
|
||||
const AnimationList& animationList = b.getAnimationList();
|
||||
for (AnimationList::const_iterator it = animationList.begin();
|
||||
|
@ -64,7 +64,7 @@ void LinkVisitor::apply(osg::Node& node)
|
||||
if (st)
|
||||
handle_stateset(st);
|
||||
|
||||
osg::NodeCallback* cb = node.getUpdateCallback();
|
||||
osg::Callback* cb = node.getUpdateCallback();
|
||||
while (cb)
|
||||
{
|
||||
osgAnimation::AnimationUpdateCallbackBase* cba = dynamic_cast<osgAnimation::AnimationUpdateCallbackBase*>(cb);
|
||||
|
@ -466,7 +466,7 @@ struct FindTimelineStats : public osg::NodeVisitor
|
||||
FindTimelineStats() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
|
||||
|
||||
void apply(osg::Node& node) {
|
||||
osg::NodeCallback* cb = node.getUpdateCallback();
|
||||
osg::Callback* cb = node.getUpdateCallback();
|
||||
while (cb) {
|
||||
osgAnimation::TimelineAnimationManager* tam = dynamic_cast<osgAnimation::TimelineAnimationManager*>(cb);
|
||||
if (tam)
|
||||
|
@ -21,7 +21,7 @@ CameraManipulator::CameraManipulator()
|
||||
|
||||
|
||||
CameraManipulator::CameraManipulator(const CameraManipulator& mm, const CopyOp& copyOp)
|
||||
: osg::Object(mm, copyOp),
|
||||
: osg::Callback(mm, copyOp),
|
||||
inherited(mm, copyOp),
|
||||
_intersectTraversalMask(mm._intersectTraversalMask),
|
||||
_autoComputeHomePosition(mm._autoComputeHomePosition),
|
||||
|
@ -44,7 +44,7 @@ FirstPersonManipulator::FirstPersonManipulator( int flags )
|
||||
|
||||
/// Constructor.
|
||||
FirstPersonManipulator::FirstPersonManipulator( const FirstPersonManipulator& fpm, const CopyOp& copyOp )
|
||||
: osg::Object(fpm, copyOp),
|
||||
: osg::Callback(fpm, copyOp),
|
||||
inherited( fpm, copyOp ),
|
||||
_eye( fpm._eye ),
|
||||
_rotation( fpm._rotation ),
|
||||
|
@ -28,7 +28,7 @@ FlightManipulator::FlightManipulator( int flags )
|
||||
|
||||
/// Constructor.
|
||||
FlightManipulator::FlightManipulator( const FlightManipulator& fm, const CopyOp& copyOp )
|
||||
: osg::Object(fm, copyOp),
|
||||
: osg::Callback(fm, copyOp),
|
||||
inherited( fm, copyOp ),
|
||||
_yawMode( fm._yawMode )
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ MultiTouchTrackballManipulator::MultiTouchTrackballManipulator( int flags )
|
||||
|
||||
/// Constructor.
|
||||
MultiTouchTrackballManipulator::MultiTouchTrackballManipulator( const MultiTouchTrackballManipulator& tm, const CopyOp& copyOp )
|
||||
: osg::Object(tm, copyOp), inherited( tm, copyOp )
|
||||
: osg::Callback(tm, copyOp), inherited( tm, copyOp )
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ NodeTrackerManipulator::NodeTrackerManipulator( int flags )
|
||||
|
||||
|
||||
NodeTrackerManipulator::NodeTrackerManipulator( const NodeTrackerManipulator& m, const CopyOp& copyOp )
|
||||
: osg::Object(m, copyOp),
|
||||
: osg::Callback(m, copyOp),
|
||||
inherited( m, copyOp ),
|
||||
_trackNodePath( m._trackNodePath ),
|
||||
_trackerMode( m._trackerMode )
|
||||
|
@ -43,7 +43,7 @@ OrbitManipulator::OrbitManipulator( int flags )
|
||||
|
||||
/// Constructor.
|
||||
OrbitManipulator::OrbitManipulator( const OrbitManipulator& om, const CopyOp& copyOp )
|
||||
: osg::Object(om, copyOp),
|
||||
: osg::Callback(om, copyOp),
|
||||
inherited( om, copyOp ),
|
||||
_center( om._center ),
|
||||
_rotation( om._rotation ),
|
||||
|
@ -48,7 +48,7 @@ StandardManipulator::StandardManipulator( int flags )
|
||||
|
||||
/// Constructor.
|
||||
StandardManipulator::StandardManipulator( const StandardManipulator& uim, const CopyOp& copyOp )
|
||||
: osg::Object(uim, copyOp),
|
||||
: osg::Callback(uim, copyOp),
|
||||
inherited( uim, copyOp ),
|
||||
_thrown( uim._thrown ),
|
||||
_allowThrow( uim._allowThrow ),
|
||||
|
@ -29,7 +29,7 @@ TerrainManipulator::TerrainManipulator( int flags )
|
||||
|
||||
/// Constructor.
|
||||
TerrainManipulator::TerrainManipulator( const TerrainManipulator& tm, const CopyOp& copyOp )
|
||||
: osg::Object(tm, copyOp),
|
||||
: osg::Callback(tm, copyOp),
|
||||
inherited( tm, copyOp ),
|
||||
_previousUp( tm._previousUp )
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ TrackballManipulator::TrackballManipulator( int flags )
|
||||
|
||||
/// Constructor.
|
||||
TrackballManipulator::TrackballManipulator( const TrackballManipulator& tm, const CopyOp& copyOp )
|
||||
: osg::Object(tm, copyOp),
|
||||
: osg::Callback(tm, copyOp),
|
||||
inherited( tm, copyOp )
|
||||
{
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public:
|
||||
parent->setMatrixInSkeletonSpace( osg::Matrix::translate(offset) *
|
||||
parent->getMatrixInSkeletonSpace() );
|
||||
osgAnimation::UpdateBone* updateBone =
|
||||
static_cast<osgAnimation::UpdateBone*>( parent->getUpdateCallback() );
|
||||
dynamic_cast<osgAnimation::UpdateBone*>( parent->getUpdateCallback() );
|
||||
if ( updateBone )
|
||||
{
|
||||
osgAnimation::StackedTransform& stack = updateBone->getStackedTransforms();
|
||||
|
@ -758,7 +758,7 @@ daeReader::ChannelPart* daeReader::processSampler(domChannel* pDomChannel, Sourc
|
||||
return NULL;
|
||||
}
|
||||
|
||||
osgAnimation::Target* findChannelTarget(osg::NodeCallback* nc, const std::string& targetName, bool& rotation)
|
||||
osgAnimation::Target* findChannelTarget(osg::Callback* nc, const std::string& targetName, bool& rotation)
|
||||
{
|
||||
if (osgAnimation::UpdateMatrixTransform* umt = dynamic_cast<osgAnimation::UpdateMatrixTransform*>(nc))
|
||||
{
|
||||
@ -827,7 +827,7 @@ void daeReader::processChannel(domChannel* pDomChannel, SourceMap& sources, Targ
|
||||
domChannelOsgAnimationUpdateCallbackMap::iterator iter = _domChannelOsgAnimationUpdateCallbackMap.find(pDomChannel);
|
||||
if (iter != _domChannelOsgAnimationUpdateCallbackMap.end())
|
||||
{
|
||||
osg::NodeCallback* nc = iter->second.get();
|
||||
osg::Callback* nc = iter->second.get();
|
||||
|
||||
std::string channelName, targetName, componentName;
|
||||
extractTargetName(pDomChannel->getTarget(), channelName, targetName, componentName);
|
||||
|
@ -44,7 +44,7 @@ osg::Transform* daeReader::processOsgMatrixTransform(domNode *node, bool isBone)
|
||||
resultNode = new osg::MatrixTransform;
|
||||
}
|
||||
|
||||
osg::NodeCallback* pNodeCallback = resultNode->getUpdateCallback();
|
||||
osg::Callback* pNodeCallback = resultNode->getUpdateCallback();
|
||||
std::vector<osg::ref_ptr<osgAnimation::StackedTransformElement> > transformElements;
|
||||
osg::ref_ptr<osgAnimation::StackedTransformElement> pLastStaticTransformElement;
|
||||
|
||||
|
@ -241,7 +241,7 @@ public:
|
||||
typedef std::map<domMaterial*, osg::ref_ptr<osg::StateSet> > domMaterialStateSetMap;
|
||||
typedef std::map<std::string, osg::ref_ptr<osg::StateSet> > MaterialStateSetMap;
|
||||
typedef std::multimap< daeElement*, domChannel*> daeElementDomChannelMap;
|
||||
typedef std::map<domChannel*, osg::ref_ptr<osg::NodeCallback> > domChannelOsgAnimationUpdateCallbackMap;
|
||||
typedef std::map<domChannel*, osg::ref_ptr<osg::Callback> > domChannelOsgAnimationUpdateCallbackMap;
|
||||
typedef std::map<domNode*, osg::ref_ptr<osgAnimation::Bone> > domNodeOsgBoneMap;
|
||||
typedef std::map<domNode*, osg::ref_ptr<osgAnimation::Skeleton> > domNodeOsgSkeletonMap;
|
||||
typedef std::map<TextureParameters, osg::ref_ptr<osg::Texture2D> > TextureParametersMap;
|
||||
|
@ -37,7 +37,7 @@ using namespace osgDAE;
|
||||
void daeWriter::writeAnimations( osg::Node &node )
|
||||
{
|
||||
const std::string nodeNameUTF( _pluginOptions.namesUseCodepage ? osgDB::convertStringFromCurrentCodePageToUTF8(node.getName()) : node.getName() );
|
||||
osg::NodeCallback* ncb = node.getUpdateCallback();
|
||||
osg::Callback* ncb = node.getUpdateCallback();
|
||||
if (ncb)
|
||||
{
|
||||
osgAnimation::AnimationManagerBase* am = dynamic_cast<osgAnimation::AnimationManagerBase*>(ncb);
|
||||
|
@ -67,7 +67,7 @@ void daeWriter::apply( osg::MatrixTransform &node )
|
||||
std::string nodeName = getNodeName(node,"matrixTransform");
|
||||
currentNode->setId(nodeName.c_str());
|
||||
|
||||
osg::NodeCallback* ncb = node.getUpdateCallback();
|
||||
osg::Callback* ncb = node.getUpdateCallback();
|
||||
bool handled = false;
|
||||
if (ncb)
|
||||
{
|
||||
@ -124,7 +124,7 @@ void daeWriter::apply( osg::PositionAttitudeTransform &node )
|
||||
const osg::Quat &q = node.getAttitude();
|
||||
const osg::Vec3 &s = node.getScale();
|
||||
|
||||
osg::NodeCallback* ncb = node.getUpdateCallback();
|
||||
osg::Callback* ncb = node.getUpdateCallback();
|
||||
bool handled = false;
|
||||
if (ncb)
|
||||
{
|
||||
@ -287,7 +287,7 @@ void daeWriter::apply( osg::Transform &node )
|
||||
osg::Matrix matrix;
|
||||
node.computeLocalToWorldMatrix(matrix, NULL);
|
||||
|
||||
osg::NodeCallback* ncb = node.getUpdateCallback();
|
||||
osg::Callback* ncb = node.getUpdateCallback();
|
||||
bool handled = false;
|
||||
if (ncb)
|
||||
{
|
||||
|
@ -93,7 +93,7 @@ public:
|
||||
|
||||
virtual void apply(osg::Node& node)
|
||||
{
|
||||
osg::NodeCallback* ncb = node.getUpdateCallback();
|
||||
osg::Callback* ncb = node.getUpdateCallback();
|
||||
if (ncb)
|
||||
{
|
||||
osgAnimation::AnimationUpdateCallback<osg::NodeCallback>* ut = dynamic_cast<osgAnimation::AnimationUpdateCallback<osg::NodeCallback>*>(ncb);
|
||||
|
@ -37,7 +37,6 @@
|
||||
|
||||
#include <osg/Group>
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
#include "TXPArchive.h"
|
||||
|
@ -985,8 +985,11 @@ void CullVisitor::apply(osg::Drawable& drawable)
|
||||
|
||||
if( drawable.getCullCallback() )
|
||||
{
|
||||
if( drawable.getCullCallback()->cull( this, &drawable, &_renderInfo ) == true )
|
||||
return;
|
||||
osg::Drawable::CullCallback* dcb = dynamic_cast<osg::Drawable::CullCallback*>(drawable.getCullCallback());
|
||||
if (dcb)
|
||||
{
|
||||
if( dcb->cull( this, &drawable, &_renderInfo ) == true ) return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!getNodePath().empty() && getNodePath().back()->isCullingActive() && isCulled(bb)) return;
|
||||
@ -1073,7 +1076,8 @@ void CullVisitor::apply(Billboard& node)
|
||||
|
||||
if( drawable->getCullCallback() )
|
||||
{
|
||||
if( drawable->getCullCallback()->cull( this, drawable, &_renderInfo ) == true )
|
||||
osg::Drawable::CullCallback* dcb = dynamic_cast<osg::Drawable::CullCallback*>(drawable->getCullCallback());
|
||||
if (dcb && dcb->cull( this, drawable, &_renderInfo ) == true )
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -903,8 +903,8 @@ bool SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod
|
||||
// If the camera has a cullCallback execute the callback which has the
|
||||
// requirement that it must traverse the camera's children.
|
||||
{
|
||||
osg::NodeCallback* callback = _camera->getCullCallback();
|
||||
if (callback) (*callback)(_camera.get(), cullVisitor);
|
||||
osg::Callback* callback = _camera->getCullCallback();
|
||||
if (callback) callback->run(_camera.get(), cullVisitor);
|
||||
else cullVisitor->traverse(*_camera);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <osg/NodeCallback>
|
||||
#include <osg/Callback>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/Input>
|
||||
|
18
src/osgWrappers/serializers/osg/Callback.cpp
Normal file
18
src/osgWrappers/serializers/osg/Callback.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#undef OBJECT_CAST
|
||||
#define OBJECT_CAST dynamic_cast
|
||||
|
||||
#include <osg/Node>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( Callback,
|
||||
new osg::Callback,
|
||||
osg::Callback,
|
||||
"osg::Object osg::Callback" )
|
||||
{
|
||||
ADD_OBJECT_SERIALIZER( NestedCallback, osg::Callback, NULL ); // _nestedCallback
|
||||
}
|
||||
|
||||
#undef OBJECT_CAST
|
||||
#define OBJECT_CAST static_cast
|
@ -43,8 +43,8 @@ REGISTER_OBJECT_WRAPPER( Drawable,
|
||||
ADD_BOOL_SERIALIZER( SupportsDisplayList, true ); // _supportsDisplayList
|
||||
ADD_BOOL_SERIALIZER( UseDisplayList, true ); // _useDisplayList
|
||||
ADD_BOOL_SERIALIZER( UseVertexBufferObjects, false ); // _useVertexBufferObjects
|
||||
ADD_OBJECT_SERIALIZER( UpdateCallback, osg::Drawable::UpdateCallback, NULL ); // _updateCallback
|
||||
ADD_OBJECT_SERIALIZER( EventCallback, osg::Drawable::EventCallback, NULL ); // _eventCallback
|
||||
ADD_OBJECT_SERIALIZER( CullCallback, osg::Drawable::CullCallback, NULL ); // _cullCallback
|
||||
ADD_OBJECT_SERIALIZER( UpdateCallback, osg::Callback, NULL ); // _updateCallback
|
||||
ADD_OBJECT_SERIALIZER( EventCallback, osg::Callback, NULL ); // _eventCallback
|
||||
ADD_OBJECT_SERIALIZER( CullCallback, osg::Callback, NULL ); // _cullCallback
|
||||
ADD_OBJECT_SERIALIZER( DrawCallback, osg::Drawable::DrawCallback, NULL ); // _drawCallback
|
||||
}
|
||||
|
@ -72,9 +72,9 @@ REGISTER_OBJECT_WRAPPER( Node,
|
||||
ADD_USER_SERIALIZER( InitialBound ); // _initialBound
|
||||
ADD_OBJECT_SERIALIZER( ComputeBoundingSphereCallback,
|
||||
osg::Node::ComputeBoundingSphereCallback, NULL ); // _computeBoundCallback
|
||||
ADD_OBJECT_SERIALIZER( UpdateCallback, osg::NodeCallback, NULL ); // _updateCallback
|
||||
ADD_OBJECT_SERIALIZER( EventCallback, osg::NodeCallback, NULL ); // _eventCallback
|
||||
ADD_OBJECT_SERIALIZER( CullCallback, osg::NodeCallback, NULL ); // _cullCallback
|
||||
ADD_OBJECT_SERIALIZER( UpdateCallback, osg::Callback, NULL ); // _updateCallback
|
||||
ADD_OBJECT_SERIALIZER( EventCallback, osg::Callback, NULL ); // _eventCallback
|
||||
ADD_OBJECT_SERIALIZER( CullCallback, osg::Callback, NULL ); // _cullCallback
|
||||
ADD_BOOL_SERIALIZER( CullingActive, true ); // _cullingActive
|
||||
ADD_HEXINT_SERIALIZER( NodeMask, 0xffffffff ); // _nodeMask
|
||||
|
||||
|
@ -1,6 +1,3 @@
|
||||
#undef OBJECT_CAST
|
||||
#define OBJECT_CAST dynamic_cast
|
||||
|
||||
#include <osg/Node>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
@ -9,10 +6,6 @@
|
||||
REGISTER_OBJECT_WRAPPER( NodeCallback,
|
||||
new osg::NodeCallback,
|
||||
osg::NodeCallback,
|
||||
"osg::Object osg::NodeCallback" )
|
||||
"osg::Object osg::Callback osg::NodeCallback" )
|
||||
{
|
||||
ADD_OBJECT_SERIALIZER( NestedCallback, osg::NodeCallback, NULL ); // _nestedCallback
|
||||
}
|
||||
|
||||
#undef OBJECT_CAST
|
||||
#define OBJECT_CAST static_cast
|
||||
|
Loading…
Reference in New Issue
Block a user