Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import MagicaVoxel models into Godot #4

Closed
acs opened this issue Sep 9, 2020 · 11 comments
Closed

Import MagicaVoxel models into Godot #4

acs opened this issue Sep 9, 2020 · 11 comments
Labels

Comments

@acs
Copy link
Contributor

acs commented Sep 9, 2020

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
Copy link
Contributor Author

acs commented Sep 10, 2020

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

@acs
Copy link
Contributor Author

acs commented Sep 10, 2020

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
Copy link
Contributor Author

acs commented Sep 10, 2020

Importing the vox file using the plugin have similar results:

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

The material is automatically added.

@acs
Copy link
Contributor Author

acs commented Sep 10, 2020

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
Copy link
Contributor Author

acs commented Sep 10, 2020

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
Copy link
Contributor Author

acs commented Sep 10, 2020

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
Copy link
Contributor Author

acs commented Sep 10, 2020

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

@acs
Copy link
Contributor Author

acs commented Sep 11, 2020

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 acs added the godot label Sep 11, 2020
@acs
Copy link
Contributor Author

acs commented Sep 19, 2020

Ok, following Zylann/godot_voxel#194 the plan is:

  • Load MagicaVoxel models over the terrain following your recommendations
  • Interact with them using the FPS demos as if the models are terrain (firing them to destroy them or to make them "grow")

@acs
Copy link
Contributor Author

acs commented Sep 21, 2020

Ok, let's try to use the code from Zylann/godot_voxel#194 (comment) to load a first model.

The support for loading vox files was added some days ago: Zylann/godot_voxel@e1b9a25

@acs
Copy link
Contributor Author

acs commented Sep 23, 2020

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

@acs acs closed this as completed Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant