## Super Car and my collision issue

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

### Re: Super Car and my collision issue

I've made one more test, I made a car without wheels and in that case the car has correct AABB. Another thing is that even on that simple polygonal plane from Maya I have problems with collision. When I put a car under the second pair of polygons, I had the same error on contact - https://drive.google.com/file/d/0B83XZ3 ... sp=sharing

P.S. finally I've fixed the AABB problem, it was my internal missing of scaling for the suspension length from the UI property.
Neill

Posts: 16
Joined: Wed Mar 25, 2015 2:11 am

### Re: Super Car and my collision issue

I think the problem Is the road mesh.

I am getting lo of warning indicating that the Mesh is not make of flat faces.
I think you are making eh mesh of Quad, but those quad are part of a curve surfaces
is that right?

I am show a simple mesh quad and it look like this.

m_localPoly x=-33.723141 y=2.9802322e-007 z=0.48729357 w=0.00000000 dgVector
m_localPoly x=-10.345694 y=-0.59050971 z=0.48729357 w=0.00000000 dgVector
m_localPoly x=-10.307526 y=-0.51028484 z=-4.3729572 w=0.00000000 dgVector
m_localPoly x=-33.635769 y=-0.95835012 z=-4.3727589 w=0.00000000 dgVector

as you can see is a squared a flat on the plan x-z, the y pat in one side one edge is a 0.5 whie the other is twisted.
My guess is that you are passing quad, and you did no optimized it.
This is the very first problem.
can you should me the code fragment you are using to build the mesh?
Julio Jerez
Moderator Posts: 11048
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: Super Car and my collision issue

For this road mesh I was starting with the flat plane with 10x4 subdivisions. Then it was sculpted a bit to have a style of the offroad surface. Mesh was created in Maya and then saved into fbx. In MoBu I'm reading fbx and using access to an original geometry.

Here is a code on how I'm preparing array of vertex positions and polygon indices.
Code: Select all
`int totalNumberOfVerts = 0;      int totalNumberOfPolys = 0;      for (int i=0; i<list.GetCount(); ++i)      {         FBModel *pModel = (FBModel*) list[i];         FBGeometry *pGeometry = pModel->Geometry;         FBMesh *pMesh = pModel->TessellatedMesh; // (FBMesh*) pGeometry;         totalNumberOfVerts += pMesh->VertexCount();         if (pMesh->IsTriangleMesh() )         {            totalNumberOfPolys += pMesh->PolygonCount();         }         else         {            for (int j=0; j<pMesh->PolygonCount(); ++j)               if (pMesh->PolygonVertexCount(j) <= 4)                {                  totalNumberOfPolys++;               }         }      }      Allocate(totalNumberOfVerts, totalNumberOfPolys);      totalNumberOfVerts = 0;      totalNumberOfPolys = 0;      auto dstVertex = mVertices.begin();      auto dstPoly = mPolys.begin();      for (int i=0; i<list.GetCount(); ++i)      {         FBModel *pModel = (FBModel*) list[i];         FBGeometry *pGeometry = pModel->Geometry;         FBMesh *pMesh = pModel->TessellatedMesh; // (FBMesh*) pGeometry;         FBMatrix tm;         pModel->GetMatrix(tm);         //         int count = 0;         FBVertex *vertices = pMesh->GetPositionsArray(count);               // apply TM to make a finish coords of the vertices         FBVertex *srcVertex = vertices;                  for (int j=0; j<count; ++j)         {            FBVertexMatrixMult( *dstVertex, tm, *srcVertex );            dstVertex++;            srcVertex++;         }         //         if (pMesh->IsTriangleMesh() )         {            int numIndices;            const int *indices = pMesh->PolygonVertexArrayGet(numIndices);            for (int j=0; j<numIndices/3; ++j)            {               dstPoly->count = 3;               dstPoly->matId = 0;               dstPoly->indices = totalNumberOfVerts + indices[j*3];               dstPoly->indices = totalNumberOfVerts + indices[j*3+1];               dstPoly->indices = totalNumberOfVerts + indices[j*3+2];                              dstPoly++;            }         }         else         {            for (int j=0; j<pMesh->PolygonCount(); ++j)            {               int polyVertCount = pMesh->PolygonVertexCount(j);               if (polyVertCount <= 4)               {                  mPolys[totalNumberOfPolys].count = polyVertCount;                  // SHIFT indices                  for (int k=0; k<polyVertCount; ++k)                     mPolys[totalNumberOfPolys].indices[k] = totalNumberOfVerts + pMesh->PolygonVertexIndex(j, k);                  mPolys[totalNumberOfPolys].matId = 0;                  totalNumberOfPolys++;               }            }         }         //         totalNumberOfVerts += count;      }`

Then I'm passing data into the newton collision tree

Code: Select all
`NewtonCollision *tree = NewtonCreateTreeCollision(pWorld, 0);   // prepare to create collision geometry   NewtonTreeCollisionBeginBuild(tree);   // iterate the entire geometry an build the collision   dVector face;   const Poly *ptrPoly = (level->GetPolyCount() > 0) ? level->GetPoly(0) : nullptr;   for (int i=0; i<level->GetPolyCount(); ++i)   {      ptrPoly = level->GetPoly(i);      assert(ptrPoly->count <= 4);      for (int j=0; j<ptrPoly->count; ++j)      {         const float *vert = level->GetVertexPosition(ptrPoly->indices[j]);         face[j] = (dFloat) vert;         face[j] = (dFloat) vert;         face[j] = (dFloat) vert;         face[j] = 1.0f;         face[j] = face[j].Scale(globalScaling);      }      NewtonTreeCollisionAddFace(tree, ptrPoly->count, &face, sizeof (dVector), ptrPoly->matId);   }   NewtonTreeCollisionEndBuild(tree, 0);`

If this way of creation geometry for collisions is not correct, what instruments I can use in Maya or 3dsMax to make a correct geometry ? And what rules should I take in a count ?
Last edited by Neill on Sat Mar 28, 2015 2:31 pm, edited 1 time in total.
Neill

Posts: 16
Joined: Wed Mar 25, 2015 2:11 am

### Re: Super Car and my collision issue

I just the code that build the mesh. because I though I have check for planarity, but id is does not.
what is has is check for Convexity, by is assume the face are 100% flat.

you can do tow things:
1-Pass triangles and the call optimized,
Optimized will convert what even is a flat quad for a triangle to a Quad.

2-Pass triangles and do no optimized the mesh will still be valise

3-You can use the Quad wi the Newton Mesh and the call Poligionized, that will fixed so that it will preserve the quad in the same way in the paces they are flat, the one that are not flat will be triangulated. Then you can make the collision form the Mesh. This will produce a High quality collision

The simples Test is to just pass two triangles for quad. The level of twisting of the road surface is too big for the collision system algorithm to handle.

I beleive this is the whole problem.
Julio Jerez
Moderator Posts: 11048
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: Super Car and my collision issue

ok, thank you, I will try these steps in practice.
Neill

Posts: 16
Joined: Wed Mar 25, 2015 2:11 am

### Re: Super Car and my collision issue

can you change the code to this?
Code: Select all
`NewtonCollision *tree = NewtonCreateTreeCollision(pWorld, 0);// prepare to create collision geometryNewtonTreeCollisionBeginBuild(tree);// iterate the entire geometry an build the collisiondVector face;const Poly *ptrPoly = (level->GetPolyCount() > 0) ? level->GetPoly(0) : nullptr;for (int i=0; i<level->GetPolyCount(); ++i){   ptrPoly = level->GetPoly(i);   assert(ptrPoly->count <= 4);   for (int j=0; j<ptrPoly->count; ++j)   {      const float *vert = level->GetVertexPosition(ptrPoly->indices[j]);      face[j] = (dFloat) vert;      face[j] = (dFloat) vert;      face[j] = (dFloat) vert;      face[j] = 1.0f;      face[j] = face[j].Scale(globalScaling);   }   dVector face0;   dVector face1;   face0 = face;   face0 = face;   face0 = face;   face1 = face;   face1 = face;   face1 = face;   NewtonTreeCollisionAddFace(tree, 3, &face0, sizeof (dVector), ptrPoly->matId);   NewtonTreeCollisionAddFace(tree, 3, &face1, sizeof (dVector), ptrPoly->matId);}// optimal, you can try this so that it recover the quads in the place that is posib;e NewtonTreeCollisionEndBuild(tree, 1);`
Julio Jerez
Moderator Posts: 11048
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: Super Car and my collision issue

I've tryed a method of loading data into the NewtonMesh, then run Polygonize function and finally, I have a stable run on the road! Thank you, I will continue my work on that! With geometry I should be very attentive, cause in most when people prepare something for animation they don't care a lot about geometry.
I've made also a stress test with 1000 cubes in mobu to compare Newton with already existing physics engines there (ODE and PhysX), and Newton has an advantage in performance. https://www.youtube.com/watch?v=ktLZK4fOLTs
Neill

Posts: 16
Joined: Wed Mar 25, 2015 2:11 am

### Re: Super Car and my collision issue

so do the car drives now?
Julio Jerez
Moderator Posts: 11048
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: Super Car and my collision issue

Yes, the car drives now. I still need to better understand the criteria of level creation, and also I would like to test with bigger level with controlling different car simulation parameters. Btw, at the moment I didn't find a way to change tire parameters after it's creation. I was thinking to add some new methods to change local tire state variables.
I'm very grateful for you Julio, you did a great job on the engine. One year ago I was trying to make a plugin for using Newton physics, and car simulation didn't work correctly on my computer even in demo sandbox, now It's ok.
I will write later about my bigger test results.
Neill

Posts: 16
Joined: Wed Mar 25, 2015 2:11 am

### Re: Super Car and my collision issue

viewtopic.php?f=12&t=8780
Julio Jerez
Moderator Posts: 11048
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

### Re: Super Car and my collision issue

Thank you, that gives me answers.
Neill

Posts: 16
Joined: Wed Mar 25, 2015 2:11 am

Previous