Page 1 of 1

IPhysic problem part 2

Posted: Wed Mar 28, 2007 1:37 pm
by Requiem
Hi,
I was having problem in introducing iphysics in my program but now that ok. thank to the forum. But now im getting another problem. My program compile well no errors... but when it initialised it stuck on this line

Code: Select all

IPhysicsEntity* levelEntity = physics.addEntity(&level);
my mesh is a static mesh created with 3DS max 8 export to ".obj" with some texture the i use irredit for a better lookin of theenvironment .THe name I've give to the mesh in irrEdit is "city" . then the code continues for some collision stuff. The code are as follows:

Code: Select all


smgr->loadScene("media/town.irr");
   
    scene_node = smgr->getSceneNodeFromName("city");
  
    if(scene_node->getType()==ESNT_MESH)
    {
                                       
         IAttributes* attribs = device->getFileSystem()->createEmptyAttributes(); 
         if (attribs) 
         {
                      
               scene_node->serializeAttributes(attribs);
               // get the mesh name out 
               core::stringc mesh_name = attribs->getAttributeAsString("Mesh");
               const c8 *meshName = mesh_name.c_str(); 
               
               attribs->drop();
              
               // get a mesh from the name 
               IAnimatedMesh* town_mesh = smgr->getMesh(meshName);
               IAnimatedMeshSceneNode* levelnode = smgr->addAnimatedMeshSceneNode(town_mesh);  
   
               	SPhysicsStaticMesh level;
	            level.mesh = town_mesh;
	            level.meshnode = levelnode;
                
	            level.meshScale = vector3df(0.1f, 0.1f, 0.10f);    
	            level.meshnode->setScale(level.meshScale);  

	            IPhysicsEntity* levelEntity = physics.addEntity(&level);   
	             
           }    
    }

Someone with any solution??

Posted: Wed Mar 28, 2007 3:11 pm
by vitek
You load the scene, find a node named 'city', get the animated mesh used for the node named 'city', then create a new animated mesh scene node using that mesh? Are you absolutely sure this is what you want to be doing, creating a duplicate of the 'city'?

Posted: Wed Mar 28, 2007 8:42 pm
by Requiem
Even if i remove the line

Code: Select all

IAnimatedMeshSceneNode* levelnode = smgr->addAnimatedMeshSceneNode(town_mesh);
and change the line

Code: Select all

level.meshnode = levelnode;
to

Code: Select all

level.meshnode=scene_node;
i get the same problem

Posted: Wed Mar 28, 2007 11:23 pm
by vitek
Oh, sorry, I didn't mean to imply that I was providing a solution to your problem. I was just commenting that you are creating a new scene node when it didn't appear that you would want to be doing that. I don't use IPhysics, so I don't really know what the problem could be.

I'll take a guess though. I'm assuming that the addEntity code builds up some sort of bounding heirarchy for collisions. This may take some time to do if your mesh is really big.

Posted: Fri Oct 17, 2008 9:06 pm
by Ethan
I had problems with casting to IAnimatedMesh from IMesh too.
But i solved the problem by importing my levelmesh as animated mesh and not as normal mesh in the irrEdit.
So i didn't get a casting error, but i don't collide anyway with this mesh?!
I tried collision with boxes before and everything works, except of collision with this mesh.

anyone can tell why?

(notice: m_node is an ISceneNode, i imported as .obj animated mesh file in the irrEdit)

Code: Select all

SPhysicsStaticMesh meshColObj;

	if(m_node->getType() == ESNT_ANIMATED_MESH)
	{
		meshColObj.mesh = (IAnimatedMesh*)(((IAnimatedMeshSceneNode*)m_node)->getMesh());
		meshColObj.meshnode = m_node;

		m_physics->addEntity(&meshColObj);
	}
	else
	{
		printf("Assigned MeshCollider NodeCode without having IAnimatedMesh");
	} 

Posted: Fri Oct 17, 2008 9:57 pm
by Ethan
Solved the problem, by syncing the SCALE and the POSITION of the physics and the irrlicht object.

Code: Select all

if(m_node->getType() == ESNT_ANIMATED_MESH)
	{
		meshColObj.mesh = (IAnimatedMesh*)(((IAnimatedMeshSceneNode*)m_node)->getMesh());
		meshColObj.meshnode = m_node;

		meshColObj.meshScale = m_node->getScale();

		IPhysicsEntity* myPhyObj = m_physics->addEntity(&meshColObj);
		myPhyObj->setPosition(m_node->getAbsolutePosition());
	}