diff --git a/include/osgUtil/SceneGraphBuilder b/include/osgUtil/SceneGraphBuilder index 08a844d27..49b009ab8 100644 --- a/include/osgUtil/SceneGraphBuilder +++ b/include/osgUtil/SceneGraphBuilder @@ -139,6 +139,7 @@ class OSGUTIL_EXPORT SceneGraphBuilder Matrices _matrixStack; osg::ref_ptr _stateset; + bool _statesetAssigned; bool _normalSet; osg::Vec3f _normal; diff --git a/src/osgUtil/SceneGraphBuilder.cpp b/src/osgUtil/SceneGraphBuilder.cpp index 3101080ef..c64d75870 100644 --- a/src/osgUtil/SceneGraphBuilder.cpp +++ b/src/osgUtil/SceneGraphBuilder.cpp @@ -36,7 +36,8 @@ using namespace osgUtil; SceneGraphBuilder::SceneGraphBuilder(): _normal(0.0f,0.0f,1.0f), _color(1.0f,1.0f,1.0f,1.0f), - _texCoord(0.f,0.0f,0.0f,0.0f) + _texCoord(0.f,0.0f,0.0f,1.0f), + _statesetAssigned(false) { } @@ -265,7 +266,43 @@ void SceneGraphBuilder::glEnd() _geometry->setNormalBinding(osg::Geometry::BIND_OFF); } - if (_maxNumTexCoordComponents>0) + if (_maxNumTexCoordComponents==1) + { + // convert Vec4Array into FloatArray + osg::FloatArray* texCoords = new osg::FloatArray; + for(osg::Vec4Array::iterator itr = _texCoords->begin(); + itr != _texCoords->end(); + ++itr) + { + texCoords->push_back(itr->x()); + } + _geometry->setTexCoordArray(0, texCoords); + } + if (_maxNumTexCoordComponents==2) + { + // convert Vec4Array into FloatArray + osg::Vec2Array* texCoords = new osg::Vec2Array; + for(osg::Vec4Array::iterator itr = _texCoords->begin(); + itr != _texCoords->end(); + ++itr) + { + texCoords->push_back(osg::Vec2(itr->x(),itr->y())); + } + _geometry->setTexCoordArray(0, texCoords); + } + if (_maxNumTexCoordComponents==3) + { + // convert Vec4Array into FloatArray + osg::Vec3Array* texCoords = new osg::Vec3Array; + for(osg::Vec4Array::iterator itr = _texCoords->begin(); + itr != _texCoords->end(); + ++itr) + { + texCoords->push_back(osg::Vec3(itr->x(),itr->y(), itr->z())); + } + _geometry->setTexCoordArray(0, texCoords); + } + else if (_maxNumTexCoordComponents==4) { _geometry->setTexCoordArray(0, _texCoords.get()); } @@ -305,8 +342,7 @@ void SceneGraphBuilder::gluCylinder(GLfloat aBase, GLint aSlices, GLint aStacks) { - osg::notify(osg::NOTICE)<<"SceneGraphBuilder::gluCylinder("<setAttribute(attribute); - - osg::notify(osg::NOTICE)<<"SceneGraphBuilder::addAttribute("<className()<<")"<setMode(mode, enabled ? osg::StateAttribute::ON : osg::StateAttribute::OFF); } @@ -392,23 +477,18 @@ void SceneGraphBuilder::addMode(GLenum mode, bool enabled) void SceneGraphBuilder::addTextureAttribute(unsigned int unit, osg::StateAttribute* attribute) { - osg::notify(osg::NOTICE)<<"SceneGraphBuilder::addAttribute("<className()<<")"<setTextureAttribute(unit, attribute); } void SceneGraphBuilder::addTextureMode(unsigned int unit, GLenum mode, bool enabled) { - osg::notify(osg::NOTICE)<<"SceneGraphBuilder::addTextureMode("<setTextureMode(unit, mode, enabled ? osg::StateAttribute::ON : osg::StateAttribute::OFF); } void SceneGraphBuilder::addShape(osg::Shape* shape) { - osg::notify(osg::NOTICE)<<"SceneGraphBuilder::addShape("<className()<setColor(_color); @@ -418,17 +498,22 @@ void SceneGraphBuilder::addShape(osg::Shape* shape) void SceneGraphBuilder::addDrawable(osg::Drawable* drawable) { if (!_geode) _geode = new osg::Geode; - + + if (_stateset.valid()) + { + drawable->setStateSet(_stateset.get()); + _statesetAssigned = true; + } + _geode->addDrawable(drawable); } void SceneGraphBuilder::allocateStateSet() { - if (_geometry.valid()) + if (_statesetAssigned) { - completeGeometry(); - - _stateset = 0; + _stateset = dynamic_cast(_stateset->clone(osg::CopyOp::SHALLOW_COPY)); + _statesetAssigned = false; } if (!_stateset) _stateset = new osg::StateSet;