diff options
Diffstat (limited to 'editor/import')
-rw-r--r-- | editor/import/resource_importer_obj.cpp | 11 | ||||
-rw-r--r-- | editor/import/resource_importer_scene.cpp | 50 | ||||
-rw-r--r-- | editor/import/resource_importer_texture.cpp | 4 |
3 files changed, 48 insertions, 17 deletions
diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 21803a2184..b8dd4a87b7 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -188,7 +188,7 @@ static Error _parse_material_library(const String &p_path, Map<String, Ref<Spati return OK; } -static Error _parse_obj(const String &p_path, List<Ref<Mesh> > &r_meshes, bool p_single_mesh, bool p_generate_tangents, Vector3 p_scale_mesh, List<String> *r_missing_deps) { +static Error _parse_obj(const String &p_path, List<Ref<Mesh> > &r_meshes, bool p_single_mesh, bool p_generate_tangents, bool p_optimize, Vector3 p_scale_mesh, List<String> *r_missing_deps) { FileAccessRef f = FileAccess::open(p_path, FileAccess::READ); @@ -200,6 +200,8 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh> > &r_meshes, bool p bool generate_tangents = p_generate_tangents; Vector3 scale_mesh = p_scale_mesh; bool flip_faces = false; + int mesh_flags = p_optimize ? Mesh::ARRAY_COMPRESS_DEFAULT : 0; + //bool flip_faces = p_options["force/flip_faces"]; //bool force_smooth = p_options["force/smooth_shading"]; //bool weld_vertices = p_options["force/weld_vertices"]; @@ -331,7 +333,7 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh> > &r_meshes, bool p surf_tool->set_material(material_map[current_material_library][current_material]); } - mesh = surf_tool->commit(mesh); + mesh = surf_tool->commit(mesh, mesh_flags); if (current_material != String()) { mesh->surface_set_name(mesh->get_surface_count() - 1, current_material.get_basename()); @@ -402,7 +404,7 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, in List<Ref<Mesh> > meshes; - Error err = _parse_obj(p_path, meshes, false, p_flags & IMPORT_GENERATE_TANGENT_ARRAYS, Vector3(1, 1, 1), r_missing_deps); + Error err = _parse_obj(p_path, meshes, false, p_flags & IMPORT_GENERATE_TANGENT_ARRAYS, p_flags & IMPORT_USE_COMPRESSION, Vector3(1, 1, 1), r_missing_deps); if (err != OK) { if (r_err) { @@ -470,6 +472,7 @@ void ResourceImporterOBJ::get_import_options(List<ImportOption> *r_options, int r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "generate_tangents"), true)); r_options->push_back(ImportOption(PropertyInfo(Variant::VECTOR3, "scale_mesh"), Vector3(1, 1, 1))); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "optimize_mesh"), true)); } bool ResourceImporterOBJ::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { @@ -480,7 +483,7 @@ Error ResourceImporterOBJ::import(const String &p_source_file, const String &p_s List<Ref<Mesh> > meshes; - Error err = _parse_obj(p_source_file, meshes, true, p_options["generate_tangents"], p_options["scale_mesh"], NULL); + Error err = _parse_obj(p_source_file, meshes, true, p_options["generate_tangents"], p_options["optimize_mesh"], p_options["scale_mesh"], NULL); ERR_FAIL_COND_V(err != OK, err); ERR_FAIL_COND_V(meshes.size() != 1, ERR_BUG); diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index fdbf66f656..91644492c3 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -224,24 +224,42 @@ String ResourceImporterScene::get_preset_name(int p_idx) const { static bool _teststr(const String &p_what, const String &p_str) { - if (p_what.findn("$" + p_str) != -1) //blender and other stuff + String what = p_what; + + //remove trailing spaces and numbers, some apps like blender add ".number" to duplicates so also compensate for this + while (what.length() && ((what[what.length() - 1] >= '0' && what[what.length() - 1] <= '9') || what[what.length() - 1] <= 32 || what[what.length() - 1] == '.')) { + + what = what.substr(0, what.length() - 1); + } + + if (what.findn("$" + p_str) != -1) //blender and other stuff return true; - if (p_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 (p_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; } static String _fixstr(const String &p_what, const String &p_str) { - if (p_what.findn("$" + p_str) != -1) //blender and other stuff - return p_what.replace("$" + p_str, ""); - if (p_what.to_lower().ends_with("-" + p_str)) //collada only supports "_" and "-" besides letters - return p_what.substr(0, p_what.length() - (p_str.length() + 1)); - if (p_what.to_lower().ends_with("_" + p_str)) //collada only supports "_" and "-" besides letters - return p_what.substr(0, p_what.length() - (p_str.length() + 1)); - return p_what; + String what = p_what; + + //remove trailing spaces and numbers, some apps like blender add ".number" to duplicates so also compensate for this + while (what.length() && ((what[what.length() - 1] >= '0' && what[what.length() - 1] <= '9') || what[what.length() - 1] <= 32 || what[what.length() - 1] == '.')) { + + what = what.substr(0, what.length() - 1); + } + + String end = p_what.substr(what.length(), p_what.length() - what.length()); + + 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 + 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 + return what.substr(0, what.length() - (p_str.length() + 1)) + end; + return what; } Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<ArrayMesh>, Ref<Shape> > &collision_map, LightBakeMode p_light_bake_mode) { @@ -437,13 +455,19 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array Node *col; if (_teststr(name, "col")) { - mi->set_name(_fixstr(name, "col")); + String new_name = _fixstr(name, "col"); + if (mi->get_parent() && !mi->get_parent()->has_node(new_name)) { + mi->set_name(new_name); + } col = mi->create_trimesh_collision_node(); ERR_FAIL_COND_V(!col, NULL); col->set_name("col"); } else { - mi->set_name(_fixstr(name, "convcol")); + String new_name = _fixstr(name, "convcol"); + if (mi->get_parent() && !mi->get_parent()->has_node(new_name)) { + mi->set_name(new_name); + } col = mi->create_convex_collision_node(); ERR_FAIL_COND_V(!col, NULL); @@ -893,7 +917,6 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String } String ext_name = p_base_path.plus_file(_make_extname(E->get()) + ".anim"); - if (FileAccess::exists(ext_name) && p_keep_animations) { //try to keep custom animation tracks Ref<Animation> old_anim = ResourceLoader::load(ext_name, "Animation", true); @@ -907,6 +930,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String } } + anim->set_path(ext_name, true); //if not set, then its never saved externally ResourceSaver::save(ext_name, anim, ResourceSaver::FLAG_CHANGE_PATH); p_animations[anim] = anim; } diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index beaa8d9600..17a9394b51 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -395,6 +395,10 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String image->resize(new_width, new_height, Image::INTERPOLATE_CUBIC); } + + if (normal) { + image->normalize(); + } } if (fix_alpha_border) { |