I have a voxel world system and I want to integrate bullet physics so that rigid bodies collide with the terrain. Unlike minecraft the world produces flat areas aswell as slopes to around 45 degrees.
I thought that probably the most efficient way to make a collision model for the terrain is to construct geometry on the fly every frame depending on all rigid bodies and their respective AABBs.
Using an AABB i can easily pick out all blocks in the world contained (or even touched) by it and construct their collision models (originally I only had cubes, but now single blocks can produce many different collision models depending on the blocks around them).
I have seen people do the approach of just making a BvhTriangleMeshShape for the entire world, but especially with a changing world I don't think this is all too viable, or at least I know that I can pick out the right blocks for collisions A LOT easier than just having the entire geometry and then use some complicated AABB tree.
Can anyone help me to implement something like that? Maybe with a custom collision shape, or -broadphase algorithm? It is enough if anyone can point me towards some information on this subject.
Voxel World, Construct collision model on the fly
-
- Posts: 7
- Joined: Sun Aug 04, 2013 8:44 pm
-
- Posts: 6
- Joined: Fri Feb 25, 2011 12:48 am
Re: Voxel World, Construct collision model on the fly
Yeah I tried a trimesh approach and also a compound shape approach. I've been away from the project for over 11 moth (I'm getting back to it) so the details may be hazy. Basically what I do is I create a bullet trimesh object for some NxNxN volume region. When I pick I pick the trimesh to get an intersection point. From the intersection point and direction I can compute a map into my volume. But you are right, it's not the best approach. I haven't gotten around to fixing it.
I have a video showing some hackish destruction code I came up with in a day:
http://www.youtube.com/watch?v=Ap2RZo-VybQ
Here is another video showing some recent work
http://www.youtube.com/watch?v=4qsVglO7kz0
frankly I probably don't even care about performance of this right now. I need to implement more game play.
I have a video showing some hackish destruction code I came up with in a day:
http://www.youtube.com/watch?v=Ap2RZo-VybQ
Here is another video showing some recent work
http://www.youtube.com/watch?v=4qsVglO7kz0
frankly I probably don't even care about performance of this right now. I need to implement more game play.
-
- Posts: 6
- Joined: Fri Feb 25, 2011 12:48 am
Re: Voxel World, Construct collision model on the fly
btw I also save the chunks to disk using leveldb. I don't think I"m doing it in an optimized way though because I'm not manually batching things up. Maybe the leveldb code will do optimized writes.
-
- Posts: 6
- Joined: Fri Feb 25, 2011 12:48 am
Re: Voxel World, Construct collision model on the fly
I've seen color picking been used in voxel projects that may work if you were just looking for some way to pick. Like I said, what I"m doing now is I just call pick on Bullet and use the returned pick results as a key into my volume structure in CPU memory. Eventually I'm looking to move everything to OpenCL (for my isometric game I may be able to just ray march the entire thing). Right now my volume code is very simple. It's just a big constant sized NxNxN chunk of memory and everything is paged into that as the world moves, so I think it may be possible to port to OpenCL and just drop a marching cube algorithm on it.
BTW the last screens looks weird because I hacked together a PBR system so I had to create custom textures for it:
http://imgur.com/nLMk7No,xQL0Ln9,JvKrJlE#0
BTW the last screens looks weird because I hacked together a PBR system so I had to create custom textures for it:
http://imgur.com/nLMk7No,xQL0Ln9,JvKrJlE#0
-
- Posts: 149
- Joined: Fri Jun 24, 2011 8:53 am
Re: Voxel World, Construct collision model on the fly
100% agreed. Back when I worked with something which (almost) looked voxel-ish, I had relatively good experiences with what could be a raw fill. Except my assets weren't really integer-aligned so my fill was pretty much more involved. How are you about that?I have seen people do the approach of just making a BvhTriangleMeshShape for the entire world, but especially with a changing world I don't think this is all too viable, or at least I know that I can pick out the right blocks for collisions A LOT easier than just having the entire geometry and then use some complicated AABB tree.
A custom voxel shape might make sense I guess but I'm not much on those voxel vibe to start with.