Voxelers / mcthings

A Python framework for creating 3D scenes in Minecraft and Minetest
Apache License 2.0
59 stars 11 forks source link

Research howto implement voxels collisions demo #122

Open acs opened 4 years ago

acs commented 4 years ago

The model can be created in MV but we need an engine in which to program the physics which describe the voxels behaviour in collision. My personal goal is to have something like:

68747470733a2f2f692e696d6775722e636f6d2f7230457748464f2e676966

acs commented 4 years ago

https://github.com/andyhall/voxel-physics-engine

acs commented 4 years ago

Related to #102

acs commented 4 years ago

Ok, let's implement it from a simple scenario and evolve it: there are two cubes. A cube is motionless (still, stopped) and B cube is moving along a line shared with A. At some point B hits A and after the hit, B changes its direction.

The speed of B is fixed in this initial scenario. No friction is modelled that can stop it. B can also hit the start of the line. When B hits C, the start of the line, it changes the direction. We can consider C another cube. So in this scenario we have:

A-------B----------------C

B moves between A and C. When B hits A or C, it changes the direction. And the speed of B is always the same.

To make it more real, we can model the 3 cubes in a shared line in MagicaVoxel. And the implement the animation of B using some voxel engine. Is it possible to do it in MagicaVoxel? Maybe with a shader that redraws the scene could be an option. We can draw it with McThings in Minecraft and do there the animation. We can also import the vox file in Blender and do the animation there. Or we can use Unity or Unreal4. Or we can use some way to visualize 3D, like Three.js. Or use some voxel engine with physics support.

I will try to do it as simple as possible and without using complex engines, in order to understand the key topics.

An pretty on topic article: https://sites.google.com/site/letsmakeavoxelengine/home/physics And it has some demos doing exactly what we want:

https://www.youtube.com/watch?v=O5YOPgYRKQI&feature=youtu.be

And the engine implemented with all of that: https://github.com/AlwaysGeeky/Vox

Our goal is to implement the animation in 1 dimension, then 2 dimensions and finally, in 3D. And increasy the physics details making it more realistic: adding friction, changing the rebound speed depending on the hit speed, chaning directions depending on hit angles, adding gravity ... and at some point. moving to a engine that has implemented physics for us :)

acs commented 4 years ago

https://twitter.com/ephtracy/status/787232375298109440?lang=en

So as expected, animations can be done with shaders in MagicaVoxel. So let's explore this direction.

After some research, it seems to be pretty basic. You just create individual frames that can be combined into an animation. With shaders, you can fill the frames easily, as the tweet above shows. Some discussion about it:

https://www.reddit.com/r/VoxelGameDev/comments/7qxecn/how_do_i_do_frame_by_frame_animation_on/

and some people getting it working:

http://drinkdecaf.com/magicavoxel_animate

This feature was removed in 0.99: «Version 0.99 (the latest) has frame-based animation removed, though it is supposed to come back in the future» So end of this travel here with in MagicaVoxel animations.

acs commented 4 years ago

Three.js

Maybe it is a good moment to try to load our model in Three.js and do the animation there:

https://luciopaiva.com/magicavoxel-threejs-howto/

But the problem here is that there is no VOX format library for JS, to it is using the export to OBJ and we want to work directly always in voxels, avoiding the conversion to polygs until the end.

https://discourse.threejs.org/t/best-way-to-add-physics-to-a-voxel-terrain/15037

acs commented 4 years ago

Blender

This is cute, but not the kind of animation we want now: https://www.youtube.com/watch?v=3Hmhtwq8Fpc

acs commented 4 years ago

OpenGL Canvas

Ok, let's try to do it directly in OpenGL. Let's start with Python.

https://github.com/acs/opengl-samples

Another 3D engine: https://www.pygame.org/project/3865

Just playing around with pygame and pyglet and PyOpenGL. Learning. pygame uses PyOpenGL (auto cstrings version for OpenGL API) and pyglet has its own OpenGL API.

http://pyopengl.sourceforge.net/documentation/index.html -> to learn OpenGL #123

http://nehe.gamedev.net/tutorial/lessons_26__30/29002/ Collision detection in OpenGL

Physical simulations:

acs commented 4 years ago

Vulkan

https://github.com/geefr/vulkan-physics

acs commented 4 years ago

https://www.gamedev.net/forums/topic/707556-voxel-worlds-and-physics-engines/ https://github.com/voxcraft/voxcraft-sim/tree/3.0

acs commented 4 years ago

Ideas on howto implement it: https://stackoverflow.com/questions/56473065/particle-collision-with-voxel-world-in-compute-shader

Research on voxels collisions: http://isg.cs.tcd.ie/cosulliv/Pubs/VolumeContact.pdf

acs commented 4 years ago

A pretty interesting plugin for MineTest which shows collision also:

https://forum.minetest.net/viewtopic.php?t=22164