}
osgDB::ReaderWriter::ReadResult
-SGReaderWriterXML::readNode(const std::string& fileName,
+SGReaderWriterXML::readNode(const std::string& name,
const osgDB::Options* options) const
{
+ std::string fileName = osgDB::findDataFile(name, options);
+
osg::Node *result=0;
try {
SGPath p = SGModelLib::findDataFile(fileName);
SGPropertyNode* typeProp = animProp->getChild("type");
if (!typeProp)
continue;
+
const char* typeString = typeProp->getStringValue();
if (!strcmp(typeString, "material")) {
effectProp
}
}
+namespace simgear {
+class SetNodeMaskVisitor : public osg::NodeVisitor {
+public:
+ SetNodeMaskVisitor(osg::Node::NodeMask nms, osg::Node::NodeMask nmc) :
+ osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), nodeMaskSet(nms), nodeMaskClear(nmc)
+ {}
+ virtual void apply(osg::Geode& node) {
+ node.setNodeMask((node.getNodeMask() | nodeMaskSet) & ~nodeMaskClear);
+ traverse(node);
+ }
+private:
+ osg::Node::NodeMask nodeMaskSet;
+ osg::Node::NodeMask nodeMaskClear;
+};
+
+}
+
+namespace {
+ class ExcludeInPreview
+ {
+ public:
+ bool operator()(SGPropertyNode* aNode) const
+ {
+ string typeString(aNode->getStringValue("type"));
+ // exclude these so we don't show yellow outlines in preview mode
+ return (typeString == "pick") || (typeString == "knob") || (typeString == "slider");
+ }
+ };
+
+ bool removeNamedNode(osg::Group* aGroup, const std::string& aName)
+ {
+ int nKids = aGroup->getNumChildren();
+ for (int i = 0; i < nKids; i++) {
+ osg::Node* child = aGroup->getChild(i);
+ if (child->getName() == aName) {
+ aGroup->removeChild(child);
+ return true;
+ }
+ }
+
+ for (int i = 0; i < nKids; i++) {
+ osg::Group* childGroup = aGroup->getChild(i)->asGroup();
+ if (!childGroup)
+ continue;
+
+ if (removeNamedNode(childGroup, aName))
+ return true;
+ } // of child groups traversal
+
+ return false;
+ }
+}
+
static osg::Node *
sgLoad3DModel_internal(const SGPath& path,
const osgDB::Options* dbOptions,
osg::ref_ptr<osg::Node> model;
osg::ref_ptr<osg::Group> group;
SGPropertyNode_ptr props = new SGPropertyNode;
-
+ bool previewMode = (dbOptions->getPluginStringData("SimGear::PREVIEW") == "ON");
+
// Check for an XML wrapper
if (modelpath.extension() == "xml") {
try {
if (overlay)
copyProperties(overlay, props);
+ if (previewMode && props->hasChild("nopreview")) {
+ return NULL;
+ }
+
if (props->hasValue("/path")) {
string modelPathStr = props->getStringValue("/path");
modelpath = SGModelLib::findDataFile(modelPathStr, NULL, modelDir);
if (props->hasValue("/texture-path")) {
string texturePathStr = props->getStringValue("/texture-path");
- texturepath = SGModelLib::findDataFile(texturePathStr, NULL, modelDir);
- if (texturepath.isNull())
- throw sg_io_exception("Texture file not found: '" + texturePathStr + "'",
- path.str());
+ if (!texturePathStr.empty())
+ {
+ texturepath = SGModelLib::findDataFile(texturePathStr, NULL, modelDir);
+ if (texturepath.isNull())
+ throw sg_io_exception("Texture file not found: '" + texturePathStr + "'",
+ path.str());
+ }
}
} else {
model = new osg::Node;
// model without wrapper
}
- options->setPropertyNode(prop_root);
-
// Assume that textures are in
// the same location as the XML file.
if (!model) {
// but introducing new data for velocities.
UserDataCopyVisitor userDataCopyVisitor;
model->accept(userDataCopyVisitor);
+
+ SetNodeMaskVisitor setNodeMaskVisitor(0, simgear::MODELLIGHT_BIT);
+ model->accept(setNodeMaskVisitor);
}
model->setName(modelpath.str());
<< "\n\tfrom:" << t.getOrigin());
continue;
}
+
+ if (!submodel)
+ continue;
osg::ref_ptr<osg::Node> submodel_final = submodel;
SGPropertyNode *offs = sub_props->getNode("offsets", false);
prop_root,
options.get()));
}
+
PropertyList effect_nodes = props->getChildren("effect");
PropertyList animation_nodes = props->getChildren("animation");
- PropertyList light_nodes = props->getChildren("light");
+
+ if (previewMode) {
+ PropertyList::iterator it;
+ it = std::remove_if(animation_nodes.begin(), animation_nodes.end(), ExcludeInPreview());
+ animation_nodes.erase(it, animation_nodes.end());
+ }
+
// Some material animations (eventually all) are actually effects.
makeEffectAnimations(animation_nodes, effect_nodes);
{
= instantiateEffects(group.get(), effect_nodes, options.get());
group = static_cast<Group*>(modelWithEffects.get());
}
- for (unsigned i = 0; i < animation_nodes.size(); ++i)
+
+ for (unsigned i = 0; i < animation_nodes.size(); ++i) {
+ if (previewMode && animation_nodes[i]->hasChild("nopreview")) {
+ PropertyList names(animation_nodes[i]->getChildren("object-name"));
+ for (unsigned int n=0; n<names.size(); ++n) {
+ removeNamedNode(group, names[n]->getStringValue());
+ } // of object-names in the animation
+ continue;
+ }
+
/// OSGFIXME: duh, why not only model?????
SGAnimation::animate(group.get(), animation_nodes[i], prop_root,
options.get(), path.str(), i);
-
+ }
+
if (!needTransform && group->getNumChildren() < 2) {
model = group->getChild(0);
group->removeChild(model.get());