71 lines
2.2 KiB
C++
71 lines
2.2 KiB
C++
#include "scene/MeshManager.h"
|
|
|
|
#include <osgDB/ReadFile>
|
|
|
|
#ifndef USE_OCEAN
|
|
#include <osgEarth/Registry>
|
|
#endif
|
|
|
|
#include "common/SpdLogger.h"
|
|
#include "common/RecourceHelper.h"
|
|
|
|
template<> MeshManager* Singleton<MeshManager>::instance_ = nullptr;
|
|
|
|
MeshManager::MeshManager(QObject* parent)
|
|
: QObject(parent) {
|
|
|
|
std::string basePath = RecourceHelper::Get().GetBasePath().toStdString();
|
|
std::string resoucePath = basePath + "/resources/";
|
|
osgDB::Registry::instance()->getDataFilePathList().push_back(resoucePath);
|
|
LOG_INFO("osgDB::Registry::instance add resources path: {}", resoucePath);
|
|
|
|
std::string effectPath = resoucePath + "effects/";
|
|
osgDB::Registry::instance()->getDataFilePathList().push_back(effectPath);
|
|
LOG_INFO("osgDB::Registry::instance add effectPath path: {}", effectPath);
|
|
|
|
std::string ocShaderPath = resoucePath + "shaders/";
|
|
osgDB::Registry::instance()->getDataFilePathList().push_back(ocShaderPath);
|
|
LOG_INFO("osgDB::Registry::instance add ocShaderPath path: {}", ocShaderPath);
|
|
|
|
std::string texturesPath = resoucePath + "textures/";
|
|
osgDB::Registry::instance()->getDataFilePathList().push_back(texturesPath);
|
|
LOG_INFO("osgDB::Registry::instance add texturesPath path: {}", texturesPath);
|
|
|
|
std::string modelPath = resoucePath + "model/";
|
|
osgDB::Registry::instance()->getDataFilePathList().push_back(modelPath);
|
|
LOG_INFO("osgDB::Registry::instance add model path: {}", modelPath);
|
|
}
|
|
|
|
MeshManager::~MeshManager(void) {
|
|
|
|
}
|
|
|
|
void MeshManager::OnDestory() {
|
|
|
|
}
|
|
|
|
osg::MatrixTransform* MeshManager::ReadNode(const std::string& file) {
|
|
LOG_INFO("load node:{}", file);
|
|
const auto iter = nodes_.find(file);
|
|
if (nodes_.end() != iter) {
|
|
osg::MatrixTransform* mt = new osg::MatrixTransform;
|
|
mt->addChild(iter->second);
|
|
return mt;
|
|
}
|
|
|
|
osg::Node* node = osgDB::readNodeFile(file);
|
|
if (nullptr == node) {
|
|
LOG_WARN("load file failed, {}", file);
|
|
return nullptr;
|
|
}
|
|
|
|
#ifndef USE_OCEAN
|
|
osgEarth::Registry::shaderGenerator().run(node);
|
|
#endif
|
|
nodes_[file] = node;
|
|
|
|
osg::MatrixTransform* mt = new osg::MatrixTransform;
|
|
mt->addChild(node);
|
|
return mt;
|
|
}
|