How to create a concave hull?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

How to create a concave hull?

Postby ep1stle » Sun Nov 09, 2008 12:19 pm

Is there a way to create a concave hull of an arbitrary mesh. I currently only get the convex shape working.

Image
I just want to create a fitting collision for an arbitrary mesh like this hut.

I guess there must be any way since my NewtonWorld also can be a concave collision, can't it?
ep1stle
 
Posts: 10
Joined: Mon Nov 27, 2006 12:38 pm
Location: GERMANY

Re: How to create a concave hull?

Postby JernejL » Sun Nov 09, 2008 2:41 pm

By creating a compound collision, you decompose our mesh manually or automaticly into separate convex hulls and create a compound collision from them like this:

Image

You can use this to decompose your meshes but it takes a lot of tweaking parameters to get anything useful like on that picture above:
http://codesuppository.blogspot.com/200 ... ition.html
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1531
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: How to create a concave hull?

Postby ep1stle » Sun Nov 09, 2008 4:50 pm

hey delfi, thanks for your reply. But I solved my problem in another way. I just create it like my "worldbody"

Code: Select all
NewtonCollision* tmpcol = NewtonCreateTreeCollision(newtWorld);
   NewtonTreeCollisionBeginBuild(tmpcol);
   int cMeshBuffer, j;
   int v1i, v2i, v3i;
   IMeshBuffer *mb;

   float vArray[9]; // vertex array (3*3 floats)

   int tmpCount = 0;

   for (cMeshBuffer=0; cMeshBuffer<mesh->getMeshBufferCount(); cMeshBuffer++)
   {   
      mb = mesh->getMeshBuffer(cMeshBuffer);

      video::S3DVertex2TCoords* mb_vertices = (irr::video::S3DVertex2TCoords*)mb->getVertices();
      //video::S3DVertex* mb_vertices = (irr::video::S3DVertex*)mb->getVertices();

      u16* mb_indices  = mb->getIndices();

      // add each triangle from the mesh
      for (j=0; j<mb->getIndexCount(); j+=3)
      {
         v1i = mb_indices[j];
         v2i = mb_indices[j+1];
         v3i = mb_indices[j+2];
   
         vArray[0] = mb_vertices[v1i].Pos.X;
         vArray[1] = mb_vertices[v1i].Pos.Y;
         vArray[2] = mb_vertices[v1i].Pos.Z;
         vArray[3] = mb_vertices[v2i].Pos.X;
         vArray[4] = mb_vertices[v2i].Pos.Y;
         vArray[5] = mb_vertices[v2i].Pos.Z;
         vArray[6] = mb_vertices[v3i].Pos.X;
         vArray[7] = mb_vertices[v3i].Pos.Y;
         vArray[8] = mb_vertices[v3i].Pos.Z;

         NewtonTreeCollisionAddFace(tmpcol, 3, (float*)vArray, 12, 1);
      }

   }
   NewtonTreeCollisionEndBuild(tmpcol, 0);


This code snippet works like a charm. But is there anything I should know about that method or is it a good way to handle it so? What about a big amount of bodies created that way?
ep1stle
 
Posts: 10
Joined: Mon Nov 27, 2006 12:38 pm
Location: GERMANY

Re: How to create a concave hull?

Postby JernejL » Mon Nov 10, 2008 7:26 am

Oh, i see you created a trimesh, trimeshes are even better than compounds, as long as you don't intend them to move, since you mentioned a "concave hull" i assumed you meant something else.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1531
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: How to create a concave hull?

Postby ep1stle » Mon Nov 10, 2008 7:56 am

Delfi wrote:[...] as long as you don't intend them to move [...]


Mh, the user should have the ability to make his objects mnoveable if he wants. Is there a major problem with the trimesh above?
Perhaps I should do a restriction that moveable objects should be convex only :?
ep1stle
 
Posts: 10
Joined: Mon Nov 27, 2006 12:38 pm
Location: GERMANY

Re: How to create a concave hull?

Postby JernejL » Mon Nov 10, 2008 10:22 am

In newton you cannot have a dynamic trimesh, ofcourse you can move it, but not in a dynamic way (that would cause interactions with other trimeshes for example), also trimeshes do not collide with other trimeshes. this is why there is compound collision.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1531
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: How to create a concave hull?

Postby ep1stle » Mon Nov 10, 2008 10:37 am

So let's summarize:

For static meshes I can use these trimeshes without any problems. But if I want to have arbitrary meshes as dynamic physic objects, which is affected by anything it collides with, either I have to use a compound collision as you described in your previous post or I have to "define" a restriction that only convex objects are allowed?!

Did I get the facts right?
ep1stle
 
Posts: 10
Joined: Mon Nov 27, 2006 12:38 pm
Location: GERMANY

Re: How to create a concave hull?

Postby JernejL » Mon Nov 10, 2008 3:33 pm

Essentially yes, and pretty much every physics engine does this the same way, simulating actual dynamic trimeshes is very difficult and cpu intensive operation so it is only used in movie industry and rarely in medical simulations and material simulation apps..

So depending on how you want your "shed" on that pic to work, you may do it with separate plank objects and use joints to hold them so it can fall apart, or use compound.. trimesh is another static option again, it all depends on the level of interaction you want to have.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1531
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: How to create a concave hull?

Postby ep1stle » Mon Nov 10, 2008 5:04 pm

Well, today I noticed the fact that my mesh is hold in several meshbuffers while each of them holds a single "primative" my whole mesh is made of. So I guess using a CompoundCollision would be the perfect solution if each of these "primatives" is kept convex. So I can create a nearly perfect collision in a very short time.

Thx to you delfi, you helped me alot
ep1stle
 
Posts: 10
Joined: Mon Nov 27, 2006 12:38 pm
Location: GERMANY


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest