Mesh and its convex

Tibo6

19-06-2010 22:06:35

Hello,

I'm wondering how to have our convex without having to create a .nxs for each mesh. Because, we need to have a .mesh AND a .nxs, which it's boring.
Can we generate our convex for a mesh in our program like we do with a Ogre::Terrain ?

Thanks.
Bye.

betajaen

19-06-2010 22:17:16

Do you mean using the Ogre Mesh, generate a convex mesh in code?

Of course you can:

NxOgre::ManualMesh m;
m.begin(NxOgre::Enums::MeshType_Convex);
m.vertex(x,y,z);
m.vertex(x,y,z);
m.vertex(x,y,z);
m.vertex(x,y,z);
NxOgre::Mesh* mesh = m.end();


You could even make it to generate a convex mesh if one doesn't exist already on disk, Sort of create-as-you-use routine.

Tibo6

20-06-2010 14:07:26

Perfect ! Thank you.

But your code is not accepted : "Error: incomplete type is not allowed" on my variable.
I tried this but I have the same thing :
NxOgre::ManualMesh m = NxOgre::ManualMesh();
m.begin(NxOgre::Enums::MeshType_Convex);
m.vertex(x,y,z);
m.vertex(x,y,z);
m.vertex(x,y,z);
m.vertex(x,y,z);
NxOgre::Mesh* mesh = m.end();


And what would you recommend personnally?
Create our convex in code or store it in a .nxs?

Tibo6

20-06-2010 22:24:46

Where is the latest NxOgre version ?
Here or here ?

betajaen

20-06-2010 22:27:02

Detritus.

Tibo6

21-06-2010 00:37:17

Thanks.

I have another problem now xD
I use this code below, and apparenty it is this line "NxOgre::Mesh *mesh = manualMesh.end();" which doesn't work.

size_t vertex_count, index_count;
Ogre::Vector3 *vertices;
unsigned long *indices;
Tools::getMeshInformation(m_sinbad->getMesh().getPointer(), vertex_count, vertices, index_count, indices);
NxOgre::ManualMesh manualMesh;
manualMesh.begin(NxOgre::Enums::MeshType_Convex, vertex_count, index_count);
for(unsigned int i = 0; i < vertex_count; ++i)
{
manualMesh.vertex(vertices[i].x, vertices[i].y, vertices[i].z);
}
for(unsigned int i = 0; i < index_count; ++i)
{
manualMesh.index(indices[i]);
}
delete[] vertices;
delete[] indices;
NxOgre::Mesh *mesh = manualMesh.end();
m_physicRenderSystem->createBody(NxOgre::ConvexDescription(mesh), NxOgre::Vec3(45.0f, 1.2f, 35.0f), "Sinbad.mesh");


Thank you for your help.
Bye.

betajaen

21-06-2010 09:54:46

If it's new sinbad animated mesh in 1.7.x, then that isn't a convex shape, it also has too many vertices/triangles (There is a limit of about 255 triangles). Which is probably the reason for the crash.

Anyway, I remember I wrote a Mesh function in Critter for situations like these:

NxOgre::MeshData* mesh_data = Critter::MeshFunctions::read(my_ogre_mesh);
mesh_data->mType = NxOgre::Enums::MeshType_Convex;
mesh_data->cook("file://my_mesh.nxs");
delete mesh_data;

NxOgre::MeshManager::getSingleton()->load("file://my_mesh.nxs", "my_mesh");


You only need to do the first part once remember.

Tibo6

21-06-2010 12:40:59

Thanks.
I tried this code but still doesn't work :(

NxOgre::MeshData* mesh_data = Critter::MeshFunctions::read(m_sinbad->getMesh());
mesh_data->mType = NxOgre::Enums::MeshType_Convex;
mesh_data->cook("file://my_mesh.nxs");
delete mesh_data;

NxOgre::Mesh *convexMesh = NxOgre::MeshManager::getSingleton()->load("file://my_mesh.nxs", "my_mesh");
m_physicRenderSystem->createBody(NxOgre::ConvexDescription(convexMesh), NxOgre::Vec3(45.0f, 1.2f, 35.0f), "Sinbad.mesh");


Apparently the problem is caused by this line


NxOgre::Mesh *convexMesh = NxOgre::MeshManager::getSingleton()->load("file://my_mesh.nxs", "my_mesh");


My .nxs file has no weight. I think it's the problem xD

betajaen

21-06-2010 12:50:29

What mesh are you converting from?

If it's the Sinbad mesh, then it will never work. It has too many triangles, and it isn't a convex shape.

Tibo6

21-06-2010 12:54:23

Yes it is the Sinbad mesh.
In fact I have a 3rd person camera. And I want to move it.

betajaen

21-06-2010 12:57:26

Your going to have to use a more simpler convex mesh, use a capsule/box, or use a bunch of shapes making up the arms, head, legs, feet, etc.

Tibo6

21-06-2010 13:34:37

Alright thank you.

betajaen

21-06-2010 13:58:35

Sadly, that's how it is with Physics engines.

Even in Half-Life 2, Fallout 3 they all use capsules for characters and players.