diff options
Diffstat (limited to 'editor/import/resource_importer_scene.cpp')
-rw-r--r-- | editor/import/resource_importer_scene.cpp | 158 |
1 files changed, 103 insertions, 55 deletions
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index f4fb0f9f0c..ec82f78e75 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -127,8 +127,9 @@ void EditorScenePostImport::_bind_methods() { } Node *EditorScenePostImport::post_import(Node *p_scene) { - if (get_script_instance()) + if (get_script_instance()) { return get_script_instance()->call("post_import", p_scene); + } return p_scene; } @@ -173,20 +174,24 @@ String ResourceImporterScene::get_resource_type() const { bool ResourceImporterScene::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { if (p_option.begins_with("animation/")) { - if (p_option != "animation/import" && !bool(p_options["animation/import"])) + if (p_option != "animation/import" && !bool(p_options["animation/import"])) { return false; + } - if (p_option == "animation/keep_custom_tracks" && int(p_options["animation/storage"]) == 0) + if (p_option == "animation/keep_custom_tracks" && int(p_options["animation/storage"]) == 0) { return false; + } - if (p_option.begins_with("animation/optimizer/") && p_option != "animation/optimizer/enabled" && !bool(p_options["animation/optimizer/enabled"])) + if (p_option.begins_with("animation/optimizer/") && p_option != "animation/optimizer/enabled" && !bool(p_options["animation/optimizer/enabled"])) { return false; + } if (p_option.begins_with("animation/clip_")) { int max_clip = p_options["animation/clips/amount"]; int clip = p_option.get_slice("/", 1).get_slice("_", 1).to_int() - 1; - if (clip >= max_clip) + if (clip >= max_clip) { return false; + } } } @@ -240,12 +245,15 @@ static bool _teststr(const String &p_what, const String &p_str) { what = what.substr(0, what.length() - 1); } - if (what.findn("$" + p_str) != -1) //blender and other stuff + if (what.findn("$" + p_str) != -1) { //blender and other stuff return true; - if (what.to_lower().ends_with("-" + p_str)) //collada only supports "_" and "-" besides letters + } + if (what.to_lower().ends_with("-" + p_str)) { //collada only supports "_" and "-" besides letters return true; - if (what.to_lower().ends_with("_" + p_str)) //collada only supports "_" and "-" besides letters + } + if (what.to_lower().ends_with("_" + p_str)) { //collada only supports "_" and "-" besides letters return true; + } return false; } @@ -259,12 +267,15 @@ static String _fixstr(const String &p_what, const String &p_str) { String end = p_what.substr(what.length(), p_what.length() - what.length()); - if (what.findn("$" + p_str) != -1) //blender and other stuff + if (what.findn("$" + p_str) != -1) { //blender and other stuff return what.replace("$" + p_str, "") + end; - if (what.to_lower().ends_with("-" + p_str)) //collada only supports "_" and "-" besides letters + } + if (what.to_lower().ends_with("-" + p_str)) { //collada only supports "_" and "-" besides letters return what.substr(0, what.length() - (p_str.length() + 1)) + end; - if (what.to_lower().ends_with("_" + p_str)) //collada only supports "_" and "-" besides letters + } + if (what.to_lower().ends_with("_" + p_str)) { //collada only supports "_" and "-" besides letters return what.substr(0, what.length() - (p_str.length() + 1)) + end; + } return what; } @@ -308,8 +319,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> if (m.is_valid()) { for (int i = 0; i < m->get_surface_count(); i++) { Ref<StandardMaterial3D> mat = m->surface_get_material(i); - if (!mat.is_valid()) + if (!mat.is_valid()) { continue; + } if (_teststr(mat->get_name(), "alpha")) { mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); @@ -353,8 +365,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> } if (_teststr(name, "colonly") || _teststr(name, "convcolonly")) { - if (isroot) + if (isroot) { return p_node; + } MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node); if (mi) { Ref<Mesh> mesh = mi->get_mesh(); @@ -436,8 +449,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> } } else if (_teststr(name, "rigid") && Object::cast_to<MeshInstance3D>(p_node)) { - if (isroot) + if (isroot) { return p_node; + } MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node); Ref<Mesh> mesh = mi->get_mesh(); @@ -523,8 +537,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> } } else if (_teststr(name, "navmesh") && Object::cast_to<MeshInstance3D>(p_node)) { - if (isroot) + if (isroot) { return p_node; + } MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node); @@ -541,8 +556,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> memdelete(p_node); p_node = nmi; } else if (_teststr(name, "vehicle")) { - if (isroot) + if (isroot) { return p_node; + } Node *owner = p_node->get_owner(); Node3D *s = Object::cast_to<Node3D>(p_node); @@ -560,8 +576,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> p_node = bv; } else if (_teststr(name, "wheel")) { - if (isroot) + if (isroot) { return p_node; + } Node *owner = p_node->get_owner(); Node3D *s = Object::cast_to<Node3D>(p_node); @@ -622,16 +639,18 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> } void ResourceImporterScene::_create_clips(Node *scene, const Array &p_clips, bool p_bake_all) { - if (!scene->has_node(String("AnimationPlayer"))) + if (!scene->has_node(String("AnimationPlayer"))) { return; + } Node *n = scene->get_node(String("AnimationPlayer")); ERR_FAIL_COND(!n); AnimationPlayer *anim = Object::cast_to<AnimationPlayer>(n); ERR_FAIL_COND(!anim); - if (!anim->has_animation("default")) + if (!anim->has_animation("default")) { return; + } Ref<Animation> default_anim = anim->get_animation("default"); @@ -640,8 +659,9 @@ void ResourceImporterScene::_create_clips(Node *scene, const Array &p_clips, boo float from = p_clips[i + 1]; float to = p_clips[i + 2]; bool loop = p_clips[i + 3]; - if (from >= to) + if (from >= to) { continue; + } Ref<Animation> new_anim = memnew(Animation); @@ -746,8 +766,9 @@ void ResourceImporterScene::_filter_anim_tracks(Ref<Animation> anim, Set<String> } void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { - if (!scene->has_node(String("AnimationPlayer"))) + if (!scene->has_node(String("AnimationPlayer"))) { return; + } Node *n = scene->get_node(String("AnimationPlayer")); ERR_FAIL_COND(!n); AnimationPlayer *anim = Object::cast_to<AnimationPlayer>(n); @@ -779,55 +800,63 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { Vector<String> filters = strings[i].substr(1, strings[i].length()).split(","); for (int j = 0; j < filters.size(); j++) { String fname = filters[j].strip_edges(); - if (fname == "") + if (fname == "") { continue; + } int fc = fname[0]; bool plus; - if (fc == '+') + if (fc == '+') { plus = true; - else if (fc == '-') + } else if (fc == '-') { plus = false; - else + } else { continue; + } String filter = fname.substr(1, fname.length()).strip_edges(); - if (!name.matchn(filter)) + if (!name.matchn(filter)) { continue; + } valid_for_this = plus; } - if (valid_for_this) + if (valid_for_this) { valid = true; + } } else if (valid_for_this) { Ref<Animation> a = anim->get_animation(name); - if (!a.is_valid()) + if (!a.is_valid()) { continue; + } for (int j = 0; j < a->get_track_count(); j++) { String path = a->track_get_path(j); String tname = strings[i]; - if (tname == "") + if (tname == "") { continue; + } int fc = tname[0]; bool plus; - if (fc == '+') + if (fc == '+') { plus = true; - else if (fc == '-') + } else if (fc == '-') { plus = false; - else + } else { continue; + } String filter = tname.substr(1, tname.length()).strip_edges(); - if (!path.matchn(filter)) + if (!path.matchn(filter)) { continue; + } - if (plus) + if (plus) { keep_local.insert(path); - else if (!keep.has(path)) { + } else if (!keep.has(path)) { keep_local.erase(path); } } @@ -844,8 +873,9 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { } void ResourceImporterScene::_optimize_animations(Node *scene, float p_max_lin_error, float p_max_ang_error, float p_max_angle) { - if (!scene->has_node(String("AnimationPlayer"))) + if (!scene->has_node(String("AnimationPlayer"))) { return; + } Node *n = scene->get_node(String("AnimationPlayer")); ERR_FAIL_COND(!n); AnimationPlayer *anim = Object::cast_to<AnimationPlayer>(n); @@ -1005,10 +1035,12 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String for (int i = 0; i < mesh->get_surface_count(); i++) { mat = mesh->surface_get_material(i); - if (!mat.is_valid()) + if (!mat.is_valid()) { continue; - if (mat->get_name() == "") + } + if (mat->get_name() == "") { continue; + } if (!p_materials.has(mat)) { String ext_name; @@ -1072,8 +1104,9 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options, in String script_ext_hint; for (List<String>::Element *E = script_extentions.front(); E; E = E->next()) { - if (script_ext_hint != "") + if (script_ext_hint != "") { script_ext_hint += ","; + } script_ext_hint += "*." + E->get(); } @@ -1130,8 +1163,9 @@ Node *ResourceImporterScene::import_scene_from_other_importer(EditorSceneImporte String ext = p_path.get_extension().to_lower(); for (Set<Ref<EditorSceneImporter>>::Element *E = importers.front(); E; E = E->next()) { - if (E->get().ptr() == p_exception) + if (E->get().ptr() == p_exception) { continue; + } List<String> extensions; E->get()->get_extensions(&extensions); @@ -1142,8 +1176,9 @@ Node *ResourceImporterScene::import_scene_from_other_importer(EditorSceneImporte } } - if (importer.is_valid()) + if (importer.is_valid()) { break; + } } ERR_FAIL_COND_V(!importer.is_valid(), nullptr); @@ -1158,8 +1193,9 @@ Ref<Animation> ResourceImporterScene::import_animation_from_other_importer(Edito String ext = p_path.get_extension().to_lower(); for (Set<Ref<EditorSceneImporter>>::Element *E = importers.front(); E; E = E->next()) { - if (E->get().ptr() == p_exception) + if (E->get().ptr() == p_exception) { continue; + } List<String> extensions; E->get()->get_extensions(&extensions); @@ -1170,8 +1206,9 @@ Ref<Animation> ResourceImporterScene::import_animation_from_other_importer(Edito } } - if (importer.is_valid()) + if (importer.is_valid()) { break; + } } ERR_FAIL_COND_V(!importer.is_valid(), nullptr); @@ -1199,8 +1236,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p } } - if (importer.is_valid()) + if (importer.is_valid()) { break; + } } ERR_FAIL_COND_V(!importer.is_valid(), ERR_FILE_UNRECOGNIZED); @@ -1208,23 +1246,29 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p float fps = p_options["animation/fps"]; int import_flags = EditorSceneImporter::IMPORT_ANIMATION_DETECT_LOOP; - if (!bool(p_options["animation/optimizer/remove_unused_tracks"])) + if (!bool(p_options["animation/optimizer/remove_unused_tracks"])) { import_flags |= EditorSceneImporter::IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS; + } - if (bool(p_options["animation/import"])) + if (bool(p_options["animation/import"])) { import_flags |= EditorSceneImporter::IMPORT_ANIMATION; + } - if (int(p_options["meshes/compress"])) + if (int(p_options["meshes/compress"])) { import_flags |= EditorSceneImporter::IMPORT_USE_COMPRESSION; + } - if (bool(p_options["meshes/ensure_tangents"])) + if (bool(p_options["meshes/ensure_tangents"])) { import_flags |= EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS; + } - if (int(p_options["materials/location"]) == 0) + if (int(p_options["materials/location"]) == 0) { import_flags |= EditorSceneImporter::IMPORT_MATERIALS_IN_INSTANCES; + } - if (bool(p_options["skins/use_named_skins"])) + if (bool(p_options["skins/use_named_skins"])) { import_flags |= EditorSceneImporter::IMPORT_USE_NAMED_SKIN_BINDS; + } Error err = OK; List<String> missing_deps; // for now, not much will be done with this @@ -1262,10 +1306,11 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p Object::cast_to<Node3D>(scene)->scale(Vector3(root_scale, root_scale, root_scale)); } - if (p_options["nodes/root_name"] != "Scene Root") + if (p_options["nodes/root_name"] != "Scene Root") { scene->set_name(p_options["nodes/root_name"]); - else + } else { scene->set_name(p_save_path.get_file().get_basename()); + } err = OK; @@ -1345,8 +1390,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p FileAccess *file = FileAccess::open(cache_file_path, FileAccess::READ, &err2); if (err2) { - if (file) + if (file) { memdelete(file); + } } else { int cache_size = file->get_len(); cache_data.resize(cache_size); @@ -1405,8 +1451,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p FileAccess *file = FileAccess::open(cache_file_path, FileAccess::WRITE, &err2); if (err2) { - if (file) + if (file) { memdelete(file); + } } else { // Store number of entries file->store_32(used_unwraps.size()); @@ -1486,8 +1533,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p //save sub-scenes as instances! for (int i = 0; i < scene->get_child_count(); i++) { Node *child = scene->get_child(i); - if (child->get_owner() != scene) + if (child->get_owner() != scene) { continue; //not a real child probably created by scene type (ig, a scrollbar) + } _replace_owner(child, scene, child); String cn = String(child->get_name()).strip_edges().replace(".", "_").replace(":", "_"); |