From 43f0efd6d2757fe094d0b69ce74c71a5da9849fd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 2 May 2006 09:45:31 +0000 Subject: [PATCH] Reorganised the Group::removeChild and Geode::removeDrawable methods so that removeChild(Node*), removeChild(uint) and equivilant Geode methods are now inline methods, not designed to be overriden, and seperated out the multiple remove method to be called removeChildren(uint, uint) which is now the only virtual method. There removeChildren is now the method to override in subclasses. This reorganisation requires some call code to be rename removeChild usage to removeChildren. --- Make/makedefs | 1 + .../osgdepthpartition/DepthPartitionNode.cpp | 10 ++-- .../osgdepthpartition/DepthPartitionNode.h | 3 +- examples/osgfxbrowser/Frame.cpp | 2 +- examples/osgfxbrowser/osgfxbrowser.cpp | 4 +- examples/osgsimulation/osgsimulation.cpp | 40 ++++---------- include/osg/Geode | 2 +- include/osg/Group | 26 +++++++++- include/osg/LOD | 9 +--- include/osg/PagedLOD | 9 +--- include/osg/ProxyNode | 3 +- include/osg/Switch | 4 +- src/osg/Geode.cpp | 4 +- src/osg/Group.cpp | 7 +-- src/osg/LOD.cpp | 22 ++------ src/osg/PagedLOD.cpp | 35 ++----------- src/osg/ProxyNode.cpp | 12 ++--- src/osg/Switch.cpp | 20 ++----- src/osgParticle/ParticleEffect.cpp | 2 +- src/osgPlugins/ESRIShape/ESRIShapeParser.cpp | 2 +- src/osgPlugins/OpenFlight/GeometryRecords.cpp | 52 +++++++++++++------ src/osgPlugins/OpenFlight/PrimaryRecords.cpp | 22 ++++++-- .../OpenFlight/ReaderWriterATTR.cpp | 16 +++++- src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp | 20 +++++-- src/osgPlugins/lwo/Converter.cpp | 2 +- src/osgUtil/Optimizer.cpp | 4 +- src/osgUtil/SceneView.cpp | 2 +- 27 files changed, 160 insertions(+), 175 deletions(-) diff --git a/Make/makedefs b/Make/makedefs index da60963ff..df89dea0f 100644 --- a/Make/makedefs +++ b/Make/makedefs @@ -361,6 +361,7 @@ endif # DEF += `getconf LFS_CFLAGS` LIBS = -lstdc++ +# DEF += -W -Wall -fPIC -pipe -Woverloaded-virtual DEF += -W -Wall -fPIC -pipe OPTF = -O2 DBGF = -g -gstabs+ -DOSG_COMPILE_UNIT_TESTS diff --git a/examples/osgdepthpartition/DepthPartitionNode.cpp b/examples/osgdepthpartition/DepthPartitionNode.cpp index 3ffd472f8..7ee730a0b 100644 --- a/examples/osgdepthpartition/DepthPartitionNode.cpp +++ b/examples/osgdepthpartition/DepthPartitionNode.cpp @@ -156,20 +156,16 @@ bool CURRENT_CLASS::insertChild(unsigned int index, osg::Node *child) return true; } -bool CURRENT_CLASS::removeChild(osg::Node *child) -{ - return Group::removeChild(child); -} -bool CURRENT_CLASS::removeChild(unsigned int pos, unsigned int numRemove) +bool CURRENT_CLASS::removeChildren(unsigned int pos, unsigned int numRemove) { - if(!Group::removeChild(pos, numRemove)) return false; // Remove child + if(!Group::removeChildren(pos, numRemove)) return false; // Remove child // Remove child from each CameraNode unsigned int totalCameras = _cameraList.size(); for(unsigned int i = 0; i < totalCameras; i++) { - _cameraList[i]->removeChild(pos, numRemove); + _cameraList[i]->removeChildren(pos, numRemove); } return true; } diff --git a/examples/osgdepthpartition/DepthPartitionNode.h b/examples/osgdepthpartition/DepthPartitionNode.h index b414c2378..2e7f84ac3 100644 --- a/examples/osgdepthpartition/DepthPartitionNode.h +++ b/examples/osgdepthpartition/DepthPartitionNode.h @@ -52,8 +52,7 @@ class CURRENT_CLASS : public osg::Group of added or removed children. */ virtual bool addChild(osg::Node *child); virtual bool insertChild(unsigned int index, osg::Node *child); - virtual bool removeChild(osg::Node *child); - virtual bool removeChild(unsigned int pos, unsigned int numRemove = 1); + virtual bool removeChildren(unsigned int pos, unsigned int numRemove = 1); virtual bool setChild(unsigned int i, osg::Node *node); protected: diff --git a/examples/osgfxbrowser/Frame.cpp b/examples/osgfxbrowser/Frame.cpp index 236261368..0adc3d528 100644 --- a/examples/osgfxbrowser/Frame.cpp +++ b/examples/osgfxbrowser/Frame.cpp @@ -24,7 +24,7 @@ void Frame::rebuild() { float zPos = -0.1f; - removeDrawable(0, getNumDrawables()); + removeDrawables(0, getNumDrawables()); addDrawable(build_quad(rect_, bgcolor_)); addDrawable(build_quad(Rect(rect_.x0 + 4, rect_.y1 - 24, rect_.x1 - 4, rect_.y1 - 4), osg::Vec4(0, 0, 0, bgcolor_.w()), false, zPos)); diff --git a/examples/osgfxbrowser/osgfxbrowser.cpp b/examples/osgfxbrowser/osgfxbrowser.cpp index 877e10bcf..0fab1e55c 100644 --- a/examples/osgfxbrowser/osgfxbrowser.cpp +++ b/examples/osgfxbrowser/osgfxbrowser.cpp @@ -180,10 +180,10 @@ protected: effect_description += "DESCRIPTION:\n" + std::string(_effects[_selected_fx]->effectDescription()); if (_scene.valid() && _root.valid()) { - _root->removeChild(0, _root->getNumChildren()); + _root->removeChildren(0, _root->getNumChildren()); osg::ref_ptr effect = _effects[_selected_fx].get(); effect->setEnabled(_fxen); - effect->removeChild(0, effect->getNumChildren()); + effect->removeChildren(0, effect->getNumChildren()); effect->addChild(_scene.get()); effect->setUpDemo(); _root->addChild(effect.get()); diff --git a/examples/osgsimulation/osgsimulation.cpp b/examples/osgsimulation/osgsimulation.cpp index 278785dbc..c33f5694d 100644 --- a/examples/osgsimulation/osgsimulation.cpp +++ b/examples/osgsimulation/osgsimulation.cpp @@ -25,8 +25,6 @@ #include #include #include -#include -#include #include #include @@ -312,15 +310,11 @@ int main(int argc, char **argv) viewer.setSceneData(root.get()); osg::CoordinateSystemNode* csn = dynamic_cast(root.get()); - osg::Group * overlaySubGraph = new osg::Group; if (csn) { bool insertOverlayNode = true; osg::ref_ptr overlayNode; - osg::Node* cessna = osgDB::readNodeFile("cessna.osg"); - double s = 200000.0 / cessna->getBound().radius(); - if (insertOverlayNode) { @@ -331,34 +325,21 @@ int main(int argc, char **argv) { overlayNode->addChild( csn->getChild(i) ); } - csn->removeChild(0, csn->getNumChildren()); + + csn->removeChildren(0, csn->getNumChildren()); csn->addChild(overlayNode.get()); - - osg::ref_ptr polymode = new osg::PolygonMode; - polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE); - osg::NodeCallback* sphereCb = new ModelPositionCallback; - osg::ref_ptr mt = new osg::MatrixTransform; - mt->setUpdateCallback(sphereCb); - - osg::ref_ptr geode = new osg::Geode; - osg::ref_ptr sd; - sd = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),s)); - sd->setColor(osg::Vec4(1.0,0.0,0.0,1.0)); - geode->addDrawable(sd.get()); - - mt->addChild(geode.get()); - overlaySubGraph->addChild(mt.get()); - geode->getOrCreateStateSet()->setAttributeAndModes(polymode.get(), osg::StateAttribute::ON); // tell the overlay node to continously update its overlay texture // as we know we'll be tracking a moving target. overlayNode->setContinuousUpdate(true); } - //osg::Node* cessna = osgDB::readNodeFile("f15.ive"); + osg::Node* cessna = osgDB::readNodeFile("cessna.osg"); if (cessna) { + double s = 200000.0 / cessna->getBound().radius(); + osg::MatrixTransform* scaler = new osg::MatrixTransform; scaler->addChild(cessna); scaler->setMatrix(osg::Matrixd::scale(s,s,s)*osg::Matrixd::rotate(rotation)); @@ -367,15 +348,18 @@ int main(int argc, char **argv) osg::MatrixTransform* mt = new osg::MatrixTransform; mt->addChild(scaler); + if (!nc) nc = new ModelPositionCallback; mt->setUpdateCallback(nc); csn->addChild(mt); - - // if (overlaySubGraph) overlaySubGraph->addChild(mt); // if we are using an overaly node, use the cessna subgraph as the overlay subgraph + if (overlayNode.valid()) + { + overlayNode->setOverlaySubgraph(mt); + } osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator; tm->setTrackerMode(trackerMode); @@ -390,10 +374,6 @@ int main(int argc, char **argv) std::cout<<"Failed to read cessna.osg"<setOverlaySubgraph(overlaySubGraph); - } } diff --git a/include/osg/Geode b/include/osg/Geode index f1d1b332d..66a7b171e 100644 --- a/include/osg/Geode +++ b/include/osg/Geode @@ -65,7 +65,7 @@ class OSG_EXPORT Geode : public Node * @return \c true if at least one \c Drawable was removed. \c false * otherwise. */ - virtual bool removeDrawable(unsigned int i,unsigned int numDrawablesToRemove=1); + virtual bool removeDrawables(unsigned int i,unsigned int numDrawablesToRemove=1); /** Replace specified Drawable with another Drawable. * Equivalent to setDrawable(getDrawableIndex(origDraw),newDraw), diff --git a/include/osg/Group b/include/osg/Group index 76aade8a6..1b9c9edef 100644 --- a/include/osg/Group +++ b/include/osg/Group @@ -63,10 +63,32 @@ class OSG_EXPORT Group : public Node * bounding sphere to force it to recompute on next getBound() and * return true for success. If Node is not found then return false * and do not change the reference count of the Node. + * Note, do not override, only override removeChildren(,) is required. */ - virtual bool removeChild( Node *child ); + inline bool removeChild( Node *child ) + { + unsigned int pos = getChildIndex(child); + if (pos<_children.size()) return removeChildren(pos,1); + else return false; + } - virtual bool removeChild(unsigned int pos,unsigned int numChildrenToRemove=1); + /** Remove Node from Group. + * If Node is contained in Group then remove it from the child + * list, decrement its reference count, and dirty the + * bounding sphere to force it to recompute on next getBound() and + * return true for success. If Node is not found then return false + * and do not change the reference count of the Node. + * Note, do not override, only override removeChildren(,) is required. + */ + inline bool removeChild( unsigned int pos ) + { + if (pos<_children.size()) return removeChildren(pos,1); + else return false; + } + + /** Remove children from Group. + * Note, must be override by subclasses of Group which add per child attributes.*/ + virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove); /** Replace specified Node with another Node. * Equivalent to setChild(getChildIndex(orignChild),node) diff --git a/include/osg/LOD b/include/osg/LOD index 7dda09c9f..ad1c014b5 100644 --- a/include/osg/LOD +++ b/include/osg/LOD @@ -49,8 +49,7 @@ class OSG_EXPORT LOD : public Group virtual bool addChild(Node *child, float min, float max); - virtual bool removeChild(Node *child); - + virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove=1); typedef std::pair MinMaxPair; typedef std::vector RangeList; @@ -124,12 +123,6 @@ class OSG_EXPORT LOD : public Group protected : virtual ~LOD() {} - virtual void childRemoved(unsigned int pos, unsigned int numChildrenToRemove); - virtual void childInserted(unsigned int pos); - - virtual void rangeRemoved(unsigned int /*pos*/, unsigned int /*numChildrenToRemove*/) {} - virtual void rangeInserted(unsigned int /*pos*/) {} - CenterMode _centerMode; Vec3 _userDefinedCenter; float _radius; diff --git a/include/osg/PagedLOD b/include/osg/PagedLOD index 2ad50bf1c..1fa5fbb2a 100644 --- a/include/osg/PagedLOD +++ b/include/osg/PagedLOD @@ -41,11 +41,10 @@ class OSG_EXPORT PagedLOD : public LOD virtual bool addChild(Node *child, float min, float max,const std::string& filename, float priorityOffset=0.0f, float priorityScale=1.0f); - virtual bool removeChild(Node *child); + virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove=1); - /** Set the database path to prepend to children's filenames.*/ void setDatabasePath(const std::string& path); @@ -112,12 +111,6 @@ class OSG_EXPORT PagedLOD : public LOD protected : virtual ~PagedLOD() {} - - virtual void childRemoved(unsigned int pos, unsigned int numChildrenToRemove); - virtual void childInserted(unsigned int pos); - - virtual void rangeRemoved(unsigned int pos, unsigned int numChildrenToRemove); - virtual void rangeInserted(unsigned int pos); void expandPerRangeDataTo(unsigned int pos); diff --git a/include/osg/ProxyNode b/include/osg/ProxyNode index 20f42f032..81f428c66 100644 --- a/include/osg/ProxyNode +++ b/include/osg/ProxyNode @@ -35,7 +35,8 @@ class OSG_EXPORT ProxyNode : public Group virtual bool addChild(Node *child); virtual bool addChild(Node *child, const std::string& filename); - virtual bool removeChild(Node *child); + + virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove); /** Set the database path to prepend to children's filenames.*/ void setDatabasePath(const std::string& path); diff --git a/include/osg/Switch b/include/osg/Switch index 017663c04..9e0a7d9f9 100644 --- a/include/osg/Switch +++ b/include/osg/Switch @@ -49,9 +49,7 @@ class OSG_EXPORT Switch : public Group virtual bool insertChild( unsigned int index, Node *child, bool value ); - virtual bool removeChild( Node *child ); - - virtual bool removeChild(unsigned int pos,unsigned int numChildrenToRemove=1); + virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove); void setValue(unsigned int pos,bool value); diff --git a/src/osg/Geode.cpp b/src/osg/Geode.cpp index 137d4fa72..436b437c3 100644 --- a/src/osg/Geode.cpp +++ b/src/osg/Geode.cpp @@ -77,10 +77,10 @@ bool Geode::addDrawable( Drawable *drawable ) bool Geode::removeDrawable( Drawable *drawable ) { - return removeDrawable(getDrawableIndex(drawable)); + return removeDrawables(getDrawableIndex(drawable),1); } -bool Geode::removeDrawable(unsigned int pos,unsigned int numDrawablesToRemove) +bool Geode::removeDrawables(unsigned int pos,unsigned int numDrawablesToRemove) { if (pos<_drawables.size() && numDrawablesToRemove>0) { diff --git a/src/osg/Group.cpp b/src/osg/Group.cpp index 6ccc22d50..bd1bb9f6d 100644 --- a/src/osg/Group.cpp +++ b/src/osg/Group.cpp @@ -144,12 +144,7 @@ bool Group::insertChild( unsigned int index, Node *child ) else return false; } -bool Group::removeChild( Node *child ) -{ - return removeChild(getChildIndex(child)); -} - -bool Group::removeChild(unsigned int pos,unsigned int numChildrenToRemove) +bool Group::removeChildren(unsigned int pos,unsigned int numChildrenToRemove) { if (pos<_children.size() && numChildrenToRemove>0) { diff --git a/src/osg/LOD.cpp b/src/osg/LOD.cpp index 0d3111b1d..7fb4fe4c6 100644 --- a/src/osg/LOD.cpp +++ b/src/osg/LOD.cpp @@ -113,16 +113,6 @@ bool LOD::addChild( Node *child ) return false; } -void LOD::childRemoved(unsigned int /*pos*/, unsigned int /*numChildrenToRemove*/) -{ - //std::cout<<"LOD::childRemoved("<=_perRangeDataList.size()) _perRangeDataList.resize(pos+1); @@ -267,16 +246,12 @@ bool PagedLOD::addChild(Node *child, float min, float max,const std::string& fil return false; } -bool PagedLOD::removeChild( Node *child ) +bool PagedLOD::removeChildren( unsigned int pos,unsigned int numChildrenToRemove) { - // find the child's position. - unsigned int pos=getChildIndex(child); - if (pos==_children.size()) return false; - - if (pos<_rangeList.size()) _rangeList.erase(_rangeList.begin()+pos); - if (pos<_perRangeDataList.size()) _perRangeDataList.erase(_perRangeDataList.begin()+pos); - - return Group::removeChild(child); + if (pos<_rangeList.size()) _rangeList.erase(_rangeList.begin()+pos, osg::minimum(_rangeList.begin()+(pos+numChildrenToRemove), _rangeList.end()) ); + if (pos<_perRangeDataList.size()) _perRangeDataList.erase(_perRangeDataList.begin()+pos, osg::minimum(_perRangeDataList.begin()+ (pos+numChildrenToRemove), _perRangeDataList.end()) ); + + return Group::removeChildren(pos,numChildrenToRemove); } bool PagedLOD::removeExpiredChildren(double expiryTime,NodeList& removedChildren) diff --git a/src/osg/ProxyNode.cpp b/src/osg/ProxyNode.cpp index 8e4951881..1a061aa78 100644 --- a/src/osg/ProxyNode.cpp +++ b/src/osg/ProxyNode.cpp @@ -92,15 +92,11 @@ bool ProxyNode::addChild(Node *child, const std::string& filename) return false; } -bool ProxyNode::removeChild( Node *child ) +bool ProxyNode::removeChildren(unsigned int pos,unsigned int numChildrenToRemove) { - // find the child's position. - unsigned int pos=getChildIndex(child); - if (pos==_children.size()) return false; - - if (pos<_filenameList.size()) _filenameList.erase(_filenameList.begin()+pos); - - return Group::removeChild(child); + if (pos<_filenameList.size()) _filenameList.erase(_filenameList.begin()+pos, osg::minimum(_filenameList.begin()+(pos+numChildrenToRemove), _filenameList.end()) ); + + return Group::removeChildren(pos,numChildrenToRemove); } BoundingSphere ProxyNode::computeBound() const diff --git a/src/osg/Switch.cpp b/src/osg/Switch.cpp index dbc703509..a20471e0e 100644 --- a/src/osg/Switch.cpp +++ b/src/osg/Switch.cpp @@ -99,25 +99,11 @@ bool Switch::insertChild( unsigned int index, Node *child, bool value ) return false; } -bool Switch::removeChild( Node *child ) +bool Switch::removeChildren(unsigned int pos,unsigned int numChildrenToRemove) { - return removeChild( getChildIndex(child) ); -} + if (pos<_values.size()) _values.erase(_values.begin()+pos, osg::minimum(_values.begin()+(pos+numChildrenToRemove), _values.end()) ); -bool Switch::removeChild(unsigned int pos,unsigned int numChildrenToRemove) -{ - if (pos>=_values.size() || numChildrenToRemove==0) return false; - - unsigned int endOfRemoveRange = pos+numChildrenToRemove; - if (endOfRemoveRange>_values.size()) - { - notify(DEBUG_INFO)<<"Warning: Switch::removeChild(i,numChildrenToRemove) has been passed an excessive number"<removeDrawable( 0, numDrawables ); + _geode->removeDrawables( 0, numDrawables ); osg::ref_ptr geometry = new osg::Geometry; geometry->setVertexArray(coords.get()); diff --git a/src/osgPlugins/OpenFlight/GeometryRecords.cpp b/src/osgPlugins/OpenFlight/GeometryRecords.cpp index ce0a0b173..9bb85b5fd 100644 --- a/src/osgPlugins/OpenFlight/GeometryRecords.cpp +++ b/src/osgPlugins/OpenFlight/GeometryRecords.cpp @@ -12,16 +12,14 @@ #include #include #include -#include #include -#include -#include #include "Registry.h" #include "Document.h" #include "RecordInputStream.h" namespace flt { + class Face : public PrimaryRecord { // flags @@ -134,9 +132,9 @@ public: virtual osg::Vec4 getPrimaryColor() const { return _primaryColor; } inline int getMaterialIndex() const { return _materialIndex; } - inline int getTextureIndex() const { return _textureIndex; } - inline int getTextureMappingIndex() const { return _textureMappingIndex; } - inline float getTransparency() const { return (float)_transparency / 65535.0f; } + inline int getTextureIndex() const { return _textureIndex; } + inline int getTextureMappingIndex() const { return _textureMappingIndex; } + inline float getTransparency() const { return (float)_transparency / 65535.0f; } inline bool isTransparent() const { return _transparency > 0; } virtual void addChild(osg::Node& child) @@ -284,7 +282,7 @@ protected: _geode->addDrawable(_geometry.get()); // StateSet - osg::StateSet* stateset = _geode->getOrCreateStateSet(); + osg::ref_ptr stateset = new osg::StateSet; // Hidden if (isHidden()) @@ -362,7 +360,8 @@ protected: // Enable alpha blend? if (isAlphaBlend() || isTransparent() || isTransparentMaterial || isImageTranslucent) { - stateset->setAttributeAndModes(new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA), osg::StateAttribute::ON); + static osg::ref_ptr blendFunc = new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA); + stateset->setAttributeAndModes(blendFunc.get(), osg::StateAttribute::ON); stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); } @@ -370,8 +369,11 @@ protected: switch(_drawFlag) { case SOLID_BACKFACED: // Enable backface culling - stateset->setAttributeAndModes(new osg::CullFace(osg::CullFace::BACK), osg::StateAttribute::ON); + { + static osg::ref_ptr cullFace = new osg::CullFace(osg::CullFace::BACK); + stateset->setAttributeAndModes(cullFace.get(), osg::StateAttribute::ON); break; + } case SOLID_NO_BACKFACE: // Disable backface culling stateset->setMode(GL_CULL_FACE,osg::StateAttribute::OFF); break; @@ -380,17 +382,23 @@ protected: // Subface if (document.subfaceLevel() > 0) { - osg::PolygonOffset* polyoffset = new osg::PolygonOffset; - polyoffset->setFactor(-10.0f); - polyoffset->setUnits(-40.0f); - stateset->setAttributeAndModes(polyoffset, osg::StateAttribute::ON); + static osg::ref_ptr polygonOffset = new osg::PolygonOffset(-10.0f, -40.0f); + stateset->setAttributeAndModes(polygonOffset.get(), osg::StateAttribute::ON); - osg::Depth* depth = new osg::Depth; - depth->setWriteMask(false); - stateset->setAttribute(depth); + static osg::ref_ptr depth = new osg::Depth(osg::Depth::LESS, 0.0, 1.0,false); + stateset->setAttribute(depth.get()); stateset->setRenderBinDetails(document.subfaceLevel(),"RenderBin"); } +#if 1 + // A simple share stateset optimization. + static osg::ref_ptr lastStateset; + if (lastStateset.valid() && (stateset->compare(*lastStateset,false)==0)) + stateset = lastStateset; + else + lastStateset = stateset; +#endif + _geode->setStateSet(stateset.get()); // Add to parent. if (_parent.valid()) @@ -623,3 +631,15 @@ protected: RegisterRecordProxy g_MorphVertexList(MORPH_VERTEX_LIST_OP); } // end namespace + + + + + + + + + + + + diff --git a/src/osgPlugins/OpenFlight/PrimaryRecords.cpp b/src/osgPlugins/OpenFlight/PrimaryRecords.cpp index a1dc76eff..7e4919d07 100644 --- a/src/osgPlugins/OpenFlight/PrimaryRecords.cpp +++ b/src/osgPlugins/OpenFlight/PrimaryRecords.cpp @@ -128,9 +128,13 @@ protected: // Flat shaded? if (flags & FLAT_SHADED) { - osg::ShadeModel* shademodel = new osg::ShadeModel; - shademodel->setMode(osg::ShadeModel::FLAT); - _object->getOrCreateStateSet()->setAttribute(shademodel); + static osg::ref_ptr shademodel; + if (!shademodel.valid()) + { + shademodel = new osg::ShadeModel; + shademodel->setMode(osg::ShadeModel::FLAT); + } + _object->getOrCreateStateSet()->setAttribute(shademodel.get()); } if (_parent.valid()) @@ -745,3 +749,15 @@ RegisterRecordProxy g_Extension(EXTENSION_OP); } // end namespace + + + + + + + + + + + + diff --git a/src/osgPlugins/OpenFlight/ReaderWriterATTR.cpp b/src/osgPlugins/OpenFlight/ReaderWriterATTR.cpp index e64318c74..49054a367 100644 --- a/src/osgPlugins/OpenFlight/ReaderWriterATTR.cpp +++ b/src/osgPlugins/OpenFlight/ReaderWriterATTR.cpp @@ -47,7 +47,9 @@ ReaderWriter::ReadResult ReaderWriterATTR::readObject(const std::string& file, c std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - std::ifstream fin(fileName.c_str(), ios::in | ios::binary); + std::ifstream fin; + fin.imbue(std::locale::classic()); + fin.open(fileName.c_str(), std::ios::in | std::ios::binary); if ( fin.fail()) return ReadResult::ERROR_IN_READING_FILE; @@ -175,3 +177,15 @@ ReaderWriter::ReadResult ReaderWriterATTR::readObject(const std::string& file, c // now register with Registry to instantiate the above // reader/writer. osgDB::RegisterReaderWriterProxy g_readerWriter_ATTR_Proxy; + + + + + + + + + + + + diff --git a/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp b/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp index f410862d5..a3cb46a0d 100644 --- a/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp +++ b/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp @@ -53,9 +53,11 @@ class FLTReaderWriter : public ReaderWriter // code for setting up the database path so that internally referenced file are searched for on relative paths. osg::ref_ptr local_opt = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; local_opt->setDatabasePath(osgDB::getFilePath(fileName)); -// local_opt->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_ALL); - - std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); + + std::ifstream istream; + istream.imbue(std::locale::classic()); + istream.open(fileName.c_str(), std::ios::in | std::ios::binary); + return readNode(istream,local_opt.get()); } @@ -185,3 +187,15 @@ class FLTReaderWriter : public ReaderWriter // now register with Registry to instantiate the above // reader/writer. RegisterReaderWriterProxy g_FLTReaderWriterProxy; + + + + + + + + + + + + diff --git a/src/osgPlugins/lwo/Converter.cpp b/src/osgPlugins/lwo/Converter.cpp index f950291ef..51b3365cf 100644 --- a/src/osgPlugins/lwo/Converter.cpp +++ b/src/osgPlugins/lwo/Converter.cpp @@ -54,7 +54,7 @@ Converter::Converter(const Options &options, const osgDB::ReaderWriter::Options* osg::Group *Converter::convert(Object &obj) { if (root_->getNumChildren() > 0) { - root_->removeChild(0, root_->getNumChildren()); + root_->removeChildren(0, root_->getNumChildren()); } osg::notify(osg::INFO) << "INFO: lwosg::Converter: flattening per-polygon vertex maps\n"; diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index b1b397b2c..bb55a9888 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -1175,7 +1175,7 @@ void Optimizer::RemoveEmptyNodesVisitor::apply(osg::Geode& geode) osg::Geometry* geom = geode.getDrawable(i)->asGeometry(); if (geom && geom->empty() && isOperationPermissibleForObject(geom)) { - geode.removeDrawable(i); + geode.removeDrawables(i,1); } } @@ -2328,7 +2328,7 @@ bool Optimizer::SpatializeGroupsVisitor::divide(osg::Group* group, unsigned int // first removing from the original group, - group->removeChild(0,group->getNumChildren()); + group->removeChildren(0,group->getNumChildren()); // add in the bb groups typedef std::vector< osg::ref_ptr > GroupList; diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index c6e6977ab..d0c4c236d 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -226,7 +226,7 @@ void SceneView::setSceneData(osg::Node* node) osg::ref_ptr temporaryRefernce = node; // remove pre existing children - _camera->removeChild(0, _camera->getNumChildren()); + _camera->removeChildren(0, _camera->getNumChildren()); // add the new one in. _camera->addChild(node);