ConvexHull from binary file

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

ConvexHull from binary file

Postby Madman07 » Fri Jul 20, 2012 5:26 am

Hi.

Let's say, I'm making an collision mesh in 3ds max. I'm splitting collision into 10-15 convex primitives, each built by 8-16 vertices (I get used to that when I was modding for Source engine). Now I'm exporting it somehow to some binary format, and load every primitive separately by Newton. So in fact, Newton wouldn't have to decompose collision, all would be made by me. Then, I'm applying all of the to one rigidbody. Is there any simple way for part "export from 3ds max" and "load by Newton", or should I pass to Newton a bunch of verticex and triangles in array and let it do a binary file? If yes, then how?

Thanks in advance,
Madman07
Madman07
 
Posts: 15
Joined: Thu Jul 19, 2012 1:40 pm

Re: ConvexHull from binary file

Postby Julio Jerez » Fri Jul 20, 2012 7:04 am

if you want to load binary data, the easiest way if you make a off line tool that make then.
For collision you can use these function
Code: Select all
NewtonCollision* NewtonCreateCollisionFromSerialization (const NewtonWorld* const newtonWorld, NewtonDeserializeCallback deserializeFunction, void* const serializeHandle);
void NewtonCollisionSerialize (const NewtonWorld* const newtonWorld, const NewtonCollision* const collision, NewtonSerializeCallback serializeFunction, void* const serializeHandle);

basically in you tool you make the collision shape, and you serialize to a file or to an archive, or whatever form, then in you game you do desirialize then.
you can serialize complete rigibodies the same way too.
Look at the sandbox demo, there are plenty samples, there is not 3dsmax plugin for doing that at this time.


Also notice that building convex collision shapes in newton is very fast an accurate, the funcion run in constant time, for example making 64 vertex convex runs in the same amound of time it it was made from a vertex cloud of 100 points or 100000 points.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: ConvexHull from binary file

Postby Madman07 » Fri Jul 20, 2012 9:15 am

I wanted a binary file just to be sure, that no one will be messing with collision. Serialize and Deserialize seems to work fine (with hardcoded vertices). The last thing that left is to read an OBJ file and convert it into vertex cloud :)
Madman07
 
Posts: 15
Joined: Thu Jul 19, 2012 1:40 pm

Re: ConvexHull from binary file

Postby Julio Jerez » Fri Jul 20, 2012 9:34 am

Newton has a poerfull wing edge mesh utility with serialization it is quite eassy to use.


bascially in you toll you cna do this
-read your OBJ using you obj loader
-create a dgNewtonMesh
-add the faces one at a time (ther are many examples in the SDK
-Create a convex hull from the mesh
-destroy teh mesh
-serialize you collsion


try usind the NewtonMesh for all mesh manipulations in your tool, it produces very high quality work.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: ConvexHull from binary file

Postby Madman07 » Fri Jul 20, 2012 12:03 pm

I was playing with mesh and I have to say it's even nice. I made my custom collision (made out by 2 boxes) and it works fine. Almost. Somtimes I get error in dgCollisionConvex.cpp at line 1416:

Code: Select all
(dgAbsf (side0 - plane.Evalue (m_vertex[firstEdge->m_vertex])) < dgFloat32 (1.0e-5f));


Here's code for custom collision (mPhysOuter is my world, polys is an array of floats, 144 floats gives 48 vertices gives 12 planes gives 2 cubes; mat is transformation matrix). Is there anything wrong with it, or am I just missing something ?

Code: Select all
   NewtonMesh* mymesh = NewtonMeshCreate(mPhysOuter);

   NewtonMeshBeginFace(mymesh);
   for (int i = 0; i < 12; i++) NewtonMeshAddFace(mymesh, 4, &polys[i*12], 12, 0);
   NewtonMeshEndFace(mymesh);

   NewtonCollision* coll = NewtonCreateConvexHullFromMesh (mPhysOuter, mymesh, 0.0f, 5);
   NewtonBody*body = NewtonCreateBody(mPhysOuter, coll, &mat[0][0]);
   NewtonDestroyCollision(coll);
Madman07
 
Posts: 15
Joined: Thu Jul 19, 2012 1:40 pm

Re: ConvexHull from binary file

Postby Julio Jerez » Fri Jul 20, 2012 12:36 pm

The NetwonMesh if a high quality computational geoimetry tool. if you buidl hull using it, it will generate exact hull.
this means that if two points in the hull are very , very close, but not identical they will be part of the hull.
for some apps like this is importtnat, but for physics using 32 bit float float this casues bad rounding errors. To solve that the convex hull funtion has a tolerance paramenter.

you are using NewtonCollision* coll = NewtonCreateConvexHullFromMesh (mPhysOuter, mymesh, 0.0f, 5);
try using NewtonCollision* coll = NewtonCreateConvexHullFromMesh (mPhysOuter, mymesh, 0.001f, 5);
this will make a hull that will guarantee that no two vertices are closer that 0.001 distance from the average plane equation and the plane test will never fail
I usially try NewtonCollision* coll = NewtonCreateConvexHullFromMesh (mPhysOuter, mymesh, 0.005f, 5); for physics
try different values so that you cna see how it works.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: ConvexHull from binary file

Postby pHySiQuE » Fri Jul 20, 2012 1:47 pm

Beware that the serialization format has changed several times in the past, and any changes in the future will invalidate all your collision files.
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: ConvexHull from binary file

Postby Julio Jerez » Fri Jul 20, 2012 5:50 pm

the serialization is not a file format is a archive system for fast loading of data.

for backward and forward comaptibility newt have the dScene format wich does supports revision number.
a tool should use the dScene format, and serialization for binary export only,
no guaranteis that serilized data will work even with wi the next version checked to source control.
All it takes is to add one byte to any class and seralization will brake.
In fact ieven a compeil setting may brake a serialized file.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: ConvexHull from binary file

Postby Madman07 » Sat Jul 21, 2012 5:41 pm

I was playing a bit with coding, and I made very simple obj to col converter. Basically, it takes exported obj file and convert it to *.col file, which can be easily deserialized by Newton. If anyone is interested, you can read about it on my blog :)

http://madman07.ugu.pl/index.php?show=003_cont
Madman07
 
Posts: 15
Joined: Thu Jul 19, 2012 1:40 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron