guillaumechereau / goxel

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

Triangle count is super high #315

Closed jerobarraco closed 1 month ago

jerobarraco commented 1 year ago

When importing a simple object to unreal i noticed that the triangle count is very very high. even for simple objects. it seems to me that there is no optimization being done when exporting.

guillaumechereau commented 1 year ago

Yes this is an issue at the moment. It would be nice to integrate a mesh optimization step in the export code, maybe there are open source libraries doing that?

jerobarraco commented 1 year ago

i hope there are. i would bet there might be. specially since your code seem to be C. I think vengi/voxedit did something similar.

on a similar note. not sure if i should open a new ticket: some of the triangles overlap with each other and result in some kind of Z fighting. this is a problem when using Nanite on unreal. the light renders with problems. also has issues due to overrendering (forgot the word).

jerobarraco commented 1 year ago

i found this one has c and cpp interfaces. https://meshoptimizer.org/

jerobarraco commented 1 year ago

i tried the utility called gtlfpack unfortunately it does some weird stuff to the gltf (like putting part of it in a bin file). and unreal does not recognizes the format. i tried using gltf glb and all the flags individually and together.

i would really like to ask if you do implement some optimization to have it as a export flag so i can turn it off/on depending on the asset to avoid issues like this and others.

guillaumechereau commented 1 year ago

The glTF export definitively needs more work. I already changed the code a bit to at least use a single mesh per layer, but for the moment this is still using several primitive per mesh.

Meshoptimizer looks interesting yes.

Can you open a new issue specifically about the overlap you see? If possible with a screenshot because I am not sure what the issue is.

jerobarraco commented 1 year ago

thanks a lot. meshoptimizer seems promising, maybe using it as a library would be more flexible (and also a bit more work). unreal does not imports it as is. i needed to use the flag -noq otherwise it fails to import. https://github.com/zeux/meshoptimizer/issues/584

if you ever implement this please make it optional or add a way to set the flags to ensure compatibility. it could make the tool unusable for me if i can't import.

it reduced the number of vertices but not the number of triangles

org image

packed image

though something better should be out there.. unreal auto lod seems to get it around 500 each. but it's really annoying to set it up every time i import a mesh (which includes when i'm modifying it) image

jerobarraco commented 1 year ago

on another news the overlapping vertices seems to be an issue with ue auto lod :/ ( i will open a new issue if i do find is something related with goxel)

lod 0 image

lod3 (the one i use as the default) image

guillaumechereau commented 1 year ago

I just pushed a first change that uses meshoptimizer to cleanup the mesh a little before export. For the moment this is not doing any advanced simplification, but should already result in better topology. Not sure if that would improve the import in UE though.

guillaumechereau commented 1 year ago

Also added an new option to simplify the mesh. With simplification Goxel will attempt to remove as many vertices as possible before exporting. All of this is still quite experimental.

jerobarraco commented 1 year ago

awesome! I will try them both whenever i get the chance :) Thanks a lot!

jerobarraco commented 1 year ago

As i feared the "simplify" option messes with the colors. this is with the simplify option image image

this is without it but with build 68 notice that the vertex and triangle count is exactly the same image image

both of the above uses texture mode since vertex colors still crashes ue.

this is build 51 without the material set just for vertex count comparison image

also i just noticed that v68 when importing the file the meshes have the appropriate name of the layer. (as opposed to build 51 which have weird names "node-something"(

guillaumechereau commented 11 months ago

Sorry for the late reply. Do you have the gox image? I am looking at this again but I cannot reproduce the issue currently.

jerobarraco commented 11 months ago

i think is this one. sorry the delay. Char18-Head.g.zip

guillaumechereau commented 11 months ago

OK I made some changes to try to fix this bug. Seems to work on your model, when I open it with blender. I also change the "simplify" from a checkbox to a float input from 0 to 1, so that we can control the algo a bit.

image

jerobarraco commented 10 months ago

if this is in i will test it right away! thanks! though in that image: the left head. bottom right of the right eye has a quirk.

guillaumechereau commented 10 months ago

Ah that's right, I didn't see that... I'll check a bit more.

jerobarraco commented 10 months ago

btw, the triangle count has definitely improved with the new simplification. thanks a lot!

guillaumechereau commented 10 months ago

Thanks. I was unable to reproduce the quirk in the eye. I wonder if my screenshot was maybe using the wrong export. Do you still see the issue?

jerobarraco commented 10 months ago

i haven't seen this lately. if i come across it i'll open a new thread to not clog this ticket which seems to be a different issue. i did had trouble with some meshes butchering the colors (as if the triangles were simplified too much), but i'll report back if i find it happening on the latest build.

jerobarraco commented 1 month ago

Screenshot_20241019_174751 Screenshot_20241019_174845

this seems to be working pretty well on 1.51 thanks a lot! i feel really uncomfortable closing the issue. but i assume that's what you'd prefer.