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);
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