Voxelers / 3d

3D in Voxelers
Apache License 2.0
9 stars 1 forks source link

Import MagicaVoxel models into Godot #4

Closed acs closed 4 years ago

acs commented 4 years ago

In order to complete #1 let's import the voxels models from MagicaVoxel!

There are already some support for importing vox files. Let's follow https://threepointfivecats.be/cat/games/b/blog20190317.php for the first test.

It seems the vox model is imported like an ArrayMesh. Let's try! The plugin in the assets library seems to be this one: https://github.com/scayze/MagicaVoxel-Importer

There is an evolution from this project at https://github.com/JohnCWakley/vox-importer and there is a fork from this one in https://github.com/CloneDeath/MagicaVoxel-Importer-with-Extensions so not sure what I will find in the assets library.

Screenshot from 2020-09-10 06-32-12

It is great to read the plugin code to learn howto extend the Godot Editor from GDScript: https://github.com/scayze/MagicaVoxel-Importer/blob/master/addons/MagicaVoxelImporter/plugin.gd

From a quick review, the importing code for vox files seems to be pretty limited so probably not all the details are imported. Let's try it. After reading then above article, we are going to have issues for sure in this workflow. But it is going to be interesting.

Our goal is to import the vox model as voxels (cubes by default) so when we hit the model, it can breakdown from this voxels. Let's see if it is possible.

acs commented 4 years ago

Reading this comment https://github.com/CloneDeath/MagicaVoxel-Importer-with-Extensions/issues/9 it seems that it is better to export vox file to OBJ in MagicaVoxel so the model is built from independent meshes.

acs commented 4 years ago

Importing as a OBJ it seems to be just one model integrated, not with different parts.

Screenshot from 2020-09-10 06-57-30

acs commented 4 years ago

Importing the vox file using the plugin have similar results:

Screenshot from 2020-09-10 07-03-27

The material is automatically added.

acs commented 4 years ago

When you import it is as a Blender exported DAE file, it includes the full scene from Blender, including the camera.

Screenshot from 2020-09-10 07-19-15

In any case, this does not help in our goal to have three different cubes inside Godot.

acs commented 4 years ago

In order to manage meshes as groups we have the https://docs.godotengine.org/en/stable/classes/class_meshlibrary.html#description It is used in gridmaps, and in some way, a voxeled structure is a grid of cubes, a grid of meshes.

Also for modifying a mesh we have the https://docs.godotengine.org/en/stable/classes/class_meshdatatool.html

Probably this two modules can help building models from voxels, which are cubes (or other form for the voxel) that are meshes.

acs commented 4 years ago

Interesting project: https://github.com/antopilo/VoxelFactory It can import voxel files. This is exactly the direction we want to follow. But it is using C#, so we need Godot Engine with this support. But probably it deserves the time needed to play with Godot C#. https://www.reddit.com/r/godot/comments/bzxkr9/voxelfactory_new_voxel_plugin_for_godot_engine/ It seems it can be used directly with GDScript.

But the bet is to use https://github.com/Zylann/godot_voxel and try to extend it not only to terrain but to other objects.

acs commented 4 years ago

An interesting project http://www.rpginabox.com/ pointed out in https://godotengine.org/qa/20788/how-to-generate-voxels

acs commented 4 years ago

VoxelFactory

The C# version is the same than the GDScript version. So we can play with the Godot C++ using GDScript. Great!

I have tested the image loading with voxels:

Screenshot from 2020-09-11 08-44-01

Screenshot from 2020-09-11 08-44-17

Screenshot from 2020-09-11 08-45-19

The problem with then GDScript version is the performance. But we will reach this issue in the future. The current API is:

Screenshot from 2020-09-11 08-52-28

and the workflow is to add voxels and once you have finished, call create_mesh.

It is a pretty basic library, supporting a basic voxel editor in godot. A good inspiration but limited.

Our goal is to have each voxel as an independent mesh with its own physics.

acs commented 4 years ago

Ok, following https://github.com/Zylann/godot_voxel/issues/194 the plan is:

acs commented 4 years ago

Ok, let's try to use the code from https://github.com/Zylann/godot_voxel/issues/194#issuecomment-693708970 to load a first model.

The support for loading vox files was added some days ago: https://github.com/Zylann/godot_voxel/commit/e1b9a25db76c2595469c621da2ab834f74e8d194

acs commented 4 years ago

Ok, the import of magica voxel files is working with the godot_voxel support. This ticket can be closed.