From 291c1d0f459abb40c146f90a336dafbdac477507 Mon Sep 17 00:00:00 2001 From: ShyRed Date: Mon, 12 Feb 2018 11:36:40 +0100 Subject: [PATCH] Add import option "scale_mesh" to obj file importer The new import option "scale_mesh" allows setting a scale that is applied to the mesh's vertices during import. --- editor/import/resource_importer_obj.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 78fc9ec9bd8..21803a2184b 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 > &r_meshes, bool p_single_mesh, bool p_generate_tangents, List *r_missing_deps) { +static Error _parse_obj(const String &p_path, List > &r_meshes, bool p_single_mesh, bool p_generate_tangents, Vector3 p_scale_mesh, List *r_missing_deps) { FileAccessRef f = FileAccess::open(p_path, FileAccess::READ); @@ -198,6 +198,7 @@ static Error _parse_obj(const String &p_path, List > &r_meshes, bool p mesh.instance(); bool generate_tangents = p_generate_tangents; + Vector3 scale_mesh = p_scale_mesh; bool flip_faces = false; //bool flip_faces = p_options["force/flip_faces"]; //bool force_smooth = p_options["force/smooth_shading"]; @@ -227,9 +228,9 @@ static Error _parse_obj(const String &p_path, List > &r_meshes, bool p Vector v = l.split(" ", false); ERR_FAIL_COND_V(v.size() < 4, ERR_FILE_CORRUPT); Vector3 vtx; - vtx.x = v[1].to_float(); - vtx.y = v[2].to_float(); - vtx.z = v[3].to_float(); + vtx.x = v[1].to_float() * scale_mesh.x; + vtx.y = v[2].to_float() * scale_mesh.y; + vtx.z = v[3].to_float() * scale_mesh.z; vertices.push_back(vtx); } else if (l.begins_with("vt ")) { //uv @@ -401,7 +402,7 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, in List > meshes; - Error err = _parse_obj(p_path, meshes, false, p_flags & IMPORT_GENERATE_TANGENT_ARRAYS, r_missing_deps); + Error err = _parse_obj(p_path, meshes, false, p_flags & IMPORT_GENERATE_TANGENT_ARRAYS, Vector3(1, 1, 1), r_missing_deps); if (err != OK) { if (r_err) { @@ -468,6 +469,7 @@ String ResourceImporterOBJ::get_preset_name(int p_idx) const { void ResourceImporterOBJ::get_import_options(List *r_options, int p_preset) const { 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))); } bool ResourceImporterOBJ::get_option_visibility(const String &p_option, const Map &p_options) const { @@ -478,7 +480,7 @@ Error ResourceImporterOBJ::import(const String &p_source_file, const String &p_s List > meshes; - Error err = _parse_obj(p_source_file, meshes, true, p_options["generate_tangents"], NULL); + Error err = _parse_obj(p_source_file, meshes, true, p_options["generate_tangents"], p_options["scale_mesh"], NULL); ERR_FAIL_COND_V(err != OK, err); ERR_FAIL_COND_V(meshes.size() != 1, ERR_BUG);