[bleeding] collision model for traffic cones and barrels?

luis

17-04-2008 14:46:01

I want to use barrels and traffic cones, what should i use and how ?
What is the difference between Convex and TriangleMesh classes? is there any limit in the poligon count for the .mesh file ?

I'll appreciate any advice !
thanks

BTW: i'm using bleeding 1.0-18/19

betajaen

17-04-2008 14:55:43

Come on Luis, you should know this. Use Convex for your cones, and there is a 255 vertex limit on Convexes.

luis

17-04-2008 15:00:41

hehe I've been so focused in wheels and vehicle physics that i'm almost a complete ignorant in a lot of features of NxOgre...

Thanks for (as usual) your fast reply.
I asume i should use Convex for the barrels also....

betajaen

17-04-2008 15:54:38

Yep. There is no other shape suitable.

luis

18-04-2008 20:22:46

I'm testing the convex (i was wrong with my nxogre version, i'm using 0.9!) shape with my meshes (cone, barrel and simple box) and i get:

NxOgre::ResourceManager::cookConvexMesh#226T0.384 F517
ConvexMesh is invalid. Reason(s) are:
+ Vertex count less than three


If i use Cake mesh: cube.1m.h.mesh it works.....
Any advice ? i read something about shared vertices... our modeler is using Maya.

betajaen

18-04-2008 23:36:40

It could be separate sub-meshes, or a weird mesh. Are you using an optimised mesh for the cone?

luis

19-04-2008 09:51:54

It could be separate sub-meshes, or a weird mesh. Are you using an optimised mesh for the cone?
It is about sub-meshes and sharedgeometry structure i beleive.

I'm not using any optimization in the meshes. I converted my box.mesh and your cube.1m.h.mesh to XML and the structure is quite different, basically @dinvog had the same problem:
http://www.ogre3d.org/phpBB2addons/view ... rtex+count

He was using Max so he had the choice to use two exporters, since our modeller is using Maya we dont have the option to change the exporter.... :(

this is the structure of cube.1m.h.mesh.xml this mesh works

<mesh>
<submeshes>
<submesh material="nx.cube" usesharedvertices="false" use32bitindexes="false" operationtype="triangle_list">
<faces count="12">
<face v1="0" v2="1" v3="2" />
<face v1="2" v2="3" v3="0" />
.....
</faces>
<geometry vertexcount="24">
<vertexbuffer positions="true" normals="true">
<vertex>
<position x="1" y="1" z="-1" />
<normal x="0" y="0" z="-1" />
.......
</vertex>
</vertexbuffer>
</geometry>
</submesh>
</submeshes>
</mesh>


this is the structure of my box.mesh.xml this mesh doesn't work

<mesh>
<sharedgeometry vertexcount="12">
<vertexbuffer positions="true" normals="true" texture_coord_dimensions_0="2" texture_coords="1">
<vertex>
<position x="-5" y="5" z="5" />
<normal x="0" y="1" z="0" />
<texcoord u="1" v="1" />
</vertex>
......
</vertexbuffer>
</sharedgeometry>
<submeshes>
<submesh material="Ac3d/Crate/Mat001_Tex00" usesharedvertices="true" use32bitindexes="false" operationtype="triangle_list">
<faces count="12">
<face v1="10" v2="11" v3="1" />
....
</faces>
</submesh>
</submeshes>
<levelofdetail numlevels="5" manual="false">
<lodgenerated fromdepthsquared="2500">
<lodfacelist submeshindex="0" numfaces="12">
<face v1="10" v2="11" v3="1" />
......
</lodfacelist>
</lodgenerated>
<lodgenerated fromdepthsquared="10000">
<lodfacelist submeshindex="0" numfaces="12">
<face v1="10" v2="11" v3="1" />
.....
</lodfacelist>
</lodgenerated>
<lodgenerated fromdepthsquared="22500">
<lodfacelist submeshindex="0" numfaces="12">
<face v1="10" v2="11" v3="1" />
.......
</lodfacelist>
</lodgenerated>
<lodgenerated fromdepthsquared="40000">
<lodfacelist submeshindex="0" numfaces="12">
<face v1="10" v2="11" v3="1" />
....
</lodfacelist>
</lodgenerated>
</levelofdetail>
</mesh>


perhaps the NxOgre code that reads/extracts the vertex data from the mesh depends on the structure of the mesh too much... all my models are exported with the same Maya exporter and Ogre doesn't complain so I asume they are 'right'.
I'll ask to the modeller to tell me the exporter options and make some test if it doens't work i'll search main forums about XML/mesh format structures and if it still doesn't work i'll take a look at NxOgre code, i beleive it should be really easy to fix... i hope.

betajaen

19-04-2008 10:41:20

Actually, it's in the Flour code. Which you are welcome to have a look at, but I've been using the same code for years to read Ogre Meshes based of the some code on the Wiki. But when it comes to convexes all is needed is the vertices. If worst comes to worse, you can manually put them in some code, manually generate the mesh using ManualMesh and save it to disk.

luis

19-04-2008 16:44:06

the code in the wiki is different exactly in the fact that it adds the shared vertices and this one no...
see:
http://www.ogre3d.org/wiki/index.php/RetrieveVertexData
and compare
NxOgre 0.9: NxOgre\source\NxOgreResourceManager_Convex.cpp
in the main loop (the one that iterates over subMeshes) the code is keeping track of the shared offset but it is never used... look for the variable: shared_offset.

I run my game in debug step by step and i found out that the part that removes the duplicated vertices removes all my 12 vertices (my box has 12) and it is correct... since all vertices are zero (they arent initialized with the right values).

I dont know if the code in the wiki works but i could try to use it and add the remove duplicated vertices and see what happens.

luis

20-04-2008 10:49:51

I'm using bleeding ! :oops:
I have so many NxOgre versions in my HD and i dont remember which directory i'm using...

Well.... i solved the problem, now NxOgre loads Cake meshes and my meshes.
I copy-paste the code in the wiki (the second version) and added the remove vertices and it works.
I dont know if I should post the code in another thread (since the title now is wrong).

here is the code:
NxOgre_1.0\NxOgre\source\NxOgreResourceManager_Convex.cpp

////////////////////////////////////////////////////////////////////////////////////////////////

ConvexMeshIntermediary* ResourceManager::generateConvexMeshDescription(Ogre::MeshPtr meshPtr, NxVec3 scale) {

Ogre::Mesh* mesh = meshPtr.getPointer();
ConvexMeshIntermediary* cmi = new ConvexMeshIntermediary();
cmi->setToNormal();

NxVec3 *RawVertices = 0;
size_t vertex_count = 0, index_count = 0;

bool added_shared = false;
size_t current_offset = 0;
size_t shared_offset = 0;
size_t next_offset = 0;
size_t index_offset = 0;

// Calculate how many vertices and indices we're going to need
for( unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i )
{
Ogre::SubMesh* submesh = mesh->getSubMesh( i );
// We only need to add the shared vertices once
if(submesh->useSharedVertices)
{
if( !added_shared ) {
vertex_count += mesh->sharedVertexData->vertexCount;
added_shared = true;
}
}
else {
vertex_count += submesh->vertexData->vertexCount;
}
// Add the indices
index_count += submesh->indexData->indexCount;
}

// Allocate space for the vertices and indices
RawVertices = new NxVec3[vertex_count];
added_shared = false;

// Run through the submeshes again, adding the data into the arrays
for( unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i) {

Ogre::SubMesh* submesh = mesh->getSubMesh(i);
Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;

if((!submesh->useSharedVertices)||(submesh->useSharedVertices && !added_shared)) {
if(submesh->useSharedVertices) {
added_shared = true;
shared_offset = current_offset;
}

const Ogre::VertexElement* posElem =
vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);

Ogre::HardwareVertexBufferSharedPtr vbuf =
vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());

unsigned char* vertex =
static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));

// There is _no_ baseVertexPointerToElement() which takes an Ogre::Real or a double
// as second argument. So make it float, to avoid trouble when Ogre::Real will
// be comiled/typedefed as double:
// Ogre::Real* pReal;
float* pReal;
for( size_t j = 0; j < vertex_data->vertexCount; ++j, vertex += vbuf->getVertexSize())
{
posElem->baseVertexPointerToElement(vertex, &pReal);

Ogre::Vector3 pt(pReal[0], pReal[1], pReal[2]);

RawVertices[current_offset + j].x = pt.x * scale.x;
RawVertices[current_offset + j].y = pt.y * scale.y;
RawVertices[current_offset + j].z = pt.z * scale.z;
}

vbuf->unlock();
next_offset += vertex_data->vertexCount;
}

current_offset = next_offset;
}

// Removed duplicate vertices.
cmi->mVertices = new NxVec3[vertex_count];
NxVec3 vertex;
bool d = false;
for( NxU32 i = 0; i < vertex_count; ++i ) {
vertex = RawVertices[i];
d = false;
for( NxU32 j = 0; j < cmi->mNbVertices; ++j ) {
if (vertex == cmi->mVertices[j]) {
d = true;
}
}
if (!d)
cmi->mVertices[cmi->mNbVertices++] = vertex;
}

delete []RawVertices;
cmi->verticesToDescription();

return cmi;
}

betajaen

20-04-2008 11:09:06

Yeah. That code doesn't even exist in NxOgre anymore, let alone that class. All the cool people now use Flour and have the mesh pre-converted before loading it in.

luis

20-04-2008 11:55:13

but will the new versions of bleeding load .mesh files as Convex or the only way will be to pre-convert those files to nxs ?

betajaen

20-04-2008 11:59:54

NXS only.

luis

20-04-2008 12:39:13

and Flour has the same code as above or it is completly different ?

Edit: Obviously NXS... I forget you're trying to make NxOgre not graphics engine dependent....

betajaen

20-04-2008 13:17:10

Flour will convert the Ogre mesh into a NXS mesh for you. It's much faster to convert it once off-line rather every time you load it.

luis

20-04-2008 13:54:33

sure it is better doing off-line, but if Flour has the same method to convert .mesh to NXS I will have the same problem with the meshes.

Or you just used the wiki code as I did to fix it ?

betajaen

20-04-2008 14:24:23

If the mesh uses 12 vertices; Just manually create it and save it to disk. Your spending way to much time on a simple problem.

luis

20-04-2008 17:57:17

If the mesh uses 12 vertices; Just manually create it and save it to disk. Your spending way to much time on a simple problem.
the mesh i used as a test (the box) has 12 vertices. The meshes i want to use have more than 12....

I have a cfg file that defines each object in the scene so anyone can modify and load his own objects in tracks, so it isn't a matter of convert every mesh to NXS format and forget it.

Also if Flour has the same code to extract vertices from ogre meshes then it has a bug that wont let it convert any meshes exported with Maya, that's why i'm asking this question ;)