Rak'kar
31-01-2007 03:01:53
I'm using a scene to load space ships. I can have the same ship more than once. But if I load it more than once I get exceptions due to name clashes. I didn't see a mechanism in the oFusion loader to append a prefix to the names (I've been using the pointer address as a prefix for CEGUI).
What have others done in the past to get around this? Should I change the name of every created node in OnNodeCreate ?
gerds
31-01-2007 12:27:45
If you look at the destructor for the oSceneLoader it does nothing, this is very wrong.
What you need to do is free the lights, cameras, entities you have created etc.
Something like this might work (untested code - let me know how you go with it):
What you'll have to do is 'new' the OSMScene before you load it, and call 'delete' on it when you want to unload it from the scene.
OSMScene::~OSMScene(void)
{
// destroy all the lights
for (size_t i = 0; i < mLights.size(); i++)
{
if (mLights[i] != NULL)
{
Ogre::SceneNode *pnode = mLights[i]->getParentSceneNode();
if (pnode != NULL)
{
pnode->detachObject(mLights[i]);
}
mSceneMgr->getRootSceneNode()->removeAndDestroyChild(pnode->getName());
mSceneMgr->destroyLight(mLights[i]);
mLights[i] = NULL;
}
}
mLights.clear();
// destroy all the cameras
for (size_t i = 0; i < mCameras.size(); i++)
{
if (mCameras[i] != NULL)
{
Ogre::SceneNode *pnode = mCameras[i]->getParentSceneNode();
if (pnode != NULL)
{
pnode->detachObject(mCameras[i]);
}
mSceneMgr->getRootSceneNode()->removeAndDestroyChild(pnode->getName());
mSceneMgr->destroyCamera(mCameras[i]);
mCameras[i] = NULL;
}
}
mCameras.clear();
// destroy all entities
for (size_t i = 0; i < mEntities.size(); i++)
{
if (mEntities[i] != NULL)
{
Ogre::SceneNode *pnode = mEntities[i]->getParentSceneNode();
if (pnode != NULL)
{
pnode->detachObject(mEntities[i]);
}
mSceneMgr->getRootSceneNode()->removeAndDestroyChild(pnode->getName());
mSceneMgr->destroyEntity(mEntities[i]);
mEntities[i] = NULL;
}
}
mEntities.clear();
}
Lioric
31-01-2007 16:21:45
If the duplicated named objects are exported within the scene, it will be better if you fix the object's naming before exporting in max, there are several tools to auto rename objects and materials using several options to avoid duplicated names
Or if you want to load multiple instances of a scene (your space ships osm file) you can add auto renamer support in the oScene loader code, in the "createNode" method, add a "hasSceneNode" test, and append a number (or rename as you need) to the node name to create a duplicated object with a different name