Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411710 Posts in 69402 Topics- by 58456 Members - Latest Member: FezzikTheGiant

May 20, 2024, 07:59:39 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityDevLogsVoxel Physics Showcase
Pages: [1]
Print
Author Topic: Voxel Physics Showcase  (Read 4567 times)
Smerik
Level 1
*



View Profile
« on: March 21, 2016, 05:19:06 AM »

Hi guys,

So this is my first post here, let me introduce shortly.
Back in the days I was a very active Flash games developer on Newgrounds with several games on my name like Unreal Flash that can be found here; http://erik.newgrounds.com/

Before I start about what I made, first quick why:

VS

So annoying how in the left Minecraft image stuff just floats.
Enough reason to dedicate to much of my spare time to fix this, right?

Here is a quick example of me destroying a voxel building (I borrowed the building from the awesome tool MagicaVoxel)




By clicking it does a raycast into the world and when hitting a voxel it destroys all voxels within a dynamic radius.

I wrote a simple script to convert any mesh into my voxel world, and the converter is flexible in resolution.

Here is one more example of a very complex Pod racer object (I like Star Wars a little too much):


This image explains a little bit what is going on:



So my world consists of voxel groups, each group has a max of 20x20x20 (8000) voxels, one reason why I can’t go larger than this is the limit of the mesh vertex size, and another one is optimizing for physics queries.
Green lines show box colliders that I compress together as much as possible during creation.
Pink circles show where my voxel groups are joint together. I use advanced joints and just the normal physx engine.

Now some info for people that are interested about the concept behind it;
The hardest thing was to detect when an object should be split into multiple objects. On paper this sounds so easy, but making the engine understand this was quite hard to optimize.
How it currently works;

1)   I destroy an x amount of voxels in an object.
2)   I find the first voxel in my object and do a flood fill over all the neighbors (so for each neighbor I search its neighbors) until it has found all neighbors of the first voxel.
3)   I see if the count of the voxels I found is the same size as the total voxel array.
4)   Is it the same size? It means I’m still a single object
It’s not the same size? this means that I’m divided into multiple objects, and I push the found array in a new voxel group.
5)   Repeat step2 for the rest of the voxels, because it could have split into multiple objects.

After all of this is done;
Each voxel group has a separate array of voxels that are visible, a voxel is visible when it has less than 6 neighbors.
After splitting it loops over all visible voxels and starts creating mesh for all the visible faces, this site was very helpful: http://wiki.unity3d.com/index.php/ProceduralPrimitives
During the same loop I build box colliders. For every voxel it tries to see if a neighbor already has a boxcollider where he could push himself in. I found that creating box colliders on the fly was quite expensive so I use an object pooler that holds a couple of thousand boxcolliders gameobjects that I can swap in and out.
It’s also this loop where I build joints to connect to other voxel groups.

Now of course there is a little bit more to it than that, but this was it in a nutshell. If anyone is interested in more, just ask and I’ll try to reply to all questions.

Also if anyone knows a good application for this, feel more than welcome to reach out, I’m still unsure what type of game to build with this Tongue.


« Last Edit: April 06, 2016, 12:39:11 AM by Smerik » Logged

keystroke massacre
TIGBaby
*


View Profile WWW
« Reply #1 on: March 21, 2016, 11:46:54 PM »

Mate, that looks incredible! Amazing bit of work, particularly seeing a whole stage crumble in real-time.

I realise not all the concepts would translate, but knowing what you've learnt from this, how would you achieve a similar result with a structure defined by arbitrary meshes rather than voxels?
Logged

km
Smerik
Level 1
*



View Profile
« Reply #2 on: March 22, 2016, 12:43:01 AM »

Thanks a bunch.

You would have to do a boolean subtraction to the original mesh, it would make things a little bit more complex as its hard to define how the inside should look textured. in my case, the inside is just tiles that have a texture i can set.
However to push you a little in the right direction i found a forum post of someone that accomplished this:
http://forum.unity3d.com/threads/boolean-subtraction-operations-on-mesh.85713/
Logged

pixelgriffin
Level 0
**


Developing With Love


View Profile WWW
« Reply #3 on: March 22, 2016, 01:20:05 AM »

Really great work, I love voxels! I think you could apply it to practically any game honestly. Are you considering releasing a sandbox or source anywhere?

Also,
have you seen anything from Voxel Farm? I used to religiously watch their videos haha. Maybe you can get some ideas from their work on directions to improve your voxel system?

Nice job!  Smiley
Logged

Twitter: @pixelgriffin
Smerik
Level 1
*



View Profile
« Reply #4 on: March 22, 2016, 02:47:44 AM »

Mate, that looks incredible! Amazing bit of work, particularly seeing a whole stage crumble in real-time.

I realise not all the concepts would translate, but knowing what you've learnt from this, how would you achieve a similar result with a structure defined by arbitrary meshes rather than voxels?

Here is a nice free opensource script Smiley
https://github.com/karl-/pb_CSG
Logged

Smerik
Level 1
*



View Profile
« Reply #5 on: March 22, 2016, 02:50:24 AM »

Really great work, I love voxels! I think you could apply it to practically any game honestly. Are you considering releasing a sandbox or source anywhere?

Also,
have you seen anything from Voxel Farm? I used to religiously watch their videos haha. Maybe you can get some ideas from their work on directions to improve your voxel system?

Nice job!  Smiley

I want to throw together a sandbox within a couple of weeks. I have to make it functional and understandable, a simple ui would do a lot. About making it open source, i wouldnt mind sharing some code and idea's but i dont think any of my source would be useful at this point.

I know Voxel farm and it looks super cool! And its part of my inspiration, also the incredible work of Branislav Siles that build http://www.atomontage.com/ has been good motivation to try and push the limits. There is always a smarter and faster way of doing something Tongue.
Logged

Smerik
Level 1
*



View Profile
« Reply #6 on: March 25, 2016, 07:16:40 AM »

Check out this Jeanne D'Arc statue being demolished Smiley

« Last Edit: April 06, 2016, 12:44:12 AM by Smerik » Logged

Smerik
Level 1
*



View Profile
« Reply #7 on: April 06, 2016, 12:45:00 AM »

Worked hard on optimizing my collider scripts. Im very satisfied with the result:

Logged

J-Snake
Level 10
*****


A fool with a tool is still a fool.


View Profile WWW
« Reply #8 on: December 28, 2016, 05:10:55 PM »

Also if anyone knows a good application for this, feel more than welcome to reach out, I’m still unsure what type of game to build with this Tongue.
I found the ideal use for it in 2D and made a puzzle game around that called Trap Them:
http://store.steampowered.com/app/375930

Destruction and the block group detection mechanism is the part that is in common, but the Newtonian physics are replaced with a "fall straight down and reconnect"-mechanism in order to enable potent puzzle gameplay.

1)   I destroy an x amount of voxels in an object.
2)   I find the first voxel in my object and do a flood fill over all the neighbors (so for each neighbor I search its neighbors) until it has found all neighbors of the first voxel.
3)   I see if the count of the voxels I found is the same size as the total voxel array.
4)   Is it the same size? It means I’m still a single object
It’s not the same size? this means that I’m divided into multiple objects, and I push the found array in a new voxel group.
5)   Repeat step2 for the rest of the voxels, because it could have split into multiple objects.
So I was interested to see how someone else might approach the problem. Yep, that part is very hard to optimize and I am not surprised to see people gravitate towards brute force flooding. Thanks to the scope Trap Them doesn't really need optimization but I used a simple optimization idea: Each flooding starts at the point of destruction. Instead of always flooding the whole structure and counting the blocks flooding is aborted when a flooded block is resting on a solid/immobile block. In that case it is known that the remaining structure has to be "grounded" and remain immobile. I guess an efficient book keeping mechanism to keep track of the properties of the block groups would be needed to enable good performance on a large scale.

Hope you too find use for the hard work. Good luck;)
« Last Edit: December 28, 2016, 05:57:09 PM by J-Snake » Logged

Independent game developer with an elaborate focus on interesting gameplay, rewarding depth of play and technical quality.<br /><br />Trap Them: http://store.steampowered.com/app/375930
Smerik
Level 1
*



View Profile
« Reply #9 on: December 29, 2016, 04:39:32 AM »

Also if anyone knows a good application for this, feel more than welcome to reach out, I’m still unsure what type of game to build with this Tongue.
I found the ideal use for it in 2D and made a puzzle game around that called Trap Them:
http://store.steampowered.com/app/375930

Destruction and the block group detection mechanism is the part that is in common, but the Newtonian physics are replaced with a "fall straight down and reconnect"-mechanism in order to enable potent puzzle gameplay.

1)   I destroy an x amount of voxels in an object.
2)   I find the first voxel in my object and do a flood fill over all the neighbors (so for each neighbor I search its neighbors) until it has found all neighbors of the first voxel.
3)   I see if the count of the voxels I found is the same size as the total voxel array.
4)   Is it the same size? It means I’m still a single object
It’s not the same size? this means that I’m divided into multiple objects, and I push the found array in a new voxel group.
5)   Repeat step2 for the rest of the voxels, because it could have split into multiple objects.
So I was interested to see how someone else might approach the problem. Yep, that part is very hard to optimize and I am not surprised to see people gravitate towards brute force flooding. Thanks to the scope Trap Them doesn't really need optimization but I used a simple optimization idea: Each flooding starts at the point of destruction. Instead of always flooding the whole structure and counting the blocks flooding is aborted when a flooded block is resting on a solid/immobile block. In that case it is known that the remaining structure has to be "grounded" and remain immobile. I guess an efficient book keeping mechanism to keep track of the properties of the block groups would be needed to enable good performance on a large scale.

Hope you too find use for the hard work. Good luck;)

That's clever, the game looks like a lot of fun. Its digger but much more complex, specially the ping pong trailer showed some cool stuff. Looking at a puzzle games mechanic makes it look 'simple', but designing meaningful puzzles is super creative and difficult process. good job.

That sounds like a cleverway of solving your destruction mechanic! I was thinking for me since i don't have these resting points of making my bigger cubes consist out of smaller cubes and just check within those smaller cubes if its still touching its neighbors. So just my concept that is already there but than dynamic with smaller cubes. Sort of a LOD for collisions.

Regarding good use, well it was fun anyway bring an idea to live. However there was this company doing cloud physics for Unity that i still might contact, because if you are running my code in the cloud on a good machine you can have a shit load of destruction going on!

Also i'm still hoping one day this guys finishes his engine: http://www.atomontage.com/
Logged

J-Snake
Level 10
*****


A fool with a tool is still a fool.


View Profile WWW
« Reply #10 on: December 29, 2016, 06:44:59 AM »

specially the ping pong trailer showed some cool stuff. Looking at a puzzle games mechanic makes it look 'simple', but designing meaningful puzzles is super creative and difficult process.
Thanks, that is certainly true. But it is also a process where you grow the most and a rewarding experience.

However there was this company doing cloud physics for Unity that i still might contact, because if you are running my code in the cloud on a good machine you can have a shit load of destruction going on!
That is also a way to increase performance, he he.

Also i'm still hoping one day this guys finishes his engine: http://www.atomontage.com/
I remember watching some of his footage from few years ago. Haven't looked more into it but it would be cool if it finds proper use in a complete game.
Logged

Independent game developer with an elaborate focus on interesting gameplay, rewarding depth of play and technical quality.<br /><br />Trap Them: http://store.steampowered.com/app/375930
Schrompf
Level 9
****

C++ professional, game dev sparetime


View Profile WWW
« Reply #11 on: January 03, 2017, 04:22:54 AM »

Good work so far. Do you have any plans to make use of this?
Logged

Snake World, multiplayer worm eats stuff and grows DevLog
Smerik
Level 1
*



View Profile
« Reply #12 on: January 03, 2017, 04:41:21 AM »

If you mean, did i make this for a purpose, not really.
Though i did had a rough idea to make sort of like a Rubble Trouble Tokyo kind of game:




But nothing concrete.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic