Page 1 of 1

Managing of manual loaded meshes

Posted: Fri Feb 01, 2019 12:57 pm
by Pellaeon
Ogre Version: 1.11.5
Operating System: Win10 x64
Render System: OGL/DX9


in my application the user can add and remove objects during runtime. So this was a problem with predefined resource groups, because the content of the corresponding directory changed. Till now, I did the following which worked: clearResourceGroup, addResourceLocation, initialiseResourceGroup every time the user changes or adds new object to my scene.

This works but is not really nice because the content of several filesystem resources is unloaded and loaded multiple times.

Ok, now to the new one. I found the wiki entry to load meshes manually, which is sufficient for my use case because my objects the user can switch are always single mesh files (no complete scene). Now I do the following to load the meshes:

Code: Select all

auto filePath = std::filesystem::absolute(std::filesystem::path(file));
std::fstream fs(file, std::ios_base::in | std::ios_base::binary);
Ogre::SharedPtr<Ogre::DataStream> ogre_stream (new Ogre::FileStreamDataStream(&fs, false));

auto p_mesh = Ogre::MeshManager::getSingleton().createManual(filePath.filename().string(), m_resGroupName);
// this part does the actual load into the live Mesh object created above
Ogre::MeshSerializer meshSerializer;
meshSerializer.importMesh(ogre_stream, p_mesh.getPointer());

auto entity = m_ogreMng.getSceneManager()->createEntity(filePath.filename().string());
Ogre::SceneNode* pNode = m_ogreMng.getSceneManager()->createSceneNode();
And regarding this apporach I have two questions. First is about the material. Because I only load the mesh I got the following warning in the log: Can't assign material '_missing_material_' to SubEntity of 'Ogre/MO1' because this Material does not exist in group 'General'. Have you forgotten to define it in a .material script?
Surpringely, the mesh is visible. Is there a default material for used meshes so that I have a defined behaviour? Or is it luck that I have a proper white material.

Second: To remove the mesh I can use MeshManager::remove, right? Is there some kind of reference counter or is the resource removed immedately. Because in my application it can happen that a user uses one mesh file for different slots. So what happens when I remove the mesh but it is still used in another scene node.
And I suppose I also must remiove the entity for myself in the scene manager? Atm I only removing the scene node.

Best regards


Re: Managing of manual loaded meshes

Posted: Sun Feb 03, 2019 2:17 am
by loath
i believe your mesh and entity are winding up in different resource groups. therefore, the default material is assigned because it assumes the material is in the entity's group and not the mesh's group.

you need to call createEntity() with either the actual mesh pointer (in which case it will use the mesh's resource group) or use the version of createEntity() that includes the group name. otherwise your mesh is in "m_resGroupName" and your entity in a default resource group.

calling remove on a resource manager just removes the resource shared pointer (a reference counted std::shared_ptr) from the manager's internal collections. if you've nulled out all of your references to the resource (either by going out of scope, calling .reset() etc) AND you call remove on the manager then your resource will be freed.

Re: Managing of manual loaded meshes

Posted: Mon Feb 04, 2019 8:58 am
by Pellaeon
Now, I remove the maual object wit hteh following code:

Code: Select all

//destroy the ogre node	
auto entityName = nodeIt->pNode->getAttachedObjects()[0]->getName();
auto p_mesh = m_ogreMng.getSceneManager()->getEntity(entityName)->getMesh();

Hopefully, I didn't forget anything.