Manual Mesh and Mesh Conversion

Amnuriak

19-03-2010 14:10:31

Hi there,

I'm working on a conversion module for meshes. It shall read STL files and convert the data found into NxOgre style meshes. Unfortunately I have to use STL so using a different format is out of the question, at least for now.

STL allows for the same vertex to be specified more then once -> first problem: PhysXs only allows one vertex at any one position in space, not two. This is a matter of parsing all the vertices and eliminating the duplicate ones while not breaking the triangles. Allthough pretty troublesome, I have an idea how to do this.

Second problem: I guess NxOgre::ManualMesh::normal() is used on a per-vertex level as opposed to normal-per-triangle STL style. I don't know the vertex normals and computing them manually is just nasty. Is there a way to supply the triangle normals (or rather have them computed based on the order of insertion of the vertices) and use those to compute the vertex normals ?

Third problem: I can't find any tutorial on how to use ManualMesh. Could somone please hint me to a short tutorial where I can see the construction of some easy body ? Something like a simple cube or a tetrahedron would do nicely. I just gave it a shot and tried to construct a simple cube but I failed miserably :?

NxOgre::ManualMesh manual;
manual.begin(NxOgre::Enums::MeshType_Triangle, 4);

manual.vertex(NxOgre::Vec3(0, 0, 0));
manual.index(0);
manual.normal(-1, -1, -1);

manual.vertex(NxOgre::Vec3(1, 0, 0));
manual.index(1);
manual.normal(1, -1, -1);

manual.vertex(NxOgre::Vec3(0, 0, 1));
manual.index(2);
manual.normal(-1, -1, 1);

manual.vertex(NxOgre::Vec3(1, 0, 1));
manual.index(3);
manual.normal(1, -1, -1);

manual.vertex(NxOgre::Vec3(0, 1, 0));
manual.index(4);
manual.normal(-1, 1, -1);

manual.vertex(NxOgre::Vec3(0, 1, 1));
manual.index(5);
manual.normal(-1, 1, 1);

manual.vertex(NxOgre::Vec3(1, 1, 1));
manual.index(6);
manual.normal(1, 1, 1);

manual.vertex(NxOgre::Vec3(1, 1, 0));
manual.index(7);
manual.normal(1, 1, -1);

NxOgre::Mesh* pMesh = manual.end();
NxOgre::ConvexDescription convDesc(pMesh);
pNxOgreScene->createActor(convDesc);

This code results in an exception thrown NxOgreRigidBody.cpp::102 "mActor = mScene->getScene()->createActor(actor_description);" so I guess my mesh construction is just wrong.

I'd be glad for some advice,
Amnu

betajaen

19-03-2010 21:09:14

Hi there

1. No, PhysX doesn't like duplicate vertices and NxOgre doesn't parse them.

However I looked up some old code, and this should help you out:

int RawVertexCount;
Vec3* RawVertices;

// Your code here. Vertices go into RawVertices, and their count into RawVertexCount

SafeVertices = new Vec3[RawVertexCount];
int SafeVertexCount = 0;

Vec3 vertex;

bool d = false;

for (unsigned int i=0;i < RawVertexCount;++i)
{
vertex = RawVertices[i];
d = false;
for (unsigned int j=0;j < SafeVertexCount;++j)
if (vertex == SafeVertices[j])
d = true;
}
if (!d)
SafeVertices[SafeVertexCount++] = vertex;
}

// Pass SafeVertices into NxOgre here.


2.

Normals are optional for for most meshes; if you don't pass them along, PhysX will auto-calculate them for you.

I've commented the functions NxOgreManualMesh.h, it's not much but if you have a look at it. Each function tells you what type of attribute your mesh needs.

For the lazy:
- Triangle Meshes need vertices and triangles. Normals are optional.
- Convexes need vertices. Triangles and normals are optional.

3.

You have an error in your code. You've said to make a triangle mesh (NxOgre::Enums::MeshType_Triangle) but then later on your loading it as a Convex Mesh. Just use NxOgre::Enums::MeshType_Convex.

Amnuriak

22-03-2010 13:14:29

So far so good, thanks for the help :-)

I want to create an actor based on a triangle mesh, possibly not a convex one. I saw a TriangleMesh/TriangleMeshDesc/etc. with PhysX but not with NxOgre. Did I miss it or does it not exist ? If so, is it planned for the future or will all actors have to be based on convex meshes ?

betajaen

22-03-2010 13:19:03

They are called TriangleGeometry