From Marco, updates to osgDB and .osg plugin to better handle reading of

objects of specified types.
This commit is contained in:
Robert Osfield
2003-07-21 18:36:47 +00:00
parent 40e38a1645
commit aa8b552ca6
10 changed files with 66 additions and 34 deletions

View File

@@ -100,7 +100,8 @@ class ReaderWriter3DC : public osgDB::ReaderWriter
if (vertices->size()>=targetNumVertices)
{
// finishing setting up the current geometry and add it to the geode.
geometry->setUseDisplayList(false);
geometry->setUseDisplayList(true);
geometry->setUseVertexBufferObjects(true);
geometry->setVertexArray(vertices);
geometry->setNormalArray(normals);
geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
@@ -133,7 +134,8 @@ class ReaderWriter3DC : public osgDB::ReaderWriter
}
geometry->setUseDisplayList(false);
geometry->setUseDisplayList(true);
geometry->setUseVertexBufferObjects(true);
geometry->setVertexArray(vertices);
geometry->setNormalArray(normals);
geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);

View File

@@ -35,15 +35,11 @@ bool Drawable_readLocalData(Object& obj, Input& fr)
iteratorAdvanced = true;
}
ref_ptr<Object> readObject = fr.readObject();
if (readObject.valid())
{
osg::Shape* shape = dynamic_cast<osg::Shape*>(readObject.get());
if (shape) drawable.setShape(shape);
else notify(WARN)<<"Warning:: "<<readObject->className()<<" loaded but cannot not be attached to Drawable."<<std::endl;
iteratorAdvanced = true;
}
Shape* shape = static_cast<Shape *>(fr.readObjectOfType(type_wrapper<Shape>()));
if (shape) {
drawable.setShape(shape);
iteratorAdvanced = true;
}
if (fr[0].matchWord("supportsDisplayList"))
{

View File

@@ -502,11 +502,10 @@ bool CompositeShape_readLocalData(Object& obj, Input& fr)
}
}
while((readObject=fr.readObject()).valid())
while((readObject=fr.readObjectOfType(type_wrapper<osg::Shape>())).valid())
{
osg::Shape* shape = dynamic_cast<osg::Shape*>(readObject.get());
if (shape) composite.addChild(shape);
else notify(WARN)<<"Warning:: "<<readObject->className()<<" loaded but cannot not be attached to Drawable."<<std::endl;
osg::Shape* shape = static_cast<osg::Shape*>(readObject.get());
composite.addChild(shape);
iteratorAdvanced = true;
}

View File

@@ -42,13 +42,10 @@ bool ShapeDrawable_readLocalData(Object& obj, Input& fr)
iteratorAdvanced = true;
}
ref_ptr<Object> readObject = fr.readObject();
ref_ptr<Object> readObject = fr.readObjectOfType(type_wrapper<TessellationHints>());
if (readObject.valid()) {
TessellationHints* hints = dynamic_cast<TessellationHints*>(readObject.get());
if (hints)
geom.setTessellationHints(hints);
else
notify(WARN) << "Warning: " << readObject->className() << " loaded but cannot be attached to ShapeDrawable.\n";
TessellationHints* hints = static_cast<TessellationHints*>(readObject.get());
geom.setTessellationHints(hints);
iteratorAdvanced = true;
}

View File

@@ -25,23 +25,19 @@ bool ModularEmitter_readLocalData(osg::Object &obj, osgDB::Input &fr)
osgParticle::ModularEmitter &myobj = static_cast<osgParticle::ModularEmitter &>(obj);
bool itAdvanced = false;
// we cannot use readObjectOfType() because the Coutner, Placer and Shooter classes are
// abstract and we can't create instances to use as prototypes.
// So, we call readObject() and then dynamic cast to the desired class.
osgParticle::Counter *counter = dynamic_cast<osgParticle::Counter *>(fr.readObject());
osgParticle::Counter *counter = static_cast<osgParticle::Counter *>(fr.readObjectOfType(osgDB::type_wrapper<osgParticle::Counter>()));
if (counter) {
myobj.setCounter(counter);
itAdvanced = true;
}
osgParticle::Placer *placer = dynamic_cast<osgParticle::Placer *>(fr.readObject());
osgParticle::Placer *placer = static_cast<osgParticle::Placer *>(fr.readObjectOfType(osgDB::type_wrapper<osgParticle::Placer>()));
if (placer) {
myobj.setPlacer(placer);
itAdvanced = true;
}
osgParticle::Shooter *shooter = dynamic_cast<osgParticle::Shooter *>(fr.readObject());
osgParticle::Shooter *shooter = static_cast<osgParticle::Shooter *>(fr.readObjectOfType(osgDB::type_wrapper<osgParticle::Shooter>()));
if (shooter) {
myobj.setShooter(shooter);
itAdvanced = true;

View File

@@ -25,7 +25,7 @@ bool ModularProgram_readLocalData(osg::Object &obj, osgDB::Input &fr)
osgParticle::ModularProgram &myobj = static_cast<osgParticle::ModularProgram &>(obj);
bool itAdvanced = false;
osgParticle::Operator *op = dynamic_cast<osgParticle::Operator *>(fr.readObject());
osgParticle::Operator *op = static_cast<osgParticle::Operator *>(fr.readObjectOfType(osgDB::type_wrapper<osgParticle::Operator>()));
if (op) {
myobj.addOperator(op);
itAdvanced = true;