Make use of SGReaderWriterOptions::copyOrCreate in SGReaderWriterXML.
This commit is contained in:
@@ -200,7 +200,7 @@ void makeEffectAnimations(PropertyList& animation_nodes,
|
|||||||
|
|
||||||
static osg::Node *
|
static osg::Node *
|
||||||
sgLoad3DModel_internal(const SGPath& path,
|
sgLoad3DModel_internal(const SGPath& path,
|
||||||
const osgDB::Options* options_,
|
const osgDB::Options* dbOptions,
|
||||||
SGPropertyNode *overlay)
|
SGPropertyNode *overlay)
|
||||||
{
|
{
|
||||||
if (!path.exists()) {
|
if (!path.exists()) {
|
||||||
@@ -208,25 +208,17 @@ sgLoad3DModel_internal(const SGPath& path,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SGReaderWriterOptions* xmlOptions;
|
osg::ref_ptr<SGReaderWriterOptions> options;
|
||||||
xmlOptions = dynamic_cast<const SGReaderWriterOptions*>(options_);
|
options = SGReaderWriterOptions::copyOrCreate(dbOptions);
|
||||||
|
|
||||||
SGSharedPtr<SGPropertyNode> prop_root;
|
|
||||||
osg::Node *(*load_panel)(SGPropertyNode *)=0;
|
|
||||||
osg::ref_ptr<SGModelData> data;
|
|
||||||
SGPath modelpath(path);
|
SGPath modelpath(path);
|
||||||
SGPath texturepath(path);
|
SGPath texturepath(path);
|
||||||
SGPath modelDir(modelpath.dir());
|
SGPath modelDir(modelpath.dir());
|
||||||
|
|
||||||
if (xmlOptions) {
|
SGSharedPtr<SGPropertyNode> prop_root = options->getPropertyNode();
|
||||||
prop_root = xmlOptions->getPropertyNode();
|
if (!prop_root.valid())
|
||||||
load_panel = xmlOptions->getLoadPanel();
|
|
||||||
data = xmlOptions->getModelData();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!prop_root) {
|
|
||||||
prop_root = new SGPropertyNode;
|
prop_root = new SGPropertyNode;
|
||||||
}
|
osg::ref_ptr<SGModelData> data = options->getModelData();
|
||||||
|
|
||||||
osg::ref_ptr<osg::Node> model;
|
osg::ref_ptr<osg::Node> model;
|
||||||
osg::ref_ptr<osg::Group> group;
|
osg::ref_ptr<osg::Group> group;
|
||||||
@@ -269,10 +261,7 @@ sgLoad3DModel_internal(const SGPath& path,
|
|||||||
// model without wrapper
|
// model without wrapper
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::ref_ptr<SGReaderWriterOptions> options
|
|
||||||
= new SGReaderWriterOptions(*options_);
|
|
||||||
options->setPropertyNode(prop_root);
|
options->setPropertyNode(prop_root);
|
||||||
options->setLoadPanel(load_panel);
|
|
||||||
|
|
||||||
// Assume that textures are in
|
// Assume that textures are in
|
||||||
// the same location as the XML file.
|
// the same location as the XML file.
|
||||||
@@ -280,9 +269,11 @@ sgLoad3DModel_internal(const SGPath& path,
|
|||||||
if (!texturepath.extension().empty())
|
if (!texturepath.extension().empty())
|
||||||
texturepath = texturepath.dir();
|
texturepath = texturepath.dir();
|
||||||
|
|
||||||
options->setDatabasePath(texturepath.str());
|
osg::ref_ptr<SGReaderWriterOptions> options2;
|
||||||
|
options2 = new SGReaderWriterOptions(*options);
|
||||||
|
options2->setDatabasePath(texturepath.str());
|
||||||
osgDB::ReaderWriter::ReadResult modelResult;
|
osgDB::ReaderWriter::ReadResult modelResult;
|
||||||
modelResult = osgDB::readNodeFile(modelpath.str(), options.get());
|
modelResult = osgDB::readNodeFile(modelpath.str(), options2.get());
|
||||||
if (!modelResult.validNode())
|
if (!modelResult.validNode())
|
||||||
throw sg_io_exception("Failed to load 3D model:" + modelResult.message(),
|
throw sg_io_exception("Failed to load 3D model:" + modelResult.message(),
|
||||||
modelpath.str());
|
modelpath.str());
|
||||||
@@ -298,7 +289,7 @@ sgLoad3DModel_internal(const SGPath& path,
|
|||||||
model->addObserver(databaseReference);
|
model->addObserver(databaseReference);
|
||||||
|
|
||||||
// Update liveries
|
// Update liveries
|
||||||
TextureUpdateVisitor liveryUpdate(options->getDatabasePathList());
|
TextureUpdateVisitor liveryUpdate(options2->getDatabasePathList());
|
||||||
model->accept(liveryUpdate);
|
model->accept(liveryUpdate);
|
||||||
|
|
||||||
// Copy the userdata fields, still sharing the boundingvolumes,
|
// Copy the userdata fields, still sharing the boundingvolumes,
|
||||||
@@ -353,11 +344,6 @@ sgLoad3DModel_internal(const SGPath& path,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::ref_ptr<SGReaderWriterOptions> options;
|
|
||||||
options = new SGReaderWriterOptions(*options_);
|
|
||||||
options->setPropertyNode(prop_root);
|
|
||||||
options->setLoadPanel(load_panel);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
submodel = sgLoad3DModel_internal(submodelPath, options.get(),
|
submodel = sgLoad3DModel_internal(submodelPath, options.get(),
|
||||||
sub_props->getNode("overlay"));
|
sub_props->getNode("overlay"));
|
||||||
@@ -405,6 +391,7 @@ sgLoad3DModel_internal(const SGPath& path,
|
|||||||
}
|
}
|
||||||
} // end of submodel loading
|
} // end of submodel loading
|
||||||
|
|
||||||
|
osg::Node *(*load_panel)(SGPropertyNode *) = options->getLoadPanel();
|
||||||
if ( load_panel ) {
|
if ( load_panel ) {
|
||||||
// Load panels
|
// Load panels
|
||||||
vector<SGPropertyNode_ptr> panel_nodes = props->getChildren("panel");
|
vector<SGPropertyNode_ptr> panel_nodes = props->getChildren("panel");
|
||||||
@@ -420,15 +407,17 @@ sgLoad3DModel_internal(const SGPath& path,
|
|||||||
std::vector<SGPropertyNode_ptr> particle_nodes;
|
std::vector<SGPropertyNode_ptr> particle_nodes;
|
||||||
particle_nodes = props->getChildren("particlesystem");
|
particle_nodes = props->getChildren("particlesystem");
|
||||||
for (unsigned i = 0; i < particle_nodes.size(); ++i) {
|
for (unsigned i = 0; i < particle_nodes.size(); ++i) {
|
||||||
|
osg::ref_ptr<SGReaderWriterOptions> options2;
|
||||||
|
options2 = new SGReaderWriterOptions(*options);
|
||||||
if (i==0) {
|
if (i==0) {
|
||||||
if (!texturepath.extension().empty())
|
if (!texturepath.extension().empty())
|
||||||
texturepath = texturepath.dir();
|
texturepath = texturepath.dir();
|
||||||
|
|
||||||
options->setDatabasePath(texturepath.str());
|
options2->setDatabasePath(texturepath.str());
|
||||||
}
|
}
|
||||||
group->addChild(Particles::appendParticles(particle_nodes[i],
|
group->addChild(Particles::appendParticles(particle_nodes[i],
|
||||||
prop_root,
|
prop_root,
|
||||||
options.get()));
|
options2.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<SGPropertyNode_ptr> text_nodes;
|
std::vector<SGPropertyNode_ptr> text_nodes;
|
||||||
|
|||||||
Reference in New Issue
Block a user