Open acs opened 4 years ago
Related to #102
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 :)
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.
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
This is cute, but not the kind of animation we want now: https://www.youtube.com/watch?v=3Hmhtwq8Fpc
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:
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
A pretty interesting plugin for MineTest which shows collision also:
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: