From 9fe4dbb9f10e611d2c24eccbfbcbb9260370b8bd Mon Sep 17 00:00:00 2001 From: Gaia Clary Date: Fri, 15 Feb 2013 15:36:02 +0000 Subject: Fix: Collada Import files with X_UP and Y_UP axis where imported with wrong orientation --- source/blender/collada/collada.cpp | 1 - source/blender/collada/collada.h | 1 + source/blender/collada/collada_internal.cpp | 24 +++++++++++++++++++++++- source/blender/collada/collada_internal.h | 9 ++++++++- source/blender/collada/collada_utils.cpp | 5 +++++ 5 files changed, 37 insertions(+), 3 deletions(-) (limited to 'source') diff --git a/source/blender/collada/collada.cpp b/source/blender/collada/collada.cpp index 1aff0f166ba..b3c288c8fc5 100644 --- a/source/blender/collada/collada.cpp +++ b/source/blender/collada/collada.cpp @@ -40,7 +40,6 @@ extern "C" /* make dummy file */ #include "BLI_fileops.h" -#include "BLI_path_util.h" #include "BLI_linklist.h" int collada_import(bContext *C, diff --git a/source/blender/collada/collada.h b/source/blender/collada/collada.h index 587dc37b7db..2fa5b22bb15 100644 --- a/source/blender/collada/collada.h +++ b/source/blender/collada/collada.h @@ -33,6 +33,7 @@ extern "C" { #endif #include "BLI_linklist.h" +#include "BLI_path_util.h" #include "RNA_types.h" typedef enum BC_export_mesh_type { diff --git a/source/blender/collada/collada_internal.cpp b/source/blender/collada/collada_internal.cpp index 64c567384a1..85f98dad437 100644 --- a/source/blender/collada/collada_internal.cpp +++ b/source/blender/collada/collada_internal.cpp @@ -33,7 +33,14 @@ UnitConverter::UnitConverter() : unit(), up_axis(COLLADAFW::FileInfo::Z_UP) { - /* pass */ + unit_m4(x_up_mat4); + rotate_m4(x_up_mat4, 'Y', -0.5 * M_PI); + + unit_m4(y_up_mat4); + rotate_m4(y_up_mat4, 'X', 0.5 * M_PI); + + unit_m4(z_up_mat4); + } void UnitConverter::read_asset(const COLLADAFW::FileInfo *asset) @@ -102,6 +109,21 @@ void UnitConverter::mat4_to_dae_double(double out[4][4], float in[4][4]) out[i][j] = mat[i][j]; } +float(&UnitConverter::get_rotation())[4][4] +{ + switch(up_axis) { + case COLLADAFW::FileInfo::X_UP: + return x_up_mat4; + break; + case COLLADAFW::FileInfo::Y_UP: + return y_up_mat4; + break; + default: + return z_up_mat4; + break; + } +} + void TransformBase::decompose(float mat[4][4], float *loc, float eul[3], float quat[4], float *size) { mat4_to_size(size, mat); diff --git a/source/blender/collada/collada_internal.h b/source/blender/collada/collada_internal.h index ba077628499..7d59932bac9 100644 --- a/source/blender/collada/collada_internal.h +++ b/source/blender/collada/collada_internal.h @@ -39,7 +39,6 @@ #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "BLI_math.h" -#include "BLI_math.h" #include "BLI_linklist.h" class UnitConverter @@ -48,6 +47,10 @@ private: COLLADAFW::FileInfo::Unit unit; COLLADAFW::FileInfo::UpAxisType up_axis; + float x_up_mat4[4][4]; + float y_up_mat4[4][4]; + float z_up_mat4[4][4]; + public: enum UnitSystem { @@ -74,6 +77,10 @@ public: void mat4_to_dae(float out[4][4], float in[4][4]); void mat4_to_dae_double(double out[4][4], float in[4][4]); + + float(&get_rotation())[4][4]; + + }; class TransformBase diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp index 3e2d1795528..45db8510cbb 100644 --- a/source/blender/collada/collada_utils.cpp +++ b/source/blender/collada/collada_utils.cpp @@ -351,6 +351,10 @@ void bc_match_scale(std::vector *objects_done, 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); for (std::vector::iterator it = objects_done->begin(); @@ -359,6 +363,7 @@ void bc_match_scale(std::vector *objects_done, { ob = *it; mult_m4_m4m4(ob->obmat, size_mat4, ob->obmat); + mult_m4_m4m4(ob->obmat, bc_unit.get_rotation(), ob->obmat); BKE_object_apply_mat4(ob, ob->obmat, 0, 0); } -- cgit v1.2.3