NewtonTreeCollision do not optimize

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: NewtonTreeCollision do not optimize

Postby FSA » Sat Aug 31, 2013 3:26 pm

No it does still not optimize.
There you can see the collision mesh:
Attachments
Pic.JPG
Pic.JPG (85.63 KiB) Viewed 3261 times
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: NewtonTreeCollision do not optimize

Postby Julio Jerez » Sat Aug 31, 2013 4:07 pm

I am sure it is doing it.
you can set a break point on this function.
..\newton-dynamics\coreLibrary_300\source\core\dgPolyhedra.cpp

void dgPolyhedra::Optimize (const dgFloat64* const array, dgInt32 strideInBytes, dgFloat64 tol)

or check the history of that file.

I just test the version that is checked with one of the complex mesh in the sand box, and after I fixed that bug now the optimization is so much cleaner.
it manage to resolve some of the difficult area where it did no do a clean job, but now is does almost a perfect commove optimization.
this is how it looks like now.
optimizeBug.png
optimizeBug.png (558.88 KiB) Viewed 3259 times


are you sure you are displaying the debug collision and no you visual mesh wire frame?
set a break point on that functions to see if the mesh is optimized.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonTreeCollision do not optimize

Postby FSA » Sat Aug 31, 2013 4:19 pm

I display the collision mesh as following:
Code: Select all
void DebugShowGeometryCollisionImp (void* userData, int vertexCount, const dFloat* faceVertec, int id)
{
   int ii = vertexCount - 1;
   dVector p0(faceVertec[ii * 3], faceVertec[ii * 3 + 1], faceVertec[ii * 3 + 2]);
   for (int i = 0; i < vertexCount; i ++) {
      dVector p1 (faceVertec[i * 3], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);

      Vector3 s,e;
      s.x = p0.m_x;
      s.y = p0.m_y;
      s.z = p0.m_z;

      e.x = p1.m_x;
      e.y = p1.m_y;
      e.z = p1.m_z;

      g_pLine->AddLine(s, e, Color(1.0f,0.0f,0.55f));
      p0 = p1;
   }
}
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: NewtonTreeCollision do not optimize

Postby FSA » Sat Aug 31, 2013 4:27 pm

And: Yes the function is called.
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: NewtonTreeCollision do not optimize

Postby Julio Jerez » Sat Aug 31, 2013 5:42 pm

in this function ..\newton-dynamics\coreLibrary_300\source\physics\dgCollisionBVH.cpp

Code: Select all
void dgCollisionBVH::EndBuild(dgInt32 optimize)
{
   dgVector p0;
   dgVector p1;

   bool state = optimize ? true : false;

// place a break point here and check the m_faceCount before and after the call to  end
   m_builder->End(state);
   Create (*m_builder, state);
   
   GetAABB (p0, p1);
   SetCollisionBBox (p0, p1);

   delete m_builder;
   m_builder = NULL;
}


set the break point as see if the variable m_faceCount is reduced after call to builder->end().
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonTreeCollision do not optimize

Postby FSA » Sun Sep 01, 2013 6:23 am

Facecount before: 1200
Facecount after: 1200

No change.
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: NewtonTreeCollision do not optimize

Postby Julio Jerez » Sun Sep 01, 2013 8:22 am

It did not optimized anything, that means that state parameter is 0. you must be calling it with optimize = 0
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonTreeCollision do not optimize

Postby FSA » Sun Sep 01, 2013 8:30 am

I call it with 1.
Attachments
Call.JPG
Call.JPG (64.31 KiB) Viewed 3244 times
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: NewtonTreeCollision do not optimize

Postby FSA » Sun Sep 01, 2013 8:34 am

Second picture. dgCollisionBVH:
Attachments
Call2.JPG
Call2.JPG (126.34 KiB) Viewed 3244 times
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: NewtonTreeCollision do not optimize

Postby Julio Jerez » Sun Sep 01, 2013 9:31 am

That makes no sense, I tested with the same mesh that you sent me and it worked. I just tested again checkout a fresh version from SVN and it works.
do you have a binary executable test that I can run using a DLL? so that I can see what is wrong
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonTreeCollision do not optimize

Postby FSA » Sun Sep 01, 2013 11:35 am

I've made a small demo. I will send you a pm for more infortmaion in about 5 minutes :wink:
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: NewtonTreeCollision do not optimize

Postby Julio Jerez » Sun Sep 01, 2013 12:32 pm

Ha I see why it is not optimizing, you are passing a unique material ID for each triangle

Code: Select all
PhysicBody* RigidBodyHandler::CreateLevelRigidBody(Model* CollisionModel, Matrix mTranslation, bool bOptimize)
{
..
      for(int i = 0; i < indexcount; i += 3)
   {
..
// here you are passing a unique material ID to each triangle
      NewtonTreeCollisionAddFace(collision, 3, (float*)vArray[0], sizeof(Vector3), i+1);
   }

}



the collision tree optimizes optimize the mesh by passes, It makes batched of face with equal Material ID, and optimizes the separate.
the in combine then all together, only face that share common Matirial ID can be optimized.

if you want that shape to be optimize dyou can eiteh pass the same id
NewtonTreeCollisionAddFace(collision, 3, (float*)vArray[0], sizeof(Vector3), ID);

or you can pass per Face IDs for example each face of the Box can have different IDs that you can se by applying different material; in your editor or modeler.

It is important for the engine to respect the boundaries of material ID, otherwise the collision respond will not be what the user expect.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonTreeCollision do not optimize

Postby FSA » Sun Sep 01, 2013 12:40 pm

Perfect! It works now :D Thank you.
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests