From 6ed233d0d23bb9a0989ccc4c2ad6151dfdae2516 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 11 Apr 2002 23:20:23 +0000 Subject: [PATCH] Added DataVariance enum and set/get fields to osg::Object to help identify which objects have values that vary over the lifetime of the object (DYNAMIC) and ones that do not vary (STATIC). Removed the equivalent code in osg::Transform, StateSet and StateAttribute, as these are now encompassed by the new DataVariance field. Removed MatrixMode enum from Matrix, and associated fields/parameters from osg::Transfrom and osg::NodeVisitor, since MatrixMode was not providing any useful functionality, but made the interface more complex (MatrixMode was an experimental API) Added ReferenceFrame field to osg::Transform which allows users to specify transforms that are relative to their parents (the default, and previous behavior) or absolute reference frame, which can be used for HUD's, camera relative light sources etc etc. Note, the view frustum culling for absolute Transform are disabled, and all their parents up to the root are also automatically have view frustum culling disabled. However, once passed an absolute Transform node culling will return to its default state of on, so you can still cull underneath an absolute transform, its only the culling above which is disabled. --- include/osg/Matrix | 18 +++--- include/osg/NodeVisitor | 4 +- include/osg/Object | 21 ++++++- include/osg/StateAttribute | 18 +----- include/osg/StateSet | 5 -- include/osg/Transform | 61 ++++++++----------- src/Demos/osgconv/OrientationConverter.cpp | 2 +- src/osg/Group.cpp | 19 ++++-- src/osg/NodeVisitor.cpp | 43 ++++++------- src/osg/Object.cpp | 5 +- src/osg/PositionAttitudeTransform.cpp | 35 ++++++----- src/osg/StateSet.cpp | 4 +- src/osg/Transform.cpp | 71 +++++++++++----------- src/osgPlugins/flt/flt2osg.cpp | 4 +- src/osgPlugins/osg/Object.cpp | 43 +++++++++++-- src/osgPlugins/osg/Transform.cpp | 12 ++-- src/osgUtil/CullVisitor.cpp | 2 +- src/osgUtil/Optimizer.cpp | 10 +-- 18 files changed, 202 insertions(+), 175 deletions(-) diff --git a/include/osg/Matrix b/include/osg/Matrix index f281a6f59..ec9c98d77 100644 --- a/include/osg/Matrix +++ b/include/osg/Matrix @@ -17,16 +17,6 @@ namespace osg { class Quat; -/** The range of matrix modes that the scene graph might utilize. - * Similar in concept to different modes in OpenGL glMatrixMode().*/ -enum MatrixMode -{ - PROJECTION, - VIEW, - MODEL, - MODELVIEW -}; - class SG_EXPORT Matrix : public Object { @@ -128,6 +118,7 @@ class SG_EXPORT Matrix : public Object inline static Matrix rotate( float, float, float, float ); inline static Matrix rotate( float angle, const Vec3& axis); inline static Matrix rotate( const Quat&); + inline static Matrix inverse( const Matrix&); /** Create a orthographic projection. See glOrtho for further details.*/ inline static Matrix ortho(const double left, const double right, @@ -276,6 +267,13 @@ inline Matrix Matrix::rotate(const Vec3& from, const Vec3& to ) return m; } +inline Matrix inverse( const Matrix& matrix) +{ + Matrix m; + m.invert(matrix); + return m; +} + inline Matrix Matrix::ortho(const double left, const double right, const double bottom, const double top, const double zNear, const double zFar) diff --git a/include/osg/NodeVisitor b/include/osg/NodeVisitor index b4d1a4974..8d0be6d71 100644 --- a/include/osg/NodeVisitor +++ b/include/osg/NodeVisitor @@ -158,10 +158,10 @@ class SG_EXPORT NodeVisitor : public Referenced const NodePath& getNodePath() const { return _nodePath; } /** Get the Local To World Matrix from the NodePath for specified Transform::Mode, and u.*/ - const bool getLocalToWorldMatrix(Matrix& matrix, MatrixMode mode,Node* node); + const bool getLocalToWorldMatrix(Matrix& matrix, Node* node); /** Get the World To Local Matrix from the NodePath for specified Transform::Mode.*/ - const bool getWorldToLocalMatrix(Matrix& matrix, MatrixMode mode,Node* node); + const bool getWorldToLocalMatrix(Matrix& matrix, Node* node); virtual void apply(Node& node) { traverse(node);} diff --git a/include/osg/Object b/include/osg/Object index bc7aee797..98ba117ad 100644 --- a/include/osg/Object +++ b/include/osg/Object @@ -34,7 +34,7 @@ class SG_EXPORT Object : public Referenced and therefore cannot be constructed on its own, only derived classes which override the clone and className methods are concrete classes and can be constructed.*/ - Object() {} + inline Object():Referenced(),_dataVariance(DYNAMIC) {} /** Copy constructor, optional CopyOp object can be used to control * shallow vs deep copying of dynamic data.*/ @@ -53,6 +53,23 @@ class SG_EXPORT Object : public Referenced /** return the name of the object's class type. Must be defined by derived classes.*/ virtual const char* className() const = 0; + + + enum DataVariance + { + DYNAMIC, + STATIC + }; + + /** Set the data variance of this object. + * Can be set to either STATIC for values that do not change over the lifetime of the object, + * or DYNAMIC for values that vary over the lifetime of the object. The DataVariance value + * can be used be routines such as optimzation codes that wish to share static data.*/ + inline void setDataVariance(const DataVariance dv) { _dataVariance = dv; } + + /** Get the data variance of this object.*/ + inline const DataVariance getDataVariance() const { return _dataVariance; } + protected: @@ -64,6 +81,8 @@ class SG_EXPORT Object : public Referenced forcing all nodes to be created on the heap i.e Node* node = new Node().*/ virtual ~Object() {} + + DataVariance _dataVariance; private: diff --git a/include/osg/StateAttribute b/include/osg/StateAttribute index 7fd803d38..e9458caef 100644 --- a/include/osg/StateAttribute +++ b/include/osg/StateAttribute @@ -149,19 +149,11 @@ class SG_EXPORT StateAttribute : public Object COLORMATRIX }; - /** Range of types that the StateAttribute can be.*/ - enum DataType - { - DYNAMIC, - STATIC - }; - - - StateAttribute():_datatype(STATIC) {} + StateAttribute() { setDataVariance(STATIC); } StateAttribute(const StateAttribute& sa,const CopyOp& copyop=CopyOp::SHALLOW_COPY): - Object(sa,copyop),_datatype(sa._datatype) {} + Object(sa,copyop) {} /** Clone the type of an attribute, with Object* return type. @@ -181,10 +173,6 @@ class SG_EXPORT StateAttribute : public Object /** return the Type identifier of the attribute's class type.*/ virtual const Type getType() const = 0; - - inline void setDataType(DataType type) { _datatype = type; } - inline const DataType getDataType() const { return _datatype; } - /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ virtual int compare(const StateAttribute& sa) const = 0; @@ -213,8 +201,6 @@ class SG_EXPORT StateAttribute : public Object virtual ~StateAttribute() {} - DataType _datatype; - }; } diff --git a/include/osg/StateSet b/include/osg/StateSet index 270b14a66..43b87bb6d 100644 --- a/include/osg/StateSet +++ b/include/osg/StateSet @@ -50,9 +50,6 @@ class SG_EXPORT StateSet : public Object nodes which inherit all of their modes for the global state.*/ void setAllToInherit(); - inline void setDataType(osg::StateAttribute::DataType type) { _datatype = type; } - inline const osg::StateAttribute::DataType getDataType() const { return _datatype; } - /** merge this stateset with stateset rhs, this overrides * the rhs if OVERRIDE is specified, otherwise rhs takes precedence.*/ void merge(const StateSet& rhs); @@ -172,8 +169,6 @@ class SG_EXPORT StateSet : public Object int _binNum; std::string _binName; - osg::StateAttribute::DataType _datatype; - }; } diff --git a/include/osg/Transform b/include/osg/Transform index 5de56339d..bd181f731 100644 --- a/include/osg/Transform +++ b/include/osg/Transform @@ -40,33 +40,26 @@ class SG_EXPORT Transform : public Group META_Node(Transform); - /** Range of types that the Transform can be.*/ - enum Type + enum ReferenceFrame { - DYNAMIC, - STATIC + RELATIVE_TO_PARENTS, + ABSOLUTE }; - /** Set the Transform Type, which can be DYNAMIC - the Matrix - * value is updated during the main loop, or STATIC - the Matrix - * is constant throughout the life of the main loop. STATIC - * Transforms can be optimized away is some instances, which - * can improve performance so unless you plan to modify the - * Matrix explicitly set the Matrix to STATIC. The default - * value is DYNAMIC.*/ - inline void setType(Type type) { _type = type; } + /** Set the transform's ReferenceFrame, either to be realtive to its parent reference frame, + * or relative to an absolute coordinate frame. RELATIVE_TO_PARENTS is the default. + * Note, setting the RefrenceFrame to be ABSOLUTE will also set the CullingActive flag on the + * transform, and hence all its parents, to false, therby disabling culling of it and all its + * parents. This is neccessary to prevent inappropriate culling, but may impact of cull times + * if the absolute transform is deep in the scene graph, it is therefore recommend to only use + * abolsoute Transforms at the top of the scene, for such things as headlight LightSource's or + * Head up displays.*/ + void setReferenceFrame(ReferenceFrame rf); + + const ReferenceFrame getReferenceFrame() const { return _referenceFrame; } - /** Get the Transform Type.*/ - inline const Type getType() const { return _type; } - - /** Set the matrix mode which tells traversers them how to treat this Transform - as Projection, View or Model transformation.*/ - inline void setMatrixMode(MatrixMode mode) { _mode = mode; } - - /** Get the transform mode.*/ - inline const MatrixMode getMatrixMode() const { return _mode; } - - /** Callback attached to an Transform to specifiy how to compute the modelview or projection transformation + /** Callback attached to an Transform to specifiy how to compute the modelview transformation * for the transform below the Transform node.*/ struct ComputeTransformCallback : public osg::Referenced { @@ -137,32 +130,28 @@ class SG_EXPORT Transform : public Group virtual const bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const { - if (_mode==VIEW) + if (_referenceFrame==RELATIVE_TO_PARENTS) { - computeInverse(); - matrix = *_inverse; - return true; + matrix.preMult(*_matrix); } - else + else // absolute { matrix = *_matrix; - return true; } + return true; } virtual const bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const { - if (_mode==VIEW) + if (_referenceFrame==RELATIVE_TO_PARENTS) { - matrix = *_matrix; - return true; + matrix.postMult(*_inverse); } - else + else // absolute { - computeInverse(); matrix = *_inverse; - return true; } + return true; } inline void computeInverse() const @@ -175,10 +164,10 @@ class SG_EXPORT Transform : public Group } - Type _type; - MatrixMode _mode; + ref_ptr _computeTransformCallback; + ReferenceFrame _referenceFrame; ref_ptr _matrix; mutable ref_ptr _inverse; mutable bool _inverseDirty; diff --git a/src/Demos/osgconv/OrientationConverter.cpp b/src/Demos/osgconv/OrientationConverter.cpp index 9608b0c59..8fcb6dc93 100644 --- a/src/Demos/osgconv/OrientationConverter.cpp +++ b/src/Demos/osgconv/OrientationConverter.cpp @@ -50,7 +50,7 @@ Node* OrientationConverter::convert( Node *node ) osg::Group* root = new osg::Group; osg::Transform* transform = new osg::Transform; - transform->setType(osg::Transform::STATIC); + transform->setDataVariance(osg::Object::STATIC); transform->setMatrix( C * R * S * T ); root->addChild(transform); diff --git a/src/osg/Group.cpp b/src/osg/Group.cpp index 68a548c35..d2899009c 100644 --- a/src/osg/Group.cpp +++ b/src/osg/Group.cpp @@ -2,11 +2,10 @@ #include #include #include +#include #include -#define square(x) ((x)*(x)) - using namespace osg; Group::Group() @@ -202,6 +201,10 @@ const bool Group::computeBound() const _bsphere.init(); if (_children.empty()) return false; + // note, special handling of the case when a child is an Transform, + // such that only Transforms which are relative to their parents coordinates frame (i.e this group) + // are handled, Transform relative to and absolute reference frame are ignored. + BoundingBox bb; bb.init(); ChildList::const_iterator itr; @@ -209,7 +212,11 @@ const bool Group::computeBound() const itr!=_children.end(); ++itr) { - bb.expandBy((*itr)->getBound()); + const osg::Transform* transform = dynamic_cast(itr->get()); + if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_TO_PARENTS) + { + bb.expandBy((*itr)->getBound()); + } } if (!bb.isValid()) return false; @@ -220,7 +227,11 @@ const bool Group::computeBound() const itr!=_children.end(); ++itr) { - _bsphere.expandRadiusBy((*itr)->getBound()); + const osg::Transform* transform = dynamic_cast(itr->get()); + if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_TO_PARENTS) + { + _bsphere.expandRadiusBy((*itr)->getBound()); + } } return true; diff --git a/src/osg/NodeVisitor.cpp b/src/osg/NodeVisitor.cpp index b6d461480..26e617f15 100644 --- a/src/osg/NodeVisitor.cpp +++ b/src/osg/NodeVisitor.cpp @@ -57,14 +57,12 @@ class TransformVisitor : public NodeVisitor }; - MatrixMode _matrixMode; CoordMode _coordMode; Matrix& _matrix; NodeVisitor* _nodeVisitor; - TransformVisitor(Matrix& matrix,MatrixMode matrixMode,CoordMode coordMode,NodeVisitor* nv): + TransformVisitor(Matrix& matrix,CoordMode coordMode,NodeVisitor* nv): NodeVisitor(), - _matrixMode(matrixMode), _coordMode(coordMode), _matrix(matrix), _nodeVisitor(nv) @@ -72,51 +70,44 @@ class TransformVisitor : public NodeVisitor virtual void apply(Transform& transform) { - bool applyTransform = - (_matrixMode==transform.getMatrixMode()) || - (_matrixMode==MODELVIEW && (transform.getMatrixMode()==MODEL || transform.getMatrixMode()==VIEW)); - - if (applyTransform) + if (_coordMode==LOCAL_TO_WORLD) { - if (_coordMode==LOCAL_TO_WORLD) - { - osg::Matrix localToWorldMat; - transform.getLocalToWorldMatrix(localToWorldMat,_nodeVisitor); - _matrix.preMult(localToWorldMat); - } - else // worldToLocal - { - osg::Matrix worldToLocalMat; - transform.getWorldToLocalMatrix(worldToLocalMat,_nodeVisitor); - _matrix.postMult(worldToLocalMat); - } + osg::Matrix localToWorldMat; + transform.getLocalToWorldMatrix(localToWorldMat,_nodeVisitor); + _matrix.preMult(localToWorldMat); + } + else // worldToLocal + { + osg::Matrix worldToLocalMat; + transform.getWorldToLocalMatrix(worldToLocalMat,_nodeVisitor); + _matrix.postMult(worldToLocalMat); } } }; -const bool NodeVisitor::getLocalToWorldMatrix(Matrix& matrix, MatrixMode mode, Node* node) +const bool NodeVisitor::getLocalToWorldMatrix(Matrix& matrix, Node* node) { - TransformVisitor tv(matrix,mode,TransformVisitor::LOCAL_TO_WORLD,this); + TransformVisitor tv(matrix,TransformVisitor::LOCAL_TO_WORLD,this); for(NodePath::iterator itr=_nodePath.begin(); itr!=_nodePath.end(); ++itr) { - if (*itr==node) return true; // don't account for matrix attached to specofied node + if (*itr==node) return true; // don't account for matrix attached to specified node (*itr)->accept(tv); } return true; } -const bool NodeVisitor::getWorldToLocalMatrix(Matrix& matrix, MatrixMode mode, Node* node) +const bool NodeVisitor::getWorldToLocalMatrix(Matrix& matrix, Node* node) { - TransformVisitor tv(matrix,mode,TransformVisitor::WORLD_TO_LOCAL,this); + TransformVisitor tv(matrix,TransformVisitor::WORLD_TO_LOCAL,this); for(NodePath::iterator itr=_nodePath.begin(); itr!=_nodePath.end(); ++itr) { - if (*itr==node) return true; // don't account for matrix attached to specofied node + if (*itr==node) return true; // don't account for matrix attached to specified node (*itr)->accept(tv); } return true; diff --git a/src/osg/Object.cpp b/src/osg/Object.cpp index 6b07e7ae3..e7efa7548 100644 --- a/src/osg/Object.cpp +++ b/src/osg/Object.cpp @@ -14,5 +14,6 @@ Referenced::~Referenced() } -Object::Object(const Object&,const CopyOp&): - Referenced() {} +Object::Object(const Object& obj,const CopyOp&): + Referenced(), + _dataVariance(obj._dataVariance) {} diff --git a/src/osg/PositionAttitudeTransform.cpp b/src/osg/PositionAttitudeTransform.cpp index d8cc8833b..b5c7e14b3 100644 --- a/src/osg/PositionAttitudeTransform.cpp +++ b/src/osg/PositionAttitudeTransform.cpp @@ -8,33 +8,36 @@ PositionAttitudeTransform::PositionAttitudeTransform() const bool PositionAttitudeTransform::computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const { - if (_mode==MODEL || _mode==MODELVIEW) + if (_referenceFrame==RELATIVE_TO_PARENTS) + { + osg::Matrix tmp; + tmp.makeRotate(_attitude); + tmp.setTrans(_position); + + matrix.preMult(tmp); + } + else // absolute { matrix.makeRotate(_attitude); matrix.setTrans(_position); - return true; - } - else // _mode==VIEW - { - matrix.makeTranslate(-_position); - matrix.postMult(osg::Matrix::rotate(_attitude.inverse())); - return true; } + return true; } const bool PositionAttitudeTransform::computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const { - if (_mode==MODEL || _mode==MODELVIEW) + if (_referenceFrame==RELATIVE_TO_PARENTS) + { + osg::Matrix tmp; + tmp.makeTranslate(-_position); + tmp.postMult(osg::Matrix::rotate(_attitude.inverse())); + matrix.postMult(tmp); + } + else // absolute { matrix.makeTranslate(-_position); matrix.postMult(osg::Matrix::rotate(_attitude.inverse())); - return true; - } - else // _mode==VIEW - { - matrix.makeRotate(_attitude); - matrix.setTrans(_position); - return true; } + return true; } diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index 70851b813..49e4421e0 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -16,8 +16,9 @@ using namespace osg; StateSet::StateSet() { + setDataVariance(osg::StateAttribute::STATIC); + _renderingHint = DEFAULT_BIN; - _datatype = osg::StateAttribute::STATIC; setRendingBinToInherit(); } @@ -41,7 +42,6 @@ StateSet::StateSet(const StateSet& rhs,const CopyOp& copyop):Object(rhs,copyop) _binMode = rhs._binMode; _binNum = rhs._binNum; _binName = rhs._binName; - _datatype = rhs._datatype; } StateSet::~StateSet() diff --git a/src/osg/Transform.cpp b/src/osg/Transform.cpp index f76fc8668..3eb510d22 100644 --- a/src/osg/Transform.cpp +++ b/src/osg/Transform.cpp @@ -4,8 +4,7 @@ using namespace osg; Transform::Transform() { - _type = DYNAMIC; - _mode = MODEL; + _referenceFrame = RELATIVE_TO_PARENTS; _matrix = osgNew Matrix; _inverse = osgNew Matrix; @@ -14,9 +13,8 @@ Transform::Transform() Transform::Transform(const Transform& transform,const CopyOp& copyop): Group(transform,copyop), - _type(transform._type), - _mode(transform._mode), _computeTransformCallback(_computeTransformCallback), + _referenceFrame(transform._referenceFrame), _matrix(osgNew Matrix(*transform._matrix)), _inverse(osgNew Matrix(*transform._inverse)), _inverseDirty(transform._inverseDirty) @@ -25,8 +23,7 @@ Transform::Transform(const Transform& transform,const CopyOp& copyop): Transform::Transform(const Matrix& mat ) { - _type = DYNAMIC; - _mode = MODEL; + _referenceFrame = RELATIVE_TO_PARENTS; _matrix = osgNew Matrix(mat); _inverse = osgNew Matrix(); @@ -38,6 +35,17 @@ Transform::~Transform() { } +void Transform::setReferenceFrame(ReferenceFrame rf) +{ + if (_referenceFrame == rf) return; + + _referenceFrame = rf; + + // switch off culling if transform is absolute. + if (_referenceFrame==ABSOLUTE) setCullingActive(false); + else setCullingActive(true); +} + const bool Transform::computeBound() const { if (!Group::computeBound()) return false; @@ -45,41 +53,36 @@ const bool Transform::computeBound() const // note, NULL pointer for NodeVisitor, so compute's need // to handle this case gracefully, normally this should not be a problem. Matrix l2w; - if (_mode!=PROJECTION && getLocalToWorldMatrix(l2w,NULL)) - { - Vec3 xdash = _bsphere._center; - xdash.x() += _bsphere._radius; - xdash = xdash*l2w; + getLocalToWorldMatrix(l2w,NULL); - Vec3 ydash = _bsphere._center; - ydash.y() += _bsphere._radius; - ydash = ydash*l2w; + Vec3 xdash = _bsphere._center; + xdash.x() += _bsphere._radius; + xdash = xdash*l2w; - Vec3 zdash = _bsphere._center; - zdash.y() += _bsphere._radius; - zdash = zdash*l2w; + Vec3 ydash = _bsphere._center; + ydash.y() += _bsphere._radius; + ydash = ydash*l2w; - _bsphere._center = _bsphere._center*l2w; + Vec3 zdash = _bsphere._center; + zdash.y() += _bsphere._radius; + zdash = zdash*l2w; - xdash -= _bsphere._center; - float len_xdash = xdash.length(); + _bsphere._center = _bsphere._center*l2w; - ydash -= _bsphere._center; - float len_ydash = ydash.length(); + xdash -= _bsphere._center; + float len_xdash = xdash.length(); - zdash -= _bsphere._center; - float len_zdash = zdash.length(); + ydash -= _bsphere._center; + float len_ydash = ydash.length(); - _bsphere._radius = len_xdash; - if (_bsphere._radiussetName(rec->getData()->szIdent); - transform->setType(osg::Transform::DYNAMIC); + transform->setDataVariance(osg::Object::DYNAMIC); // note for Judd (and others) shouldn't there be code in here to set up the transform matrix? // as a transform with an identity matrix is effectively only a @@ -1179,7 +1179,7 @@ osg::Node* ConvertFromFLT::visitMatrix(osg::Group* osgParent, MatrixRecord* rec) pos *= (float)_unitScale; m *= osg::Matrix::translate(pos); - transform->setType(osg::Transform::STATIC); + transform->setDataVariance(osg::Object::STATIC); transform->setMatrix(m); osgParent->addChild(transform); diff --git a/src/osgPlugins/osg/Object.cpp b/src/osgPlugins/osg/Object.cpp index bfe750c6e..f2c59117b 100644 --- a/src/osgPlugins/osg/Object.cpp +++ b/src/osgPlugins/osg/Object.cpp @@ -8,8 +8,8 @@ using namespace osg; using namespace osgDB; // forward declare functions to use later. -// bool Object_readLocalData(Object& obj, Input& fr); -// bool Object_writeLocalData(const Object& obj, Output& fw); +bool Object_readLocalData(Object& obj, Input& fr); +bool Object_writeLocalData(const Object& obj, Output& fw); // register the read and write functions with the osgDB::Registry. // note, Object doesn't currently require any read and write. @@ -18,6 +18,41 @@ RegisterDotOsgWrapperProxy g_ObjectProxy /*new osg::Object*/NULL, "Object", "Object", - NULL, - NULL + &Object_readLocalData, + &Object_writeLocalData ); + +bool Object_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + + if (fr[0].matchWord("DataVariance")) + { + if (fr[1].matchWord("DYNAMIC")) + { + obj.setDataVariance(osg::Object::DYNAMIC); + fr +=2 ; + iteratorAdvanced = true; + } + else if (fr[1].matchWord("STATIC")) + { + obj.setDataVariance(osg::Object::STATIC); + fr +=2 ; + iteratorAdvanced = true; + } + } + + return iteratorAdvanced; +} + + +bool Object_writeLocalData(const Object& obj, Output& fw) +{ + switch(obj.getDataVariance()) + { + case(osg::Object::STATIC): fw.indent() << "DataVariance STATIC" << std::endl;break; + default: fw.indent() << "DataVariance DYNAMIC" << std::endl;break; + } + + return true; +} diff --git a/src/osgPlugins/osg/Transform.cpp b/src/osgPlugins/osg/Transform.cpp index 51de17912..a1b0657e0 100644 --- a/src/osgPlugins/osg/Transform.cpp +++ b/src/osgPlugins/osg/Transform.cpp @@ -44,13 +44,15 @@ bool Transform_readLocalData(Object& obj, Input& fr) { if (fr[1].matchWord("DYNAMIC")) { - transform.setType(osg::Transform::DYNAMIC); + transform.setDataVariance(osg::Object::DYNAMIC); fr +=2 ; + iteratorAdvanced = true; } else if (fr[1].matchWord("STATIC")) { - transform.setType(osg::Transform::STATIC); + transform.setDataVariance(osg::Object::STATIC); fr +=2 ; + iteratorAdvanced = true; } } @@ -75,12 +77,6 @@ bool Transform_writeLocalData(const Object& obj, Output& fw) { const Transform& transform = static_cast(obj); - switch(transform.getType()) - { - case(osg::Transform::STATIC): fw.indent() << "Type STATIC" << std::endl;break; - default: fw.indent() << "Type DYNAMIC" << std::endl;break; - } - fw.writeObject(transform.getMatrix()); return true; diff --git a/src/osgUtil/CullVisitor.cpp b/src/osgUtil/CullVisitor.cpp index 6cfc8ee7e..908bd1db4 100644 --- a/src/osgUtil/CullVisitor.cpp +++ b/src/osgUtil/CullVisitor.cpp @@ -577,8 +577,8 @@ void CullVisitor::apply(Transform& node) if (node_state) pushStateSet(node_state); ref_ptr matrix = createOrReuseMatrix(); + *matrix = *getCurrentMatrix(); node.getLocalToWorldMatrix(*matrix,this); - matrix->postMult(*getCurrentMatrix()); pushModelViewMatrix(matrix.get()); traverse(node); diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index 31046395e..04a56e0d5 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -129,7 +129,7 @@ void Optimizer::StateVisitor::addStateSet(osg::StateSet* stateset,osg::Object* o void Optimizer::StateVisitor::apply(osg::Node& node) { osg::StateSet* ss = node.getStateSet(); - if (ss && ss->getDataType()==osg::StateAttribute::STATIC) addStateSet(ss,&node); + if (ss && ss->getDataVariance()==osg::Object::STATIC) addStateSet(ss,&node); traverse(node); } @@ -137,14 +137,14 @@ void Optimizer::StateVisitor::apply(osg::Node& node) void Optimizer::StateVisitor::apply(osg::Geode& geode) { osg::StateSet* ss = geode.getStateSet(); - if (ss && ss->getDataType()==osg::StateAttribute::STATIC) addStateSet(ss,&geode); + if (ss && ss->getDataVariance()==osg::Object::STATIC) addStateSet(ss,&geode); for(int i=0;igetStateSet(); - if (ss && ss->getDataType()==osg::StateAttribute::STATIC) addStateSet(ss,drawable); + if (ss && ss->getDataVariance()==osg::Object::STATIC) addStateSet(ss,drawable); } } } @@ -172,7 +172,7 @@ void Optimizer::StateVisitor::optimize() aitr!=attributes.end(); ++aitr) { - if (aitr->second.first->getDataType()==osg::StateAttribute::STATIC) + if (aitr->second.first->getDataVariance()==osg::Object::STATIC) { _attributeToStateSetMap[aitr->second.first.get()].insert(sitr->first); } @@ -328,7 +328,7 @@ void Optimizer::FlattenStaticTransformsVisitor::apply(osg::LOD& lod) void Optimizer::FlattenStaticTransformsVisitor::apply(osg::Transform& transform) { - if (_ignoreDynamicTransforms && transform.getType()==osg::Transform::DYNAMIC) + if (_ignoreDynamicTransforms && transform.getDataVariance()==osg::Object::DYNAMIC) { // simple traverse the children as if this Transform didn't exist. traverse(transform);