Managing of manual loaded meshes

Problems building or running the engine, queries about how to use features etc.
Post Reply
Pellaeon
Halfling
Posts: 94
Joined: Thu Apr 28, 2011 12:23 pm
x 3

Managing of manual loaded meshes

Post by Pellaeon » Fri Feb 01, 2019 12:57 pm

Ogre Version: 1.11.5
Operating System: Win10 x64
Render System: OGL/DX9

Hi,

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();
pNode->attachObject(entity);
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

Pellaeon
0 x

loath
Platinum Sponsor
Platinum Sponsor
Posts: 89
Joined: Tue Jan 17, 2012 5:18 am
x 1

Re: Managing of manual loaded meshes

Post by loath » Sun Feb 03, 2019 2:17 am

1.
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.

2.
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.
0 x

Pellaeon
Halfling
Posts: 94
Joined: Thu Apr 28, 2011 12:23 pm
x 3

Re: Managing of manual loaded meshes

Post by Pellaeon » Mon Feb 04, 2019 8:58 am

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();
nodeIt->pNode->detachAllObjects();

m_ogreMng.getSceneManager()->destroyEntity(entityName);
m_ogreMng.getSceneManager()->destroySceneNode(nodeIt->pNode);
Ogre::MeshManager::getSingleton().remove(p_mesh);
Hopefully, I didn't forget anything.
0 x

Post Reply