Convex cast and face id

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Convex cast and face id

Postby Julio Jerez » Thu Jan 24, 2013 12:37 pm

Oh I see teh contact id is alway zero

here this is the code fomre conevex cast, it simpel set teh id to zero.
Code: Select all
                        for (dgInt32 i = 0; i < count; i++) {
                           info[totalCount].m_hitBody = body;
                           info[totalCount].m_point[0] = points[i].m_x;
                           info[totalCount].m_point[1] = points[i].m_y;
                           info[totalCount].m_point[2] = points[i].m_z;
                           info[totalCount].m_normal[0] = normals[i].m_x;
                           info[totalCount].m_normal[1] = normals[i].m_y;
                           info[totalCount].m_normal[2] = normals[i].m_z;
                           info[totalCount].m_penetration = penetration[i];
                           info[totalCount].m_contaID = 0;
                           totalCount++;
                        }


this is eassy to fix. teh othe thing is not so eassy.
Tell me if I make so that is repost teh proper material ID, an dteh proper sub collsion shape, does that help.
The positing the face index is no so eassy as newton does not have a super class to represent shape format or mesh format.
the face repost in a clall back is simpel because they are in report in a local search, as soon as the function exit the data is lost.
I can see thsi si eeasy for collision tree, but oteh stuff liek higfiedll conve hull, do no have face index.

on the other hand if you have the index id that was saved to the face, plus the collision shape, then you can get bothe the material and the face by making a lookup table
I can make the demo to report that information if you want.
but first I will fix teh Bug
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convex cast and face id

Postby belfegor » Thu Jan 24, 2013 1:02 pm

Yes, m_contaID alway return 0, just tried to dipslay it...
Looks like lower cylinder of player is not triggering contacts but only upper one does. I put breakpoint in BasicPlayerControllerManager::ProcessContacts function and is not triggered until upper part is touch something.
I could use NewtonMaterialGetContactFaceAttribute in material callback but player lower part is not making contact so this is never called.

on the other hand if you have the index id that was saved to the face, plus the collision shape, then you can get bothe the material and the face by making a lookup table


Are you suggesting that i should use static compound collision instead tree collision? Is it slower then tree?

I can make the demo to report that information if you want.


Example is always nice.

Thank you for your time.

EDIT:
Tell me if I make so that is repost teh proper material ID, an dteh proper sub collsion shape, does that help.


Isn't "faceAttribute" different then "materialID"?
How to make sub-shapes within tree collision?
From what i can see there is only faceAttribute to differentiate different parts of tree object.
User avatar
belfegor
 
Posts: 53
Joined: Mon Sep 18, 2006 4:42 pm
Location: Serbia

Re: Convex cast and face id

Postby Julio Jerez » Thu Jan 24, 2013 2:40 pm

-no I am not suggesting using compound collision that will not solve the problem, collision tree is perfectly fine for what you are doing

-no face attribute and material id are not the same thing.
a Face attribute is the shape ID of a face for any polygon base collision shape.
this is the same of the Shape ID of for a compound collision.
and Material ID is the a material generated the id of two collision shapes, you can see the material as a 2d Matrix where the rows are collision IDs, and the columns are collision ID as well.
Each Cell of the matrix represents a Material ID.

-I will complete the player demo, I will make so that I play a food step sound depending on the material ID of the face the player is on. The example will show you how to extract the face form the collision shape the player is on.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convex cast and face id

Postby Julio Jerez » Fri Jan 25, 2013 9:25 am

I see what teh problem is, it copmes dow to an deficeint on teh contact point data structure.
This is how it looks like
Code: Select all
class dgContactPoint
{
   public:
   dgVector m_point;
   dgVector m_normal;
   dgBody* m_body0;
   dgBody* m_body1;
   dgCollisionInstance* m_collision0;
   dgCollisionInstance* m_collision1;
   dgInt64 m_userId;
   dgFloat32 m_penetration;
   dgUnsigned16 m_deformableIndex0;
   dgUnsigned16 m_deformableIndex1;
};



each cocat can collect info abpu what bodey and what shape was hit, but it only have support for one ID,
thsi work well for ray cast, and coudl work for conve cast.
however in newton 300 the convex cast and, reay cast, closet distance, and all teh rest of teh collsion system is unified.
tehrfore having just one ID in teh contact structute is no sufficinet to determine where whta shape orpginated the conatc
this is why you see then set to zero, in some place

I am changing the contact structure to this format
Code: Select all
class dgContactPoint
{
   public:
   dgVector m_point;
   dgVector m_normal;
   dgBody* m_body0;
   dgBody* m_body1;
   dgCollisionInstance* m_collision0;
   dgCollisionInstance* m_collision1;
//   dgInt64 m_userId;
                   dgInt64 m_shapeID0;
                   dgInt64 m_shapeID1;
   dgFloat32 m_penetration;
   dgUnsigned16 m_deformableIndex0;
   dgUnsigned16 m_deformableIndex1;
};


this will provide all the informantion to retrieve the face info and or anythonmg else that is needed.
It will take over the weeked to change all that, but it should work.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convex cast and face id

Postby belfegor » Fri Jan 25, 2013 10:32 am

Thank you very much for support. Looking forward for those changes.
User avatar
belfegor
 
Posts: 53
Joined: Mon Sep 18, 2006 4:42 pm
Location: Serbia

Re: Convex cast and face id

Postby Julio Jerez » Fri Jan 25, 2013 12:46 pm

this is no ready yes by tshi si waht what I was sayin before.
I wrote a c\small class teh take teh collsion tree and enumarate all teh face with a cadianl number.
thsi ar eteh steps;
-you make the colliosn tress jsu as you were doing before.
-the you instanceate thsi class, and you save with you game data.

Code: Select all
class CollsionTreeFaceMap
{
   public:
   struct FaceInfo
   {
      //void* m_face;
      int m_materialIndex;
   };

   CollsionTreeFaceMap (NewtonCollision* const collisionTree)
      :m_faceCount(0)
      ,m_collisionTree(collisionTree)
   {
      NewtonTreeCollisionForEachFace (m_collisionTree, CountFaces, this);
      m_faceMapInfo = new FaceInfo[m_faceCount];

      m_faceCount = 0;
      NewtonTreeCollisionForEachFace (m_collisionTree, MarkFaces, this);
   }

   ~CollsionTreeFaceMap()
   {
      delete[] m_faceMapInfo;
   }

   static int CountFaces (void* const context, const dFloat* const polygon, int strideInBytes, const int* const indexArray, int indexCount)
   {
      CollsionTreeFaceMap* const me = (CollsionTreeFaceMap*) context;
      me->m_faceCount ++;
      return 1;
   }
   static int MarkFaces (void* const context, const dFloat* const polygon, int strideInBytes, const int* const indexArray, int indexCount)
   {
      CollsionTreeFaceMap* const me = (CollsionTreeFaceMap*) context;

      // repmap material index, by enumerating the face and storing the user material info at each face index
      int faceIndex = NewtonTreeCollisionGetFaceAtribute (me->m_collisionTree, indexArray, indexCount);
      me->m_faceMapInfo[me->m_faceCount].m_materialIndex = faceIndex;
      NewtonTreeCollisionSetFaceAtribute (me->m_collisionTree, indexArray, indexCount, me->m_faceCount);

      me->m_faceCount ++;
      return 1;
   }
   int m_faceCount;
   FaceInfo* m_faceMapInfo;
   NewtonCollision* m_collisionTree;
};



-then on any call back were teh collsion tree is involve,
-after you validate that it si in fact a collsion tree, you will get the sub shape id Face generation teh contact or the raycast.
-this id will be teh ordinal face number tah will be ia ind of to the faceMapInfo wich will contaion the face data to you prevouslly save
-I only save teh face ID, by you cna save anythong you wan to associate with the face.

Later after I fix the bug with contact indice, I will make so that dat is carried wit the body.


for nwo I am testing liek this

Code: Select all
static NewtonBody* CreateLevelMeshBody (NewtonWorld* const world, DemoEntity* const ent, bool optimization)
{
   // measure the time to build a collision tree
   unsigned64 timer0 = dGetTimeInMicrosenconds();

   // create the collision tree geometry
   NewtonCollision* const collision = NewtonCreateTreeCollision(world, 0);

   // prepare to create collision geometry
   NewtonTreeCollisionBeginBuild(collision);

   // iterate the entire geometry an build the collision
   for (DemoEntity* model = ent->GetFirst(); model; model = model->GetNext()) {

      dMatrix matrix (model->CalculateGlobalMatrix(ent));
      DemoMesh* const mesh = model->GetMesh();
      dFloat* const vertex = mesh->m_vertex;
      for (DemoMesh::dListNode* nodes = mesh->GetFirst(); nodes; nodes = nodes->GetNext()) {
         DemoSubMesh& segment = nodes->GetInfo();
         int matID = segment.m_textureHandle;
         for (int i = 0; i < segment.m_indexCount; i += 3) {
            int index;   
            dVector face[3];

            index = segment.m_indexes[i + 0] * 3;
            face[0] = dVector (vertex[index + 0], vertex[index + 1], vertex[index + 2]);

            index = segment.m_indexes[i + 1] * 3;
            face[1] = dVector (vertex[index + 0], vertex[index + 1], vertex[index + 2]);

            index = segment.m_indexes[i + 2] * 3;
            face[2] = dVector (vertex[index + 0], vertex[index + 1], vertex[index + 2]);

            matrix.TransformTriplex (&face[0].m_x, sizeof (dVector), &face[0].m_x, sizeof (dVector), 3);

            // use material ids as physics materials
            NewtonTreeCollisionAddFace(collision, 3, &face[0].m_x, sizeof (dVector), matID);
         }
      }
   }
   NewtonTreeCollisionEndBuild(collision, optimization ? 1 : 0);

   // measure the time to build a collision tree
   timer0 = (dGetTimeInMicrosenconds() - timer0) / 1000;

   // Get the root Matrix
   dMatrix matrix (ent->CalculateGlobalMatrix(NULL));

   // create the level rigid body
   NewtonBody* const level = NewtonCreateDynamicBody(world, collision, &matrix[0][0]);

   // save the pointer to the graphic object with the body.
   NewtonBodySetUserData (level, ent);

   // set a destructor for this rigid body
   //NewtonBodySetDestructorCallback (m_level, Destructor);

   // release the collision tree (this way the application does not have to do book keeping of Newton objects
   NewtonDestroyCollision (collision);

//**************************** test enumeration of face array
   // now we will make a loop table for quick material index lookup for face to index
   CollsionTreeFaceMap faceMap (NewtonBodyGetCollision(level));

   return level;
}


if you synk yo uwill find that chnage in file : ..\applications\demosSandbox\sdkDemos\toolBox\PhysicsUtils.cpp
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convex cast and face id

Postby belfegor » Fri Jan 25, 2013 3:32 pm

So you will add indices within contact so i can index into FaceInfo and extract my faceAttribute/material?
Don't forget about lower body part of player controller.
Maybe add another virtual function CustomPlayerControllerManager::ProcessContact2 for m_supportShape collision since this is our "feet" and is more important for what i want to do.

Thank you for your time.

EDIT: Oh i see now, NewtonMaterialGetContactFaceAttribute will now return face index with witch i can index into FaceInfo, in material callback. Must try this if it works...

EDIT2: YESSSS. This works.
User avatar
belfegor
 
Posts: 53
Joined: Mon Sep 18, 2006 4:42 pm
Location: Serbia

Re: Convex cast and face id

Postby belfegor » Mon Feb 04, 2013 5:06 pm

I have updated Newton from latest SVN and it broke my code as player isn't generating contact with TreeCollision.
I found that your r3251 update is source for this bug and replaced with previous code as workaround:

Code: Select all
//body->m_sleeping = true;
//body->m_autoSleep = true;
body->m_sleeping = false;
body->m_autoSleep = false;
User avatar
belfegor
 
Posts: 53
Joined: Mon Sep 18, 2006 4:42 pm
Location: Serbia

Re: Convex cast and face id

Postby Julio Jerez » Tue Feb 05, 2013 10:07 am

Yes I did that because the make the player very slow.
tempotrarilly did it until I compilet the material ID, the I have to find out why the player make the collision so slow with interact with terrain
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convex cast and face id

Postby Julio Jerez » Tue Feb 05, 2013 10:18 am

Ok I think I finally refactored the collision ID in the low lever engine
now the contact has two id, and that forced me to change many callbacks.
also the id now are pointer instead of int. This is because there are many structure alignment when casting point to integers in 64 bit since pointer are 64 bit in 64 bit code but ints are 32.
I beleive I cover almost everything, but I am still not sure.
you should only will have to change some call backs prototypes.
Now I will see how to fix the player controller.
for the callbacks, and the kinematic bodies collision of with the environment
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Convex cast and face id

Postby belfegor » Tue Feb 05, 2013 5:51 pm

Updated to latest SVN to test new NewtonTreeCollisionGetVertexListTriangleListInAABB function, but now above "hack" doesn't work any more.
Code: Select all
body->m_sleeping = false;
body->m_autoSleep = false;


Again no contact in material callback for player with tree collision.
User avatar
belfegor
 
Posts: 53
Joined: Mon Sep 18, 2006 4:42 pm
Location: Serbia

Re: Convex cast and face id

Postby Julio Jerez » Mon Feb 11, 2013 10:54 am

I am working on this now. The problem I see is the cyliden is the most expensive shape of all.

this because, althught cylinders like a capusule, is a surce of revolution, the have hard boundaes tha make it hard to resolve then parametrically.

the one thing I noticed is that iy is possible to brake teh generat solution into two solvers, wone teh is very fast and use the line, and if tow fail use the general with is expensive.
this may work because in abput 9 out 10 time a cylder is actually rolling not hitting the on the caps.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests