[solved] ManualObject -> Mesh -> TreeCollision problem

technique

07-12-2010 21:40:39

I am sorry for asking for help again, but it have another problem with passing a ManualObject to the OgreNewt::CollisionPrimitive::TreeCollision. I get no error using the function "convertToMesh()" ob my ManualObject to get a mesh, but if i try to create a CollisionPrimitive out of the mesh my app crashes. When i use other CollisionPrimitives like a box or a ellipse it works very well.

My Object is a simple box (without bottom) i created this way:


this->mName = name;
this->mBoxManual = mSceneMgr->createManualObject( Ogre::String( "manual" ) + name );
mBoxManual->setDynamic(true);
mBoxManual->setCastShadows(false);
mBoxManual->estimateIndexCount(20);
mBoxManual->estimateVertexCount(20);

float pos = 0.5 * size;
float neg = -0.5 * size;

mBoxManual->begin("box", Ogre::RenderOperation::OT_TRIANGLE_LIST);
{
/*
// Bottom
mBoxManual->normal(0,-1,0);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->position(pos, neg, pos);
mBoxManual->position( pos, neg, neg);
mBoxManual->position( neg, neg, neg);
mBoxManual->position(neg, neg, pos);
mBoxManual->quad(3,2,1,0);
*/

// Top
mBoxManual->position(pos, pos, pos); //0
mBoxManual->normal(0, 1, 0);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(0, 0);

mBoxManual->position( pos, pos, neg); //1
mBoxManual->normal(0, 1, 0);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(1, 0);

mBoxManual->position( neg, pos, neg); //2
mBoxManual->normal(0, 1, 0);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(1, 1);

mBoxManual->position(neg, pos, pos); //3
mBoxManual->normal(0, 1, 0);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(0, 1);

mBoxManual->triangle(0,1,3);
mBoxManual->triangle(1,2,3);

// Left
mBoxManual->position(neg, neg, pos); //4
mBoxManual->normal(-1,0,0);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(0, 0);

mBoxManual->position( neg, pos, pos); //5
mBoxManual->normal(-1,0,0);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(1, 0);

mBoxManual->position( neg, pos, neg); //6
mBoxManual->normal(-1,0,0);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(1, 1);

mBoxManual->position(neg, neg, neg); //7
mBoxManual->normal(-1,0,0);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(0, 1);

mBoxManual->triangle(4,5,6);
mBoxManual->triangle(6,7,4);

// Right
mBoxManual->position(pos, neg, pos); //8
mBoxManual->normal(1,0,0);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(0, 0);

mBoxManual->position( pos, pos, pos); //9
mBoxManual->normal(1,0,0);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(0, 1);

mBoxManual->position( pos, pos, neg); //10
mBoxManual->normal(1,0,0);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(1, 1);

mBoxManual->position(pos, neg, neg); //11
mBoxManual->normal(1,0,0);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(1, 0);

mBoxManual->triangle(8,11,9);
mBoxManual->triangle(11,10,9);

// Front
mBoxManual->position(neg, neg, pos); //12
mBoxManual->normal(0,0,1);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(0, 0);

mBoxManual->position( neg, pos, pos); //13
mBoxManual->normal(0,0,1);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(0, 1);

mBoxManual->position( pos, pos, pos); //14
mBoxManual->normal(0,0,1);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(1, 1);

mBoxManual->position(pos, neg, pos); //15
mBoxManual->normal(0,0,1);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(1, 0);

mBoxManual->triangle(12,15,13);
mBoxManual->triangle(13,15,14);

// Back
mBoxManual->position(neg, neg, neg); //16
mBoxManual->normal(0,0,-1);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(0, 0);

mBoxManual->position( neg, pos, neg); //17
mBoxManual->normal(0,0,-1);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(0, 1);

mBoxManual->position( pos, pos, neg); //18
mBoxManual->normal(0,0,-1);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(1, 1);

mBoxManual->position(pos, neg, neg); //19
mBoxManual->normal(0,0,-1);
mBoxManual->colour( 1, 1, 1 );
mBoxManual->textureCoord(1, 0);

mBoxManual->triangle(16,17,19);
mBoxManual->triangle(19,17,18);
}
mBoxManual->end();


This is the way i tried to create a Mesh and parse it to the physic:


mBoxNode->detachAllObjects();
mBoxMesh = mBoxManual->convertToMesh( Ogre::String( "mesh" ) + mName );
mBoxEntity = mSceneMgr->createEntity( Ogre::String( "entitiy" ) + mName, Ogre::String( "mesh" ) + mName );
mBoxNode->attachObject( mBoxEntity );

if( mBoxManual ) delete mBoxManual;

OgreNewt::CollisionPrimitives::TreeCollision* boxCol = new OgreNewt::CollisionPrimitives::TreeCollision( mWorld, mBoxEntity, false, 0 ); // On this line the app crashes
OgreNewt::CollisionPtr col;
col = OgreNewt::CollisionPtr( boxCol );
mBody = new OgreNewt::Body( mWorld, col );
mBody->attachNode( mBoxNode );
mBody->setPositionOrientation( position, Ogre::Quaternion::IDENTITY );



If i comment out the "parse to physic" lines i get the box as expected (so i think the function convertToMesh() succeed).

technique

08-12-2010 11:47:56

Instead of my converted mesh, i used the ninja.mesh for the TreeCollision but the app crashes at the same position. I think i did basically something wrong.

Is there antoher function to use meshes for collision?
Maybe i have to prepare the meshes in a special way?

All tutorials and the minimal ogrenewt application load the meshes this way - i dont know what's the problem right know...

technique

08-12-2010 12:53:51

Its me again. I tried the playground.mesh of the demo examples of OgreNewt but i get the same problem.

This is the exception-error of access violation VisualStudio2010 put out (ya..its german - but it may help?):

technique

13-12-2010 14:33:41

Me again...
Today i met a few buddies at my university to debug - but we could not get it to work..

Nobody has an idea?
Maybe u need more informations? Please ask for - i'll try to answer them!
It is possible that bad .dlls etc. can cause that problem? Or a bug at OgreNewt?
(mind that other CollisionPrimitives works fine and with TreeCollision a lot of different .mesh's have beed tested!)

Is there anther way to parse the .mesh to the physic? No problem if it becomes more tricky - but i really need to get this working (need it for a project @ my university)!

technique

13-12-2010 22:00:55

I finally got it!
Maybe other people will get into that trouble too - so here is my solution:

The version of OgreNewt i used were not completly compatible to Newton-SDK 2.26. So i had to rebuild OgreNewt (i used a svn checkout version - up to date) with Newton 2.24.

Now i can parse my mesh file to the physic - using exactly that source above.
It was hard to find that solution because it looked like OgreNewt and Newton works very well since the CollisionPrimitive::Box aso. works without trouble.