1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#pragma once
#include "imodel.h"
#include "ifilesystem.h"
#include "os/path.h"
#include "NullModelNode.h"
namespace model
{
namespace
{
// name may be absolute or relative
inline std::string rootPath(const std::string& name) {
return GlobalFileSystem().findRoot(
path_is_absolute(name.c_str()) ? name : GlobalFileSystem().findFile(name)
);
}
} // namespace
class NullModelLoader;
typedef std::shared_ptr<NullModelLoader> NullModelLoaderPtr;
class NullModelLoader :
public IModelImporter
{
public:
// NullModelLoader returns an empty extension
const std::string& getExtension() const override
{
static std::string _ext;
return _ext;
}
scene::INodePtr loadModel(const std::string& modelName) override
{
// Initialise the paths, this is all needed for realisation
std::string path = rootPath(modelName);
std::string name = os::getRelativePath(modelName, path);
// Try to load the model from the given VFS path
NullModelPtr model =
std::static_pointer_cast<NullModel>(loadModelFromPath(name));
model->setModelPath(modelName);
model->setFilename(name);
// Construct a NullModelNode using this resource
return std::make_shared<NullModelNode>(model);
}
// Required function, not implemented.
IModelPtr loadModelFromPath(const std::string& name) override
{
NullModelPtr model(new NullModel);
model->setModelPath(name);
return model;
}
};
} // namespace model
|