Use marker_error.nif as replacement when a mesh fails to load

pull/695/head
scrawl 10 years ago
parent ac1f64b559
commit 26656707dd

@ -100,11 +100,20 @@ namespace Resource
Index::iterator it = mIndex.find(normalized);
if (it == mIndex.end())
{
Files::IStreamPtr file = mVFS->get(normalized);
// TODO: add support for non-NIF formats
osg::ref_ptr<osg::Node> loaded;
try
{
Files::IStreamPtr file = mVFS->get(normalized);
osg::ref_ptr<osg::Node> loaded = NifOsg::Loader::load(Nif::NIFFilePtr(new Nif::NIFFile(file, normalized)), mTextureManager);
loaded = NifOsg::Loader::load(Nif::NIFFilePtr(new Nif::NIFFile(file, normalized)), mTextureManager);
}
catch (std::exception& e)
{
std::cerr << "Failed to load '" << name << "': " << e.what() << ", using marker_error.nif instead" << std::endl;
Files::IStreamPtr file = mVFS->get("meshes/marker_error.nif");
loaded = NifOsg::Loader::load(Nif::NIFFilePtr(new Nif::NIFFile(file, normalized)), mTextureManager);
}
osgDB::Registry::instance()->getOrCreateSharedStateManager()->share(loaded.get());
// TODO: run SharedStateManager::prune on unload

@ -38,12 +38,16 @@ namespace Resource
~SceneManager();
/// Get a read-only copy of this scene "template"
/// @note If the given filename does not exist or fails to load, an error marker mesh will be used instead.
/// If even the error marker mesh can not be found, an exception is thrown.
osg::ref_ptr<const osg::Node> getTemplate(const std::string& name);
/// Create an instance of the given scene template
/// @see getTemplate
osg::ref_ptr<osg::Node> createInstance(const std::string& name);
/// Create an instance of the given scene template and immediately attach it to a parent node
/// @see getTemplate
osg::ref_ptr<osg::Node> createInstance(const std::string& name, osg::Group* parentNode);
/// Attach the given scene instance to the given parent node

Loading…
Cancel
Save