creating collision shapes in a seperate thread

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

creating collision shapes in a seperate thread

Postby ker » Sun Apr 17, 2011 6:40 pm

Hey everyone.

I'm using PolyVox to generate Meshes from Voxeldata.
These meshes easily have 4000 triangles for some complex parts.
Also I am changing 8 meshes (each possibly having 4000 triangles) every few frames.

I use one NewtonTreeCollision per mesh. so I end up with about 50-100 NewtonTreeCollisions.
Once all the NetwonTreeCollisions are created the game runs smoothly even if in some setups the total triangle count is somewhere in the millions. (and 5*60 newton updates per second).

So, now to my problem:

The creation of the mesh happens in the same thread, so if I change a single mesh with 4000 triangles, that takes about 40-80 ms depending on the mesh.
This obviously won't do for a realtime game.

Is there any way I could create my Collision in a thread while NewtonUpdate calls are happening in another thread?

Greetings

/ker
ker
 
Posts: 4
Joined: Sun Apr 17, 2011 12:48 pm

Re: creating collision shapes in a seperate thread

Postby JernejL » Sun Apr 17, 2011 6:58 pm

I don't think that this would be any problem at all, newton is intended to run multithreaded so this should not be a issue.

Also since you have voxels data - you don't really have to build tree collisions for newton. You can build a custom collision shape ( NewtonCreateUserMeshCollision ) with callbacks instead, which tell newton geometry and can be modified in real-time with minimal resources.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: creating collision shapes in a seperate thread

Postby Julio Jerez » Sun Apr 17, 2011 8:53 pm

ker wrote:Is there any way I could create my Collision in a thread while NewtonUpdate calls are happening in another thread?

I believe you could, if you just make one a a time. I never tried Unfortunally the collision creation is not thread safe,
I do not think it will support make to collision tree at the same time from twe separate thread.
However, I beleive you can make a child thread I create one at a time,

however I do not think that will solve the problem because what will the runtime do while the collision is not ready.
However like Delfi says, it you have your faces available, you can use a user mesh collision.
by doing that you are free to make it on a separate thread and even with multicores.

Do you have a way to generate the faces on a boudning box on demeand?
or are you using collison tree for the runtime speed of the collision tree?

if you Boxel thechnology can generate collisions faces on demand, then the user defined collision will be your fastest solution.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: creating collision shapes in a seperate thread

Postby ker » Sun May 08, 2011 3:21 pm

threading does not work at all. I only use one thread for collision creation. but it ends up crashing somewhere in NewtonUpdate.

yes I was counting on the runtime speed...

generating the meshes on demand is a heavy process. but I can pregenerate them and just take them out of a std::map or sth... but the regions would need to be lined up...
I'll look into that.
ker
 
Posts: 4
Joined: Sun Apr 17, 2011 12:48 pm

Re: creating collision shapes in a seperate thread

Postby JernejL » Sun May 08, 2011 3:58 pm

Here's a idea: run another copy of newton library in another thread, serialize & pass over the shapes to main thread that way.

Serialization should be the main way to store newton shapes to load them efficiently.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: creating collision shapes in a seperate thread

Postby ker » Sun May 08, 2011 4:07 pm

hey good idea, thanks... as long as I get it down to less than 10 ms I think I can use it.
ker
 
Posts: 4
Joined: Sun Apr 17, 2011 12:48 pm

Re: creating collision shapes in a seperate thread

Postby JernejL » Sun May 08, 2011 4:57 pm

Why don't you pre-build shapes originally in a offline tool & load the serialized data quickly? that's the fastest way..
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: creating collision shapes in a seperate thread

Postby ker » Mon May 09, 2011 3:37 pm

not an option... I have too many changes at runtime...
but hey, it works now! thanks. 2.5 ms for a deserialization in the main thread, when it took 50 ms for creating the shape in another thread and serializing it there. That's good enough for me...
ker
 
Posts: 4
Joined: Sun Apr 17, 2011 12:48 pm

Re: creating collision shapes in a seperate thread

Postby JernejL » Mon May 09, 2011 6:34 pm

You could implement a user mesh in the future, that's the most efficient way to handle a custom mesh in newton with custom (very dynamic) data supplied by your app.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: creating collision shapes in a seperate thread

Postby Julio Jerez » Mon May 09, 2011 10:37 pm

Ker, what Delfy is say will be the best way to go about.

A user Mesh collison does not have to make any mesh and serialize it, I will only have to produce the faces about an AABB, then you can implement a good caching system and that wil do it.
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 0 guests

cron