From 8a024ca29402a4041cdacf7428153a7ee9715677 Mon Sep 17 00:00:00 2001 From: Alex Bustin Date: Sat, 23 May 2020 16:02:48 -0700 Subject: [PATCH] Respect 'mesh compression' editor import option in Assimp (ie. FBX) and glTF importers --- editor/import/editor_scene_importer_gltf.cpp | 6 +++++- editor/import/editor_scene_importer_gltf.h | 3 +++ editor/import/resource_importer_scene.h | 1 - modules/assimp/editor_scene_importer_assimp.cpp | 5 ++++- modules/assimp/import_state.h | 3 +++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index 45bab4fa1dd..f4db2563017 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -951,6 +951,9 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) { if (!state.json.has("meshes")) return OK; + bool compress_vert_data = state.import_flags & IMPORT_USE_COMPRESSION; + uint32_t mesh_flags = compress_vert_data ? Mesh::ARRAY_COMPRESS_DEFAULT : 0; + Array meshes = state.json["meshes"]; for (GLTFMeshIndex i = 0; i < meshes.size(); i++) { @@ -1207,7 +1210,7 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) { } //just add it - mesh.mesh->add_surface_from_arrays(primitive, array, morphs); + mesh.mesh->add_surface_from_arrays(primitive, array, morphs, mesh_flags); if (p.has("material")) { const int material = p["material"]; @@ -2987,6 +2990,7 @@ Node *EditorSceneImporterGLTF::import_scene(const String &p_path, uint32_t p_fla String version = asset["version"]; + state.import_flags = p_flags; state.major_version = version.get_slice(".", 0).to_int(); state.minor_version = version.get_slice(".", 1).to_int(); state.use_named_skin_binds = p_flags & IMPORT_USE_NAMED_SKIN_BINDS; diff --git a/editor/import/editor_scene_importer_gltf.h b/editor/import/editor_scene_importer_gltf.h index 8e9c44db935..1712e3f7951 100644 --- a/editor/import/editor_scene_importer_gltf.h +++ b/editor/import/editor_scene_importer_gltf.h @@ -325,6 +325,9 @@ class EditorSceneImporterGLTF : public EditorSceneImporter { Map scene_nodes; + // EditorSceneImporter::ImportFlags + uint32_t import_flags; + ~GLTFState() { for (int i = 0; i < nodes.size(); i++) { memdelete(nodes[i]); diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h index 20e7af15b5d..c7b9991a48e 100644 --- a/editor/import/resource_importer_scene.h +++ b/editor/import/resource_importer_scene.h @@ -37,7 +37,6 @@ #include "scene/resources/shape.h" class Material; - class EditorSceneImporter : public Reference { GDCLASS(EditorSceneImporter, Reference); diff --git a/modules/assimp/editor_scene_importer_assimp.cpp b/modules/assimp/editor_scene_importer_assimp.cpp index a547dabb608..806922886d4 100644 --- a/modules/assimp/editor_scene_importer_assimp.cpp +++ b/modules/assimp/editor_scene_importer_assimp.cpp @@ -308,6 +308,7 @@ EditorSceneImporterAssimp::_generate_scene(const String &p_path, aiScene *scene, state.assimp_scene = scene; state.max_bone_weights = p_max_bone_weights; state.animation_player = NULL; + state.import_flags = p_flags; // populate light map for (unsigned int l = 0; l < scene->mNumLights; l++) { @@ -848,6 +849,8 @@ EditorSceneImporterAssimp::_generate_mesh_from_surface_indices(ImportState &stat Ref mesh; mesh.instance(); bool has_uvs = false; + bool compress_vert_data = state.import_flags & IMPORT_USE_COMPRESSION; + uint32_t mesh_flags = compress_vert_data ? Mesh::ARRAY_COMPRESS_DEFAULT : 0; Map morph_mesh_string_lookup; @@ -1295,7 +1298,7 @@ EditorSceneImporterAssimp::_generate_mesh_from_surface_indices(ImportState &stat morphs[j] = array_copy; } - mesh->add_surface_from_arrays(primitive, array_mesh, morphs); + mesh->add_surface_from_arrays(primitive, array_mesh, morphs, mesh_flags); mesh->surface_set_material(i, mat); mesh->surface_set_name(i, AssimpUtils::get_assimp_string(ai_mesh->mName)); } diff --git a/modules/assimp/import_state.h b/modules/assimp/import_state.h index 26aad423cd8..f8a0f0abb44 100644 --- a/modules/assimp/import_state.h +++ b/modules/assimp/import_state.h @@ -88,6 +88,9 @@ struct ImportState { // this means we can detect // what bones are for other armatures List bone_stack; + + // EditorSceneImporter::ImportFlags + uint32_t import_flags; }; struct AssimpImageData {