Loading and unloading an irr file and destroying some nodes
Loading and unloading an irr file and destroying some nodes
Hello everyone, I have a problem.
I have the meshviewer example, and I want to keep to mesh constant, but I want to be able to load an irr file as a background envionment. Then I want to unload it and load a new one.
Right now I can load the irr file (by loadScene) and the mesh stays too, but I can't unload the irr file without cleaning everything. But I want the user to be able to manipulate the mesh, and it should stay the same while the environment changes.
Can anyone give me a few tips for this one? I can clarify my problem if you think it isn't clear.
Thanks in advance for your help.
I have the meshviewer example, and I want to keep to mesh constant, but I want to be able to load an irr file as a background envionment. Then I want to unload it and load a new one.
Right now I can load the irr file (by loadScene) and the mesh stays too, but I can't unload the irr file without cleaning everything. But I want the user to be able to manipulate the mesh, and it should stay the same while the environment changes.
Can anyone give me a few tips for this one? I can clarify my problem if you think it isn't clear.
Thanks in advance for your help.
Last edited by nayon on Mon Mar 23, 2009 10:19 am, edited 1 time in total.
The mesh isn't in the irr file, it is loaded independently from a 3ds file. So smgr->clear removes the mesh too, which I do not want. The program looks like this:
load animated scene node (the 3ds mesh)
load scene (the irr file)
Now after that step I need to somehow unload the irr file, but I can't do it. Is it clearer now?
Thanks.
load animated scene node (the 3ds mesh)
load scene (the irr file)
Now after that step I need to somehow unload the irr file, but I can't do it. Is it clearer now?
Thanks.
Alright, now I have a new problem. I have a few IAnimatedMeshSceneNodes, and I want to destroy them when loading a new irr file. But I can't figure out how. If I just call their deconstructor, it gives an error. Is it due to the collision animators they contain? Just dropping doesn't seem to work when I try to add new ones. What should I do?
ie, how do I truly destroy a scene node that has animators ( I also want to destroy the animators too)
ie, how do I truly destroy a scene node that has animators ( I also want to destroy the animators too)
It just generates an exception when I try to do that...
Well let me share the relevant parts of my code if you want:
This is the agent class, and I want to call the destroy method in my loadLevel method, which I will post after the Agent
This is the loadLevel method called by main, agents is a vector containing all Agent s. Is the problem clear now? What am I doing wrong?
Well let me share the relevant parts of my code if you want:
This is the agent class, and I want to call the destroy method in my loadLevel method, which I will post after the Agent
Code: Select all
class Agent{
public:
scene::IAnimatedMeshSceneNode *agent_node;
enum animation {RUN, STAND};
core::vector3df prevPos;
animation enim;
public: Agent (core::vector3df pos){
enim = RUN;
core::array<scene::ISceneNode *> nodes;
scene::IMetaTriangleSelector * meta = smgr->createMetaTriangleSelector();
smgr->getSceneNodesFromType(scene::ESNT_ANY, nodes); // Find all nodes
for (u32 i=0; i < nodes.size(); ++i)
{
scene::ISceneNode * node = nodes[i];
scene::ITriangleSelector * selector = 0;
switch(node->getType())
{
case scene::ESNT_CUBE:
case scene::ESNT_ANIMATED_MESH:
// Because the selector won't animate with the mesh,
// and is only being used for camera collision, we'll just use an approximate
// bounding box instead of ((scene::IAnimatedMeshSceneNode*)node)->getMesh(0)
selector = smgr->createTriangleSelectorFromBoundingBox(node);
break;
case scene::ESNT_MESH:
case scene::ESNT_SPHERE: // Derived from IMeshSceneNode
selector = smgr->createTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
break;
case scene::ESNT_TERRAIN:
selector = smgr->createTerrainTriangleSelector((scene::ITerrainSceneNode*)node);
break;
case scene::ESNT_OCT_TREE:
selector = smgr->createOctTreeTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
break;
default:
// Don't create a selector for this node type
break;
}
if(selector)
{
// Add it to the meta selector, which will take a reference to it
meta->addTriangleSelector(selector);
// And drop my reference to it, so that the meta selector owns it.
selector->drop();
}
}
video::SMaterial material;
material.setTexture(0, driver->getTexture("../../media/faerie2.bmp"));
material.Lighting = true;
scene::IAnimatedMesh* faerie = smgr->getMesh("../../media/faerie.md2");
agent_node = smgr->addAnimatedMeshSceneNode(faerie);
faerie->drop();
agent_node->setPosition(pos);
agent_node->setMD2Animation(scene::EMAT_RUN);
agent_node->getMaterial(0) = material;
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(meta,agent_node, core::vector3df(20,40,20),
core::vector3df(0,-10,0),
core::vector3df(0,0,0));
agent_node->addAnimator(anim);
anim->drop();
material.setTexture(0, 0);
material.Lighting = false;
}
void destroy(){
agent_node->remove();
}
This is the loadLevel method called by main, agents is a vector containing all Agent s. Is the problem clear now? What am I doing wrong?
Code: Select all
void loadLevel(const c8* fn){
core::stringc filename(fn);
for ( unsigned int gg = 0; gg < agents.size(); gg ++ ){
agents[gg]->destroy();
}
agents.clear();
smgr->loadScene(filename.c_str());
EDIT: I also tried clearing the meshCache before deleting the agents, but I still get the crash described below...
I have changed the code a bit, so it doesn't give any more errors when removing agents, I call this within my loadLevel method:
But now I get an error when I try to add a new agent, at the last line of this code:
yes, at the AddAnimatedMeshSceneNode, why might that be?
I have changed the code a bit, so it doesn't give any more errors when removing agents, I call this within my loadLevel method:
Code: Select all
void loadLevel(const c8* fn){
core::stringc filename(fn);
addingAgent = false;
for ( unsigned int gg = 0; gg < agents.size(); gg ++ ){
agents[gg]->destroy();
}
agents.clear();
core::array<scene::ISceneNode *> nodes1;
smgr->getSceneNodesFromType(scene::ESNT_ANY, nodes1); // Find all nodes
for (u32 i=0; i < nodes1.size(); ++i)
{
if( nodes1[i]->getType() != scene::ESNT_CAMERA ){
nodes1[i]->remove();
}
}
smgr->loadScene(filename.c_str());
But now I get an error when I try to add a new agent, at the last line of this code:
Code: Select all
public: Agent (core::vector3df pos){
enim = RUN;
core::array<scene::ISceneNode *> nodes;
scene::IMetaTriangleSelector * meta = smgr->createMetaTriangleSelector();
smgr->getSceneNodesFromType(scene::ESNT_ANY, nodes); // Find all nodes
for (u32 i=0; i < nodes.size(); ++i)
{
scene::ISceneNode * node = nodes[i];
scene::ITriangleSelector * selector = 0;
switch(node->getType())
{
case scene::ESNT_CUBE:
case scene::ESNT_ANIMATED_MESH:
// Because the selector won't animate with the mesh,
// and is only being used for camera collision, we'll just use an approximate
// bounding box instead of ((scene::IAnimatedMeshSceneNode*)node)->getMesh(0)
selector = smgr->createTriangleSelectorFromBoundingBox(node);
break;
case scene::ESNT_MESH:
case scene::ESNT_SPHERE: // Derived from IMeshSceneNode
selector = smgr->createTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
break;
case scene::ESNT_TERRAIN:
selector = smgr->createTerrainTriangleSelector((scene::ITerrainSceneNode*)node);
break;
case scene::ESNT_OCT_TREE:
selector = smgr->createOctTreeTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
break;
default:
// Don't create a selector for this node type
break;
}
if(selector)
{
// Add it to the meta selector, which will take a reference to it
meta->addTriangleSelector(selector);
// And drop my reference to it, so that the meta selector owns it.
selector->drop();
}
}
video::SMaterial material;
material.setTexture(0, driver->getTexture("../../media/faerie2.bmp"));
material.Lighting = true;
scene::IAnimatedMesh* faerie = smgr->getMesh("../../media/faerie.md2");
agent_node = smgr->addAnimatedMeshSceneNode(faerie);
yes, at the AddAnimatedMeshSceneNode, why might that be?