osg::ref_ptr<const osg::Node> SceneManager::getTemplate(const std::string &name) { std::string normalized = name; mVFS->normalizeFilename(normalized); osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized); if (obj) return osg::ref_ptr<const osg::Node>(static_cast<osg::Node*>(obj.get())); else { osg::ref_ptr<osg::Node> loaded; try { Files::IStreamPtr file = mVFS->get(normalized); loaded = load(file, normalized, mImageManager, mNifFileManager); } catch (std::exception& e) { static const char * const sMeshTypes[] = { "nif", "osg", "osgt", "osgb", "osgx", "osg2" }; for (unsigned int i=0; i<sizeof(sMeshTypes)/sizeof(sMeshTypes[0]); ++i) { normalized = "meshes/marker_error." + std::string(sMeshTypes[i]); if (mVFS->exists(normalized)) { std::cerr << "Failed to load '" << name << "': " << e.what() << ", using marker_error." << sMeshTypes[i] << " instead" << std::endl; Files::IStreamPtr file = mVFS->get(normalized); loaded = load(file, normalized, mImageManager, mNifFileManager); break; } } if (!loaded) throw; } // set filtering settings SetFilterSettingsVisitor setFilterSettingsVisitor(mMinFilter, mMagFilter, mMaxAnisotropy); loaded->accept(setFilterSettingsVisitor); SetFilterSettingsControllerVisitor setFilterSettingsControllerVisitor(mMinFilter, mMagFilter, mMaxAnisotropy); loaded->accept(setFilterSettingsControllerVisitor); // share state mSharedStateMutex.lock(); osgDB::Registry::instance()->getOrCreateSharedStateManager()->share(loaded.get()); mSharedStateMutex.unlock(); if (mIncrementalCompileOperation) mIncrementalCompileOperation->add(loaded); mCache->addEntryToObjectCache(normalized, loaded); return loaded; } }
osg::ref_ptr<const osg::Node> SceneManager::getTemplate(const std::string &name) { std::string normalized = name; mVFS->normalizeFilename(normalized); osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized); if (obj) return osg::ref_ptr<const osg::Node>(static_cast<osg::Node*>(obj.get())); else { osg::ref_ptr<osg::Node> loaded; try { Files::IStreamPtr file = mVFS->get(normalized); loaded = load(file, normalized, mImageManager, mNifFileManager); } catch (std::exception& e) { static const char * const sMeshTypes[] = { "nif", "osg", "osgt", "osgb", "osgx", "osg2" }; for (unsigned int i=0; i<sizeof(sMeshTypes)/sizeof(sMeshTypes[0]); ++i) { normalized = "meshes/marker_error." + std::string(sMeshTypes[i]); if (mVFS->exists(normalized)) { std::cerr << "Failed to load '" << name << "': " << e.what() << ", using marker_error." << sMeshTypes[i] << " instead" << std::endl; Files::IStreamPtr file = mVFS->get(normalized); loaded = load(file, normalized, mImageManager, mNifFileManager); break; } } if (!loaded) throw; } // set filtering settings SetFilterSettingsVisitor setFilterSettingsVisitor(mMinFilter, mMagFilter, mMaxAnisotropy); loaded->accept(setFilterSettingsVisitor); SetFilterSettingsControllerVisitor setFilterSettingsControllerVisitor(mMinFilter, mMagFilter, mMaxAnisotropy); loaded->accept(setFilterSettingsControllerVisitor); Shader::ShaderVisitor shaderVisitor(*mShaderManager.get(), *mImageManager, "objects_vertex.glsl", "objects_fragment.glsl"); shaderVisitor.setForceShaders(mForceShaders); shaderVisitor.setClampLighting(mClampLighting); shaderVisitor.setForcePerPixelLighting(mForcePerPixelLighting); shaderVisitor.setAutoUseNormalMaps(mAutoUseNormalMaps); shaderVisitor.setNormalMapPattern(mNormalMapPattern); shaderVisitor.setNormalHeightMapPattern(mNormalHeightMapPattern); shaderVisitor.setAutoUseSpecularMaps(mAutoUseSpecularMaps); shaderVisitor.setSpecularMapPattern(mSpecularMapPattern); loaded->accept(shaderVisitor); // share state mSharedStateMutex.lock(); mSharedStateManager->share(loaded.get()); mSharedStateMutex.unlock(); if (mIncrementalCompileOperation) mIncrementalCompileOperation->add(loaded); mCache->addEntryToObjectCache(normalized, loaded); return loaded; } }