2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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.
|
|
|
|
*/
|
2001-10-19 22:22:02 +08:00
|
|
|
|
|
|
|
#ifndef OSGUTIL_OPTIMIZER
|
|
|
|
#define OSGUTIL_OPTIMIZER
|
|
|
|
|
|
|
|
#include <osg/NodeVisitor>
|
|
|
|
#include <osg/Matrix>
|
2002-07-18 08:53:03 +08:00
|
|
|
#include <osg/Geometry>
|
2002-08-30 23:07:10 +08:00
|
|
|
#include <osg/Transform>
|
2001-10-19 22:22:02 +08:00
|
|
|
|
|
|
|
#include <osgUtil/Export>
|
|
|
|
|
2002-02-07 09:15:15 +08:00
|
|
|
#include <set>
|
|
|
|
|
2001-10-19 22:22:02 +08:00
|
|
|
namespace osgUtil {
|
|
|
|
|
|
|
|
/** Insert impostor nodes into scene graph.
|
|
|
|
* For example of usage see src/Demos/osgimpostor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class OSGUTIL_EXPORT Optimizer
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Optimizer() {}
|
2003-12-12 07:26:22 +08:00
|
|
|
virtual ~Optimizer() {}
|
2001-10-19 22:22:02 +08:00
|
|
|
|
|
|
|
enum OptimizationOptions
|
|
|
|
{
|
2003-12-04 05:45:32 +08:00
|
|
|
FLATTEN_STATIC_TRANSFORMS = 0x001,
|
|
|
|
REMOVE_REDUNDANT_NODES = 0x002,
|
|
|
|
COMBINE_ADJACENT_LODS = 0x004,
|
|
|
|
SHARE_DUPLICATE_STATE = 0x008,
|
|
|
|
MERGE_GEOMETRY = 0x010,
|
|
|
|
CHECK_GEOMETRY = 0x020,
|
|
|
|
SPATIALIZE_GROUPS = 0x040,
|
|
|
|
COPY_SHARED_NODES = 0x080,
|
|
|
|
TRISTRIP_GEOMETRY = 0x100,
|
2003-12-28 06:17:25 +08:00
|
|
|
TESSELATE_GEOMETRY = 0x200,
|
2004-07-12 21:20:18 +08:00
|
|
|
OPTIMIZE_TEXTURE_SETTINGS = 0x400,
|
2003-12-04 05:45:32 +08:00
|
|
|
DEFAULT_OPTIMIZATIONS = FLATTEN_STATIC_TRANSFORMS |
|
|
|
|
REMOVE_REDUNDANT_NODES |
|
|
|
|
COMBINE_ADJACENT_LODS |
|
|
|
|
SHARE_DUPLICATE_STATE |
|
|
|
|
MERGE_GEOMETRY |
|
2004-07-12 21:20:18 +08:00
|
|
|
CHECK_GEOMETRY |
|
|
|
|
OPTIMIZE_TEXTURE_SETTINGS,
|
2001-10-19 22:22:02 +08:00
|
|
|
ALL_OPTIMIZATIONS = FLATTEN_STATIC_TRANSFORMS |
|
2002-12-07 14:59:08 +08:00
|
|
|
REMOVE_REDUNDANT_NODES |
|
2001-10-19 22:22:02 +08:00
|
|
|
COMBINE_ADJACENT_LODS |
|
2003-05-22 23:29:20 +08:00
|
|
|
SHARE_DUPLICATE_STATE |
|
2003-09-24 23:54:22 +08:00
|
|
|
MERGE_GEOMETRY |
|
2003-12-01 18:28:23 +08:00
|
|
|
CHECK_GEOMETRY |
|
2003-12-04 05:45:32 +08:00
|
|
|
SPATIALIZE_GROUPS |
|
|
|
|
COPY_SHARED_NODES |
|
2004-07-12 21:20:18 +08:00
|
|
|
TRISTRIP_GEOMETRY |
|
|
|
|
OPTIMIZE_TEXTURE_SETTINGS
|
2001-10-19 22:22:02 +08:00
|
|
|
};
|
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
/** reset internal data to initial state - the getPrimissableOptionsMap is cleared.*/
|
|
|
|
void reset();
|
|
|
|
|
2001-10-19 22:22:02 +08:00
|
|
|
/** traverse the node and its subgraph with a series of optimization
|
|
|
|
* visitors, specificied by the OptizationOptions.*/
|
2003-12-04 05:45:32 +08:00
|
|
|
void optimize(osg::Node* node);
|
|
|
|
|
|
|
|
/** traverse the node and its subgraph with a series of optimization
|
|
|
|
* visitors, specificied by the OptizationOptions.*/
|
|
|
|
virtual void optimize(osg::Node* node, unsigned int options);
|
2001-10-19 22:22:02 +08:00
|
|
|
|
|
|
|
|
2003-12-12 07:33:27 +08:00
|
|
|
inline void setPermissableOptimizationsForObject(const osg::Object* object, unsigned int options)
|
2003-12-12 07:26:22 +08:00
|
|
|
{
|
2003-12-12 07:33:27 +08:00
|
|
|
_permissableOptimizationsMap[object] = options;
|
2003-12-12 07:26:22 +08:00
|
|
|
}
|
|
|
|
|
2003-12-12 07:33:27 +08:00
|
|
|
inline unsigned int getPermissableOptimizationsForObject(const osg::Object* object) const
|
2003-12-12 07:26:22 +08:00
|
|
|
{
|
2003-12-12 07:33:27 +08:00
|
|
|
PermissableOptimizationsMap::const_iterator itr = _permissableOptimizationsMap.find(object);
|
|
|
|
if (itr!=_permissableOptimizationsMap.end()) return itr->second;
|
2003-12-12 07:26:22 +08:00
|
|
|
else return 0xffffffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isOperationPermissableForObject(const osg::Object* object,unsigned int option) const
|
|
|
|
{
|
2003-12-12 07:33:27 +08:00
|
|
|
return (option & getPermissableOptimizationsForObject(object))!=0;
|
2003-12-12 07:26:22 +08:00
|
|
|
}
|
|
|
|
|
2003-12-12 07:33:27 +08:00
|
|
|
typedef std::map<const osg::Object*,unsigned int> PermissableOptimizationsMap;
|
2003-12-12 07:26:22 +08:00
|
|
|
|
2003-12-12 07:33:27 +08:00
|
|
|
PermissableOptimizationsMap& getPrimissableOptionsMap() { return _permissableOptimizationsMap; }
|
|
|
|
const PermissableOptimizationsMap& getPrimissableOptionsMap() const { return _permissableOptimizationsMap; }
|
2003-12-12 07:26:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2003-12-12 07:33:27 +08:00
|
|
|
PermissableOptimizationsMap _permissableOptimizationsMap;
|
2003-12-12 07:26:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
public:
|
2002-06-24 05:43:46 +08:00
|
|
|
|
|
|
|
|
2001-10-19 22:22:02 +08:00
|
|
|
/** Flatten Static Trasform nodes by applying their transform to the
|
|
|
|
* geometry on the leaves of the scene graph, then removing the
|
2002-12-07 14:59:08 +08:00
|
|
|
* now redundant transforms.*/
|
2001-11-19 19:52:58 +08:00
|
|
|
class OSGUTIL_EXPORT FlattenStaticTransformsVisitor : public osg::NodeVisitor
|
2001-10-19 22:22:02 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
2001-12-17 23:05:06 +08:00
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
FlattenStaticTransformsVisitor(Optimizer* optimizer=0):
|
|
|
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
|
|
|
_optimizer(optimizer) {}
|
2001-10-19 22:22:02 +08:00
|
|
|
|
2004-07-29 18:13:02 +08:00
|
|
|
virtual void apply(osg::Node& geode);
|
2001-10-19 22:22:02 +08:00
|
|
|
virtual void apply(osg::Geode& geode);
|
2002-08-30 23:07:10 +08:00
|
|
|
virtual void apply(osg::Billboard& geode);
|
2002-06-24 05:43:46 +08:00
|
|
|
virtual void apply(osg::Transform& transform);
|
|
|
|
|
2003-01-22 20:06:22 +08:00
|
|
|
bool removeTransforms(osg::Node* nodeWeCannotRemove);
|
2002-06-24 05:43:46 +08:00
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
inline bool isOperationPermissableForObject(const osg::Object* object) const
|
|
|
|
{
|
|
|
|
return _optimizer ? _optimizer->isOperationPermissableForObject(object,FLATTEN_STATIC_TRANSFORMS) : true;
|
|
|
|
}
|
|
|
|
|
2002-06-24 05:43:46 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2002-08-30 23:07:10 +08:00
|
|
|
typedef std::vector<osg::Transform*> TransformStack;
|
|
|
|
typedef std::set<osg::Drawable*> DrawableSet;
|
|
|
|
typedef std::set<osg::Billboard*> BillboardSet;
|
2004-07-29 18:13:02 +08:00
|
|
|
typedef std::set<osg::Node* > NodeSet;
|
2002-08-30 23:07:10 +08:00
|
|
|
typedef std::set<osg::Transform*> TransformSet;
|
2003-12-12 07:26:22 +08:00
|
|
|
|
|
|
|
Optimizer* _optimizer;
|
2002-06-24 05:43:46 +08:00
|
|
|
TransformStack _transformStack;
|
2004-07-29 18:13:02 +08:00
|
|
|
NodeSet _excludedNodeSet;
|
2002-08-30 23:07:10 +08:00
|
|
|
DrawableSet _drawableSet;
|
|
|
|
BillboardSet _billboardSet;
|
|
|
|
TransformSet _transformSet;
|
2002-06-24 05:43:46 +08:00
|
|
|
};
|
|
|
|
|
2002-08-30 23:07:10 +08:00
|
|
|
|
2003-12-05 22:39:32 +08:00
|
|
|
/** Combine Static Trasform nodes that sit above on another.*/
|
|
|
|
class OSGUTIL_EXPORT CombineStaticTransformsVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
CombineStaticTransformsVisitor(Optimizer* optimizer=0):
|
|
|
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
|
|
|
_optimizer(optimizer) {}
|
2003-12-05 22:39:32 +08:00
|
|
|
|
|
|
|
virtual void apply(osg::MatrixTransform& transform);
|
|
|
|
|
|
|
|
bool removeTransforms(osg::Node* nodeWeCannotRemove);
|
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
inline bool isOperationPermissableForObject(const osg::Object* object) const
|
|
|
|
{
|
|
|
|
return _optimizer ? _optimizer->isOperationPermissableForObject(object,FLATTEN_STATIC_TRANSFORMS) : true;
|
|
|
|
}
|
|
|
|
|
2003-12-05 22:39:32 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
typedef std::set<osg::MatrixTransform*> TransformSet;
|
2003-12-12 07:26:22 +08:00
|
|
|
Optimizer* _optimizer;
|
2003-12-05 22:39:32 +08:00
|
|
|
TransformSet _transformSet;
|
|
|
|
};
|
|
|
|
|
2002-12-07 14:59:08 +08:00
|
|
|
/** Remove rendundant nodes, such as groups with one single child.*/
|
2002-06-24 05:43:46 +08:00
|
|
|
class OSGUTIL_EXPORT RemoveEmptyNodesVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
typedef std::set<osg::Node*> NodeList;
|
2002-12-07 14:59:08 +08:00
|
|
|
NodeList _redundantNodeList;
|
2002-06-24 05:43:46 +08:00
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
RemoveEmptyNodesVisitor(Optimizer* optimizer=0):
|
|
|
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
|
|
|
_optimizer(optimizer) {}
|
|
|
|
|
2002-06-24 05:43:46 +08:00
|
|
|
virtual void apply(osg::Geode& geode);
|
|
|
|
virtual void apply(osg::Group& group);
|
|
|
|
|
|
|
|
void removeEmptyNodes();
|
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
inline bool isOperationPermissableForObject(const osg::Object* object) const
|
|
|
|
{
|
|
|
|
return _optimizer ? _optimizer->isOperationPermissableForObject(object,REMOVE_REDUNDANT_NODES) : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Optimizer* _optimizer;
|
2002-06-24 05:43:46 +08:00
|
|
|
};
|
|
|
|
|
2002-12-07 14:59:08 +08:00
|
|
|
/** Remove rendundant nodes, such as groups with one single child.*/
|
|
|
|
class OSGUTIL_EXPORT RemoveRedundantNodesVisitor : public osg::NodeVisitor
|
2001-10-19 22:22:02 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef std::set<osg::Node*> NodeList;
|
2002-12-07 14:59:08 +08:00
|
|
|
NodeList _redundantNodeList;
|
2001-10-19 22:22:02 +08:00
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
RemoveRedundantNodesVisitor(Optimizer* optimizer=0):
|
|
|
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
|
|
|
_optimizer(optimizer) {}
|
2002-06-24 05:43:46 +08:00
|
|
|
|
2001-10-19 22:22:02 +08:00
|
|
|
virtual void apply(osg::Group& group);
|
2002-06-24 05:43:46 +08:00
|
|
|
virtual void apply(osg::Transform& transform);
|
2001-10-19 22:22:02 +08:00
|
|
|
|
2002-12-07 14:59:08 +08:00
|
|
|
void removeRedundantNodes();
|
2001-10-19 22:22:02 +08:00
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
inline bool isOperationPermissableForObject(const osg::Object* object) const
|
|
|
|
{
|
|
|
|
return _optimizer ? _optimizer->isOperationPermissableForObject(object,REMOVE_REDUNDANT_NODES) : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Optimizer* _optimizer;
|
2001-10-19 22:22:02 +08:00
|
|
|
};
|
|
|
|
|
2003-12-28 06:17:25 +08:00
|
|
|
/** Tesselate all geodes, to remove POLYGONS
|
|
|
|
* complementary ranges.*/
|
|
|
|
class OSGUTIL_EXPORT TesselateVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef std::set<osg::Group*> GroupList;
|
|
|
|
GroupList _groupList;
|
|
|
|
|
|
|
|
TesselateVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
|
|
|
|
|
|
|
|
virtual void apply(osg::Geode& geode);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2001-10-19 22:22:02 +08:00
|
|
|
/** Optimize the LOD groups, by combining adjacent LOD's which have
|
|
|
|
* complementary ranges.*/
|
2001-11-19 19:52:58 +08:00
|
|
|
class OSGUTIL_EXPORT CombineLODsVisitor : public osg::NodeVisitor
|
2001-10-19 22:22:02 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef std::set<osg::Group*> GroupList;
|
|
|
|
GroupList _groupList;
|
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
CombineLODsVisitor(Optimizer* optimizer=0):
|
|
|
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
|
|
|
_optimizer(optimizer) {}
|
2001-10-19 22:22:02 +08:00
|
|
|
|
|
|
|
virtual void apply(osg::LOD& lod);
|
|
|
|
|
|
|
|
void combineLODs();
|
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
inline bool isOperationPermissableForObject(const osg::Object* object) const
|
|
|
|
{
|
|
|
|
return _optimizer ? _optimizer->isOperationPermissableForObject(object,COMBINE_ADJACENT_LODS) : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Optimizer* _optimizer;
|
2001-10-19 22:22:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Optimize State in the scene graph by removing duplicate state,
|
|
|
|
* replacing it with shared instances, both for StateAttributes,
|
|
|
|
* and whole StateSets.*/
|
2001-11-19 19:52:58 +08:00
|
|
|
class OSGUTIL_EXPORT StateVisitor : public osg::NodeVisitor
|
2001-10-19 22:22:02 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// default to traversing all children.
|
2003-12-12 07:26:22 +08:00
|
|
|
StateVisitor(Optimizer* optimizer=0):
|
|
|
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
|
|
|
_optimizer(optimizer) {}
|
2001-10-19 22:22:02 +08:00
|
|
|
|
|
|
|
/** empty visitor, make it ready for next traversal.*/
|
|
|
|
virtual void reset();
|
|
|
|
|
|
|
|
virtual void apply(osg::Node& node);
|
|
|
|
|
|
|
|
virtual void apply(osg::Geode& geode);
|
|
|
|
|
|
|
|
void optimize();
|
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
inline bool isOperationPermissableForObject(const osg::Object* object) const
|
|
|
|
{
|
|
|
|
return _optimizer ? _optimizer->isOperationPermissableForObject(object,SHARE_DUPLICATE_STATE) : true;
|
|
|
|
}
|
|
|
|
|
2001-10-19 22:22:02 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
void addStateSet(osg::StateSet* stateset,osg::Object* obj);
|
|
|
|
|
|
|
|
typedef std::set<osg::Object*> ObjectSet;
|
|
|
|
typedef std::map<osg::StateSet*,ObjectSet> StateSetMap;
|
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
Optimizer* _optimizer;
|
2001-10-19 22:22:02 +08:00
|
|
|
StateSetMap _statesets;
|
|
|
|
|
|
|
|
};
|
2002-07-18 08:53:03 +08:00
|
|
|
|
2003-09-24 23:54:22 +08:00
|
|
|
class OSGUTIL_EXPORT CheckGeometryVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// default to traversing all children.
|
2003-12-12 07:26:22 +08:00
|
|
|
CheckGeometryVisitor(Optimizer* optimizer=0):
|
|
|
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
|
|
|
_optimizer(optimizer) {}
|
2003-09-24 23:54:22 +08:00
|
|
|
|
|
|
|
virtual void apply(osg::Geode& geode) { checkGeode(geode); }
|
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
void checkGeode(osg::Geode& geode);
|
|
|
|
|
|
|
|
inline bool isOperationPermissableForObject(const osg::Object* object) const
|
|
|
|
{
|
|
|
|
return _optimizer ? _optimizer->isOperationPermissableForObject(object,CHECK_GEOMETRY) : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Optimizer* _optimizer;
|
2003-09-24 23:54:22 +08:00
|
|
|
|
|
|
|
};
|
2002-07-18 08:53:03 +08:00
|
|
|
|
|
|
|
class OSGUTIL_EXPORT MergeGeometryVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// default to traversing all children.
|
2003-12-12 07:26:22 +08:00
|
|
|
MergeGeometryVisitor(Optimizer* optimizer=0) :
|
|
|
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
|
|
|
_optimizer(optimizer) {}
|
2001-10-19 22:22:02 +08:00
|
|
|
|
2002-07-18 08:53:03 +08:00
|
|
|
virtual void apply(osg::Geode& geode) { mergeGeode(geode); }
|
2002-07-18 17:17:50 +08:00
|
|
|
virtual void apply(osg::Billboard&) { /* don't do anything*/ }
|
2002-07-18 08:53:03 +08:00
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
bool mergeGeode(osg::Geode& geode);
|
2002-07-19 22:19:49 +08:00
|
|
|
|
2003-01-08 00:29:07 +08:00
|
|
|
static bool geometryContainsSharedArrays(osg::Geometry& geom);
|
|
|
|
|
2002-07-18 08:53:03 +08:00
|
|
|
static bool mergeGeometry(osg::Geometry& lhs,osg::Geometry& rhs);
|
|
|
|
|
2002-07-19 22:19:49 +08:00
|
|
|
static bool mergePrimitive(osg::DrawArrays& lhs,osg::DrawArrays& rhs);
|
|
|
|
static bool mergePrimitive(osg::DrawArrayLengths& lhs,osg::DrawArrayLengths& rhs);
|
|
|
|
static bool mergePrimitive(osg::DrawElementsUByte& lhs,osg::DrawElementsUByte& rhs);
|
|
|
|
static bool mergePrimitive(osg::DrawElementsUShort& lhs,osg::DrawElementsUShort& rhs);
|
|
|
|
static bool mergePrimitive(osg::DrawElementsUInt& lhs,osg::DrawElementsUInt& rhs);
|
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
inline bool isOperationPermissableForObject(const osg::Object* object) const
|
|
|
|
{
|
|
|
|
return _optimizer ? _optimizer->isOperationPermissableForObject(object,MERGE_GEOMETRY) : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Optimizer* _optimizer;
|
2002-07-18 08:53:03 +08:00
|
|
|
};
|
2003-12-01 18:28:23 +08:00
|
|
|
|
|
|
|
/** Spatialize scene into a balanced quad/oct tree.*/
|
|
|
|
class OSGUTIL_EXPORT SpatializeGroupsVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
SpatializeGroupsVisitor(Optimizer* optimizer=0):
|
|
|
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
|
|
|
_optimizer(optimizer) {}
|
2003-12-01 18:28:23 +08:00
|
|
|
|
|
|
|
virtual void apply(osg::Group& group);
|
|
|
|
|
|
|
|
bool divide(unsigned int maxNumTreesPerCell=8);
|
|
|
|
|
|
|
|
bool divide(osg::Group* group, unsigned int maxNumTreesPerCell);
|
|
|
|
|
|
|
|
typedef std::set<osg::Group*> GroupsToDivideList;
|
|
|
|
GroupsToDivideList _groupsToDivideList;
|
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
inline bool isOperationPermissableForObject(const osg::Object* object) const
|
|
|
|
{
|
|
|
|
return _optimizer ? _optimizer->isOperationPermissableForObject(object,SPATIALIZE_GROUPS) : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Optimizer* _optimizer;
|
|
|
|
|
2003-12-01 18:28:23 +08:00
|
|
|
};
|
2003-12-04 05:45:32 +08:00
|
|
|
|
|
|
|
/** Copy any shared subgraphs, enabling flattening of static transforms.*/
|
|
|
|
class OSGUTIL_EXPORT CopySharedSubgraphsVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2003-12-12 07:26:22 +08:00
|
|
|
CopySharedSubgraphsVisitor(Optimizer* optimizer=0):
|
|
|
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
|
|
|
_optimizer(optimizer) {}
|
2003-12-04 05:45:32 +08:00
|
|
|
|
|
|
|
virtual void apply(osg::Node& node);
|
|
|
|
|
|
|
|
void copySharedNodes();
|
|
|
|
|
|
|
|
typedef std::set<osg::Node*> SharedNodeList;
|
|
|
|
SharedNodeList _sharedNodeList;
|
2003-12-12 07:26:22 +08:00
|
|
|
|
|
|
|
inline bool isOperationPermissableForObject(const osg::Object* object) const
|
|
|
|
{
|
|
|
|
return _optimizer ? _optimizer->isOperationPermissableForObject(object,COPY_SHARED_NODES) : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Optimizer* _optimizer;
|
2003-12-04 05:45:32 +08:00
|
|
|
|
|
|
|
};
|
2004-07-12 21:20:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
/** For all textures apply settings.*/
|
|
|
|
class OSGUTIL_EXPORT TextureVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
TextureVisitor(bool changeAutoUnRef, bool valueAutoUnRef,
|
|
|
|
bool changeClientImageStorage, bool valueClientImageStorage,
|
|
|
|
bool changeAnisotropy, float valueAnisotropy,
|
|
|
|
Optimizer* optimizer=0):
|
|
|
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
|
|
|
_optimizer(optimizer),
|
|
|
|
_changeAutoUnRef(changeAutoUnRef), _valueAutoUnRef(valueAutoUnRef),
|
|
|
|
_changeClientImageStorage(changeClientImageStorage), _valueClientImageStorage(valueClientImageStorage),
|
|
|
|
_changeAnisotropy(changeAnisotropy), _valueAnisotropy(valueAnisotropy) {}
|
|
|
|
|
|
|
|
virtual void apply(osg::Geode& node);
|
|
|
|
virtual void apply(osg::Node& node);
|
|
|
|
|
|
|
|
void apply(osg::StateSet& stateset);
|
|
|
|
void apply(osg::Texture& texture);
|
|
|
|
|
|
|
|
inline bool isOperationPermissableForObject(const osg::Object* object) const
|
|
|
|
{
|
|
|
|
return _optimizer ? _optimizer->isOperationPermissableForObject(object,OPTIMIZE_TEXTURE_SETTINGS) : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Optimizer* _optimizer;
|
|
|
|
bool _changeAutoUnRef, _valueAutoUnRef;
|
|
|
|
bool _changeClientImageStorage, _valueClientImageStorage;
|
2004-07-22 15:41:17 +08:00
|
|
|
bool _changeAnisotropy;
|
|
|
|
float _valueAnisotropy;
|
2004-07-12 21:20:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2001-10-19 22:22:02 +08:00
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-10-19 22:22:02 +08:00
|
|
|
|
|
|
|
#endif
|