guillaumechereau / goxel

Goxel: Free and Open Source 3D Voxel Editor
GNU General Public License v3.0
2.79k stars 222 forks source link

How to import gltf files properly to Godot Engine? #173

Open DeybisMelendez opened 4 years ago

DeybisMelendez commented 4 years ago

I am trying to export my model to gltf or obj and use it in my project in godot, but the colors do not appear to me, and I don't know how to get the image to put the albedo.

Spanish: Estoy intentando exportar mi modelo a gltf o obj y usarlo en mi proyecto en godot, pero no me aparecen los colores, y no sé como obtener la imagen para ponerle el albedo.

Captura de pantalla de 2019-10-01 10-04-29

guillaumechereau commented 4 years ago

Thanks for the report. Might be a bug in the glTF export. I will check it out.

guillaumechereau commented 4 years ago

Can you try to open the glTF file in https://gltf-viewer.donmccurdy.com/ ? I just tested and it seems to work. I guess Godot uses some glTF attributes that I don't set in goxel...

DeybisMelendez commented 4 years ago

I do not know the problem, with MagicaVoxel if it works but not very well, it would be great to review the problem, some godot developers would greatly appreciate it since the model is placed in the right place and in MagicaVoxel you have to adjust it when you import a model.

DeybisMelendez commented 4 years ago

When I place the obj file in my project, normally Godot exports the .png of the model and then place it as albedo, this does not happen with the models exported with Goxel.

guillaumechereau commented 4 years ago

I think it's a problem similar to what happens with blender: at the moment, goxel exports the color as vertices attributes, not in a texture. I think it makes more sense for voxel models, but by default blender doesn't show the vertices colors, only the mapped texture. In blender you can change the rendering option to see the vertices color, maybe there is a similar option in Godot?

viniciuscsg commented 4 years ago

I have been around this problem today. It is possible to show vertex color from Goxel models but it is convoluted, and the colors end up looking very wrong: 1- double click to edit the gltf scene generated by Godot when it imports a gltf file. It will warn you that to edit such a scene from Godot a copy must be made. 2- once the scene is opened, you will see that object is sliced into a number of mesh instances, depending on the size of the model. These meshes are like vertical and horizontal slices of the full mesh, apparently 32 voxels appart from each other, and not related to the layers defined in Goxel. 3- to make the vertex color appear, you have to select every mesh and give it a new material (can be one single material for all pieces), enter the material options and enable both the "is srgb" and "vertex color" options in the inspector. However, the displayed colors are completely distorted and look like they are 4-bit (magenta, cyan, white etc) and nothing like the ones shown in Goxel.

Alternatively, you can first import the gltf into blender, and fuse the meshes into one, export as gldf again, so when you import it on Godot you have to assign your custom material to a single mesh to show vertex colors. This improves the colors, as they are not so bizarrely reduced and saturated, but they look very washed-out. This issue looks similar to how textures look in godot when, in a texture node, they are loaded in "data" mode instead of "color" mode and plugged into the albedo of a mesh (color mode is used for albedo maps, and data mode is used for most of other maps such as normalmaps). Since the colors are from vertex instead of from a texture, one cannot change the color mode to solve this issue, and vertex color from meshes imported from other software such as blender don't seem to have this issue in godot.

It seems like a texture based export (like magica voxel does) would be superior for hassle free Goxel to Godot flow, and in that case a obj export might be easier(?). Keypoints for that approach would be preventing the model from being sliced into multiple meshes, generating a small texture looking like a palette, with a single pixel to each color, then uv mapping the vertex which make up a face to the corresponding pixel with that right color in the texture.

I'll edit this post soon to add pictures showing how the vertex colors appear in each case.

guillaumechereau commented 4 years ago

Have you tried to compile the current master version from GitHub? The glTF export now support putting the colors in a texture instead of vertices attributes.

On Sun, Jun 7, 2020 at 2:05 PM Vinik notifications@github.com wrote:

I have been around this problem today. It is possible to show vertex color from Goxel models but it is convoluted, and the colors end up looking very wrong: 1- double click to edit the gltf scene generated by Godot when it imports a gltf file. It will warn you that to edit such a scene from Godot a copy must be made. 2- once the scene is opened, you will see that object is sliced into a number of mesh instances, typically 12 in my experience. These meshes are like vertical and horizontal slices of the full mesh, apparently 32 voxels appart from each other, and not related to the layers defined in Goxel. 3- to make the vertex color appear, you have to select every mesh and give it a new material (can be one single material for all pieces), enter the material options and enable both the "is srgb" and "vertex color" options in the inspector. However, the displayed colors are completely distorted and look like they are 4-bit (magenta, cyan, white etc) and nothing like the ones shown in Goxel.

Alternatively, you can first import the gltf into blender, and fuse the meshes into one, export as gldf again, so when you import it on Godot you have to assign your custom material to a single mesh to show vertex colors. This improves the colors, as they are not so bizarrely reduced and saturated, but they look very washed-out. This issue looks similar to how textures look in godot when, in a texture node, they are loaded in "data" mode instead of "color" mode and plugged into the albedo of a mesh (color mode is used for albedo maps, and data mode is used for most of other maps such as normalmaps). Since the colors are from vertex instead of from a texture, one cannot change the color mode to solve this issue, and vertex color from meshes imported from other software such as blender don't seem to have this issue in godot.

It seems like a texture based export (like magica voxel does) would be superior for hassle free Goxel to Godot flow, and in that case a obj export might be easier(?). Keypoints for that approach would be preventing the model from being sliced into multiple meshes, generating a small texture looking like a palette, with a single pixel to each color, then uv mapping the vertex which make up a face to the corresponding pixel with that right color in the texture.

I'll edit this post soon to add pictures showing how the vertex colors appear in each case.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/guillaumechereau/goxel/issues/173#issuecomment-640162834, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2JHYTDX2GSSY7HRRIHP3RVMUYZANCNFSM4I4LVCXQ .

-- Sent from my iPad.

viniciuscsg commented 4 years ago

Hello Mr, Guillaume,

Thank you for the quick response, as mentioned I am having trouble compiling the current master, and would be very thankful if you could provide a new release. Thanks again.

guillaumechereau commented 4 years ago

Hi @viniciuscsg

You need to run the 'make release' command from within the goxel directory, maybe that is the issue?

I can also make a new release later today, so that you don't have to build anything.

viniciuscsg commented 4 years ago

Thank you a new release would be awesome! I'll clean up compiling related comments on this issue.

guillaumechereau commented 4 years ago

I just made a new minor release: https://goxel.xyz/download/ If you use the export menu from the tabs, you should see an option to put the colors either as vertice attributes or as texture. The default uses texture, in a way that should make it easier to import into other applications.

Let me know if that works.

image

viniciuscsg commented 4 years ago

Thank you very much for your attention and care :)

Em ter., 9 de jun. de 2020 às 03:55, Guillaume Chereau < notifications@github.com> escreveu:

I just made a new minor release: https://goxel.xyz/download/ If you use the export menu from the tabs, you should see an option to put the colors either as vertice attributes or as texture. The default uses texture, in a way that should make it easier to import into other applications.

Let me know if that works.

[image: image] https://user-images.githubusercontent.com/107679/84115727-1dfeaa00-aa61-11ea-830e-4f515223262f.png

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/guillaumechereau/goxel/issues/173#issuecomment-641073210, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJA2O6G3TZJP2JIYZPLOHTRVXMGVANCNFSM4I4LVCXQ .

DeybisMelendez commented 4 years ago

I'm very sorry but I still have the same problem, it turned on the vertex color and still can't see the texture in Godot. I am currently using Godot 3.2, can you write step by step instructions?

guillaumechereau commented 4 years ago

Have you tried with voxel color turned off ?

On Thu, Jun 11, 2020 at 9:20 AM Deybis Melendez notifications@github.com wrote:

I'm very sorry but I still have the same problem, it turned on the vertex color and still can't see the texture in Godot. I am currently using Godot 3.2, can you write step by step instructions?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/guillaumechereau/goxel/issues/173#issuecomment-642348917, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2JHYT7HLNIZRJMZ57D6DRWAWMJANCNFSM4I4LVCXQ .

-- Sent from my iPad.

PanTrakX commented 3 years ago

Hello @guillaumechereau

The problem still persists. Enabling vertex color on export and enabling to use vertex color as albedo on godot doesn't work. glTF Viewer can see the model fine.

Maybe i should open an issue on godot about that or is it a goxel issue?

guillaumechereau commented 3 years ago

I just tried it with Godot and indeed it doesn't seem to work! I'll have a look. There seems to be a bug in the exported glTF.

guillaumechereau commented 3 years ago

OK I think the problem is that Godot doesn't support embedded images in glTF files. For example this glTF also doesn't seem to have colors. https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/BoxTextured/glTF-Embedded/BoxTextured.gltf

I think the solution would be to add proper support for glb files in goxel.

guillaumechereau commented 3 years ago

I started a branch to work on using cgltf library to export (instead of my hand written code). When this is merged we should be able to save in glb, hopefully directly usable by godot.

guillaumechereau commented 3 years ago

Turns out cgltf doesn't support writing in glb format... However I realized that by changing the way I store texture data in the gltf file I can make Godot open them properly. Seems that it was a bug in godot that will be fixed in the next release.

@PanTrakX if you have the time could you check the current master version of goxel and see if the new glTF export code works better for you?

PanTrakX commented 3 years ago

Hello @guillaumechereau !

Yes, i can confirm that the export works properly now! image

ghost commented 2 years ago

Hello! I always have a problem I try to import into Godot a gltf model, but the transparency is not displayed.

v0x9a7a commented 2 years ago

Hello! Using Godot 3.4.4 (419e713a2) on Win 11 and trying to import gltf files which were exported from VoxEdit. There are 3 gltf files, all created from the same asset template. All import into Blender without any problems. All open in the online gltf viewer fine. When imported into Godot, the first in the series imports without issue. The second one degenerates usually with random blotches on texture. Third one degenerates even further. Anything I might be doing incorrectly? Thank you!

PanTrakX commented 2 years ago

@v0x9a7a

trying to import gltf files which were exported from VoxEdit

Goxel and VoxEdit are different tools. This github repository is for Goxel.