TreeCollision questions - voxel world

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

TreeCollision questions - voxel world

Postby Dragonic » Fri Jan 31, 2014 5:48 am

Hello,
I have some questions for the use of NewtonTreeCollision with my voxel world ( minecraft-like game ).

I would like some clarification on the optimization process .

Code: Select all
NewtonTreeCollisionEndBuild (tree , 1) ;


I noticed that for a simple cube ( 6 faces = 6 quads or 12 triangles, 8 vertices and 36 indices for the graphic part, 6 quad sent as geometry for NewtonTreeCollision ), NewtonTreeCollisionEndBuild takes about 8 milliseconds.

Finding that huge, I've quickly tested by disabling optimization : about 2 milliseconds on average.

But I do not know if optimization remains essential in case I know very well the faces to send to the NewtonTreeCollision ?!

Then just out of curiosity, I wonder how the engine create the final geometry for the following shape :

Image

In my graphic part I have 2 quad and 8 vertices :

Image

If I send these 2 quads to the NewtonTreeCollision, it remains the same with the optimization ? Or do we have this instead :

Image

I ask this because if I can avoid optimization I do not know what I need to send in this case ^^ !


Finally, I need to know if NewtonTreeCollision is the right solution for my voxel world ? Because there is no function to remove faces and I often need to edit the blocks, and I don't really see how to apply the modification to NewtonTreeCollision effectively !

Thank you in advance for the answer! And sorry if some have seemed obvious, this is the first time I use a physics engine ^^ !
User avatar
Dragonic
 
Posts: 10
Joined: Wed Jan 29, 2014 12:25 pm

Re: TreeCollision questions - voxel world

Postby Julio Jerez » Fri Jan 31, 2014 7:13 am

The collision tree is not designed to run and being edit in real time, it is designed to be build an optimal mesh and them load it from a pre serialized data.

why not using the user collision mesh? the user collision is derived form the same collision trees, and since you know how your geometry nee to be configure, you can simple pass that in the callback.
some people use it for Voxel collision.
the collision is not slower that hieghfield, of collision trees, essentially those tow are a special case of a user collision with a dedicated callback that build the patch of colliding face with a know how function.

see demo
../newton-dynamics\applications\demosSandbox\sdkDemos\demos\UserStaticCollision.cpp
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: TreeCollision questions - voxel world

Postby Dragonic » Fri Jan 31, 2014 11:37 am

Ok, thank you for the quick reply !

Since this is the first time, like I said, that I use a physics engine (and the first time I create a 3D game ^^), it is a little difficult to assimilate as much knowledge and know what to do in the most optimal way ^^ !

Just out of curiosity, I go back to a previous question :
For NewtonTreeCollision optimization : does it remains essential even if we really know that we cannot simplify more than the quads that we sent to it ? Or it will still optimize other things ?
User avatar
Dragonic
 
Posts: 10
Joined: Wed Jan 29, 2014 12:25 pm

Re: TreeCollision questions - voxel world

Postby Julio Jerez » Fri Jan 31, 2014 12:16 pm

The optimization for collision tree is not obligatory, both optimized and not optimized contain the same information.
However optimized collision are goo for performance, for memory saving and most importantly for better collision respond.

The optimization perform a constrained Delaney triangulation of mesh, and then convert the mesh to a convex polygonal mesh.
this has tree effect.
-The mesh is converted to a equivalent input mesh but with the topology in which each face has a maximizes area.
-Reduce the number of Flat and convex edge in the mesh that can generate contact but that are not necessary for the collision respond because they are linear combination of other contacts

some people do not use optimize collision because they require to have the exact same input mesh, but these case are rare.
The engine operate in optimal condition with optimized meshes.

to see the difference you can implement the debug display and see how an optimized and an no optimized collision tree looks like.

The collision tree does not generate Boolean, so if the example you show me was made of a set of non overlapping faces, the result of the optimized mesh will be this
1391161102-f1.jpg
1391161102-f1.jpg (11.44 KiB) Viewed 2823 times


the smallest set of convex faces that can be constructed from the delanay triangulated mesh.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: TreeCollision questions - voxel world

Postby Dragonic » Mon Feb 03, 2014 4:18 am

Ok ok ^^ !

I'll probably have to ask later some details about stuff that seems obvious ^^ ! Sorry about that !

While I understand gradually the differents tools of the engine, I do not necessarily know which I should use in which case, and especially how to handle some particular case I need (water management, raycast in my voxel world for edition, a body which has to pass through another, ...).
User avatar
Dragonic
 
Posts: 10
Joined: Wed Jan 29, 2014 12:25 pm

Re: TreeCollision questions - voxel world

Postby Dragonic » Fri Mar 07, 2014 8:24 am

Julio Jerez wrote:see demo
../newton-dynamics\applications\demosSandbox\sdkDemos\demos\UserStaticCollision.cpp


Sorry, again I need some help in this topic because I don't really understand this UserMeshCollision system !
In the demo (UserPlaneCollision.cpp) I can only see that :

Code: Select all
m_collision = NewtonCreateUserMeshCollision (world, &minBox[0], &maxBox[0], this,
                                        PlaneCollisionCollideCallback, PlaneMeshCollisionRayHitCallback,
                                        PlaneCollisionDestroyCallback, PlaneCollisionGetCollisionInfo,
                                        PlaneCollisionAABBOverlapTest, PlaneCollisionGetFacesInAABB,
                                        UserCollisionSerializationCallback, 0);


This seems to be about a box and callbacks for it ! That don't explain for me how to add my complex mesh geometry ^^ !
Also, I read this topic, who seems to be realy helpful in my case : viewtopic.php?f=9&t=7786
But again can't see a real tuto for building my voxel world with the engine !

If someone can explain how to do this from the begining this could be really helpful ^^ :
- create the UserMesh with any kind of geometry
- add / delete faces (or group of faces) to the geometry
- raycasting in order to get a single voxel (for add or deletion)
- good practices in order to edit the collision shape fastly : If I add/delete a voxel in a chunk, I rebuild the whole chunk for the graphic part, and I think I could recreate a whole UserMeshCollision with that, but don't know if this is better to just edit the current UserMeshCollision in order to add/delete faces !?
(about this last part, I have to say that I use the greedy merging algorithm for my chunks, and because of that I don't know if it's really easy to delete for example a single voxel from the collision geometry)

And maybe a question about blocks that move : I have a piston system in my game, not really like minecraft but when it's activated it moves a part of the chunk at small speed ! Do I need another kind of collision system for that ?

Really sorry, things need to be really easy for a beginner like me in order to understand ^^' !
User avatar
Dragonic
 
Posts: 10
Joined: Wed Jan 29, 2014 12:25 pm

Re: TreeCollision questions - voxel world

Postby Julio Jerez » Fri Mar 07, 2014 10:52 am

you do not build mesh when using user mesh collision, user mesh collision is for people who already have there own mesh and need to use integrated with the collision system in the engine.
In the The call back you pass the path of face of the mesh that intersect minBox and maxBox.
There is not add or delete faces. you simple the the engine what is available in the call back

if you have you boxed engine all you nee to do if\si find the faces that tow that box, the same what that you will figure out that face that are visible in the frustum of view.
then for each visible face you code them isn the rule the engine expect them.

the same go for ray cast. the call back will call with tow point in the space of the AABB that define the user shape (the voxel world)
you engine does the ray cast and pass the result to newton.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest