diff options
Diffstat (limited to 'modules/gltf/gltf_document.cpp')
-rw-r--r-- | modules/gltf/gltf_document.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index bac988630d..595b14f260 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -66,8 +66,10 @@ #endif // MODULE_GRIDMAP_ENABLED // FIXME: Hardcoded to avoid editor dependency. +#define GLTF_IMPORT_GENERATE_TANGENT_ARRAYS 8 #define GLTF_IMPORT_USE_NAMED_SKIN_BINDS 16 #define GLTF_IMPORT_DISCARD_MESHES_AND_MATERIALS 32 +#define GLTF_IMPORT_FORCE_DISABLE_MESH_COMPRESSION 64 #include <stdio.h> #include <stdlib.h> @@ -2208,7 +2210,7 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> p_state) { } Array array = import_mesh->get_surface_arrays(surface_i); - uint32_t format = import_mesh->get_surface_format(surface_i); + uint64_t format = import_mesh->get_surface_format(surface_i); int32_t vertex_num = 0; Dictionary attributes; { @@ -2568,7 +2570,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> p_state) { import_mesh->set_name(_gen_unique_name(p_state, vformat("%s_%s", p_state->scene_name, mesh_name))); for (int j = 0; j < primitives.size(); j++) { - uint32_t flags = 0; + uint64_t flags = RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES; Dictionary p = primitives[j]; Array array; @@ -2795,7 +2797,11 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> p_state) { array[Mesh::ARRAY_INDEX] = indices; } - bool generate_tangents = (primitive == Mesh::PRIMITIVE_TRIANGLES && !a.has("TANGENT") && a.has("TEXCOORD_0") && a.has("NORMAL")); + bool generate_tangents = p_state->force_generate_tangents && (primitive == Mesh::PRIMITIVE_TRIANGLES && !a.has("TANGENT") && a.has("TEXCOORD_0") && a.has("NORMAL")); + + if (p_state->force_disable_compression || !a.has("POSITION") || !a.has("NORMAL") || !(a.has("TANGENT") || generate_tangents) || p.has("targets") || (a.has("JOINTS_0") || a.has("JOINTS_1"))) { + flags &= ~RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES; + } Ref<SurfaceTool> mesh_surface_tool; mesh_surface_tool.instantiate(); @@ -2935,7 +2941,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> p_state) { // Enforce blend shape mask array format for (int l = 0; l < Mesh::ARRAY_MAX; l++) { - if (!(Mesh::ARRAY_FORMAT_BLEND_SHAPE_MASK & (1 << l))) { + if (!(Mesh::ARRAY_FORMAT_BLEND_SHAPE_MASK & (1ULL << l))) { array_copy[l] = Variant(); } } @@ -7415,6 +7421,8 @@ Error GLTFDocument::append_from_scene(Node *p_node, Ref<GLTFState> p_state, uint ERR_FAIL_COND_V(p_state.is_null(), FAILED); p_state->use_named_skin_binds = p_flags & GLTF_IMPORT_USE_NAMED_SKIN_BINDS; p_state->discard_meshes_and_materials = p_flags & GLTF_IMPORT_DISCARD_MESHES_AND_MATERIALS; + p_state->force_generate_tangents = p_flags & GLTF_IMPORT_GENERATE_TANGENT_ARRAYS; + p_state->force_disable_compression = p_flags & GLTF_IMPORT_FORCE_DISABLE_MESH_COMPRESSION; if (!p_state->buffers.size()) { p_state->buffers.push_back(Vector<uint8_t>()); } @@ -7452,6 +7460,8 @@ Error GLTFDocument::append_from_buffer(PackedByteArray p_bytes, String p_base_pa Error err = FAILED; p_state->use_named_skin_binds = p_flags & GLTF_IMPORT_USE_NAMED_SKIN_BINDS; p_state->discard_meshes_and_materials = p_flags & GLTF_IMPORT_DISCARD_MESHES_AND_MATERIALS; + p_state->force_generate_tangents = p_flags & GLTF_IMPORT_GENERATE_TANGENT_ARRAYS; + p_state->force_disable_compression = p_flags & GLTF_IMPORT_FORCE_DISABLE_MESH_COMPRESSION; Ref<FileAccessMemory> file_access; file_access.instantiate(); @@ -7575,6 +7585,9 @@ Error GLTFDocument::append_from_file(String p_path, Ref<GLTFState> p_state, uint p_state->filename = p_path.get_file().get_basename(); p_state->use_named_skin_binds = p_flags & GLTF_IMPORT_USE_NAMED_SKIN_BINDS; p_state->discard_meshes_and_materials = p_flags & GLTF_IMPORT_DISCARD_MESHES_AND_MATERIALS; + p_state->force_generate_tangents = p_flags & GLTF_IMPORT_GENERATE_TANGENT_ARRAYS; + p_state->force_disable_compression = p_flags & GLTF_IMPORT_FORCE_DISABLE_MESH_COMPRESSION; + Error err; Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::READ, &err); ERR_FAIL_COND_V(err != OK, ERR_FILE_CANT_OPEN); |