Heightfoeld missing collision on ChamferCylinder

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Heightfoeld missing collision on ChamferCylinder

Postby Esharc » Tue May 09, 2023 11:42 am

Hi Julio,

It seems that if I have a height field with many triangles the chamfer cylinder shape seems to miss collisions when it is tilted slightly.

We have heightfields like this for our dynamic ground, and some vehicles can change the camber of the wheels. I was able to reproduce the issue in the sandbox. Here is the test.

Code: Select all
ndBodyKinematic* AddChamferCylinder(ndDemoEntityManager* const scene, const ndMatrix& location, ndFloat32 mass, ndFloat32 radius, ndFloat32 width, const char* const textName)
{
   ndShapeInstance shape(new ndShapeChamferCylinder(0.5, 1.0));
   shape.SetScale(ndVector(width, radius, radius, 1.0));
   ndBodyKinematic* const body = CreateBody(scene, shape, location, mass, textName);
   return body;
}

static void BuildHeightField(ndDemoEntityManager* const scene)
{
   size_t iDim = 120;
   ndFloat32 dSize = 15, dMaxHeight = 0.0;
   std::vector<ndFloat32> aData; aData.resize(iDim * iDim);
   ndFloat32 fHorizontalScale = ndFloat32(dSize / ndFloat32(iDim - 1));
   ndShapeInstance shape(new ndShapeHeightfield(ndInt32 (iDim), ndInt32(iDim), ndShapeHeightfield::m_normalDiagonals, fHorizontalScale, fHorizontalScale));
   //ndShapeInstance shape(new ndShapeHeightfield(ndInt32(iDim), ndInt32(iDim), ndShapeHeightfield::m_invertedDiagonals, fHorizontalScale, fHorizontalScale));
   ndMatrix mLocal(ndGetIdentityMatrix());
   mLocal.m_posit = ndVector(-(dSize * 0.5), 0.0, -(dSize * 0.5), 1.0);
   shape.SetLocalMatrix(mLocal);
   auto pShapeHeightField = shape.GetShape()->GetAsShapeHeightfield();
   for (int i = 0; i < ndInt32(iDim * iDim); ++i)
   {
      pShapeHeightField->GetElevationMap()[i] = ndReal(ndFloat32(rand()) * ndFloat32(2.0) * dMaxHeight / RAND_MAX);
   }

   pShapeHeightField->UpdateElevationMapAabb();
   ndMatrix uvMatrix(ndGetIdentityMatrix());
   uvMatrix[0][0] *= 0.025f;
   uvMatrix[1][1] *= 0.025f;
   uvMatrix[2][2] *= 0.025f;

   ndSharedPtr<ndDemoMeshInterface>geometry(new ndDemoMesh("box", scene->GetShaderCache(), &shape, "marbleCheckBoard.tga", "marbleCheckBoard.tga", "marbleCheckBoard.tga", 1.0f, uvMatrix, false));
   ndMatrix location(ndGetIdentityMatrix());
   ndDemoEntity* const entity = new ndDemoEntity(location, nullptr);
   entity->SetMesh(geometry);

   ndBodyKinematic* const body = new ndBodyDynamic();
   body->SetMatrix(location);
   body->SetCollisionShape(shape);
   ndSharedPtr<ndBody> bodyPtr(body);
   scene->GetWorld()->AddBody(bodyPtr);
   scene->AddEntity(entity);
}

static void AddBodies(ndDemoEntityManager* const scene)
{
   ndVector vStart(0.0f, 3.0f, 0.0f, 1.0f);
   ndMatrix location(ndRollMatrix(10.0 * ndDegreeToRad));
   location.m_posit = vStart;

   ndBodyKinematic* const body = AddChamferCylinder(scene, location, 1.0f, 1.0f, 1.25f, "wood_0.tga");
   body->SetMatrix(location);
}

//void ndHeightFieldTest(ndDemoEntityManager* const scene)
void ndStaticMeshCollisionDemo(ndDemoEntityManager* const scene)
{
   // build the height field
   BuildHeightField(scene);
   AddBodies(scene);

   ndQuaternion rot;
   ndVector origin(-15.0f, 5.0f, 0.0f, 1.0f);
   scene->SetCameraMatrix(rot, origin);
}


Thank you for all the help you have been giving me so far. I really appreciate it
Esharc
 
Posts: 120
Joined: Tue Jan 10, 2017 5:23 am
Location: South Africa

Re: Heightfoeld missing collision on ChamferCylinder

Postby Julio Jerez » Tue May 09, 2023 12:50 pm

I pasted in the sand box, and yes it fails miserably.

the convex cast for placement passes, but the collision fail.
still do not know what it is I will debug it later tonight.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Heightfoeld missing collision on ChamferCylinder

Postby Julio Jerez » Tue May 09, 2023 1:38 pm

oh I believe I found it.

and yest another obscured hard bug.
on this function. ndInt32 ndContactSolver::ConvexToConvexContactsDiscrete()

also related to the convex cap of mesh polygon.

basically, convex shape do not collide with faces, instead collide with a extruded convex caps.
shape are preprocced, but after the contact are found, ther must be unprocessed.

that is only contacts whos projection on the face plane, is inside the mesh face are part of the collisions.

this is just a simple point polygon distance test, done here.

Code: Select all
                  ndBigVector point(m_buffer[i]);
                  point.m_y = -0.96805524826049805;
                  ndBigVector pointInPoly(ndPointToPolygonDistance(point, &poly[0], convexPolygon->m_count));

                  const ndBigVector error(point - pointInPoly);
                  ndFloat64 dist2 = error.DotProduct(error & ndBigVector::m_triplexMask).GetScalar();

                  ndTrace (("%d %f\n", xxxx++, dist2));



the problem is that, is a polygon is fairly large, the contact point is very close to the plane. in thsi case the polygon is quite small, so the contact distance on the plane are comprable to the disatnce perpendicual to the plane.

the fix is a simple projection on the contact point onto the polygon plane before calculation teh distance.
not fixed yet, I will do more test. but I am positive that's the bug.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Heightfoeld missing collision on ChamferCylinder

Postby Julio Jerez » Tue May 09, 2023 2:00 pm

ok you can sync and try again.

I see some different in behavior in double, the convex shape is no going to rest as fast.
I will debug that tonight.

that could be a failure in contact pruning routine.
but anyway that should be fine now.

note:
I see the quad size are 0.1 x 0.1
good to make the collision system more robust but can put some strength of the collision.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Heightfoeld missing collision on ChamferCylinder

Postby Esharc » Wed May 10, 2023 2:08 am

Thank you, tested and it is working now. I also noticed the shape taking long to rest in our system.
But it seems to take longer in the sand box demo. Not sure if that helps any at all.

Yes that height field is very fine. It is a worst case scenario for us, and we limit usage of those to only vehicles that need such a fine mesh for the dynamic ground.
Esharc
 
Posts: 120
Joined: Tue Jan 10, 2017 5:23 am
Location: South Africa


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 20 guests