Problem with static mesh collision in core 300

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Sun Dec 04, 2011 11:06 am

[quote="Bird"]But doesn't that mean that the the normalIndex and uvIndex arrays in our cube example should hold 36 values ... 3 for each of the 12 triangles.[/code]
upps my mistake, yes you are corrent. facesindexListm normal list, uv0indexlint, and uv1Index List, are arrays of index tah amount to teh sum of all vertex of all faces.
for a cube like that 12 triangles * 3 = 36 indices.

the rest in the same, teh normal and UV, can point to a single dummy point.
sorry about that mistake, I did not write it the editir I wrote in the forum editor.


faceIndexCount and faceMaterialIndex are still array equal to teh numbe of face because those are per face attributes.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with static mesh collision in core 300

Postby Bird » Sun Dec 04, 2011 2:02 pm

the rest in the same, teh normal and UV, can point to a single dummy point.
sorry about that mistake, I did not write it the editir I wrote in the forum editor.

No worries, I've think I've got it working now. The dummy point option is actually quite useful to me since my project is a plugin and the host application does the rendering. I can save some bytes by not storing the normals or uvs.

Thanks for the help.

-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Sun Dec 04, 2011 5:10 pm

Bird wrote:
The HACD is dont an checked in. if you are running the lastest build you will see the Camel, and the Cow being generated amost intantaneuslly.

That's great. I'll test it out on a bunch of different models.


I checked in the latest fix on the HACD, I fixed my max plugin, so that I can test it with few model without having to modofo code every time. The Max plugin is part of the SDK too.

some stats in my intel Icore7 2.8 ghz.
the camel mode with about 20000 faces takes 4 secunds in max, to decompse into 16 convex. and about 2 secund for 32 convexes.
the bonny that has 70000 faces takes 55 secunds to make 16 convex, and about 30 secunds for 32 convexes.
and that time includes the overhead of converting the mesh from Max to NetwonMesh and back again.
It is almost the same amount of time that takes Max to load the WRL file.
anything under 1000 faces is practically instantaneus.

note: I just realiced have a bug in one of the metric of the concavity components, because the bunny does not looks good, but this has nothing to do wi the performance of the implementation if anything it will make even faster.
I am gueesing it is because I had being tryin to chneg teh meaning of eth concavity to make a normalized metric, but that is turnin to be very difficult.
anyway it is all checked it, you can test it in your plugin see how it goes for you.

I will work of the concacity bug after I cover some of the bug/features in the feature list.


the one that really stress test the pugin is teh elephan, whi has 158000 faces, and it take 270 secunds to decompose, bu that is because I cam no doin any hierachcal subdividion of mesh optimization.
this can be fixes to take maybe 30 of 40 secund by doing that, but I do not know hwo is usin mesh of this kind of resolution.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with static mesh collision in core 300

Postby Bird » Sun Dec 04, 2011 6:39 pm

I checked in the latest fix on the HACD

I haven't been able to get off the ground yet unfortunately. I am using this code to create the convexApproximation and extract the convex pieces. I need to do this before sending to convex pieces to NewtonEngine to be assembled into a CompoundCollision shape because I have to display the pieces to the user.

Code: Select all
void Newton3Tools::createConvexComposite (const TriMesh * const triMesh,
                                          TriMeshes & pieces)
{   TRACE("Newton3Tools::createConvexComposite")

   NewtonMesh* const newtonMesh = triMeshToNewtonMesh(triMesh);
   
   NewtonMesh* const convexApproximation = NewtonMeshApproximateConvexDecomposition (newtonMesh, 0.2f, 16);
   NewtonMesh* nextSegment = NULL;
   for (NewtonMesh* segment = NewtonMeshCreateFirstSingleSegment (convexApproximation); segment; segment = nextSegment)
   {
      nextSegment = NewtonMeshCreateNextSingleSegment (convexApproximation, segment);
      pieces.push_back( newtonMeshToTriMesh(segment) );
      
      NewtonMeshDestroy(segment);
   }
   NewtonMeshDestroy (newtonMesh);
   NewtonMeshDestroy (convexApproximation);
}

When I try to covert the NewtonMesh back to my TriMesh object, I'm seeing unexpected results when querying the NewtonMesh for its data.

Code: Select all
TriMesh * Newton3Tools::newtonMeshToTriMesh (const NewtonMesh * const newtonMesh)
{   TRACE("Newton3Tools::newtonMeshToTriMesh")

   int vertexCount = NewtonMeshGetVertexCount(newtonMesh);
   debug("*************This newton mesh has: " + ToString<int>(vertexCount) + " vertices");
   for (void* vertex = NewtonMeshGetFirstVertex(newtonMesh); vertex; vertex = NewtonMeshGetNextVertex(newtonMesh, vertex))
   {
      int index = NewtonMeshGetVertexIndex(newtonMesh, vertex) * stride;
      dFloat x = dFloat(vertexList[index + 0]);
      dFloat y = dFloat(vertexList[index + 1]);
      dFloat z = dFloat(vertexList[index + 2]);

      Vector3f p(x, y, z);
      debug(printVector(p));
   }
}


For instance, vertexCount might be 42 but when iterating through the vertices only 10 vectors are provided.

Am I doing something wrong here that you can see.?

-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Sun Dec 04, 2011 6:48 pm

will it help is I make a demo that show how to create a MeshEffet form a empty verts list Index list liek thr cube you posted?

I can write a L shape mesh to a text file and I will paste in the code, that way it will mak eteh mesh form teh static data, rather than from a dScene xml.
will that be suffucent?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with static mesh collision in core 300

Postby Bird » Sun Dec 04, 2011 6:55 pm

Yes, anything will help at this point. :)

-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Sun Dec 04, 2011 11:53 pm

Ok I check it the first an I beleiev teh simples demo using NewtonMesh. thsi si the script

Code: Select all
static void LoadLoadSimpleBox (DemoEntityManager* const scene, const dVector& origin)
{
   // the vertex array, vertices's has for values, x, y, z, w
   // w is use as a id to have multiple copy of the same very, like for example mesh that share more than two edges.
   // in most case w can be set to 0.0
   static float BoxPoints[] = {
      -0.5,    -0.5,    -0.5, 0.0,
      -0.5,    -0.5,    0.5, 0.0,
      -0.5,    0.5,    0.5, 0.0,
      -0.5,    0.5,    -0.5, 0.0,
      0.5,    -0.5,    -0.5, 0.0,
      0.5,    -0.5,    0.5, 0.0,
      0.5,    0.5,    0.5, 0.0,
      0.5,    0.5,    -0.5, 0.0,
   };

   // the vertex index list is an array of all the face, in any order, the can be convex or concave,
   // and has and variable umber of indices
   static int BoxIndices[] = {
      2,3,0,1,  // this is quad
      5,2,1,    // triangle
      6,2,5,    // another triangle
      5,1,0,4,  // another quad
      2,7,3,    // and so on
      6,7,2,
      3,4,0,
      7,4,3,
      7,5,4,
      6,5,7
   };

   // the number of index for each face is specified by an array of consecutive face index
   static int faceIndexList [] = {4, 3, 3, 4, 3, 3, 3, 3, 3, 3};
 
   // each face can have an arbitrary index that the application can use as a material index
   // for example the index point to a texture, we can have the each face of the cube with a different texture
   static int faceMateriaIndexList [] = {0, 4, 4, 2, 3, 3, 3, 3, 3, 3};


   // the normal is specified per vertex and each vertex can have a unique normal or a duplicated
   // for example a cube has 6 normals
   static const float Normal[] = {
      1.0, 0.0, 0.0,
      -1.0, 0.0, 0.0,
      0.0, 1.0, 0.0,
      0.0, -1.0, 0.0,
      0.0, 0.0, 1.0,
      0.0, 0.0, -1.0,
   };

   static int faceNormalIndex [] = {
      0, 0, 0, 0, // first face uses the first normal o each vertex
      3, 3, 3,    // second face uses the third normal
      3, 3, 3,    // third face uses the fifth normal
      1, 1, 1, 1, // third face use the second normal
      2, 2, 2,    // and so on
      2, 2, 2,   
      4, 4, 4,   
      4, 4, 4,   
      5, 5, 5,    // two coplanar face can even has different normals
      3, 2, 0,   
   };
   

   // the UV are encode the same way as the vertex an the normals, a UV list and an index list
   // since we do no have UV we can assign the all to zero
   static const float uv0[] = { 0, 0};
   static const int uv0_indexList [] = {
      0, 0, 0, 0,
      0, 0, 0,
      0, 0, 0,
      0, 0, 0, 0,
      0, 0, 0,
      0, 0, 0,
      0, 0, 0,
      0, 0, 0,
      0, 0, 0,
      0, 0, 0,
   };
   // we can reuse the same same UV input for the second channel, if they have different UV then it will be code the exact same way as UV0


   
   // now we create and empty mesh
   NewtonMesh* const newtonMesh = NewtonMeshCreate (scene->GetNewton());

   // build the mesh from an index list vertex list, alternatively we can also build the mesh by parring one face at at time
   NewtonMeshBuildFromVertexListIndexList(newtonMesh,
      10, faceIndexList, faceMateriaIndexList,
      BoxPoints, 4 * sizeof (float), BoxIndices,
      Normal, 3 * sizeof (float), faceNormalIndex,
      uv0, 2 * sizeof (float), uv0_indexList,
      uv0, 2 * sizeof (float), uv0_indexList);



   // now we can use this mesh for lot of stuff, we can apply UV, we can decompose into convex,
   // we can apply boolean operations we can turn into voronoi debris, am so on
   NewtonCollision* const collision = NewtonCreateConvexHullFromMesh(scene->GetNewton(), newtonMesh, 0.01f, 0);

   // for now we will simple make simple Box,  make a visual Mesh
   DemoMesh* const visualMesh = new DemoMesh (newtonMesh);

   int instaceCount = 4;
   dMatrix matrix (GetIdentityMatrix());
   matrix.m_posit = origin;
   for (int ix = 0; ix < instaceCount; ix ++) {
      for (int iz = 0; iz < instaceCount; iz ++) {
         dFloat y = origin.m_y;
         dFloat x = origin.m_x + (ix - instaceCount/2) * 4.0f;
         dFloat z = origin.m_z + (iz - instaceCount/2) * 4.0f;
         matrix.m_posit = FindFloor (scene->GetNewton(), dVector (x, y + 10.0f, z, 0.0f), 20.0f); ;
         matrix.m_posit.m_y += 2.0f;
         CreateSimpleSolid (scene, visualMesh, 10.0f, matrix, collision, 0);
      }
   }

   visualMesh->Release();
   NewtonReleaseCollision(scene->GetNewton(), collision);

   NewtonMeshDestroy (newtonMesh);

}


basically it makes a cube for array of data, and place few of then in the world.
please see if thsi helps you figure it out, teh mesh is a very pweful tool, similat to what programe liek Max, Maya, Lighwave do.
In some way is even more poewful than that because it use extremally robust arithemetic ( in fact is uses exact arithemtic for many algorithm), is very fast and also has some advance features.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with static mesh collision in core 300

Postby Bird » Mon Dec 05, 2011 12:18 am

the one that really stress test the pugin is teh elephan, whi has 158000 faces, and it take 270 secunds to decompose, bu that is because I cam no doin any hierachcal subdividion of mesh optimization.
this can be fixes to take maybe 30 of 40 secund by doing that, but I do not know hwo is usin mesh of this kind of resolution.

Hehe, 158,000 faces is considered low-res for film and tv users. They want to blow up 4 million poly spaceships.

I tried some tests with the NewtonMeshApproximateConvexDecomposition even though I don't have it totally hooked up yet.. Most of the simpler models like the cow were at least 4 times faster than HACD. But when I tried more complex models, HACD was much faster. Here a video of the meshes I tried http://www.hurleyworks.com/media/flash/ConvexDecompTests/ConvexDecompTests.html

And here's the timing results:

HACD decomposed: Noodle with 43272 triangles in: 9.73334 seconds
NewtonMeshApproximateConvexDecomposition: Noodle with 43272 triangles in: 32.1327 seconds

HACD decomposed: Han_Solo with 65988 triangles in: 13.8479 seconds
NewtonMeshApproximateConvexDecomposition: Han_Solo with 65988 triangles in: 53.0813 seconds

HACD decomposed: armadillo with 100000 triangles in: 22.961 seconds
NewtonMeshApproximateConvexDecomposition: armadillo with 100000 triangles in: 349.892 seconds

I wrapped my stopwatch around the call to NewtonMeshApproximateConvexDecomposition like this
And I used default settings for HACD and the same ones that you used in your demo for Newton

-Bird

Code: Select all
Tracer::X86Timer timer;
timer.start();

NewtonMesh* const convexApproximation = NewtonMeshApproximateConvexDecomposition (newtonMesh, 0.2f, 16);

UInt64 nanoSecs = timer.stop();
double secs = (double)nanoSecs/1000000000.0;
std::string msg(triMesh->getName() + " with " + ToString<int>(triMesh->getTriangleCount()) + " triangles in: " );
msg += ToString<double>(secs) + " seconds";
debug(" ******** NewtonMeshApproximateConvexDecomposition: " + msg);
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Mon Dec 05, 2011 12:35 am

That is because teh HACD is using a pre mesh simplication step.
The newton version is faste in every aspect when no using mesh simplification.
the newton version is operation on teh mesh as it is given.
But in any case I will add the mesh simplification because that come for free.

bascially teh newr version is decimation teh mesh abtitrallyli, for exampel teh bonny example has pordinally 70,000 face.
when the decimate to 16000 face teh procces take 200 secund. The newton one take less than that but work on the 7000 faces.

There is still some work I need to do on the code
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with static mesh collision in core 300

Postby Bird » Mon Dec 05, 2011 12:38 am

Code: Select all
asically it makes a cube for array of data, and place few of then in the world.
please see if thsi helps you figure it out, teh mesh is a very pweful tool, similat to what programe liek Max, Maya, Lighwave do.
In some way is even more poewful than that because it use extremally robust arithemetic ( in fact is uses exact arithemtic for many algorithm), is very fast and also has some advance features.


Yes, MeshEffects looks very powerful with all sorts of goodies inside that I want to use.:)

Thanks for the script. That's very clear now .... except for the normals. If the normal is per vertex, then a cube should have 8 normals, correct?

-Bird

// the normal is specified per vertex and each vertex can have a unique normal or a duplicated
// for example a cube has 6 normals
static const float Normal[] = {
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Mon Dec 05, 2011 12:41 am

Bird wrote:If the normal is per vertex, then a cube should have 8 normals, correct?

normals are per vertex per face. I point on a cube can have upto 6 normals if the at that vertex all the face share the diagnals of each face of the cube.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with static mesh collision in core 300

Postby Bird » Mon Dec 05, 2011 12:51 am

Julio Jerez wrote:
Bird wrote:Thanks for the script. That's very clear now .... except for the normals. If the normal is per vertex, then a cube should have 8 normals, correct?


normal are per vertex per face. I point on a cube can have upto 6 normals if eact face happen to heb the diagina of teh tow tringel tha make a cube face.


Ok, I get it now. Thanks for the explanation.

-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Problem with static mesh collision in core 300

Postby Bird » Mon Dec 05, 2011 6:54 pm

I figured out why I couldn't parse the convex NewtonMesh pieces generated by NewtonMeshApproximateConvexDecomposition. I assumed that each piece had it's own vertex array instead of sharing a common one like they actually do.

BTW, this is really great! Not only did you make it much faster, your version appears to handle small holes much more cleanly than HACD does and this is a really big win for some simulations .http://www.hurleyworks.com/downloads/Newton_deocmp.jpg

Thanks again for taking the time to add this improvement to Newton.

-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Tue Dec 06, 2011 12:21 pm

Ha very cool, afte I am done wi thsi short Bug and feature list I will add some imporvmen to make even faste, and gerneration more human like partitions.
I am not satisfied witg the result yet, but I am glad you find it useful.

Ok now I completed the first bug.
You can add and remove pieces from a compound collision at will.
I change teh inetface a litle to make it simple to use.
you can check file ..\applications\newtonDemos\sdkDemos\demos\CompoundCollision.cpp
to see how it you can use it.

Now I am on to the secund feature, Getting the force form a contact Joint at teh moment of Impact.
righ now ipulisve force are no considred resting force, so you read zero. bu this is iportant for many thing, specially for the Destruction feature.
that sopdul be veryh eassy to get it going.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with static mesh collision in core 300

Postby Bird » Tue Dec 06, 2011 9:47 pm

Ok now I completed the first bug.
You can add and remove pieces from a compound collision at will.
I change teh inetface a litle to make it simple to use.
you can check file ..\applications\newtonDemos\sdkDemos\demos\CompoundCollision.cpp
to see how it you can use it.


Excellent! Nice and easy to understand and use ... as most of Newton's API is. I had no problems using it .

I'd like to remove nodes from a CompoundCollision during NewtonMaterialSetCollisionCallback. Is it possible to know on which node the contact occurred when the Collision type is CompoundCollision?

-Bird
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

PreviousNext

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 2 guests

cron