NewtonMeshApproximateConvexDecomposition tests

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Re: NewtonMeshApproximateConvexDecomposition tests

Postby Julio Jerez » Fri Dec 09, 2011 6:44 pm

Oh I am sorry, I forget that compound was no added teh the dScene format. I will add that and also the collison tree tonight.
It is good you have the dscene integrated because after those missing features are added it is much simpler to debug a scene.
I will also add a load meny option for loading the scene in the demo, so you can righ away see if it run or not.

I will add that funtionality the moment I get home tonight.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMeshApproximateConvexDecomposition tests

Postby Julio Jerez » Sun Dec 11, 2011 2:23 pm

Ok I just completed the two missing shapes for the dScene file format. CollsionTree and Compound
this is how you use it. say you have a NetwonWorld, to serialize that world you do this
Code: Select all
dScene testScene (world);
testScene.NewtonWorldToScene (world);
testScene.Serialize ("somefileName.ngd");

to recreate the same scene
Code: Select all
   dScene database (world);
   database.Deserialize(fileName);

   // Load the Visual Scene if you want to see some visual mesh
                 //EntityDictionary entDictionary;
   //LoadVisualScene(&database, entDictionary);

   //Load the physics world, convet each rigid body definntion in the file format to a rigid body in the world, return teh list of rigid bodies
   dList<NewtonBody*> bodyList;
   database.SceneToNewtonWorld(m_world, bodyList);

               // this is optinal, but very important, you need to plug the tranform call back on each body
                // each info can be associated with a variable info, these variable can be used to bind any ifo to some oeth data.
                // for example "rigidBodyType"  contaoin teh defual value "gravity object" thsio si use to asign teh Gravity force an torque callback to graboty bodies 
   for (dList<NewtonBody*>::dListNode* bodyNode = bodyList.GetFirst(); bodyNode; bodyNode = bodyNode->GetNext()) {
      // find the user data and set to the visual entity in the scene
      NewtonBody* const body = bodyNode->GetInfo();
      dScene::dTreeNode* const sceneNode = (dScene::dTreeNode*)NewtonBodyGetUserData(body);
      DemoEntity* const entity = entDictionary.Find(sceneNode)->GetInfo();
      NewtonBodySetUserData(body, entity);

      // see if this body have some special setups
      dScene::dTreeNode* const node = database.FindChildByType(sceneNode, dRigidbodyNodeInfo::GetRttiType());
      _ASSERTE (node);
      dRigidbodyNodeInfo* const bodyData = (dRigidbodyNodeInfo*) database.GetInfoFromNode(node);
      dVariable* bodyType = bodyData->FindVariable("rigidBodyType");

      // set the default call backs
      if (!bodyType || !strcmp (bodyType->GetString(), "default gravity")) {
         NewtonBodySetTransformCallback(body, DemoEntity::SetTransformCallback);
         NewtonBodySetForceAndTorqueCallback(body, PhysicsApplyGravityForce);
         NewtonBodySetDestructorCallback (body, PhysicsBodyDestructor);
      }
   }



I added a sample of a serialized compound collision, you can run SDK after you compile it, and go to File->Load, find file "test1.ngd" it will load that scene.
basically if you add the dScene to your plugin all you need to insert is this code fragment in order to save phsics scenes
Code: Select all
dScene testScene (world);
testScene.NewtonWorldToScene (world);
testScene.Serialize ("somefileName.ngd");

and you should be aable to load the scen in teh SDK demo.
I hope it is not too confusing.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMeshApproximateConvexDecomposition tests

Postby Bird » Sun Dec 11, 2011 4:39 pm

Ok I just completeed those two missing shapes for the dScene file format.

Since I really love the Newton way of doing things, I decided to branch off and make new Newton only version of my plugin so I don't have to deal with Bullet and PhysX at the same time. I still have a day or 2 of work before I'll be ready to try loading and saving the .ngd files .... I'll let you know as soon as I'm able to test out the new code

Thanks!

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

Re: NewtonMeshApproximateConvexDecomposition tests

Postby Bird » Mon Dec 12, 2011 12:43 am

Ok I just completed the two missing shapes for the dScene file format. CollsionTree and Compound

Cool, now I can give you the concave_cube.ngd file http://www.hurleyworks.com/downloads/concave_cube.zip

When I load it into the newtonDemo.exe, it looks like it's seeing a full box without the concave part.

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

Re: NewtonMeshApproximateConvexDecomposition tests

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

yes that is a box alright, but that is the result of the convesion. I need the source.

basically I need you so save the original mesh with the file, ther are way to do that but it is complicated now, I will and a contex call back to thsi funtion

void NewtonWorldToScene (const NewtonWorld* const world);

It will be like this void NewtonWorldToScene (const NewtonWorld* const world, GetVisualMeshContext);

where GetVisualMeshContext is a pointe to a class for geting the ubject to render

Code: Select all
class GetVisualMeshContext
{
   virtual NetwonMesh* GetBodyVisualMesh(NetwonBody* const mesh)
   {
       return NULL;   
   }
 
   void MeshName(NetwonBody* const mesh, char* const name, int maxsize)
   {
   }

  virtual void DisposeMesh (NetwonMesh* const mesh)
  {
  }
}


in that form it will be possible to save teh corrent mesh that was use to make the conve patition, as opase to what it si doing now that is simple make a Mesh out of the collision shape.
and that of cource will show the source mesh as a box as well.
stand by
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMeshApproximateConvexDecomposition tests

Postby Julio Jerez » Mon Dec 12, 2011 7:47 am

Ok if you update, now you can save the visual mesh alone wit teh collsion shape.
this is how you use now
Code: Select all
class MakeViualMesh: public dScene::dSceneExportCallback
{
   public:
   MakeViualMesh (NewtonWorld* const world)
      :m_world (world)
   {
   }

   NewtonMesh* CreateVisualMesh (NewtonBody* const body, char* const name, int maxNameSize) const
   {
      // here the use should take the user data from the body create newtonMesh form it and return that back
      NewtonCollision* collision = NewtonBodyGetCollision(body);
      NewtonMesh* const mesh = NewtonMeshCreateFromCollision(collision);

      sprintf (name, "visual Mesh");
      return mesh;
   }

   NewtonWorld* m_world;
};

void ExportScene (NewtonWorld* const world, const char* const fileName)
{
   MakeViualMesh context (world);
   dScene testScene (world);
   testScene.NewtonWorldToScene (world, &context);
   testScene.Serialize (fileName);
}

in NewtonMesh* CreateVisualMesh (NewtonBody* const body, char* const name, int maxNameSize) const
I am simply makin a NetwonMehs Out of the collison on the body, you shopudl take teh user Data, find you visual object am make a NetwonMesh from the face.
Later I will do the same to comple that.

with this you will have a more complete format. Still long way to go but more complet that simple usin the collision as visuals.

doing that wil allow me to determine where is the Bug, because I can simple get the visual mesh and run the concave decompsition with the same parameters you did and compare the results.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMeshApproximateConvexDecomposition tests

Postby Bird » Mon Dec 12, 2011 10:50 am

Ok if you update, now you can save the visual mesh alone wit teh collsion shape.

Ok, here's the version saved using ExportScene (). http://www.hurleyworks.com/downloads/concave_cube2.zip

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

Re: NewtonMeshApproximateConvexDecomposition tests

Postby Julio Jerez » Mon Dec 12, 2011 11:57 am

Ok Thansk, but times up for me now have to go to work.
I will do it tomorrow morning.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMeshApproximateConvexDecomposition tests

Postby Julio Jerez » Tue Dec 13, 2011 8:40 am

I download the mesh, but the graphics mesh is still not the righ one these are the vetices taken from the .ngd file

    -0.500000 -0.500000 -0.500000
    0.000000 -0.500000 0.500000
    -0.500000 0.000000 0.500000
    -0.500000 -0.500000 0.000000
    0.500000 -0.500000 0.500000
    0.000000 -0.500000 -0.500000
    0.500000 0.000000 -0.500000
    0.500000 0.500000 0.000000
no way they will come a concave cobe, thsi si very diffrent that the OBJ file you end first wich has these verices.

    v -0.5 -0.5 0.5
    v -0.5 -0.5 -0.5
    v -0.5 0.5 0.5
    v -0.5 0.5 -0.5
    v -0.2 -0.15 0.5
    v -0.2 -0.15 -0.5
    v 0.5 -0.5 0.5
    v 0.5 -0.5 -0.5

are you sure you are using the right mesh?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMeshApproximateConvexDecomposition tests

Postby Bird » Tue Dec 13, 2011 11:47 am

are you sure you are using the right mesh?

Definitely using the right mesh but maybe I'm doing something else wrong on my end. I'll see if I can figure out what's happening now that I understand the Newton file format a little better.

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

Re: NewtonMeshApproximateConvexDecomposition tests

Postby Bird » Tue Dec 13, 2011 1:04 pm

I verified I'm passing the correct vertex positions to NewtonCreateConvexHullFromMesh
But if I debug dump the NewtonMesh vertex data from MakeViualMesh::CreateVisualMesh it's wrong ... it's not concave anymore.

Code: Select all
class MakeViualMesh: public dScene::dSceneExportCallback
    {
       public:
       MakeViualMesh (NewtonWorld* const world)
          :m_world (world)
       {}

       NewtonMesh* CreateVisualMesh (NewtonBody* const body, char* const name, int maxNameSize) const
       {
          // here the use should take the user data from the body create newtonMesh form it and return that back
          NewtonCollision* collision = NewtonBodyGetCollision(body);
          NewtonMesh* const mesh = NewtonMeshCreateFromCollision(collision);

         int vertexCount = NewtonMeshGetVertexCount(mesh);
         int stride = NewtonMeshGetVertexStrideInByte(mesh);
         dFloat64* verts = NewtonMeshGetVertexArray(mesh);
            
         debug(" ------------------ MakeViualMesh Vertex dump");
         int index = 0;
         for( int i = 0; i < vertexCount; i++ )
         {
            for( int j = 0; j < stride/sizeof(dFloat64); j++ )
               debug(Mace::ToString<dFloat64>(verts[index++]));
         }

          sprintf (name, "visual Mesh");
          return mesh;
       }

       NewtonWorld* m_world;
    };


Here's a dump of the vertex data at various stages:
Code: Select all
2011-12-13 16:59:55.3 DJ[4392]:FileLogger:D:Newton3 engine created
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:---------next LW vertex:
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:---------next LW vertex:
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:---------next LW vertex:
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:---------next LW vertex:
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:---------next LW vertex:
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:---------next LW vertex:
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:---------next LW vertex:
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.2
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.15
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:---------next LW vertex:
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.2
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.15
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D: ------------------ DemoMesh Vertex dump
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.2
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.15
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.2
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.15
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:55.4 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:56.6 DJ[4392]:FileLogger:D: ------------------ MakeViualMesh Vertex dump
2011-12-13 16:59:56.6 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:56.6 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:56.6 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:56.6 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:56.6 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:56.6 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:56.6 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:56.6 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:56.6 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:56.6 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:56.6 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:56.7 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:56.7 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:56.7 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:56.7 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:56.7 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:56.7 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:56.7 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:56.7 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:56.7 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:56.7 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:56.7 DJ[4392]:FileLogger:D:-0.5
2011-12-13 16:59:56.7 DJ[4392]:FileLogger:D:0.5
2011-12-13 16:59:56.7 DJ[4392]:FileLogger:D:0
2011-12-13 16:59:56.7 DJ[4392]:FileLogger:D:Newton3 engine destroyed
2011-12-13 16:59:56.7 DJ[4392]:FileLogger:D:Memory leaked: 0 bytes


Any ideas why that might happen?

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

Re: NewtonMeshApproximateConvexDecomposition tests

Postby Julio Jerez » Tue Dec 13, 2011 1:37 pm

Code: Select all
      // here the use should take the user data from the body create newtonMesh form it and return that back
          NewtonCollision* collision = NewtonBodyGetCollision(body);
          NewtonMesh* const mesh = NewtonMeshCreateFromCollision(collision);

         int vertexCount = NewtonMeshGetVertexCount(mesh);


yes that will be the case, you are building a visual mesh from the collision of the rigid body.
youd need to build it from the userData of the rigid body which I asume Is your visual mesh.

I put that as a quick sample, but I added the commet.
I will chngeteh sample tonight, so tha it make more sence.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonMeshApproximateConvexDecomposition tests

Postby Bird » Thu Dec 15, 2011 8:33 am

Ok, I think I finally have the data I'm using for the convex cube stored in a.ngd file http://www.hurleyworks.com/downloads/concave_cube3.zip

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

Re: NewtonMeshApproximateConvexDecomposition tests

Postby Julio Jerez » Thu Dec 15, 2011 3:37 pm

Oh I did not see thsi this mornig. I will test tonight, thank.
I will also make a better interface for the exporting the visual mesh for when we need to use it next time.

Bascially I will add teh option that you will syore an asset name, so teh dCenet can be liek a blue print for defining a physi effect.
the the application can get the callback to teh asset and load the file it want.

save a Mesh effect can be veryt restritive for many user even for a plugin it, an asset name can import the physics effect and use any graphics data that was already in the modeler or even load a native graphics file.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Previous

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 8 guests