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.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -113,16 +113,6 @@ bool LOD::addChild( Node *child )
|
||||
return false;
|
||||
}
|
||||
|
||||
void LOD::childRemoved(unsigned int /*pos*/, unsigned int /*numChildrenToRemove*/)
|
||||
{
|
||||
//std::cout<<"LOD::childRemoved("<<pos<<","<<numChildrenToRemove<<")"<<std::endl;
|
||||
}
|
||||
|
||||
void LOD::childInserted(unsigned int /*pos*/)
|
||||
{
|
||||
//std::cout<<"LOD::childInserted("<<pos<<")"<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
bool LOD::addChild(Node *child, float min, float max)
|
||||
{
|
||||
@@ -136,15 +126,11 @@ bool LOD::addChild(Node *child, float min, float max)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LOD::removeChild( Node *child )
|
||||
bool LOD::removeChildren( unsigned int pos,unsigned int numChildrenToRemove)
|
||||
{
|
||||
// find the child's position.
|
||||
unsigned int pos=getChildIndex(child);
|
||||
if (pos==_children.size()) return false;
|
||||
|
||||
_rangeList.erase(_rangeList.begin()+pos);
|
||||
|
||||
return Group::removeChild(child);
|
||||
if (pos<_rangeList.size()) _rangeList.erase(_rangeList.begin()+pos, osg::minimum(_rangeList.begin()+(pos+numChildrenToRemove), _rangeList.end()) );
|
||||
|
||||
return Group::removeChildren(pos,numChildrenToRemove);
|
||||
}
|
||||
|
||||
void LOD::setRange(unsigned int childNo, float min,float max)
|
||||
|
||||
@@ -208,27 +208,6 @@ void PagedLOD::traverse(NodeVisitor& nv)
|
||||
}
|
||||
|
||||
|
||||
void PagedLOD::childRemoved(unsigned int pos, unsigned int numChildrenToRemove)
|
||||
{
|
||||
LOD::childRemoved(pos, numChildrenToRemove);
|
||||
}
|
||||
|
||||
void PagedLOD::childInserted(unsigned int pos)
|
||||
{
|
||||
LOD::childInserted(pos);
|
||||
}
|
||||
|
||||
void PagedLOD::rangeRemoved(unsigned int pos, unsigned int numChildrenToRemove)
|
||||
{
|
||||
LOD::rangeRemoved(pos, numChildrenToRemove);
|
||||
}
|
||||
|
||||
void PagedLOD::rangeInserted(unsigned int pos)
|
||||
{
|
||||
LOD::rangeInserted(pos);
|
||||
expandPerRangeDataTo(pos);
|
||||
}
|
||||
|
||||
void PagedLOD::expandPerRangeDataTo(unsigned int pos)
|
||||
{
|
||||
if (pos>=_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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"<<std::endl;
|
||||
notify(DEBUG_INFO)<<" of chilren to remove, trimming just to end of value list."<<std::endl;
|
||||
endOfRemoveRange=_values.size();
|
||||
}
|
||||
_values.erase(_values.begin()+pos,_values.begin()+endOfRemoveRange);
|
||||
|
||||
return Group::removeChild(pos, numChildrenToRemove);
|
||||
return Group::removeChildren(pos,numChildrenToRemove);
|
||||
}
|
||||
|
||||
void Switch::setValue(unsigned int pos,bool value)
|
||||
|
||||
@@ -150,7 +150,7 @@ void ParticleEffect::buildEffect()
|
||||
|
||||
|
||||
// clear the children.
|
||||
removeChild(0,getNumChildren());
|
||||
removeChildren(0,getNumChildren());
|
||||
|
||||
// add the emitter
|
||||
addChild(emitter.get());
|
||||
|
||||
@@ -219,7 +219,7 @@ void ESRIShapeParser::_combinePointToMultipoint()
|
||||
}
|
||||
}
|
||||
|
||||
_geode->removeDrawable( 0, numDrawables );
|
||||
_geode->removeDrawables( 0, numDrawables );
|
||||
|
||||
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
|
||||
geometry->setVertexArray(coords.get());
|
||||
|
||||
@@ -12,16 +12,14 @@
|
||||
#include <osg/CullFace>
|
||||
#include <osg/PolygonOffset>
|
||||
#include <osg/Depth>
|
||||
#include <osg/ShadeModel>
|
||||
#include <osg/BlendFunc>
|
||||
#include <osgUtil/Tesselator>
|
||||
#include <osgUtil/SmoothingVisitor>
|
||||
#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<osg::StateSet> 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<osg::BlendFunc> 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<osg::CullFace> 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<osg::PolygonOffset> 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<osg::Depth> 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<osg::StateSet> 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<MorphVertexList> g_MorphVertexList(MORPH_VERTEX_LIST_OP);
|
||||
|
||||
} // end namespace
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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<osg::ShadeModel> 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<Extension> g_Extension(EXTENSION_OP);
|
||||
|
||||
|
||||
} // end namespace
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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<ReaderWriterATTR> g_readerWriter_ATTR_Proxy;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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<Options> local_opt = options ? static_cast<Options*>(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<FLTReaderWriter> g_FLTReaderWriterProxy;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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<osg::Group> > GroupList;
|
||||
|
||||
@@ -226,7 +226,7 @@ void SceneView::setSceneData(osg::Node* node)
|
||||
osg::ref_ptr<osg::Node> temporaryRefernce = node;
|
||||
|
||||
// remove pre existing children
|
||||
_camera->removeChild(0, _camera->getNumChildren());
|
||||
_camera->removeChildren(0, _camera->getNumChildren());
|
||||
|
||||
// add the new one in.
|
||||
_camera->addChild(node);
|
||||
|
||||
Reference in New Issue
Block a user