diff --git a/include/osg/Geode b/include/osg/Geode index 83af40f13..76ec55a67 100644 --- a/include/osg/Geode +++ b/include/osg/Geode @@ -34,13 +34,13 @@ class SG_EXPORT Geode : public Node virtual bool addDrawable( Drawable *drawable ); /** Remove Drawable from Geode. - * Equivalent to setDrawabke(findDrawableNum(orignChild),node), + * Equivalent to setDrawabke(getDrawableIndex(orignChild),node), * see docs for setNode for futher details on implementation.*/ virtual bool removeDrawable( Drawable *drawable ); /** Replace specified Drawable with another Drawable. - * Equivalent to setDrawable(findDrawableNum(orignChild),node), + * Equivalent to setDrawable(getDrawableIndex(orignChild),node), * see docs for setDrawable for futher details on implementation.*/ virtual bool replaceDrawable( Drawable *origDraw, Drawable *newDraw ); @@ -107,10 +107,10 @@ class SG_EXPORT Geode : public Node return _drawables.end(); } - /** Find the index number of drawable, return a value between + /** Get the index number of drawable, return a value between * 0 and _drawables.size()-1 if found, if not found then * return _drawables.size().*/ - inline unsigned int findDrawableNum( const Drawable* node ) const + inline unsigned int getDrawableIndex( const Drawable* node ) const { for (unsigned int drawableNum=0;drawableNum<_drawables.size();++drawableNum) { diff --git a/include/osg/Geometry b/include/osg/Geometry index 3e71de8c1..c3702cc2b 100644 --- a/include/osg/Geometry +++ b/include/osg/Geometry @@ -128,7 +128,22 @@ class SG_EXPORT Geometry : public Drawable PrimitiveSet* getPrimitiveSet(unsigned int pos) { return _primitives[pos].get(); } const PrimitiveSet* getPrimitiveSet(unsigned int pos) const { return _primitives[pos].get(); } - void addPrimitiveSet(PrimitiveSet* primitive) { if (primitive) _primitives.push_back(primitive); dirtyDisplayList(); dirtyBound(); } + /** Add a primtive set to the geometry.*/ + bool addPrimitiveSet(PrimitiveSet* primitiveset); + + /** Set a primtive set to the specified position in geometry's primtive set list.*/ + bool setPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset); + + /** Insert a primtive set to the specified position in geometry's primtive set list.*/ + bool insertPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset); + + /** Remove primtive set(s) from the specified position in geometry's primtive set list.*/ + bool removePrimitiveSet(unsigned int i,unsigned int numElementsToRemove=1); + + /** Get the index number of a primitive set, return a value between + * 0 and getNumPrimitiveSet()-1 if found, if not found then return getNumPrimitiveSet(). + * When checking for a valid find value use if ((value=geoemtry->getPrimitiveSetIndex(primitive))!=geometry.getNumPrimitiveSet()) as*/ + unsigned int getPrimitiveSetIndex(const PrimitiveSet* primitiveset) const; /** return true if OpenGL fast paths will be used with drawing this Geometry. diff --git a/include/osg/Group b/include/osg/Group index 164746e3a..dc6f76403 100644 --- a/include/osg/Group +++ b/include/osg/Group @@ -50,7 +50,7 @@ class SG_EXPORT Group : public Node virtual bool removeChild( Node *child ); /** Replace specified Node with another Node. - * Equivalent to setChild(findChildNum(orignChild),node), + * Equivalent to setChild(getChildIndex(orignChild),node), * see docs for setChild for futher details on implementation.*/ virtual bool replaceChild( Node *origChild, Node* newChild ); @@ -116,10 +116,10 @@ class SG_EXPORT Group : public Node return _children.end(); } - /** Find the index number of child, return a value between + /** Get the index number of child, return a value between * 0 and _children.size()-1 if found, if not found then * return _children.size().*/ - inline unsigned int findChildNum( const Node* node ) const + inline unsigned int getChildIndex( const Node* node ) const { for (unsigned int childNum=0;childNum<_children.size();++childNum) { diff --git a/src/osg/Geode.cpp b/src/osg/Geode.cpp index 9e39957e4..94c4c108c 100644 --- a/src/osg/Geode.cpp +++ b/src/osg/Geode.cpp @@ -84,7 +84,7 @@ bool Geode::replaceDrawable( Drawable *origDrawable, Drawable *newDrawable ) { if (newDrawable==NULL || origDrawable==newDrawable) return false; - unsigned int pos = findDrawableNum(origDrawable); + unsigned int pos = getDrawableIndex(origDrawable); if (pos<_drawables.size()) { return setDrawable(pos,newDrawable); diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index df46b67ae..50b3be28d 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -269,6 +269,86 @@ const IndexArray* Geometry::getTexCoordIndices(unsigned int unit) const else return 0; } +bool Geometry::addPrimitiveSet(PrimitiveSet* primitiveset) +{ + if (primitiveset) + { + _primitives.push_back(primitiveset); + dirtyDisplayList(); + dirtyBound(); + return true; + } + notify(WARN)<<"Warning: invalid index i or primitiveset passed to osg::Geometry::addPrimitiveSet(i,primitiveset), ignoring call."<0) + { + if (i+numElementsToRemove<_primitives.size()) + { + _primitives.erase(_primitives.begin()+i,_primitives.begin()+i+numElementsToRemove); + } + else + { + // asking to delete too many elements, report a warning, and delete to + // the end of the primitive list. + notify(WARN)<<"Warning: osg::Geometry::removePrimitiveSet(i,numElementsToRemove) has been asked to remove more elements than are available,"<