diff options
Diffstat (limited to 'modules/assimp')
-rw-r--r-- | modules/assimp/editor_scene_importer_assimp.cpp | 40 | ||||
-rw-r--r-- | modules/assimp/import_state.h | 4 | ||||
-rw-r--r-- | modules/assimp/import_utils.h | 44 | ||||
-rw-r--r-- | modules/assimp/register_types.cpp | 1 |
4 files changed, 40 insertions, 49 deletions
diff --git a/modules/assimp/editor_scene_importer_assimp.cpp b/modules/assimp/editor_scene_importer_assimp.cpp index cc74674eff..aedc4b690a 100644 --- a/modules/assimp/editor_scene_importer_assimp.cpp +++ b/modules/assimp/editor_scene_importer_assimp.cpp @@ -44,7 +44,6 @@ #include <assimp/scene.h> #include <assimp/Importer.hpp> #include <assimp/LogStream.hpp> -#include <string> // move into assimp aiBone *get_bone_by_name(const aiScene *scene, aiString bone_name) { @@ -53,7 +52,6 @@ aiBone *get_bone_by_name(const aiScene *scene, aiString bone_name) { // iterate over all the bones on the mesh for this node only! for (unsigned int boneIndex = 0; boneIndex < mesh->mNumBones; boneIndex++) { - aiBone *bone = mesh->mBones[boneIndex]; if (bone->mName == bone_name) { printf("matched bone by name: %s\n", bone->mName.C_Str()); @@ -66,7 +64,6 @@ aiBone *get_bone_by_name(const aiScene *scene, aiString bone_name) { } void EditorSceneImporterAssimp::get_extensions(List<String> *r_extensions) const { - const String import_setting_string = "filesystem/import/open_asset_import/"; Map<String, ImportFormat> import_format; @@ -104,8 +101,6 @@ void EditorSceneImporterAssimp::_bind_methods() { Node *EditorSceneImporterAssimp::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) { Assimp::Importer importer; - std::wstring w_path = ProjectSettings::get_singleton()->globalize_path(p_path).c_str(); - std::string s_path(w_path.begin(), w_path.end()); importer.SetPropertyBool(AI_CONFIG_PP_FD_REMOVE, true); // Cannot remove pivot points because the static mesh will be in the wrong place importer.SetPropertyBool(AI_CONFIG_IMPORT_FBX_PRESERVE_PIVOTS, false); @@ -147,7 +142,8 @@ Node *EditorSceneImporterAssimp::import_scene(const String &p_path, uint32_t p_f // aiProcess_EmbedTextures | //aiProcess_SplitByBoneCount | 0; - aiScene *scene = (aiScene *)importer.ReadFile(s_path.c_str(), post_process_Steps); + String g_path = ProjectSettings::get_singleton()->globalize_path(p_path); + aiScene *scene = (aiScene *)importer.ReadFile(g_path.utf8().ptr(), post_process_Steps); ERR_FAIL_COND_V_MSG(scene == nullptr, nullptr, String("Open Asset Import failed to open: ") + String(importer.GetErrorString())); @@ -156,14 +152,11 @@ Node *EditorSceneImporterAssimp::import_scene(const String &p_path, uint32_t p_f template <class T> struct EditorSceneImporterAssetImportInterpolate { - T lerp(const T &a, const T &b, float c) const { - return a + (b - a) * c; } T catmull_rom(const T &p0, const T &p1, const T &p2, const T &p3, float t) { - float t2 = t * t; float t3 = t2 * t; @@ -185,7 +178,6 @@ struct EditorSceneImporterAssetImportInterpolate { //thank you for existing, partial specialization template <> struct EditorSceneImporterAssetImportInterpolate<Quat> { - Quat lerp(const Quat &a, const Quat &b, float c) const { ERR_FAIL_COND_V_MSG(!a.is_normalized(), Quat(), "The quaternion \"a\" must be normalized."); ERR_FAIL_COND_V_MSG(!b.is_normalized(), Quat(), "The quaternion \"b\" must be normalized."); @@ -214,8 +206,9 @@ T EditorSceneImporterAssimp::_interpolate_track(const Vector<float> &p_times, co //could use binary search, worth it? int idx = -1; for (int i = 0; i < p_times.size(); i++) { - if (p_times[i] > p_time) + if (p_times[i] > p_time) { break; + } idx++; } @@ -223,7 +216,6 @@ T EditorSceneImporterAssimp::_interpolate_track(const Vector<float> &p_times, co switch (p_interp) { case AssetImportAnimation::INTERP_LINEAR: { - if (idx == -1) { return p_values[0]; } else if (idx >= p_times.size() - 1) { @@ -236,7 +228,6 @@ T EditorSceneImporterAssimp::_interpolate_track(const Vector<float> &p_times, co } break; case AssetImportAnimation::INTERP_STEP: { - if (idx == -1) { return p_values[0]; } else if (idx >= p_times.size() - 1) { @@ -247,7 +238,6 @@ T EditorSceneImporterAssimp::_interpolate_track(const Vector<float> &p_times, co } break; case AssetImportAnimation::INTERP_CATMULLROMSPLINE: { - if (idx == -1) { return p_values[1]; } else if (idx >= p_times.size() - 1) { @@ -260,7 +250,6 @@ T EditorSceneImporterAssimp::_interpolate_track(const Vector<float> &p_times, co } break; case AssetImportAnimation::INTERP_CUBIC_SPLINE: { - if (idx == -1) { return p_values[1]; } else if (idx >= p_times.size() - 1) { @@ -307,10 +296,10 @@ EditorSceneImporterAssimp::_generate_scene(const String &p_path, aiScene *scene, state.assimp_scene = scene; state.max_bone_weights = p_max_bone_weights; state.animation_player = nullptr; + state.import_flags = p_flags; // populate light map for (unsigned int l = 0; l < scene->mNumLights; l++) { - aiLight *ai_light = scene->mLights[l]; ERR_CONTINUE(ai_light == nullptr); state.light_cache[AssimpUtils::get_assimp_string(ai_light->mName)] = l; @@ -490,7 +479,6 @@ EditorSceneImporterAssimp::_generate_scene(const String &p_path, aiScene *scene, if (assimp_node->mNumMeshes > 0) { MeshInstance3D *mesh = create_mesh(state, assimp_node, node_name, parent_node, node_transform); if (mesh) { - parent_node->remove_child(mesh_template); // re-parent children @@ -530,7 +518,6 @@ EditorSceneImporterAssimp::_generate_scene(const String &p_path, aiScene *scene, } if (p_flags & IMPORT_ANIMATION && scene->mNumAnimations) { - state.animation_player = memnew(AnimationPlayer); state.root->add_child(state.animation_player); state.animation_player->set_owner(state.root); @@ -621,7 +608,6 @@ void EditorSceneImporterAssimp::_insert_animation_track(ImportState &scene, cons int skeleton_bone = skeleton->find_bone(node_name); if (skeleton_bone >= 0 && track_bone) { - Transform xform; xform.basis.set_quat_scale(rot, scale); xform.origin = pos; @@ -666,7 +652,6 @@ Node *EditorSceneImporterAssimp::get_node_by_name(ImportState &state, String nam /* Bone stack is a fifo handler for multiple armatures since armatures aren't a thing in assimp (yet) */ void EditorSceneImporterAssimp::RegenerateBoneStack(ImportState &state) { - state.bone_stack.clear(); // build bone stack list for (unsigned int mesh_id = 0; mesh_id < state.assimp_scene->mNumMeshes; ++mesh_id) { @@ -700,7 +685,6 @@ void EditorSceneImporterAssimp::RegenerateBoneStack(ImportState &state, aiMesh * // animation tracks are per bone void EditorSceneImporterAssimp::_import_animation(ImportState &state, int p_animation_index, int p_bake_fps) { - ERR_FAIL_INDEX(p_animation_index, (int)state.assimp_scene->mNumAnimations); const aiAnimation *anim = state.assimp_scene->mAnimations[p_animation_index]; @@ -795,7 +779,6 @@ void EditorSceneImporterAssimp::_import_animation(ImportState &state, int p_anim //blend shape tracks for (size_t i = 0; i < anim->mNumMorphMeshChannels; i++) { - const aiMeshMorphAnim *anim_mesh = anim->mMorphMeshChannels[i]; const String prop_name = AssimpUtils::get_assimp_string(anim_mesh->mName); @@ -816,14 +799,12 @@ void EditorSceneImporterAssimp::_import_animation(ImportState &state, int p_anim //add the tracks for this mesh int base_track = animation->get_track_count(); for (int j = 0; j < mesh->get_blend_shape_count(); j++) { - animation->add_track(Animation::TYPE_VALUE); animation->track_set_path(base_track + j, base_path + ":blend_shapes/" + mesh->get_blend_shape_name(j)); } for (size_t k = 0; k < anim_mesh->mNumKeys; k++) { for (size_t j = 0; j < anim_mesh->mKeys[k].mNumValuesAndWeights; j++) { - float t = anim_mesh->mKeys[k].mTime / ticks_per_second; float w = anim_mesh->mKeys[k].mWeights[j]; @@ -836,6 +817,7 @@ void EditorSceneImporterAssimp::_import_animation(ImportState &state, int p_anim state.animation_player->add_animation(name, animation); } } + // // Mesh Generation from indices ? why do we need so much mesh code // [debt needs looked into] @@ -843,10 +825,11 @@ Ref<Mesh> EditorSceneImporterAssimp::_generate_mesh_from_surface_indices(ImportState &state, const Vector<int> &p_surface_indices, const aiNode *assimp_node, Ref<Skin> &skin, Skeleton3D *&skeleton_assigned) { - Ref<ArrayMesh> 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<String, uint32_t> morph_mesh_string_lookup; @@ -894,7 +877,6 @@ EditorSceneImporterAssimp::_generate_mesh_from_surface_indices(ImportState &stat int bone_index = skeleton_assigned->find_bone(bone_name); ERR_CONTINUE(bone_index == -1); for (size_t w = 0; w < bone->mNumWeights; w++) { - aiVertexWeight ai_weights = bone->mWeights[w]; BoneInfo bi; @@ -920,7 +902,6 @@ EditorSceneImporterAssimp::_generate_mesh_from_surface_indices(ImportState &stat st->begin(Mesh::PRIMITIVE_TRIANGLES); for (size_t j = 0; j < ai_mesh->mNumVertices; j++) { - // Get the texture coordinates if they exist if (ai_mesh->HasTextureCoords(0)) { has_uvs = true; @@ -956,7 +937,6 @@ EditorSceneImporterAssimp::_generate_mesh_from_surface_indices(ImportState &stat // We have vertex weights right? if (vertex_weights.has(j)) { - Vector<BoneInfo> bone_info = vertex_weights[j]; Vector<int> bones; bones.resize(bone_info.size()); @@ -1200,7 +1180,6 @@ EditorSceneImporterAssimp::_generate_mesh_from_surface_indices(ImportState &stat Mesh::PrimitiveType primitive = Mesh::PRIMITIVE_TRIANGLES; for (size_t j = 0; j < ai_mesh->mNumAnimMeshes; j++) { - String ai_anim_mesh_name = AssimpUtils::get_assimp_string(ai_mesh->mAnimMeshes[j]->mName); if (ai_anim_mesh_name.empty()) { @@ -1288,7 +1267,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, Dictionary(), mesh_flags); mesh->surface_set_material(i, mat); mesh->surface_set_name(i, AssimpUtils::get_assimp_string(ai_mesh->mName)); } @@ -1482,7 +1461,6 @@ Node3D *EditorSceneImporterAssimp::create_camera( void EditorSceneImporterAssimp::_generate_node( ImportState &state, const aiNode *assimp_node) { - ERR_FAIL_COND(assimp_node == nullptr); state.nodes.push_back(assimp_node); String parent_name = AssimpUtils::get_assimp_string(assimp_node->mParent->mName); diff --git a/modules/assimp/import_state.h b/modules/assimp/import_state.h index cda1a854f0..ee22800ac4 100644 --- a/modules/assimp/import_state.h +++ b/modules/assimp/import_state.h @@ -55,7 +55,6 @@ namespace AssimpImporter { * This makes the code simpler and contains useful lookups. */ struct ImportState { - String path; Node3D *root; const aiScene *assimp_scene; @@ -88,6 +87,9 @@ struct ImportState { // this means we can detect // what bones are for other armatures List<aiBone *> bone_stack; + + // EditorSceneImporter::ImportFlags + uint32_t import_flags; }; struct AssimpImageData { diff --git a/modules/assimp/import_utils.h b/modules/assimp/import_utils.h index f78931add3..dc85d06fed 100644 --- a/modules/assimp/import_utils.h +++ b/modules/assimp/import_utils.h @@ -162,7 +162,6 @@ public: } static String get_anim_string_from_assimp(const aiString &p_string) { - String name; name.parse_utf8(p_string.C_Str() /*,p_string.length*/); if (name.find(":") != -1) { @@ -202,20 +201,34 @@ public: */ static float get_fbx_fps(int32_t time_mode, const aiScene *p_scene) { switch (time_mode) { - case AssetImportFbx::TIME_MODE_DEFAULT: return 24; //hack - case AssetImportFbx::TIME_MODE_120: return 120; - case AssetImportFbx::TIME_MODE_100: return 100; - case AssetImportFbx::TIME_MODE_60: return 60; - case AssetImportFbx::TIME_MODE_50: return 50; - case AssetImportFbx::TIME_MODE_48: return 48; - case AssetImportFbx::TIME_MODE_30: return 30; - case AssetImportFbx::TIME_MODE_30_DROP: return 30; - case AssetImportFbx::TIME_MODE_NTSC_DROP_FRAME: return 29.9700262f; - case AssetImportFbx::TIME_MODE_NTSC_FULL_FRAME: return 29.9700262f; - case AssetImportFbx::TIME_MODE_PAL: return 25; - case AssetImportFbx::TIME_MODE_CINEMA: return 24; - case AssetImportFbx::TIME_MODE_1000: return 1000; - case AssetImportFbx::TIME_MODE_CINEMA_ND: return 23.976f; + case AssetImportFbx::TIME_MODE_DEFAULT: + return 24; //hack + case AssetImportFbx::TIME_MODE_120: + return 120; + case AssetImportFbx::TIME_MODE_100: + return 100; + case AssetImportFbx::TIME_MODE_60: + return 60; + case AssetImportFbx::TIME_MODE_50: + return 50; + case AssetImportFbx::TIME_MODE_48: + return 48; + case AssetImportFbx::TIME_MODE_30: + return 30; + case AssetImportFbx::TIME_MODE_30_DROP: + return 30; + case AssetImportFbx::TIME_MODE_NTSC_DROP_FRAME: + return 29.9700262f; + case AssetImportFbx::TIME_MODE_NTSC_FULL_FRAME: + return 29.9700262f; + case AssetImportFbx::TIME_MODE_PAL: + return 25; + case AssetImportFbx::TIME_MODE_CINEMA: + return 24; + case AssetImportFbx::TIME_MODE_1000: + return 1000; + case AssetImportFbx::TIME_MODE_CINEMA_ND: + return 23.976f; case AssetImportFbx::TIME_MODE_CUSTOM: int32_t frame_rate = -1; p_scene->mMetaData->Get("FrameRate", frame_rate); @@ -340,7 +353,6 @@ public: * Load or load from cache image :) */ static Ref<Image> load_image(ImportState &state, const aiScene *p_scene, String p_path) { - Map<String, Ref<Image>>::Element *match = state.path_to_image_cache.find(p_path); // if our cache contains this image then don't bother diff --git a/modules/assimp/register_types.cpp b/modules/assimp/register_types.cpp index 3af8827bf9..6cb0fc982f 100644 --- a/modules/assimp/register_types.cpp +++ b/modules/assimp/register_types.cpp @@ -42,7 +42,6 @@ static void _editor_init() { #endif void register_assimp_types() { - #ifdef TOOLS_ENABLED ClassDB::APIType prev_api = ClassDB::get_current_api(); ClassDB::set_current_api(ClassDB::API_EDITOR); |