Problem with static mesh collision in core 300

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Problem with static mesh collision in core 300

Postby Bird » Fri Dec 02, 2011 8:28 pm

I'm seeing collision problems in core_300 when using NewtonTreeCollision to create static meshes. Here's a simple example http://www.hurleyworks.com/media/flash/StaticMeshProb/StaticMeshProb.html

The container mesh is made using with NewtonCreateTreeCollision and has 0 mass. I tried linking my project to core_200 and it worked as expected so I think this is a core_300 problem. If you need the objects just let me know but I think it should be easy to reproduce using any objects.

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

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Fri Dec 02, 2011 9:52 pm

wow that's a big bug.

you know they is a library in the sdk that if you link it to the project you can serialize a newton world to a xml file that I can use to debug teh scene.
basically all you have to do is link teh dScene libary to your project and do this

Code: Select all
dScene database (newtonWorld);
database.NewtonWorldToScene (newtonWorld);
database.Serialize(fileName);


and that will save an exact copy of the state of the world. to an xml file.
then I can use that to debug the scene.

if you do that then it will be so much simpler to debug scenes.
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 » Sat Dec 03, 2011 1:06 pm

you know they is a library in the sdk that if you link it to the project you can serialize a newton world to a xml file that I can use to debug teh scene.
basically all you have to do is link teh dScene libary to your project and do this


I gave that a try but it looks like Tree types are not supported yet ... so I hit the _ASSERTE in line 159 of dScene.cpp.

-Bird


Code: Select all
case SERIALIZE_ID_CONVEXMODIFIER:
case SERIALIZE_ID_TREE:
case SERIALIZE_ID_NULL:
case SERIALIZE_ID_HEIGHTFIELD:
case SERIALIZE_ID_USERMESH:
case SERIALIZE_ID_SCENE:
case SERIALIZE_ID_COMPOUND_BREAKABLE:
{
   _ASSERTE(0);
   break;
}
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Sat Dec 03, 2011 1:38 pm

Ha I forget about that, let use do this

try using a box, just to see if you can get the dScene working. you sodul be able to serialize and deserialize a scene. basically si soem king of export inport that you cna use for phsyics scenes, and even graphics as well.

I will quickly add the dTreeCollision type support so that we can share information that way. I think that since some shage on teh dtree form 200 to tree hundred this is why is not working because
SERIALIZE_ID_TREE is teh tree collision id.

any way usig this method is the faster way that we can share information afte I get it ready.
I was planning using collada for that but collada si too huge, and si ever changind. I was writing oen version and even before I finished the next made useless.
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 Julio Jerez » Sat Dec 03, 2011 2:08 pm

let us do this:

I got there Bug/ feature In me list that are important from you:
1- make MeshEffect recorve conneted segments
2-Add remove conves form compound
3-add Collision trees to serialization
4- I beleve there is anoteh bu it scape me now.


I am going to change the order because teh last tree are eassy fix and are more imprtant that the MeshEffect,
that way I can check in those fixts and clean up the Task list
so I will do in thsi order

1-Add/Remove convex from compound collision
2-add Collision trees to serialization
3- I need to inegrate a Makefiel Patch for Linux Users
4- make MeshEffect recorver conneted segments
5- please remind me what was the other one.
6- continue the sotf body support

this way I cna hav ethe forst tow fix today, and then continues the other teh Mesh effect,
It is more involve that I was imagining at first.
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 » Sat Dec 03, 2011 3:33 pm

4- I beleve there is anoteh bu it scape me now.

I couldn't obtain the contact force from the NewtonMaterialSetCollisionCallback() ... it is always 0.

I can extract disconnected pieces on my side, so it's not a priority if it's difficult to do in MeshhEffect.

One thing I'm really really desperate for is dynamic shattering of complex meshes. I can do box shapes with using my toolkit http://www.hurleyworks.com/media/flash/FixedFracturing/FixedFracturing.html But I need to break up a cow, for instance. Can I use Newton do that now? If not, that would be a big priority to me.

How is the speedup of HACD going? That would be a great help to my project as well . I see you've been working on it.

Thanks for all the support! It's something that's hard to come by in other physics engine projects out there. :)

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

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Sat Dec 03, 2011 3:36 pm

ha, yes that was the one missing

1-Add/Remove convex from compound collision
2- hook contact force callback for contcat joints.
3-add Collision trees to serialization
4- I need to inegrate a Makefiel Patch for Linux Users
5- make MeshEffect recorver conneted segments
6- please remind me what was the other one.
7- continue the sotf body support
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 Julio Jerez » Sat Dec 03, 2011 3:44 pm

Bird wrote:
4- I beleve there is anoteh bu it scape me now.

One thing I'm really really desperate for is dynamic shattering of complex meshes. I can do box shapes with using my toolkit http://www.hurleyworks.com/media/flash/FixedFracturing/FixedFracturing.html But I need to break up a cow, for instance. Can I use Newton do that now? If not, that would be a big priority to me.
How is the speedup of HACD going? That would be a great help to my project as well . I see you've been working on it.
-Bird


you can break the cow or any close maniford mesh using the Mesh effect,
you can actually do better than just that, you can breeak it and have teh iterior painet with a material.

but they is a bug that I do not fixed, bascially after the break of the pat into a tetar herat array, the extrieo has tro be remove, an dI has a bug the was calulation teh wrong UVs.
I try to fixex bu Y realice that si is a mistake to do that, vecaise very lareg object will inevitable run in problems becais eth vorinoi shatte will generate touns and tound of degnerate tertar hedrom.
what I going to do now is to break the mesh into sub meshe and usin eh conve partition.
then sinc eeach enclose body will be a smale set tha is almos conve then teh remove of extreion part become musg simpler.
I will put that to teh end of the list.

The HACD is dont an chek in. if yo usin to laste build you will see teh Camel, an dteh Cow being generated amost intantanuswlly.

here is a code sample code to do it

Code: Select all
static void LoadCompoundModel_NewtonVersion (const char* const name, DemoEntityManager* const scene, const dVector& origin, int instaceCount)
{

   char fileName[2048];
   GetWorkingFileName (name, fileName);

   NewtonWorld* const world = scene->GetNewton();
   dScene compoundTestMesh (world);
   compoundTestMesh.Deserialize(fileName);

   // freeze the scale and pivot on the model
   compoundTestMesh.FreezeScale();
   compoundTestMesh.FreezePivot ();


   dMeshNodeInfo* mesh = NULL;
   for (dScene::dTreeNode* node = compoundTestMesh.GetFirstNode (); node; node = compoundTestMesh.GetNextNode (node)) {
      dNodeInfo* info = compoundTestMesh.GetInfoFromNode(node);
      if (info->GetTypeId() == dMeshNodeInfo::GetRttiType()) {
         mesh = (dMeshNodeInfo*) info;
         break;
      }
   }

   _ASSERTE (mesh);
   _ASSERTE (mesh->GetMesh());

   NewtonMesh* const newtonMesh = mesh->GetMesh();

   // create a convex approximation form the original mesh
   NewtonMesh* const convexApproximation = NewtonMeshApproximateConvexDecomposition (newtonMesh, 0.2f, 16);

   // create a compound collision by creation a convex hull of each segment of the source mesh
   NewtonCollision* const compound = NewtonCreateCompoundCollisionFromMesh (world, convexApproximation, 0.001f, 0, 0);
   
   // make a visual Mesh
   DemoMesh* const visualMesh = new DemoMesh (newtonMesh);

   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 (world, dVector (x, y + 10.0f, z, 0.0f), 20.0f); ;
         matrix.m_posit.m_y += 2.0f;
         CreateSimpleSolid (scene, visualMesh, 10.0f, matrix, compound, 0);
      }
   }

   visualMesh->Release();

   NewtonReleaseCollision(world, compound);

   NewtonMeshDestroy (convexApproximation);
}


afte I fix these bug and added teh new funtionality, I iwll makd anoteh demo were the Cow an dteh camel can be broken to pieces. how's that?
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 » Sat Dec 03, 2011 5:11 pm

The HACD is dont an chek in. if yo usin to laste build you will see teh Camel, an dteh Cow being generated amost intantanuswlly.

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

afte I fix these bug and added teh new funtionality, I iwll makd anoteh demo were the Cow an dteh camel can be broken to pieces. how's that?


That would be wonderful. :) Thank you very much!

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

Re: Problem with static mesh collision in core 300

Postby Bird » Sat Dec 03, 2011 8:03 pm

I'm still having a problem converting my mesh data structures to a NewtonMesh. I found an example that helps me in PhysicsUtils::ExtrudeFaces() and I think I found a bug there while looking at the code.

Code: Select all
float face[32][10];
// add the face displace by some offset
for (int i = 0; i < vertexCount; i ++) {
dVector p1 (faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
p1 += displacemnet;

face[i][0] = p1.m_x;
face[i][1] = p1.m_y; 
face[i][2] = p1.m_z;   

face[i][3] = normal.m_x;
face[i][4] = normal.m_y; 
face[i][5] = normal.m_z; 

face[i][6] = 0.0f;
face[i][7] = 0.0f; 
face[i][8] = 0.0f; 
face[i][9] = 0.0f; 
}
// add the face
   NewtonMeshAddFace (mesh, vertexCount, &face[0][0], 10 * sizeof (float), id);


When filling out the vertex list, there's no value set for the p1.m_w component but in dgMeshEffect::AddPolygon (), the m_w is expected so there will be an off by 1 problem. So I think the correct code should be:

Code: Select all
float face[32][11];
// add the face displace by some offset
for (int i = 0; i < vertexCount; i ++) {
dVector p1 (faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
p1 += displacemnet;

face[i][0] = p1.m_x;
face[i][1] = p1.m_y; 
face[i][2] = p1.m_z;   
face[i][3] = p1.m_w; 

face[i][4] = normal.m_x;
face[i][5] = normal.m_y; 
face[i][6] = normal.m_z; 

face[i][7] = 0.0f;
face[i][8] = 0.0f; 
face[i][9] = 0.0f; 
face[i][10] = 0.0f; 
}
// add the face
   NewtonMeshAddFace (mesh, vertexCount, &face[0][0], 11 * sizeof (float), id);


Is that right?

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

Re: Problem with static mesh collision in core 300

Postby Bird » Sat Dec 03, 2011 9:30 pm

If you get a chance, could you please explain the the parameters for NewtonMeshBuildFromVertexListIndexList(). I searched the SDK and it's not called anywhere that I could find. Could you show an example of how to create a NewtonMesh from the vertices and indices of a cube like this?

-Bird

Code: Select all
static const float BoxVertices[] = {
   -0.5,    -0.5,    -0.5,
   -0.5,    -0.5,    0.5,
   -0.5,    0.5,    0.5,
   -0.5,    0.5,    -0.5,
   0.5,    -0.5,    -0.5,
   0.5,    -0.5,    0.5,
   0.5,    0.5,    0.5,
   0.5,    0.5,    -0.5
};

static const unsigned int BoxIndices[12][3] = {
   {1,0,3},
   {2,1,3},
   {4,0,1},
   {5,4,1},
   {5,1,2},
   {6,5,2},
   {2,3,7},
   {6,2,7},
   {3,0,4},
   {7,3,4},
   {7,4,5},
   {6,7,5}
}
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Problem with static mesh collision in core 300

Postby Julio Jerez » Sat Dec 03, 2011 11:00 pm

that code is commented out, it is legacy form wha I starrf the mesh and the vertx was 3 float, now is for floats. so yes it woudl be wrong.


here is a sample to how to pass that dat to the mesh

Code: Select all
static const float BoxVertices[] = {
   -0.5,    -0.5,    -0.5, 0
   -0.5,    -0.5,    0.5, 0
   -0.5,    0.5,    0.5, 0
   -0.5,    0.5,    -0.5, 0
   0.5,    -0.5,    -0.5, 0
   0.5,    -0.5,    0.5, 0
   0.5,    0.5,    0.5, 0
   0.5,    0.5,    -0.5, 0
};

static const float Normal[] = { 0, 1, 0};

static const unsigned int BoxIndices[12][3] = {
   {1,0,3},
   {2,1,3},
   {4,0,1},
   {5,4,1},
   {5,1,2},
   {6,5,2},
   {2,3,7},
   {6,2,7},
   {3,0,4},
   {7,3,4},
   {7,4,5},
   {6,7,5}
}

static const float Normal[] = { 0, 1, 0};
static const float uv0[] = { 0, 0};
static const float uv1[] = { 0, 0};

static const unsigned int faceIndexCount [12] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3};
static const unsigned int faceMaterialIndex [12] = { 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 3, 2};
static const unsigned int normalIndex [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static const unsigned int uv0 [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static const unsigned int uv1 [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

NewtonMeshBuildFromVertexListIndexList(
   mesh,                     \\am empty newton mesh
   12,                        \\ a cube has 12 faces,
   faceIndexCount,                  \\ the number of vetices of each face (it also suport polygons, an even concave polygons too)
   faceMaterialIndex,               \\ an user id that can be use to assign a materia to teh face (in the cube some face has matrial 0, some mateail 2 and one materil 3)
   BoxVertices,                  \\ the start of the verts array         
   4 * sizeof (float),            \\ the stride isn byte of each vertex
   BoxIndices,                      \\ the begining of the vertex index list
   normal,                     \\ the start of the normal array             
   3 * sizeof (float),            \\ the stride in byte of each normal
   normalIndex,                     \\ the begining of the normal index list
   uv0,                         \\ the start of the uv0 channel array             
   2 * sizeof (float),            \\ the stride in byte of each uv
   uv0Index,                        \\ the begining of the normal uv0 list
   uv1,                         \\ the start of the uv0 channel array             
   2 * sizeof (float),            \\ the stride in byte of each uv
   uv1Index,                        \\ the begining of the normal uv1 list
)

   


basically each channel is a independe vetrs list indes list:
the vertice is a vertex list idnes list,
the normal is anothe vertex list indes list,
the UV0 and UV1 are also vertex ist index list.

the faces are passed in the face index array, each enty is teh numbe of point on each face:
for example a piramid with 3 triangle and one quad will be li this : (3, 3, 3, 3, 4)
the material is an arbitrary index that isa ssociated with the face.
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:45 am

Code: Select all
static const unsigned int normalIndex [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static const unsigned int uv0 [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static const unsigned int uv1 [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};


Sorry for being dense but I still can't get this to work. I don't understand what normals you're using there. It looks like face normals, since there's only 12 allocated. Why are the normalIndex values all 0? Same goes for the uvs. Why are there only 12 allocated? I'm lost. :)

-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 8:55 am

since the cube does no have any normals and UV I made a dommy normal set to 0, 1, 0 and and UV set to 0, 0
and the I pointed each all normal indix and uv index to those respective values

say a face has for points, then each point also has a normal and an UV, if you ste the indes array to [0, 0, 0, 0] fo normal and uv then it will point to the normal loacate at pointion 0, of eh normal array, and he same goes fo the UVs.
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 10:20 am

say a face has for points, then each point also has a normal and an UV, if you ste the indes array to [0, 0, 0, 0] fo normal and uv then it will point to the normal loacate at pointion 0, of eh normal array, and he same goes fo the UVs.

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: Select all
const unsigned int normalIndex [36] = {0};
const unsigned int uv0Index [36] = {0};
const unsigned int uv1Index [36] = {0};

Here's the code I'm trying to get to work. I had to make a few changes to get it to compile and I set the normals and uv to values I could easily pick out while debugging. If I run this code there's a crash in dgMeshEffect while extracting the normals and uvs

-Bird

Code: Select all
static const float BoxVertices[] = {
   -0.5,    -0.5,    -0.5, 0,
   -0.5,    -0.5,    0.5, 0,
   -0.5,    0.5,    0.5, 0,
   -0.5,    0.5,    -0.5, 0,
   0.5,    -0.5,    -0.5, 0,
   0.5,    -0.5,    0.5, 0,
   0.5,    0.5,    0.5, 0,
   0.5,    0.5,    -0.5, 0
};

static const int BoxIndices[] = {
   1,0,3,
   2,1,3,
   4,0,1,
   5,4,1,
   5,1,2,
   6,5,2,
   2,3,7,
   6,2,7,
   3,0,4,
   7,3,4,
   7,4,5,
   6,7,5
};

 const float Normal[] = {.111, .222, .333};
 const float uv0[] = {.444, .555};
 const float uv1[] = {.666, .777};

 const int faceIndexCount [12] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3};
 const int faceMaterialIndex [12] = { 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 3, 2};
 const int normalIndex [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 const int uv0Index [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 const int uv1Index [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

TEST(NewtonMesh)
{
   NewtonWorld* world = NewtonCreate ();
   NewtonMesh* mesh = NewtonMeshCreate(world);
    NewtonMeshBuildFromVertexListIndexList(
       mesh,               //am empty newton mesh
       12,                  // a cube has 12 faces,
       faceIndexCount,          // the number of vetices of each face (it also suport polygons, an even concave polygons too)
       faceMaterialIndex,       // an user id that can be use to assign a materia to teh face (in the cube some face has matrial 0, some mateail 2 and one materil 3)
       BoxVertices,             // the start of the verts array         
       4 * sizeof (float),      // the stride isn byte of each vertex
       BoxIndices,              // the begining of the vertex index list
       Normal,                  // the start of the normal array             
       3 * sizeof (float),      // the stride in byte of each normal
       normalIndex,             // the begining of the normal index list
       uv0,                  // the start of the uv0 channel array             
       2 * sizeof (float),      // the stride in byte of each uv
       uv0Index,                // the begining of the normal uv0 list
       uv1,                     // the start of the uv0 channel array             
       2 * sizeof (float),      // the stride in byte of each uv
       uv1Index                 // the begining of the normal uv1 list
    );

   int vertexCount = NewtonMeshGetVertexCount (mesh);
   CHECK( vertexCount == 8 );

   int faceCount = NewtonMeshGetTotalFaceCount(mesh); 
   CHECK (faceCount == 12 );
}
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Next

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 7 guests

cron