Skip to content

Commit

Permalink
Add interface to get mesh and datablock without creating an item
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Brainville (Ybalrid) <[email protected]>
  • Loading branch information
Ybalrid committed Jul 22, 2018
1 parent 3d32713 commit 0011a2b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 15 deletions.
35 changes: 35 additions & 0 deletions include/Ogre_glTF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,45 @@ namespace Ogre_glTF
//Forward declare main class
class glTFLoader;

///struct that contains a mesh and the datablock that should be used with it.
///This represent what an extracted object from a glTF asset contains.
///The mash should have a skeletonInstance attached to it the glTF file defined a skin;
struct MeshAndDataBlock
{
///Pointer to the Ogre Mesh
Ogre::MeshPtr Mesh;

///Pointer to the HlmsDatablock. This should be a HlmsPbsDatablock
Ogre::HlmsDatablock* datablock;
};

///Plugin accessible interface that plugin users can use
struct glTFLoaderInterface
{
///Polymorphic dtor
virtual ~glTFLoaderInterface() = default;

///Get you an item from a GLB file loaded inside an Ogre resource group
/// \param name The name of the resource
/// \param smgr The scene manager where the Item will be used
/// \return pointer to a created item in your scene manager using the mesh in the glTF asset
virtual Ogre::Item* getItemFromResource(const std::string& name, Ogre::SceneManager* smgr) = 0;

///Get you an item from a GLB or a GLTF file from the filesystem.
/// \param name The name of the resource
/// \param smgr The scene manager where the Item will be used
/// \return pointer to a created item in your scene manager using the mesh in the glTF asset
virtual Ogre::Item* getItemFromFileSystem(const std::string& fileName, Ogre::SceneManager* smgr) = 0;

///Get you a mesh and a material datablock from a GLB in the resource manager
/// \param name The name of the resource
/// \return a struct containing pointers to a mesh and a datablock
virtual MeshAndDataBlock getMeshFromResource(const std::string& name) = 0;

///Get you mesh and a material datablock from GLB or a GLTF file from the filesystem
/// \param name The name of the resource
/// \return a struct containing pointers to a mesh and a datablock
virtual MeshAndDataBlock getMeshFromFileSystem(const std::string& name) = 0;
};

///Class that hold the loaded content of a glTF file and that can create Ogre objects from it
Expand Down Expand Up @@ -47,6 +77,9 @@ namespace Ogre_glTF
///Deleted asignment constructor : non copyable class
loaderAdapter& operator=(const loaderAdapter&) = delete;

Ogre::MeshPtr getMesh() const;
Ogre::HlmsDatablock* getDatablock() const;

///Construct an item for this object
/// \param smgr pointer to the scene manager where we are creating the item
Ogre::Item* getItem(Ogre::SceneManager* smgr) const;
Expand Down Expand Up @@ -95,6 +128,8 @@ namespace Ogre_glTF

Ogre::Item* getItemFromResource(const std::string& name, Ogre::SceneManager* smgr) override;
Ogre::Item* getItemFromFileSystem(const std::string& fileName, Ogre::SceneManager* smgr) override;
MeshAndDataBlock getMeshFromResource(const std::string& name) override;
MeshAndDataBlock getMeshFromFileSystem(const std::string& name) override;

///Deleted copy contructor
glTFLoader(const glTFLoader&) = delete;
Expand Down
2 changes: 1 addition & 1 deletion pluginTest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ int main()
#endif


//Startup Ogre as you woul generally do it
//Startup Ogre as you would generally do it
root->showConfigDialog();
root->getRenderSystem()->setConfigOption("FSAA", "16");
root->getRenderSystem()->setConfigOption("sRGB Gamma Conversion", "Yes");
Expand Down
65 changes: 51 additions & 14 deletions src/Ogre_glTF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,33 @@ loaderAdapter::~loaderAdapter()

Ogre::Item* loaderAdapter::getItem(Ogre::SceneManager* smgr) const
{
if(isOk()) {
if(isOk())
{
pimpl->textureImp.loadTextures();
auto Mesh = pimpl->modelConv.getOgreMesh();
if(pimpl->modelConv.hasSkins()) {
//load skeleton information
auto skeleton = pimpl->skeletonImp.getSkeleton(adapterName);
Mesh->_notifySkeleton(skeleton);
}
Ogre::MeshPtr Mesh = getMesh();

auto Item = smgr->createItem(Mesh);
Item->setDatablock(pimpl->materialLoad.getDatablock());
Item->setDatablock(getDatablock());
return Item;
}
return nullptr;
}

Ogre::MeshPtr loaderAdapter::getMesh() const
{
auto Mesh = this->pimpl->modelConv.getOgreMesh();

if(this->pimpl->modelConv.hasSkins())
{
//load skeleton information
auto skeleton = this->pimpl->skeletonImp.getSkeleton(this->adapterName);
Mesh->_notifySkeleton(skeleton);
}
return Mesh;
}

Ogre::HlmsDatablock* loaderAdapter::getDatablock() const { return pimpl->materialLoad.getDatablock(); }

loaderAdapter::loaderAdapter(loaderAdapter&& other) noexcept : pimpl{ std::move(other.pimpl) }
{
//OgreLog("Moved adapter object...");
Expand Down Expand Up @@ -116,7 +127,8 @@ struct glTFLoader::glTFLoaderImpl
for(size_t i{ 0 }; i < 4; ++i) probe >> buffer[i];
buffer[4] = 0;

if(std::string("glTF") == std::string(buffer.data())) {
if(std::string("glTF") == std::string(buffer.data()))
{
//OgreLog("Detected binary file thanks to the magic number at the start!");
return FileType::Binary;
}
Expand Down Expand Up @@ -185,7 +197,8 @@ loaderAdapter glTFLoader::loadGlbResource(const std::string& name) const
auto glbFile = glbManager.load(name, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);

loaderAdapter adapter;
if(glbFile) {
if(glbFile)
{
loaderImpl->loadGlb(adapter, glbFile);
adapter.pimpl->valid = true;
}
Expand All @@ -198,10 +211,7 @@ Ogre::Item* glTFLoader::getItemFromResource(const std::string& name, Ogre::Scene
{
OgreLog("Getting resource");
auto adapter = loadGlbResource(name);
if(adapter.isOk())
{
OgreLog("Adapter is ok!");
}
if(adapter.isOk()) { OgreLog("Adapter is ok!"); }
else
{
OgreLog("Adapter is not okay!");
Expand All @@ -214,9 +224,36 @@ Ogre::Item* glTFLoader::getItemFromResource(const std::string& name, Ogre::Scene
Ogre::Item* glTFLoader::getItemFromFileSystem(const std::string& fileName, Ogre::SceneManager* smgr)
{
auto adapter = loadFromFileSystem(fileName);
if(adapter.isOk()) { OgreLog("Adapter is ok!"); }
else
{
OgreLog("Adapter is not okay!");
}
return adapter.getItem(smgr);
}

MeshAndDataBlock glTFLoader::getMeshFromFileSystem(const std::string& name)
{
auto adapter = loadFromFileSystem(name);
if(adapter.isOk()) { OgreLog("Adapter is ok!"); }
else
{
OgreLog("Adapter is not okay!");
}
return { adapter.getMesh(), adapter.getDatablock() };
}

MeshAndDataBlock glTFLoader::getMeshFromResource(const std::string& name)
{
auto adapter = loadGlbResource(name);
if(adapter.isOk()) { OgreLog("Adapter is ok!"); }
else
{
OgreLog("Adapter is not okay!");
}
return { adapter.getMesh(), adapter.getDatablock() };
}

glTFLoader::glTFLoader(glTFLoader&& other) noexcept : loaderImpl(std::move(other.loaderImpl)) {}

glTFLoader& glTFLoader::operator=(glTFLoader&& other) noexcept
Expand Down

0 comments on commit 0011a2b

Please sign in to comment.