CloneDeath / MagicaVoxel-Importer-with-Extensions

A Godot plugin to import MagicaVoxel .vox files as meshes.
21 stars 6 forks source link

Greedy Mesh Generation #1

Closed qbradq closed 5 years ago

qbradq commented 5 years ago

Implemented Greedy Mesh Generation and made it the new default mesh generator. The culled mesh generator is still available by option. The results have been tested with my personal project, but not with very large meshes.

In my project I have about 2M surface voxels with about 50% facing the camera at any one time. The project was getting 40's FPS on my system. After re-importing everything with greedy mesh generation the FPS is now pegged at 60.

References: https://0fps.net/2012/06/30/meshing-in-a-minecraft-game/ https://www.gedge.ca/dev/2014/08/17/greedy-voxel-meshing

Upstream Issue: https://github.com/scayze/MagicaVoxel-Importer/issues/8

CloneDeath commented 5 years ago

Hey! I love it! I was actually hoping to implement something like this myself, so right off the bat it's going to get approved.

I also like the way that you pulled the logic out of the main script, good work keeping things clean.

I want your opinion though (you don't have to make this change, I'll gladly do it in time): I don't see any reason to keep the basic culling method. I think the greedy approach is best for all cases. Reading the links you provided, it also performs just as fast. I was planning on dropping culling, and only doing greedy. Do you see a problem with only doing greedy? / Was there a reason you kept a flag to support both?

CloneDeath commented 5 years ago

Also, I'm pretty busy with moving apartments and a vacation next week. Let me know if you're on a time crunch, and I can expedite this project for you, and get it updated in the Asset store ASAP.

qbradq commented 5 years ago

The face culling method might be useful when you want to deform the voxel mesh. With greedy meshing you'll loose subdivisions and end up with quads that do not align and stay together as they are deformed.

There's no big rush on this. I've got my git repo linked into my project directory at the moment. Once it's updated on the asset store I'll just switch over.

CloneDeath commented 5 years ago

Alright. It's merged into master.

Also, currently in master, is the implementation for materials in the culled generator. If you want to try merging that in somehow with the greedy generator, then that'd be swell!

Otherwise, I'll do it myself, but it'll take some time. Either way, once materials are implemented for greedy, I'll go ahead and update it to 1.2, and update it in the asset store!

qbradq commented 5 years ago

I plan to continue contributing. I'm not quite sure what you are doing with the materials but I'll try to figure it out. I want to refactor my mesh generator to be more object-oriented instead of using all those data arrays. After than I plan to add a texture generator and U/V wrapper to allow greater freedom of palette without sacrificing render speed. Lastly I want to also support importing all of the models from a single .vox as separate meshes. Those are the features I see myself needing, in addition to advanced materials handling.

I would normally open an issue to discuss this but I can't seem to find the "Issues" tab. I think it's a new feature :)