diff options
author | clayjohn <claynjohn@gmail.com> | 2023-08-29 21:04:32 +0200 |
---|---|---|
committer | clayjohn <claynjohn@gmail.com> | 2023-10-05 12:02:23 -0600 |
commit | 51ed3aef63c0fdfc7666c004cc6d94dd15322d81 (patch) | |
tree | de596e05a1319438fb08024f23be417d29446494 /editor/import/editor_import_collada.cpp | |
parent | d31794c4a26e5e10fc30c34a1ae9722fd9f50123 (diff) | |
download | redot-engine-51ed3aef63c0fdfc7666c004cc6d94dd15322d81.tar.gz |
Vertex and attribute compression to reduce the size of the vertex format.
This allows Godot to automatically compress meshes to save a lot of bandwidth.
In general, this requires no interaction from the user and should result in
no noticable quality loss.
This scheme is not backwards compatible, so we have provided an upgrade
mechanism, and a mesh versioning mechanism.
Existing meshes can still be used as a result, but users can get a
performance boost by reimporting assets.
Diffstat (limited to 'editor/import/editor_import_collada.cpp')
-rw-r--r-- | editor/import/editor_import_collada.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 1e410b7272..de9daddd38 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -919,6 +919,12 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p } } + uint64_t mesh_flags = 0; + + if (p_use_compression) { + mesh_flags = RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES; + } + Ref<SurfaceTool> surftool; surftool.instantiate(); surftool->begin(Mesh::PRIMITIVE_TRIANGLES); @@ -969,14 +975,21 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p } if (!normal_src) { - //should always be normals + // Should always have normals. surftool->generate_normals(); } - if ((!binormal_src || !tangent_src) && normal_src && uv_src && force_make_tangents) { + bool generate_tangents = (!binormal_src || !tangent_src) && uv_src && force_make_tangents; + + if (generate_tangents) { surftool->generate_tangents(); } + if (!binormal_src || !(tangent_src || generate_tangents) || p_mesh->get_blend_shape_count() != 0 || p_skin_controller) { + // Can't compress if attributes missing or if using vertex weights. + mesh_flags &= ~RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES; + } + //////////////////////////// // FINALLY CREATE SUFRACE // //////////////////////////// @@ -996,7 +1009,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p // Enforce blend shape mask array format for (int mj = 0; mj < Mesh::ARRAY_MAX; mj++) { - if (!(Mesh::ARRAY_FORMAT_BLEND_SHAPE_MASK & (1 << mj))) { + if (!(Mesh::ARRAY_FORMAT_BLEND_SHAPE_MASK & (1ULL << mj))) { a[mj] = Variant(); } } @@ -1011,7 +1024,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p } surface_name = material->get_name(); } - p_mesh->add_surface(Mesh::PRIMITIVE_TRIANGLES, d, mr, Dictionary(), mat, surface_name); + p_mesh->add_surface(Mesh::PRIMITIVE_TRIANGLES, d, mr, Dictionary(), mat, surface_name, mesh_flags); } /*****************/ @@ -1773,7 +1786,7 @@ Node *EditorSceneFormatImporterCollada::import_scene(const String &p_path, uint3 state.use_mesh_builtin_materials = true; state.bake_fps = (float)p_options["animation/fps"]; - Error err = state.load(p_path, flags, p_flags & EditorSceneFormatImporter::IMPORT_GENERATE_TANGENT_ARRAYS, false); + Error err = state.load(p_path, flags, p_flags & EditorSceneFormatImporter::IMPORT_GENERATE_TANGENT_ARRAYS, !bool(p_flags & EditorSceneFormatImporter::IMPORT_FORCE_DISABLE_MESH_COMPRESSION)); if (r_err) { *r_err = err; |