Trying another format...

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Trying another format...

Postby Eltran » Mon Dec 22, 2008 8:01 am

Hello,
I want to get rid off the BSP format in my game, then I convert my map into ASE so I can load collisions easier.
But, there's something weird (could be simple) in it, in BSP, when I draw 6 brushes, (brush is something like a wall), I get 6 faces per brush, I had to get tons of vertices and stuff.

And now this time, I only have the brush's full size, like this :

*GEOMOBJECT {
*NODE_NAME "mat1model0surf1"
*NODE_TM {
*NODE_NAME "mat1model0surf1"
*INHERIT_POS 0 0 0
*INHERIT_ROT 0 0 0
*INHERIT_SCL 0 0 0
*TM_ROW0 1.0 0 0
*TM_ROW1 0 1.0 0
*TM_ROW2 0 0 1.0
*TM_ROW3 0 0 0
*TM_POS 0.000000 0.000000 0.000000
}
*MESH {
*TIMEVALUE 0
*MESH_NUMVERTEX 4
*MESH_NUMFACES 2
*COMMENT "SURFACETYPE MST_PLANAR"
*MESH_VERTEX_LIST {
*MESH_VERTEX 0 512.000000 -512.000000 368.000000
*MESH_VERTEX 1 512.000000 -512.000000 8.000000
*MESH_VERTEX 2 512.000000 512.000000 368.000000
*MESH_VERTEX 3 512.000000 512.000000 8.000000
}

*MESH_NORMALS {
*MESH_FACENORMAL 0 0.000000 0.000000 1.000000
*MESH_FACENORMAL 1 0.000000 0.000000 1.000000
*MESH_VERTEXNORMAL 0 -1.000000 0.000000 0.000000
*MESH_VERTEXNORMAL 1 -1.000000 0.000000 0.000000
*MESH_VERTEXNORMAL 2 -1.000000 0.000000 0.000000
*MESH_VERTEXNORMAL 3 -1.000000 0.000000 0.000000
}
*MESH_FACE_LIST {
*MESH_FACE 0 A: 0 B: 2 C: 1 AB: 1 BC: 1 CA: 1 *MESH_SMOOTHING 0 *MESH_MTLID 0
*MESH_FACE 1 A: 2 B: 3 C: 1 AB: 1 BC: 1 CA: 1 *MESH_SMOOTHING 0 *MESH_MTLID 0
}
*MESH_NUMTVERTEX 4
*MESH_TVERTLIST {
*MESH_TVERT 0 -0.370370 0.378289 1.000000
*MESH_TVERT 1 -0.370370 0.008224 1.000000
*MESH_TVERT 2 0.370370 0.378289 1.000000
*MESH_TVERT 3 0.370370 0.008224 1.000000
}
*MESH_NUMTVFACES 2
*MESH_TFACELIST {
*MESH_TFACE 0 0 2 1
*MESH_TFACE 1 2 3 1
}
}
*PROP_MOTIONBLUR 0
*PROP_CASTSHADOW 1
*PROP_RECVSHADOW 1
*MATERIAL_REF 1
}


Each mesh is reprensented by "GEOMOBJECT", and that's the only thing I can get from a mesh...
Can I use NewtonTreeCollisionAddFace for that ? Or is there another method ?
Or does Newton loads COLLADA easily ? I will try that if there's no solution about that format.

Thanks.
Eltran
 
Posts: 16
Joined: Sun Nov 18, 2007 5:32 am

Re: Trying another format...

Postby Julio Jerez » Mon Dec 22, 2008 9:36 am

The answer is yes to all of the above.
Using Newton collision tree you do not have to pass triangles, you can take the face of the brush and pass then to the tree, it will make a much cleaner collision mesh and way faster that BSP co collision.
To the second is question Collada is a file format, and Netwon is a physics engine, there is no connection between a physics engine and a file format despite of the confusion created by the Khronos group and self appointed physics experts.
There is a demo that implements loading and save collada scenes,

viewtopic.php?f=14&t=3406

It is very complete, in the sense that it support all of eth collada physics objects, I but I do no remember if I added the collision tree.
If you like I can send you the source and you can see how I use it and can help you to get started.

I discontinue supporting collada because if is and unbearably heavy handed file format, plus when I post over the Khronos group they do no like it that I was using there format, they consider use too insignificant for they format, “they do no want that hobbies project making waves of their site” they said.
Julio Jerez
Moderator
Moderator
 
Posts: 11154
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Trying another format...

Postby Eltran » Mon Dec 22, 2008 10:26 am

Hmm, I prefer trying ASE before going into something that is maybe more complicated, just because I can't find a good ASE to DAE or a BSP converter.

I tried my ASE map into a simple ASE viewer, it's really OK, the mesh doesn't have any degenerated faces, it has 6 faces, just a simple room, like a cube.
If I have to define a box for it's size, it would be

-512
-512
8

512
512
368

(Yeah, again, Quake 3 inverts the Y and Z axis,... sorry.)

There are 4 vertices by mesh, I can use that code successfully :

Code: Select all
   col = NewtonCreateTreeCollision(g_NewtonWorld);
   NewtonTreeCollisionBeginBuild(col);

   for (int i = 0 ; i < m->objectCount; i++) {
      ASE_GeomObject * tmpObj = &m->objs[i];
      int nbVertices = tmpObj->mesh.vertexCount;
      float   vArray[12];

      vArray[0] = tmpObj->mesh.vertices[0].x;
      vArray[1] = tmpObj->mesh.vertices[0].y;
      vArray[2] = tmpObj->mesh.vertices[0].z;

      vArray[3] = tmpObj->mesh.vertices[1].x;
      vArray[4] = tmpObj->mesh.vertices[1].y;
      vArray[5] = tmpObj->mesh.vertices[1].z;

      vArray[6] = tmpObj->mesh.vertices[2].x;
      vArray[7] = tmpObj->mesh.vertices[2].y;
      vArray[8] = tmpObj->mesh.vertices[2].z;

      vArray[9]  = tmpObj->mesh.vertices[3].x;
      vArray[10] = tmpObj->mesh.vertices[3].y;
      vArray[11] = tmpObj->mesh.vertices[3].z;

      G_Printf("-- Mesh %i Start --\n", i);
      G_Printf("[0] = %f, [1] = %f, [2] = %f\n", vArray[0], vArray[1], vArray[2]);
      G_Printf("[3] = %f, [4] = %f, [5] = %f\n", vArray[3], vArray[4], vArray[5]);
      G_Printf("[6] = %f, [7] = %f, [8] = %f\n", vArray[6], vArray[7], vArray[8]);
      G_Printf("[9] = %f, [10] = %f, [11] = %f\n", vArray[9], vArray[10], vArray[11]);
      G_Printf("--- Mesh %i End ---\n",i);

      NewtonTreeCollisionAddFace(col, 4, (float*)vArray, sizeof(float) * 4, 0);
   }

   NewtonTreeCollisionEndBuild(col, 0);


Log output :

Code: Select all
-- Mesh 0 Start --
[0] = 512.000000, [1] = -512.000000, [2] = 8.000000
[3] = -512.000000, [4] = -512.000000, [5] = 8.000000
[6] = 512.000000, [7] = 512.000000, [8] = 8.000000
[9] = -512.000000, [10] = 512.000000, [11] = 8.000000
--- Mesh 0 End ---
-- Mesh 1 Start --
[0] = 512.000000, [1] = -512.000000, [2] = 368.000000
[3] = 512.000000, [4] = -512.000000, [5] = 8.000000
[6] = 512.000000, [7] = 512.000000, [8] = 368.000000
[9] = 512.000000, [10] = 512.000000, [11] = 8.000000
--- Mesh 1 End ---
-- Mesh 2 Start --
[0] = 512.000000, [1] = 512.000000, [2] = 368.000000
[3] = -512.000000, [4] = 512.000000, [5] = 8.000000
[6] = -512.000000, [7] = 512.000000, [8] = 368.000000
[9] = 512.000000, [10] = 512.000000, [11] = 8.000000
--- Mesh 2 End ---
-- Mesh 3 Start --
[0] = -512.000000, [1] = 512.000000, [2] = 368.000000
[3] = -512.000000, [4] = -512.000000, [5] = 368.000000
[6] = 512.000000, [7] = 512.000000, [8] = 368.000000
[9] = 512.000000, [10] = -512.000000, [11] = 368.000000
--- Mesh 3 End ---
-- Mesh 4 Start --
[0] = -512.000000, [1] = -512.000000, [2] = 368.000000
[3] = -512.000000, [4] = -512.000000, [5] = 8.000000
[6] = 512.000000, [7] = -512.000000, [8] = 368.000000
[9] = 512.000000, [10] = -512.000000, [11] = 8.000000
--- Mesh 4 End ---
-- Mesh 5 Start --
[0] = -512.000000, [1] = 512.000000, [2] = 368.000000
[3] = -512.000000, [4] = -512.000000, [5] = 8.000000
[6] = -512.000000, [7] = -512.000000, [8] = 368.000000
[9] = -512.000000, [10] = 512.000000, [11] = 8.000000
--- Mesh 5 End ---


But it doesn't seem that it's loaded perfectly, because when I do

Code: Select all
   float boxP0[3];
   float boxP1[3];
   float matrix[4][4];
   NewtonBodyGetMatrix (g_NewtonRigidBody, &matrix[0][0]);
   NewtonCollisionCalculateAABB (g_NewtonCollision, &matrix[0][0],  &boxP0[0], &boxP1[0]);
   NewtonSetWorldSize (g_NewtonWorld, (float*)boxP0, (float*)boxP1);
   G_Printf("World Min Size : [0] = %f, [1] = %f, [2] = %f\n", boxP0[0], boxP0[1], boxP0[2]);
   G_Printf("World Max Size : [0] = %f, [1] = %f, [2] = %f\n", boxP1[0], boxP1[1], boxP1[2]);


The log prints :

Code: Select all
World Min Size : [0] = -512.224976, [1] = -512.224976, [2] = -512.224976
World Max Size : [0] = 512.224976, [1] = 512.224976, [2] = 512.224976


It should be something like...

Code: Select all
World Min Size : [0] = -512.224976, [1] = -512.224976, [2] = 8.000000
World Max Size : [0] = 512.224976, [1] = 512.224976, [2] = 368.000000


Then I try to simulate a simple cube, with a small size, NewtonCreateBox... The cube falls, pass through the floor and it stops at -538.000000 in the Z (normally Y) axis.
Image

Is there a problem ? I already tried to invert some axis in the Tree Collision building stuff...
If you wanna look at my ASE file, just have to look at something like that :

Code: Select all
      *MESH_VERTEX_LIST   {
         *MESH_VERTEX   0   512.000000   -512.000000   8.000000
         *MESH_VERTEX   1   -512.000000   -512.000000   8.000000
         *MESH_VERTEX   2   512.000000   512.000000   8.000000
         *MESH_VERTEX   3   -512.000000   512.000000   8.000000
      }


Thanks so much for your help, I think again there's something stupid I missed...
Eltran
 
Posts: 16
Joined: Sun Nov 18, 2007 5:32 am

Re: Trying another format...

Postby Julio Jerez » Mon Dec 22, 2008 11:41 am

if you are going to yse SAE then you nee to pass teh faces one tringle at a time.

I think ASE formal is a vertex list index list, not a vertex list format.

thre for you have to mak eteh face in a locla veriable an dpass then to teh tree


Code: Select all
 for (int i = 0 ; i < m->objectCount; i++) {
      ASE_GeomObject * tmpObj = &m->objs[i];

     FACE*     tmpObj->FaceList; 
     for  (int j = 0; j <  tmpObj->FaceCount
       float   vArray[9];

        int index = tmpObj->FaceList[j][0]
        vArray[0] = tmpObj->mesh.vertices[index].x;
      vArray[1] = tmpObj->mesh.vertices[index].y;
      vArray[2] = tmpObj->mesh.vertices[index].z;

        int index = tmpObj->FaceList[j][1]
      vArray[3] = tmpObj->mesh.vertices[index].x;
      vArray[4] = tmpObj->mesh.vertices[index].y;
      vArray[5] = tmpObj->mesh.vertices[index].z;

        int index = tmpObj->FaceList[j][2]
      vArray[6] = tmpObj->mesh.vertices[index].x;
      vArray[7] = tmpObj->mesh.vertices[index].y;
      vArray[8] = tmpObj->mesh.vertices[index].z;

      vArray[9]  = tmpObj->mesh.vertices[3].x;
      vArray[10] = tmpObj->mesh.vertices[3].y;
      vArray[11] = tmpObj->mesh.vertices[3].z;

      NewtonTreeCollisionAddFace(col, 3, (float*)vArray, sizeof(float) * 3, 0);
}
   }
Julio Jerez
Moderator
Moderator
 
Posts: 11154
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Trying another format...

Postby Eltran » Mon Dec 22, 2008 1:41 pm

Thanks a lot it worked, you're a genius !

Arrh, there's a last little problem...
I want to make my cube from it's own ASE file, I do the same steps as I've done with the map to load the ASE file, but the cube is stucked in the air, doesn't move at all and the applyforceandtorque callback is not called...

But I can see in the debugger, at those lines :

Code: Select all
   NewtonConvexCollisionCalculateInertialMatrix (collision, &inertia[0], &origin[0]);
   mass = 10;
   Ixx = mass * inertia[0];
   Iyy = mass * inertia[1];
   Izz = mass * inertia[2];


The function NewtonConvexCollisionCalculateInertialMatrix returns null values inside inertia and origin... Weird, when I create the collision directly from the NewtonCreateBox function, it works perfectly...

Then the object has no inertia, and even if I put a fake one inside Ixx, Iyy and Izz, it doesn't move at all.

Here's the code :

Code: Select all
   dFloat Ixx;
   dFloat Iyy;
   dFloat Izz;
   NewtonBody* rigidBody;
   NewtonCollision* collision;
   dVector origin;
   dVector inertia;
   dFloat mass, volume;
   dMatrix matrix (GetIdentityMatrix());

   matrix.m_posit.m_x = ent->s.origin[0];
   matrix.m_posit.m_y = ent->s.origin[1];
   matrix.m_posit.m_z = ent->s.origin[2];

   collision = G_PhysicsLoadModel(ent->fullName);

   if (!collision)
      return;

   volume = 0.5f * NewtonConvexCollisionCalculateVolume (collision);

   // calculate the moment of inertia and the relative center of mass of the solid
   NewtonConvexCollisionCalculateInertialMatrix (collision, &inertia[0], &origin[0]);
   mass = 10;
   Ixx = mass * inertia[0];
   Iyy = mass * inertia[1];
   Izz = mass * inertia[2];

   //create the rigid body
   rigidBody = NewtonCreateBody (g_NewtonWorld, collision);

   // release the collision geometry when not need it
   NewtonReleaseCollision (g_NewtonWorld, collision);

   // set the correct center of gravity for this body
   NewtonBodySetCentreOfMass (rigidBody, &origin[0]);

   // set the mass matrix
   NewtonBodySetMassMatrix (rigidBody, mass, Ixx, Iyy, Izz);

   // activate
   //   NewtonBodyCoriolisForcesMode (blockBoxBody, 1);

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

   // assign the wood id
   NewtonBodySetMaterialGroupID (rigidBody, NewtonMaterialGetDefaultGroupID (g_NewtonWorld));

//  set continue collision mode
   NewtonBodySetContinuousCollisionMode (rigidBody, 1);

   // set a destructor for this rigid body
   NewtonBodySetDestructorCallback (rigidBody, PhysicsBodyDestructor);

   // set the transform call back function
   NewtonBodySetTransformCallback (rigidBody, PhysicsSetTransform);

   // set the force and torque call back function
   NewtonBodySetForceAndTorqueCallback (rigidBody, PhysicsApplyGravityForce);

   // set the matrix for both the rigid body and the graphic body
   NewtonBodySetMatrix (rigidBody, &matrix[0][0]);
   //NewtonBodySetFreezeTreshold(rigidBody, 1.0, 1.0, 1.0, 1.0);

   PhysicsSetTransform (rigidBody, &matrix[0][0], 0);


Thank you very much, it's a little step.
Eltran
 
Posts: 16
Joined: Sun Nov 18, 2007 5:32 am

Re: Trying another format...

Postby Julio Jerez » Mon Dec 22, 2008 3:12 pm

you can not use collision trees as dynamics files. this is why it is hard to use a graphics file for physics,
you can use a naming convetion with the graphics file to make a parametric cube using the dimention of the shape.
or you can use the convex hull and wrap a hull around the shaped for you dynamics bodies.
then you only use Hull and collision trees with graphics meshed, later when you fell more confortable wite teh engoen you cna use your on format and start shape liek cubes, of cylider whi are more efficents.
Julio Jerez
Moderator
Moderator
 
Posts: 11154
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Trying another format...

Postby Julio Jerez » Mon Dec 22, 2008 3:15 pm

I see you are using 1.53 version of the engine, send me and PM for 2.0 if you do not have it.
It is much better, faster, and simpler to use.
Julio Jerez
Moderator
Moderator
 
Posts: 11154
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Trying another format...

Postby Eltran » Mon Dec 22, 2008 4:15 pm

I'm already using 2.0, it works better than 1.53.

Hmm then I've tried multiple time to do the same thing with NewtonCreateConvexHull, but that function always returns a NULL value, I'm doing something wrong again...
I tried a lot of combinaisons, that's the last one I tried...

Code: Select all
         int index;
         
         index = faces[j].vertex[0];
         vFaceArray[0] = object->mesh.vertices[index].x;
         vFaceArray[1] = object->mesh.vertices[index].y;
         vFaceArray[2] = object->mesh.vertices[index].z;

         index = faces[j].vertex[1];
         vFaceArray[3] = object->mesh.vertices[index].x;
         vFaceArray[4] = object->mesh.vertices[index].y;
         vFaceArray[5] = object->mesh.vertices[index].z;

         index = faces[j].vertex[2];
         vFaceArray[6] = object->mesh.vertices[index].x;
         vFaceArray[7] = object->mesh.vertices[index].y;
         vFaceArray[8] = object->mesh.vertices[index].z;

         col = NewtonCreateConvexHull (g_NewtonWorld, 3, &vFaceArray[0], sizeof(float) * 3, NULL, NULL);


If I have to set a box around the object, could you tell me how can I retrieve the exact size from the bounding boxes please ? (AABB coordinates, I can get them easily from Quake 3)

Thanks.
Eltran
 
Posts: 16
Joined: Sun Nov 18, 2007 5:32 am

Re: Trying another format...

Postby Julio Jerez » Mon Dec 22, 2008 6:11 pm

that code will fail to make a convex hull because it is a flat face.
for a convex hul you jsut take all of teh point of the mesh and full pass then to the funtion.
the funtion build the geomtery for you.

in the SAE samples meshe you show you only have faces, a box for exmapel will have at lease 8 vetices

so for a box with 8 vetices you call

//if say the MeshVertexStruct is the structure of eth mesh vetes array
col = NewtonCreateConvexHull (g_NewtonWorld, 8, &object->mesh.vertices[0].x, sizeof (MeshVertexStructr), 0, NULL);

remenber a convex hull have to have some volume, you cna no make hull iof flat shapes.
Julio Jerez
Moderator
Moderator
 
Posts: 11154
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Trying another format...

Postby Eltran » Mon Dec 22, 2008 8:26 pm

Thank you, I finally found a way to get it working ! :D
Quake 3 is very very large. For the callback, if I set the gravity to mass * -9.81f, it will be terribly slow.
To speed up, I do mass * -9.81 * 200, but if I set it too high to get the real game speed, the box will shake all the time once he gets on the ground.

Is there another way than increasing the object's mass ?
I already tried to increase NewtonUpdate(nWorld, 0.01f) to 9000000.0f but it doesn't change anything...

If I must set the mass so high, how to prevent the cube shaking ? Increase the friction, elasticity, and all other stuff ?

Thanks.
Eltran
 
Posts: 16
Joined: Sun Nov 18, 2007 5:32 am

Re: Trying another format...

Postby JoeWright » Mon Dec 22, 2008 8:50 pm

Sorry if this is irrelevant. Before scaling the acceleration, have you tried setting the damping to minimum (0.0001) with NewtonBodySetLinearDamping and NewtonBodySetAngularDamping?

Cheers, Joe
JoeWright
 
Posts: 69
Joined: Sat Apr 30, 2005 1:42 pm

Re: Trying another format...

Postby Eltran » Mon Dec 22, 2008 9:00 pm

Hey, thanks but this doesn't change anything :/
Eltran
 
Posts: 16
Joined: Sun Nov 18, 2007 5:32 am

Re: Trying another format...

Postby Julio Jerez » Mon Dec 22, 2008 10:12 pm

ah this is a quake engine.
Your having a problem that is very hard to fix.
Basically all of the constant in the engine are set in the Meter, kilogram second system.
I need to add a function Set global Scale to the engine, a thing I wanted to do for a long time but never god the time to actually do it.
Must people do the on there side but it is in fact a hassle to do it.

I did it back when I wrote the firs Game studio plug it, but then I forgot about since the engine was going to general.

This is what I can do for you.
-I can implement it the next few days if you send me you test application that I can use for testing it.
-if you are in a hurry you can do it yourself by that maybe be hard for you since you will have you think ion two different scale system.
Julio Jerez
Moderator
Moderator
 
Posts: 11154
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Trying another format...

Postby Eltran » Wed Dec 24, 2008 12:39 pm

Or maybe I just should scale each vertices of the collision tree to 10 or 100, and scale the quake 3 entity's coordinates ?
Eltran
 
Posts: 16
Joined: Sun Nov 18, 2007 5:32 am

Re: Trying another format...

Postby Julio Jerez » Wed Dec 24, 2008 12:42 pm

tha will work for the time being, but I will do the scaling.
Julio Jerez
Moderator
Moderator
 
Posts: 11154
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 4 guests