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 export to a 3d model and still have the colors ? #124

Open Timotheeee opened 6 years ago

Timotheeee commented 6 years ago

when I export a kv6 to obj there's no colors. is there any way to keep the colors ?

guillaumechereau commented 6 years ago

The obj format doesn't specify a standard way to add color information. What software are you using to open the file? You can maybe try to export as ply instead of obj.

Timotheeee commented 6 years ago

The obj format doesn't specify a standard way to add color information. What software are you using to open the file? You can maybe try to export as ply instead of obj.

I figured it out, I have to export it to .vox and then export it to obj after opening it in magicavoxel. pretty time consuming process though.

Mapachana commented 5 years ago

Would it be possible to export the object (.obj) file with other files (just like MagicaVoxel) or something so you can maintain the colors after exporting the 3d model? Exporting it to MagicaVoxel and then export the obj from there is not an option for me since when I export from Goxel to MagicaVoxel all lights and material properties are lost. Also, when exporting the png from the model from Goxel it doesn't render the lights and emission propperties from the model.

jonbobbly commented 4 years ago

Not sure if this is the right place to comment:

I can't get textures to load in Blender 2.81 Beta with any of Blenders included importers.

guillaumechereau commented 4 years ago

Thanks for letting me know. I just tried with a gltf export and the colors don't show indeed on blender. I am not really familiar with blender, but I'll try to make at least the gltf export work properly, as it seems to be the most useful export format.

guillaumechereau commented 4 years ago

OK, I found a way to show the colors in blender 2.8. In the viewport shading, you have to select color 'vertex', instead of 'material'.

Screenshot from 2019-12-18 14-51-35

shadowmint commented 4 years ago

@guillaumechereau I'm very happy using goxel, but this continue to be a pain point for me.

I export all my goxel models to magikavoxel and export from magikavoxel as a 3d model, because goxel's exports attach the color as vertex data. Since Migikavoxel has limited size imports, this makes the workflow of using goxel quite painful.

Practically speaking, the issue here is that when you export a mesh with vertex data, and apply modifiers to optimize the mesh, it loses the vertex data!

This is because mesh optimisation usually does one of the two following things:

Both of these operations discard vertex data, such as color.

So the workflow is currently:

Model in goxel -> export to magika -> export to 3d mesh -> optimize and edit using a 3d editor.

It's not a matter of being able to view the colors in blender; basically all 3d tooling is designed to preserve texture maps over mesh operations, not vertex operations.

I know this is effort, etc; I just wanted to point out that it may 'make sense' to attach colors to vertexes, but there are actually tangible reasons why this is approach isn't optimal.

guillaumechereau commented 4 years ago

I agree it would be easier to support both: either exporting the color as vertex attribute or as a texture. I will have a look at how to do that.

guillaumechereau commented 4 years ago

I started to work on that. It is still a bit messy, but if you can compile the current code you can try it out. I will add an option so that we can switch between texture or vertex color, for the moment it is fixed to texture.

guillaumechereau commented 4 years ago

@shadowmint: also, could you tell me what kind of treatment you usually do with blender to clean up a voxel mesh? At the moment goxel doesn't do any merging of edges or planes, but I don't really want to add this feature if it's easier to do it directly from blender as post processing.

shadowmint commented 4 years ago

@guillaumechereau I personally use the decimate and remesh operators in blender, then manually correct any messy faces by merging faces. I know other people use meshlab for the same purpose, but I'm not familiar with that workflow.

I can't speak for others, but personally I'm perfectly happy doing this in an external piece of software; several excellent open source tools exist for this (meshlab is literally devoted entirely to cleaning up meshes in this way).

shadowmint commented 4 years ago

@guillaumechereau I built a version of goxel off master, and this is exactly what I'm looking for.

You can see the workflow below that converts the example 5000 face model down into a 450 face one using blender:

guide

NB. I had to apply this patch to get the build to run on my mac, not sure why:

diff --git a/SConstruct b/SConstruct
index 288e5fe..2b25da1 100644
--- a/SConstruct
+++ b/SConstruct
@@ -107,7 +107,7 @@ if target_os == 'msys':
 if target_os == 'darwin':
     sources += glob.glob('src/*.m')
     env.Append(FRAMEWORKS=['OpenGL', 'Cocoa'])
-    env.Append(LIBS=['m', 'glfw3', 'objc'])
+    env.Append(LIBS=['m', 'glfw', 'objc'])

 # Add external libs.
 env.Append(CPPPATH=['ext_src/uthash'])
diff --git a/src/goxel.h b/src/goxel.h
index 3768070..3315e91 100644
--- a/src/goxel.h
+++ b/src/goxel.h
@@ -21,6 +21,8 @@
 #ifndef GOXEL_H
 #define GOXEL_H

+#define GL_SILENCE_DEPRECATION 1
+
 #ifndef _GNU_SOURCE
 #   define _GNU_SOURCE
 #endif
diff --git a/src/utils/gl.h b/src/utils/gl.h
index ca978c2..15b6dd0 100644
--- a/src/utils/gl.h
+++ b/src/utils/gl.h
@@ -21,6 +21,8 @@

 #include <stdbool.h>

+#define GL_SILENCE_DEPRECATION 1
+
 // Set the DEBUG macro if needed.
 #ifndef DEBUG
 #   if !defined(NDEBUG)

Still, thank you very much, this very much helps.

theghostronaut commented 4 years ago

I am also trying to carry over the colors of my model from Goxel to Unity. I built the current Master and see an option to switch to Vertex colors when exporting as gITF only, so I'm assuming the texture variant is only applied to this export? I do need to export an OBJ, as Unity only accepts that. Magica Voxel exports an .mtl file and a png that holds the texture alongside the obj. Is there no way for Goxel to also handle it like this? Thank you for your help!

guillaumechereau commented 4 years ago

@theghostronaut : goxel doesn't have an obj + mtl export at the moment :(. I was hopping that the glTF export could be used all the time instead. I understand that this is not a very good solution. Maybe a proper obj + mtl export should be added. As a workaround could you use an other app (like blender) to convert the gltf to obj + mtl?

theghostronaut commented 4 years ago

@guillaumechereau Thank you for your reply. Yes indeed, I actually just managed to kind of work around it by exporting the gITF with texture from Goxel, importing into Blender and then exporting obj + mtl + texture. However, there will be a lot of back and forth between Unity and Goxel on this particular project as the model is tied to the game mechanics and I will need to make changes quite often. So this probably won't work for me, unfortunately. I actually thought I could export the mtl and texture once from Blender; and then just continue work in Goxel, export an obj from there and apply mtl and texture to that obj. But the texture is off, probably because of alignment issues. Will try to make this route work, as I won't change the colors as I keep making changes, just the geometry. Not sure if this will work!

mikev0321 commented 3 years ago

HI, when I export from goxel to Magica voxel all of my colors are gone. I tried dragging the file into the palette but that did not work. Any advice would be greatly appreciated.