From 1a3a252e06811bdf625dbd0b7bed5de3b3e428a2 Mon Sep 17 00:00:00 2001 From: Gaia Clary Date: Mon, 29 Jul 2013 21:51:53 +0000 Subject: Collada: Import now always rotates input to match blender's Z_UP axis --- source/blender/collada/DocumentImporter.cpp | 7 ++-- source/blender/collada/collada_utils.cpp | 65 +++++++---------------------- source/blender/collada/collada_utils.h | 3 +- 3 files changed, 20 insertions(+), 55 deletions(-) (limited to 'source/blender') diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 80bde1842dd..97678159247 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -185,6 +185,7 @@ void DocumentImporter::finish() Main *bmain = CTX_data_main(mContext); // TODO: create a new scene except the selected - use current blender scene for it Scene *sce = CTX_data_scene(mContext); + unit_converter.calculate_scale(*sce); /** TODO Break up and put into 2-pass parsing of DAE */ std::vector::iterator it; @@ -224,10 +225,8 @@ void DocumentImporter::finish() std::vector *objects_done; objects_done = write_node(roots[i], NULL, sce, NULL, false); - if (!this->import_settings->import_units) { - // Match incoming scene with current unit settings - bc_match_scale(objects_done, *sce, unit_converter); - } + // Match incoming scene with current unit settings + bc_match_scale(objects_done, unit_converter, !this->import_settings->import_units); } // update scene diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp index d4196bacf0d..3e17472e9c2 100644 --- a/source/blender/collada/collada_utils.cpp +++ b/source/blender/collada/collada_utils.cpp @@ -324,65 +324,30 @@ std::string bc_replace_string(std::string data, const std::string& pattern, * Calculate a rescale factor such that the imported scene's scale * is preserved. I.e. 1 meter in the import will also be * 1 meter in the current scene. - * XXX : I am not sure if it is correct to map 1 Blender Unit - * to 1 Meter for unit type NONE. But it looks reasonable to me. */ -void bc_match_scale(std::vector *objects_done, - Scene &sce, - UnitConverter &bc_unit) -{ - Object *ob = NULL; - - PointerRNA scene_ptr, unit_settings; - PropertyRNA *system_ptr, *scale_ptr; - RNA_id_pointer_create(&sce.id, &scene_ptr); - - unit_settings = RNA_pointer_get(&scene_ptr, "unit_settings"); - system_ptr = RNA_struct_find_property(&unit_settings, "system"); - scale_ptr = RNA_struct_find_property(&unit_settings, "scale_length"); - - int type = RNA_property_enum_get(&unit_settings, system_ptr); - float bl_scale; - - switch (type) { - case USER_UNIT_NONE: - bl_scale = 1.0; // map 1 Blender unit to 1 Meter - break; - - case USER_UNIT_METRIC: - bl_scale = RNA_property_float_get(&unit_settings, scale_ptr); - break; - - default : - bl_scale = RNA_property_float_get(&unit_settings, scale_ptr); - // it looks like the conversion to Imperial is done implicitly. - // So nothing to do here. - break; +void bc_match_scale(Object *ob, UnitConverter &bc_unit, bool scale_to_scene) +{ + if (scale_to_scene) { + mul_m4_m4m4(ob->obmat, bc_unit.get_scale(), ob->obmat); } - - float scale_conv = bc_unit.getLinearMeter() / bl_scale; - - float rescale[3]; - rescale[0] = rescale[1] = rescale[2] = scale_conv; - - float size_mat4[4][4]; - - float axis_mat4[4][4]; - unit_m4(axis_mat4); - - size_to_mat4(size_mat4, rescale); + mul_m4_m4m4(ob->obmat, bc_unit.get_rotation(), ob->obmat); + BKE_object_apply_mat4(ob, ob->obmat, 0, 0); +} +void bc_match_scale(std::vector *objects_done, + UnitConverter &bc_unit, + bool scale_to_scene) +{ for (std::vector::iterator it = objects_done->begin(); it != objects_done->end(); ++it) { - ob = *it; - mul_m4_m4m4(ob->obmat, size_mat4, ob->obmat); - mul_m4_m4m4(ob->obmat, bc_unit.get_rotation(), ob->obmat); - BKE_object_apply_mat4(ob, ob->obmat, 0, 0); + Object *ob = *it; + if (ob -> parent == NULL) { + bc_match_scale(*it, bc_unit, scale_to_scene); + } } - } void bc_triangulate_mesh(Mesh *me) diff --git a/source/blender/collada/collada_utils.h b/source/blender/collada/collada_utils.h index f8e6f09e498..4bc2f55cf33 100644 --- a/source/blender/collada/collada_utils.h +++ b/source/blender/collada/collada_utils.h @@ -83,7 +83,8 @@ extern int bc_get_active_UVLayer(Object *ob); extern std::string bc_replace_string(std::string data, const std::string& pattern, const std::string& replacement); extern std::string bc_url_encode(std::string data); -extern void bc_match_scale(std::vector *objects_done, Scene &sce, UnitConverter &unit_converter); +extern void bc_match_scale(Object *ob, UnitConverter &bc_unit, bool scale_to_scene); +extern void bc_match_scale(std::vector *objects_done, UnitConverter &unit_converter, bool scale_to_scene); extern void bc_triangulate_mesh(Mesh *me); -- cgit v1.2.3