DEBUG logging of model animation counts.

This commit is contained in:
Stuart Buchanan
2018-12-19 20:05:06 +00:00
parent b71e9eac51
commit 232cbbac5e
+36 -28
View File
@@ -56,7 +56,7 @@ using namespace std;
using namespace simgear; using namespace simgear;
using namespace osg; using namespace osg;
static osg::Node * static std::tuple<int, osg::Node *>
sgLoad3DModel_internal(const SGPath& path, sgLoad3DModel_internal(const SGPath& path,
const osgDB::Options* options, const osgDB::Options* options,
SGPropertyNode *overlay = 0); SGPropertyNode *overlay = 0);
@@ -88,8 +88,10 @@ SGReaderWriterXML::readNode(const std::string& name,
if (!p.exists()) { if (!p.exists()) {
return ReadResult::FILE_NOT_FOUND; return ReadResult::FILE_NOT_FOUND;
} }
result=sgLoad3DModel_internal(p, options); static std::tuple<int, osg::Node *> retval;
int num_anims;
std::tie(num_anims, result) = sgLoad3DModel_internal(p, options);
} catch (const sg_exception &t) { } catch (const sg_exception &t) {
SG_LOG(SG_INPUT, SG_ALERT, "Failed to load model: " << t.getFormattedMessage() SG_LOG(SG_INPUT, SG_ALERT, "Failed to load model: " << t.getFormattedMessage()
<< "\n\tfrom:" << fileName); << "\n\tfrom:" << fileName);
@@ -160,13 +162,13 @@ void makeEffectAnimations(PropertyList& animation_nodes,
SGPropertyNode* typeProp = animProp->getChild("type"); SGPropertyNode* typeProp = animProp->getChild("type");
if (!typeProp) if (!typeProp)
continue; continue;
const char* typeString = typeProp->getStringValue(); const char* typeString = typeProp->getStringValue();
if (!strcmp(typeString, "material")) { if (!strcmp(typeString, "material")) {
effectProp effectProp
= SGMaterialAnimation::makeEffectProperties(animProp); = SGMaterialAnimation::makeEffectProperties(animProp);
} else if (!strcmp(typeString, "shader")) { } else if (!strcmp(typeString, "shader")) {
SGPropertyNode* shaderProp = animProp->getChild("shader"); SGPropertyNode* shaderProp = animProp->getChild("shader");
if (!shaderProp || strcmp(shaderProp->getStringValue(), "chrome")) if (!shaderProp || strcmp(shaderProp->getStringValue(), "chrome"))
continue; continue;
@@ -215,7 +217,7 @@ private:
osg::Node::NodeMask nodeMaskSet; osg::Node::NodeMask nodeMaskSet;
osg::Node::NodeMask nodeMaskClear; osg::Node::NodeMask nodeMaskClear;
}; };
} }
namespace { namespace {
@@ -229,7 +231,7 @@ namespace {
return (typeString == "pick") || (typeString == "knob") || (typeString == "slider") || (typeString == "touch"); return (typeString == "pick") || (typeString == "knob") || (typeString == "slider") || (typeString == "touch");
} }
}; };
bool removeNamedNode(osg::Group* aGroup, const std::string& aName) bool removeNamedNode(osg::Group* aGroup, const std::string& aName)
{ {
int nKids = aGroup->getNumChildren(); int nKids = aGroup->getNumChildren();
@@ -240,28 +242,28 @@ namespace {
return true; return true;
} }
} }
for (int i = 0; i < nKids; i++) { for (int i = 0; i < nKids; i++) {
osg::Group* childGroup = aGroup->getChild(i)->asGroup(); osg::Group* childGroup = aGroup->getChild(i)->asGroup();
if (!childGroup) if (!childGroup)
continue; continue;
if (removeNamedNode(childGroup, aName)) if (removeNamedNode(childGroup, aName))
return true; return true;
} // of child groups traversal } // of child groups traversal
return false; return false;
} }
} }
static osg::Node * static std::tuple<int, osg::Node *>
sgLoad3DModel_internal(const SGPath& path, sgLoad3DModel_internal(const SGPath& path,
const osgDB::Options* dbOptions, const osgDB::Options* dbOptions,
SGPropertyNode *overlay) SGPropertyNode *overlay)
{ {
if (!path.exists()) { if (!path.exists()) {
SG_LOG(SG_INPUT, SG_ALERT, "Failed to load file: \"" << path << "\""); SG_LOG(SG_INPUT, SG_ALERT, "Failed to load file: \"" << path << "\"");
return NULL; return std::make_tuple(0, (osg::Node *) NULL);
} }
osg::ref_ptr<SGReaderWriterOptions> options; osg::ref_ptr<SGReaderWriterOptions> options;
@@ -270,19 +272,20 @@ sgLoad3DModel_internal(const SGPath& path,
SGPath modelpath(path); SGPath modelpath(path);
SGPath texturepath(path); SGPath texturepath(path);
SGPath modelDir(modelpath.dir()); SGPath modelDir(modelpath.dir());
int animationcount = 0;
SGSharedPtr<SGPropertyNode> prop_root = options->getPropertyNode(); SGSharedPtr<SGPropertyNode> prop_root = options->getPropertyNode();
if (!prop_root.valid()) if (!prop_root.valid())
prop_root = new SGPropertyNode; prop_root = new SGPropertyNode;
// The model data appear to be only used in the topmost model // The model data appear to be only used in the topmost model
osg::ref_ptr<SGModelData> data = options->getModelData(); osg::ref_ptr<SGModelData> data = options->getModelData();
options->setModelData(0); options->setModelData(0);
osg::ref_ptr<osg::Node> model; osg::ref_ptr<osg::Node> model;
osg::ref_ptr<osg::Group> group; osg::ref_ptr<osg::Group> group;
SGPropertyNode_ptr props = new SGPropertyNode; SGPropertyNode_ptr props = new SGPropertyNode;
bool previewMode = (dbOptions->getPluginStringData("SimGear::PREVIEW") == "ON"); bool previewMode = (dbOptions->getPluginStringData("SimGear::PREVIEW") == "ON");
// Check for an XML wrapper // Check for an XML wrapper
if (modelpath.extension() == "xml") { if (modelpath.extension() == "xml") {
try { try {
@@ -296,9 +299,9 @@ sgLoad3DModel_internal(const SGPath& path,
copyProperties(overlay, props); copyProperties(overlay, props);
if (previewMode && props->hasChild("nopreview")) { if (previewMode && props->hasChild("nopreview")) {
return NULL; return std::make_tuple(0, (osg::Node *) NULL);
} }
if (props->hasValue("/path")) { if (props->hasValue("/path")) {
string modelPathStr = props->getStringValue("/path"); string modelPathStr = props->getStringValue("/path");
modelpath = SGModelLib::findDataFile(modelPathStr, NULL, modelDir); modelpath = SGModelLib::findDataFile(modelPathStr, NULL, modelDir);
@@ -399,9 +402,9 @@ sgLoad3DModel_internal(const SGPath& path,
SGPath submodelpath; SGPath submodelpath;
osg::ref_ptr<osg::Node> submodel; osg::ref_ptr<osg::Node> submodel;
string subPathStr = sub_props->getStringValue("path"); string subPathStr = sub_props->getStringValue("path");
SGPath submodelPath = SGModelLib::findDataFile(subPathStr, SGPath submodelPath = SGModelLib::findDataFile(subPathStr,
NULL, modelDir); NULL, modelDir);
if (submodelPath.isNull()) { if (submodelPath.isNull()) {
@@ -419,14 +422,16 @@ sgLoad3DModel_internal(const SGPath& path,
} }
try { try {
submodel = sgLoad3DModel_internal(submodelPath, options.get(), int num_anims;
std::tie(num_anims, submodel) = sgLoad3DModel_internal(submodelPath, options.get(),
sub_props->getNode("overlay")); sub_props->getNode("overlay"));
animationcount += num_anims;
} catch (const sg_exception &t) { } catch (const sg_exception &t) {
SG_LOG(SG_INPUT, SG_ALERT, "Failed to load submodel: " << t.getFormattedMessage() SG_LOG(SG_INPUT, SG_ALERT, "Failed to load submodel: " << t.getFormattedMessage()
<< "\n\tfrom:" << t.getOrigin()); << "\n\tfrom:" << t.getOrigin());
continue; continue;
} }
if (!submodel) if (!submodel)
continue; continue;
@@ -491,7 +496,7 @@ sgLoad3DModel_internal(const SGPath& path,
if (i==0) { if (i==0) {
if (!texturepath.extension().empty()) if (!texturepath.extension().empty())
texturepath = texturepath.dir(); texturepath = texturepath.dir();
options2->setDatabasePath(texturepath.local8BitStr()); options2->setDatabasePath(texturepath.local8BitStr());
} }
group->addChild(Particles::appendParticles(particle_nodes[i], group->addChild(Particles::appendParticles(particle_nodes[i],
@@ -510,13 +515,13 @@ sgLoad3DModel_internal(const SGPath& path,
PropertyList effect_nodes = props->getChildren("effect"); PropertyList effect_nodes = props->getChildren("effect");
PropertyList animation_nodes = props->getChildren("animation"); PropertyList animation_nodes = props->getChildren("animation");
if (previewMode) { if (previewMode) {
PropertyList::iterator it; PropertyList::iterator it;
it = std::remove_if(animation_nodes.begin(), animation_nodes.end(), ExcludeInPreview()); it = std::remove_if(animation_nodes.begin(), animation_nodes.end(), ExcludeInPreview());
animation_nodes.erase(it, animation_nodes.end()); animation_nodes.erase(it, animation_nodes.end());
} }
// Some material animations (eventually all) are actually effects. // Some material animations (eventually all) are actually effects.
makeEffectAnimations(animation_nodes, effect_nodes); makeEffectAnimations(animation_nodes, effect_nodes);
{ {
@@ -543,13 +548,15 @@ sgLoad3DModel_internal(const SGPath& path,
/// OSGFIXME: duh, why not only model????? /// OSGFIXME: duh, why not only model?????
SGAnimation::animate(modelData); SGAnimation::animate(modelData);
} }
animationcount += animation_nodes.size();
if (!needTransform && group->getNumChildren() < 2) { if (!needTransform && group->getNumChildren() < 2) {
model = group->getChild(0); model = group->getChild(0);
group->removeChild(model.get()); group->removeChild(model.get());
if (data.valid()) if (data.valid())
data->modelLoaded(modelpath.utf8Str(), props, model.get()); data->modelLoaded(modelpath.utf8Str(), props, model.get());
return model.release(); return std::make_tuple(animationcount, model.release());
} }
if (data.valid()) if (data.valid())
data->modelLoaded(modelpath.utf8Str(), props, group.get()); data->modelLoaded(modelpath.utf8Str(), props, group.get());
@@ -559,6 +566,7 @@ sgLoad3DModel_internal(const SGPath& path,
osgDB::writeNodeFile(*group, outputfile); osgDB::writeNodeFile(*group, outputfile);
} }
return group.release(); SG_LOG(SG_GENERAL, SG_DEBUG, "Model " << path << " animation count: " << animationcount);
}
return std::make_tuple(animationcount, group.release());
}