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
+17 -9
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);
@@ -89,7 +89,9 @@ SGReaderWriterXML::readNode(const std::string& name,
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);
@@ -254,14 +256,14 @@ namespace {
} }
} }
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,6 +272,7 @@ 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())
@@ -296,7 +299,7 @@ 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")) {
@@ -419,8 +422,10 @@ 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());
@@ -544,12 +549,14 @@ sgLoad3DModel_internal(const SGPath& path,
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());
}