Added conversion to osg::GeoSet::converToGeometry() utility to help the

migration to and testing of the new osg::Geometry class.
This commit is contained in:
Robert Osfield
2002-06-23 21:43:46 +00:00
parent bbc129e5c6
commit f2e215bf44
10 changed files with 1022 additions and 88 deletions

View File

@@ -42,7 +42,19 @@ class OSGUTIL_EXPORT Optimizer
virtual void optimize(osg::Node* node, unsigned int options = ALL_OPTIMIZATIONS);
/** ConvertGeoSetsToGeometryVisitor all the old GeoSet Drawables to the new Geometry Drawables.*/
class OSGUTIL_EXPORT ConvertGeoSetsToGeometryVisitor : public osg::NodeVisitor
{
public:
ConvertGeoSetsToGeometryVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
virtual void apply(osg::Geode& geode);
virtual void apply(osg::Node& node) { traverse(node); }
};
/** Flatten Static Trasform nodes by applying their transform to the
* geometry on the leaves of the scene graph, then removing the
* now redundent transforms.*/
@@ -133,6 +145,113 @@ class OSGUTIL_EXPORT Optimizer
};
/** Remove the lowest static transforms in the scene.*/
class OSGUTIL_EXPORT RemoveLowestStaticTransformsVisitor : public osg::NodeVisitor
{
public:
RemoveLowestStaticTransformsVisitor(bool ignoreDynamicTransforms=true):
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
_ignoreDynamicTransforms(ignoreDynamicTransforms) {}
virtual void apply(osg::Geode& geode);
virtual void apply(osg::Billboard& billboard);
virtual void apply(osg::LOD& lod);
virtual void apply(osg::Transform& transform);
bool removeTransforms();
typedef std::vector<osg::Transform*> TransformStack;
typedef std::vector<osg::Matrix> MatrixStack;
protected:
struct TransformStruct
{
typedef std::set<osg::Object*> ObjectSet;
TransformStruct():_containsTransform(false),_canBeApplied(true) {}
void add(osg::Object* obj) { _objectSet.insert(obj); }
bool _containsTransform;
bool _canBeApplied;
ObjectSet _objectSet;
};
struct ObjectStruct
{
typedef std::set<osg::Transform*> TransformSet;
ObjectStruct():_canBeApplied(true),_matrixSet(false),_moreThanOneMatrixRequired(false) {}
void add(osg::Transform* transform,osg::Matrix& matrix)
{
_transformSet.insert(transform);
if (!_matrixSet)
{
_matrixSet = true;
_moreThanOneMatrixRequired = false;
_matrix = matrix;
}
else if (_matrix!=matrix)
{
_moreThanOneMatrixRequired = true;
}
}
bool _canBeApplied;
bool _matrixSet;
bool _moreThanOneMatrixRequired;
osg::Matrix _matrix;
TransformSet _transformSet;
};
typedef std::map<osg::Transform*,TransformStruct> TransformMap;
typedef std::map<osg::Object*,ObjectStruct> ObjectMap;
void disableObject(osg::Object* object)
{
disableObject(_objectMap.find(object));
}
void disableObject(ObjectMap::iterator itr);
void disableTransform(osg::Transform* transform);
void doTransform(osg::Object* obj,osg::Matrix& matrix);
bool _ignoreDynamicTransforms;
MatrixStack _matrixStack;
TransformStack _transformStack;
TransformMap _transformMap;
ObjectMap _objectMap;
};
/** Remove rendundent nodes, such as groups with one single child.*/
class OSGUTIL_EXPORT RemoveEmptyNodesVisitor : public osg::NodeVisitor
{
public:
typedef std::set<osg::Node*> NodeList;
NodeList _redundentNodeList;
RemoveEmptyNodesVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
virtual void apply(osg::Geode& geode);
virtual void apply(osg::Group& group);
void removeEmptyNodes();
};
/** Remove rendundent nodes, such as groups with one single child.*/
class OSGUTIL_EXPORT RemoveRedundentNodesVisitor : public osg::NodeVisitor
{
@@ -142,8 +261,9 @@ class OSGUTIL_EXPORT Optimizer
NodeList _redundentNodeList;
RemoveRedundentNodesVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
virtual void apply(osg::Group& group);
virtual void apply(osg::Transform& transform);
void removeRedundentNodes();