Hi,

I want to resolve the application of an osg::PositionAttitudeTransform
to an osg::Geode by using osgUtil::Optimizer (FLATTEN_STATIC_TRANSFORMS)
as follows:


#include <osg/Geometry>
#include <osg/Geode>
#include <osg/Group>
#include <osg/PositionAttitudeTransform>
#include <osg/Notify>
#include <osgDB/WriteFile>
#include <osgUtil/Optimizer>

int main( int argc, char ** argv )
{
  // set notify level
  osg::setNotifyLevel( osg::DEBUG_FP );

  // create geometry
  osg::ref_ptr< osg::Geometry > geometry = new osg::Geometry;

  // create vertices
  osg::ref_ptr< osg::Vec3Array > vertices = new osg::Vec3Array;
  vertices->push_back( osg::Vec3d( 0.0, -0.5, -0.5 ) );
  vertices->push_back( osg::Vec3d( 0.0,  0.5, -0.5 ) );
  vertices->push_back( osg::Vec3d( 0.0,  0.5,  0.5 ) );
  vertices->push_back( osg::Vec3d( 0.0, -0.5,  0.5 ) );

  // assign vertices to geometry
  geometry->setVertexArray( vertices.get() );

  // create quad as primitive set and assign it to geometry
  geometry->addPrimitiveSet( new osg::DrawArrays( GL_QUADS, 0, 4 ) );

  // create geode and assign geometry
  osg::ref_ptr< osg::Geode > geode = new osg::Geode;
  geode->addDrawable( geometry.get() );

  // create group
  osg::ref_ptr< osg::Group > group = new osg::Group;

  // create transform
  osg::PositionAttitudeTransform * transform = new
osg::PositionAttitudeTransform;

  // add transform to group
  group->addChild( transform );

  // set scaling
  transform->setScale( osg::Vec3d( 1.0, 5.0, 10.0 ) );

  // add geode to transform
  transform->addChild( geode.get() );

  // save group to file
  osgDB::writeNodeFile( * group.get(), "pre_transformed.osg" );

  // optimize group
  osgUtil::Optimizer optimizer;
  optimizer.optimize( group.get(),
osgUtil::Optimizer::FLATTEN_STATIC_TRANSFORMS );

  // save transformed group to file
  osgDB::writeNodeFile( * group.get(), "transformed.osg" );

  return 0;
}


Running this prints to screen:

Optimizer::optimize() doing FLATTEN_STATIC_TRANSFORMS
** RemoveStaticTransformsVisitor *** Pass 0

But the "optimized" scene graph doesn't differ from the original:

Group {
  DataVariance DYNAMIC
  nodeMask 0xffffffff
  cullingActive TRUE
  num_children 1
  PositionAttitudeTransform {
    DataVariance DYNAMIC
    nodeMask 0xffffffff
    cullingActive TRUE
    referenceFrame RELATIVE
    position 0 0 0
    attitude 0 0 0 1
    scale 1 5 10
    pivotPoint 0 0 0
    num_children 1
    Geode {
      UniqueID Geode_0
      DataVariance DYNAMIC
      nodeMask 0xffffffff
      cullingActive TRUE
      num_drawables 1
      Geometry {
        UniqueID Geometry_1
        DataVariance DYNAMIC
        useDisplayList TRUE
        useVertexBufferObjects FALSE
        PrimitiveSets 1
        {
          DrawArrays QUADS 0 4
        }
        VertexArray UniqueID Vec3Array_2 Vec3Array 4
        {
          0 -0.5 -0.5
          0 0.5 -0.5
          0 0.5 0.5
          0 -0.5 0.5
        }
      }
    }
  }
}

Does anyone know what I'm doing wrong?

Thanks in advance!
Rudi
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to