question about NewtonMeshAddFace usage

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

question about NewtonMeshAddFace usage

Postby sinisa » Tue Nov 10, 2009 8:49 am

Hi all,

I've been working on a fast-paced game for iPhone, using Newton for physics. Everything works great (very easy to use, works without any problems, congrats to developers on this one), except part when I want to use NewtonMesh to create collision, instead of Newton's box/sphere body. I need it because one model needs to have precise collision detection, and has some curved surface part.

Problem:

When I generate NewtonMesh, create a Convex Hull Collision based on that mesh, and then NewtonBody, bounding box of that body is significantly bigger than mesh's bounding box should be. I've read supporting vertices from newton's body (up/down/left/right/front/back) and rendered it in wireframe over actual 3d mesh to see what's going on, and wire box is huge. I've initially used code sample found somewhere on this forum. That sample was including vertex (smoothing) normals and texture coordinates (I have no idea why it was required for collision calculation).

I've changed code to what looked logical to me, and apparently it worked (now bounding box received back from NewtonBody is the same as the one loaded with real mesh, and body reacts on hits in a way I would expect it).

However, I'd like to check with Newton crew if this is how newton mesh was supposed to be generated, and also I have few more questions (below source code):

Code: Select all
   vec3f *data_verts = ddata->vertices; // ptr to array of vertices (vertices are glDrawElement ready, so 3 vertices in a row are 1 face)
   NewtonMesh *nwMesh = NewtonMeshCreate(); // allocate new newton mesh
   NewtonMeshBeginFace(nwMesh); // start adding faces
   xfloat verts[3*3];
   for( xint t = 0; t < trinum; t++) // for each triangle fill coordinates of 3 vertices (9 float values) ...
   {
      for( xint v = 0; v<3; v++)
      {
         verts[v*3+0] = data_verts[ t*3+v ].x;
         verts[v*3+1] = data_verts[ t*3+v  ].y;
         verts[v*3+2] = data_verts[ t*3+v  ].z;
      }
      NewtonMeshAddFace( nwMesh,3,verts,sizeof(xfloat)*3,0); // ...and add them to newton's mesh.
   }
   NewtonMeshEndFace(nwMesh);
   col = NewtonCreateConvexHullFromMesh(nwWorld, nwMesh, 0.1f, 0);
   body = NewtonCreateBody(nwWorld, col);
   ..... etc .....


Code: Select all
NewtonMeshBeginFace(nwMesh);

QUESTION: is this really needed? I've tried without begin/end function pair and it worked too. what is the purpose of begin/end functions?

Code: Select all
NewtonMeshAddFace( nwMesh,3,verts,sizeof(xfloat)*3,0);

QUESTION: why function 'add face' requires number of vertices? triangle has 3 vertices. is newton mesh able to load triangle fan instead? or multiple triangles with 1 function call? if so, is it better to pass to newton all triangles at once, or one-by-one? also, stride size is distance between vertex data (size of 1 vertex data), and in the case number of vertices is not 3, is this also affected?

Code: Select all
col = NewtonCreateConvexHullFromMesh(nwWorld, nwMesh, 0.1f, 0);

QUESTION: if mesh is already defined with triangles, how will 'tolerance' parameter in this function affect collision calculation?

Thanks in advance!
Cheers,
sinisa
 
Posts: 12
Joined: Mon Nov 09, 2009 11:26 am

Re: question about NewtonMeshAddFace usage

Postby JernejL » Tue Nov 10, 2009 9:47 am

Newton trimesh can happly support triangles, quads, and even more vertices per face, i assume newton mesh is same.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: question about NewtonMeshAddFace usage

Postby sinisa » Tue Nov 10, 2009 2:16 pm

Delfi wrote:Newton trimesh can happly support triangles, quads, and even more vertices per face, i assume newton mesh is same.

Thanx for prompt reply, however didn't answer my questions :roll:
sinisa
 
Posts: 12
Joined: Mon Nov 09, 2009 11:26 am

Re: question about NewtonMeshAddFace usage

Postby Stucuk » Tue Nov 10, 2009 3:58 pm

sinisa wrote:
Delfi wrote:Newton trimesh can happly support triangles, quads, and even more vertices per face, i assume newton mesh is same.

Thanx for prompt reply, however didn't answer my questions :roll:


What Delfi is saying is you can pass any Polygon shape as a face (As long as its Convex.. At least i think it has to be Convex. Never used NewtonMesh). So it works with all Polygon types rather than just Trianges.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: question about NewtonMeshAddFace usage

Postby Julio Jerez » Tue Nov 10, 2009 4:10 pm

the triangle of the mesh are not part of teh face of teh convex shape.

to tolerance is a parameter that is used for post processing of teh hull,
after a conevex hull is made, it takes each point point and calculate the average plane equation of the face formed by all the point that are directly conected too the center point.
then it calculate the distacne from the center point to the plane equation and if it is less than the tolerance, it means that point can be removed from the Hull.
It keeps doing that until no more points can be extracted while each time it removes a point, the Hull is repaired.
This have the effect that simplify convex hull where points are clustered too close

a value of 0.1 is probably too big,
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: question about NewtonMeshAddFace usage

Postby sinisa » Tue Nov 10, 2009 4:18 pm

Julio Jerez wrote:the triangle of the mesh are not part of teh face of teh convex shape.

to tolerance is a parameter that is used for post processing of teh hull,
after a conevex hull is made, it takes each point point and calculate the average plane equation of the face formed by all the point that are directly conected too the center point.
then it calculate the distacne from the center point to the plane equation and if it is less than the tolerance, it means that point can be removed from the Hull.
It keeps doing that until no more points can be extracted while each time it removes a point, the Hull is repaired.
This have the effect that simplify convex hull where points are clustered too close

a value of 0.1 is probably too big,


Thnx! :-)))
sinisa
 
Posts: 12
Joined: Mon Nov 09, 2009 11:26 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest