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

[3.x] Added Mesh Compression Import Options #48625

Merged
merged 1 commit into from
Nov 2, 2021

Conversation

The-O-King
Copy link
Contributor

Fleshed out the "Optimize Mesh" options found in the mesh import UI
Gave a checkbox to every vertex attribute that can be compressed

Also surfaces the vertex position compression option which previously
inaccessible because the defaults did not compress vertex positions

Supports all current importers (obj, fbx, collada, gltf)

@fire
Copy link
Member

fire commented May 11, 2021

Are you familiar with the quantize options in mesh optimizer? https://github.com/zeux/meshoptimizer#vertex-quantization

@The-O-King
Copy link
Contributor Author

Are you familiar with the quantize options in mesh optimizer? https://github.com/zeux/meshoptimizer#vertex-quantization

Oh no I had not run into this before! From reading through, this is an external tool for optimizing mesh data correct? Is this integrated into godot already? Some cursory searching led me to see it being used for LOD generation

What this PR does right now is just expose the existing ARRA_COMPRESS_* enums/functionality in the editor - do you think there's a way to pipe meshoptimizer up to these import options for example?

@fire
Copy link
Member

fire commented May 11, 2021

So meshoptimize quantize code is already in Godot Engine but not exposed.

The standard pattern is expose a pointer in surface tool. Add the implementation in mesh optimizer and use the function.

Try it out!

@akien-mga
Copy link
Member

Seems like you need to update the glTF module too:

modules/gltf/editor_scene_importer_gltf.h:65:16: error: 'EditorSceneImporterGLTF::import_scene' hides overloaded virtual function [-Werror,-Woverloaded-virtual]
        virtual Node *import_scene(const String &p_path, uint32_t p_flags,
                      ^
./editor/import/resource_importer_scene.h:68:16: note: hidden overloaded virtual function 'EditorSceneImporter::import_scene' declared here: different number of parameters (6 vs 5)
        virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, uint32_t p_compress_flags, List<String> *r_missing_deps, Error *r_err = nullptr);
                      ^
In file included from modules/gltf/editor_scene_importer_gltf.cpp:38:
In file included from modules/gltf/gltf_state.h:36:
modules/gltf/editor_scene_importer_gltf.h:65:16: error: 'EditorSceneImporterGLTF::import_scene' hides overloaded virtual function [-Werror,-Woverloaded-virtual]
        virtual Node *import_scene(const String &p_path, uint32_t p_flags,
                      ^
./editor/import/resource_importer_scene.h:68:16: note: hidden overloaded virtual function 'EditorSceneImporter::import_scene' declared here: different number of parameters (6 vs 5)
        virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, uint32_t p_compress_flags, List<String> *r_missing_deps, Error *r_err = nullptr);
                      ^

@The-O-King
Copy link
Contributor Author

Oh I was wondering where the gltf importer went when I rebased! Thanks for the heads up I didn't notice it moved, I'm working on updating the PR right now, thanks!

@The-O-King The-O-King force-pushed the compression_options branch from 389e8d0 to 3e65801 Compare July 30, 2021 17:38
@The-O-King
Copy link
Contributor Author

@akien-mga I updated this PR to fix the docs, add the GLTF, and the option to enable/disable octahedral vertex compression

One thing I'm wondering ender user experience wise is whether we should provide the octahedral compression option at all because I'm worried that it might be confusing. The current options matrix looks like:

+-----------------------------------+-----------------+------------------+
|                 -                 | Octahedral True | Octahedral False |
+-----------------------------------+-----------------+------------------+
| Normal/Tangent Compression True:  | oct16           | unorm8x3         |
| Normal/Tangent Compression False: | oct32           | float32x3        |
+-----------------------------------+-----------------+------------------+

Based on the rendering quality though I'm leaning towards removing the option and always having it enabled, as rendering quality wise this is what we are looking at (see godotengine/godot-proposals#2395 (comment) for photo reference/context):

Best Quality (these two are equivalent):
16 bytes - float32x3 + 1 padding
04 bytes - oct32

Ok Quality:
04 bytes - unorm8x3 + 1 padding

Lower Quality (but still acceptable in a majority of cases):
02 bytes - unorm8x2

Since oct32 has the same quality as totally uncompressed float32x3 while at the size of ok quality unorm8x3, that's why I suggest it should always be chosen

What are your thoughts - should we just give the users all the choice or would it be reasonable to make it always on by default?

@lyuma
Copy link
Contributor

lyuma commented Oct 26, 2021

I thought mesh compression already made it in. Is this PR still relevant?

ClassDB::bind_method(D_METHOD("import_gltf_scene", "path", "flags", "bake_fps", "state"),
&PackedSceneGLTF::import_gltf_scene, DEFVAL(0), DEFVAL(1000.0f), DEFVAL(Ref<GLTFState>()));
ClassDB::bind_method(D_METHOD("pack_gltf", "path", "flags", "bake_fps", "compress_flags", "state"),
&PackedSceneGLTF::pack_gltf, DEFVAL(0), DEFVAL(1000.0f), DEFVAL(0), DEFVAL(Ref<GLTFState>()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the default value be Mesh::ARRAY_COMPRESS_DEFAULT here too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

@akien-mga
Copy link
Member

I thought mesh compression already made it in. Is this PR still relevant?

I think it is, though it's a bummer that it got limbo'ed for so long and now we're so close to the 3.4 release. This PR makes it possible to toggle octahedral compression at import time, while currently it's forced on, unless you tweak compression flags manually in an import plugin I suppose.

Given that there are regression cases with octahedral compression enabled, that does seem like something important to include.

Fleshed out the "Optimize Mesh" options found in the mesh import UI
Gave a checkbox to every vertex attribute that can be compressed

Surfaced option to enable/disable Octahedral compression for
normal/tangent vectors

Also surfaces the vertex position compression option which previously
inaccessible because the defaults did not compress vertex positions

Supports all current importers (obj, fbx, collada, gltf)
@akien-mga akien-mga merged commit e499688 into godotengine:3.x Nov 2, 2021
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants