diff --git a/src/Demos/osgconv/OrientationConverter.cpp b/src/Demos/osgconv/OrientationConverter.cpp index 87d6b6f8c..4c2bab608 100644 --- a/src/Demos/osgconv/OrientationConverter.cpp +++ b/src/Demos/osgconv/OrientationConverter.cpp @@ -1,52 +1,14 @@ #include + #include +#include +#include +#include + #include "OrientationConverter.h" using namespace osg; -class TransformFunctor : public osg::Drawable::AttributeFunctor -{ - public: - - osg::Matrix _m; - osg::Matrix _im; - - TransformFunctor(const osg::Matrix& m): - osg::Drawable::AttributeFunctor(osg::Drawable::COORDS|osg::Drawable::NORMALS) - { - _m = m; - _im.invert(_m); - } - - virtual ~TransformFunctor() {} - - virtual bool apply(osg::Drawable::AttributeBitMask abm,osg::Vec3* begin,osg::Vec3* end) - { - if (abm == osg::Drawable::COORDS) - { - for (osg::Vec3* itr=begin;itrapplyAttributeOperation(tf); - -/* - GeoSet *gset = dynamic_cast(geode.getDrawable(i)); - - if( gset == NULL ) - continue; - int numcoords = gset->getNumCoords(); - Vec3 *vertex = gset->getCoords(); - - for( int i = 0; i < numcoords; i++ ) - { - Vec3 vv = vertex[i]; - vertex[i] = vv * _mat; - } - - int numnormals = gset->getNumNormals(); - Vec3 *normals = gset->getNormals(); - for( int i = 0; i < numnormals; i++ ) - { - Vec3 vv = normals[i]; - normals[i] = vv * _mat; - } -*/ - } + for(int i=0;iapplyAttributeOperation(_tf); + } +} + +void OrientationConverter::ConvertVisitor::apply(osg::Billboard& billboard) +{ + osg::Vec3 axis = osg::Matrix::transform3x3(_tf._im,billboard.getAxis()); + billboard.setAxis(axis); + + for(int i=0;iapplyAttributeOperation(_tf); + } +} + +void OrientationConverter::ConvertVisitor::apply(osg::LOD& lod) +{ + lod.setCenter(lod.getCenter()*_tf._m); + traverse(lod); } diff --git a/src/Demos/osgconv/OrientationConverter.h b/src/Demos/osgconv/OrientationConverter.h index cd2aafef5..9bed4fb91 100644 --- a/src/Demos/osgconv/OrientationConverter.h +++ b/src/Demos/osgconv/OrientationConverter.h @@ -16,23 +16,65 @@ class OrientationConverter { OrientationConverter( const OrientationConverter& ) {} OrientationConverter& operator = (const OrientationConverter& ) { return *this; } + class TransformFunctor : public osg::Drawable::AttributeFunctor + { + public: + osg::Matrix _m; + osg::Matrix _im; + + TransformFunctor(): + osg::Drawable::AttributeFunctor(osg::Drawable::COORDS|osg::Drawable::NORMALS) + { + } + + void set(const osg::Matrix& m) + { + _m = m; + _im.invert(_m); + } + + virtual ~TransformFunctor() {} + + virtual bool apply(osg::Drawable::AttributeBitMask abm,osg::Vec3* begin,osg::Vec3* end) + { + if (abm == osg::Drawable::COORDS) + { + for (osg::Vec3* itr=begin;itr +#include #include #include #include @@ -88,6 +89,32 @@ class FlattenStaticTransformsVisitor : public osg::NodeVisitor } } + virtual void apply(osg::Billboard& billboard) + { + if (!_matrixStack.empty()) + { + osg::Matrix& matrix = _matrixStack.back(); + TransformFunctor tf(matrix); + + osg::Vec3 axis = osg::Matrix::transform3x3(tf._im,billboard.getAxis()); + billboard.setAxis(axis); + + for(int i=0;iapplyAttributeOperation(tf); + } + } + } + + virtual void apply(osg::LOD& lod) + { + if (!_matrixStack.empty()) + { + lod.setCenter(lod.getCenter()*_matrixStack.back()); + } + traverse(lod); + } virtual void apply(osg::Transform& transform) { @@ -187,6 +214,80 @@ class RemoveRedundentNodesVisitor : public osg::NodeVisitor }; +class CombineLODsVisitor : public osg::NodeVisitor +{ + public: + + typedef std::set GroupList; + GroupList _groupList; + + CombineLODsVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} + + virtual void apply(osg::LOD& lod) + { + for(int i=0;i RangeLODMap; + typedef std::set LODSet; + typedef std::multimap CenterLODMap; + typedef std::set NodeSet; + + CenterLODMap centerLODMap; + NodeSet otherChildren; + + for(int i=0;igetNumChildren();++i) + { + osg::Node* child = group->getChild(i); + osg::LOD* lod = dynamic_cast(child); + if (lod) + { + centerLODMap.insert(std::pair(lod->getCenter(),lod)); + } + else + { + otherChildren.insert(child); + } + } + + cout << "Group "<first<<")"; + osg::LOD* lod = clod_itr->second; + for(int i=0;igetNumRanges();++i) + { + cout << ", "<< lod->getRange(i); + } + cout <accept(osv); osv.optimize(); #endif - /* FlattenStaticTransformsVisitor fstv; rootnode->accept(fstv); @@ -327,7 +427,11 @@ int main( int argc, char **argv ) RemoveRedundentNodesVisitor rrnv; rootnode->accept(rrnv); rrnv.removeRedundentNodes(); -*/ + + CombineLODsVisitor clv; + rootnode->accept(clv); + clv.combineLODs(); +*/ // initialize the viewer. osgGLUT::Viewer viewer; viewer.addViewport( rootnode );