Fix: Collada Import files with X_UP and Y_UP axis where imported with wrong orientation
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -351,6 +351,10 @@ void bc_match_scale(std::vector<Object *> *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<Object *>::iterator it = objects_done->begin();
|
||||
@@ -359,6 +363,7 @@ void bc_match_scale(std::vector<Object *> *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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user