Commit: 9afc694c13389550cd51e5e01bc6b3589c211df2 Author: Gaia Clary Date: Thu Apr 4 17:11:04 2019 +0200 Branches: collada https://developer.blender.org/rB9afc694c13389550cd51e5e01bc6b3589c211df2
refactor: Collada: Reorganize=ing Classes and add new utility functions - Added new utility methods to collada_utils - Made BCMatrix class more powerfull for future usage - Moved Blender related data structures and definitions to BlenderContext.h - Adjusted according to changes above =================================================================== M source/blender/collada/BCSampleData.cpp M source/blender/collada/BCSampleData.h M source/blender/collada/BlenderContext.h M source/blender/collada/ExportSettings.h M source/blender/collada/collada_utils.cpp M source/blender/collada/collada_utils.h =================================================================== diff --git a/source/blender/collada/BCSampleData.cpp b/source/blender/collada/BCSampleData.cpp index 812ac3c2a5a..8f67278e9d8 100644 --- a/source/blender/collada/BCSampleData.cpp +++ b/source/blender/collada/BCSampleData.cpp @@ -53,6 +53,28 @@ BCMatrix::BCMatrix(Object *ob) set_transform(ob); } +BCMatrix::BCMatrix() +{ + unit(); +} + +BCMatrix::BCMatrix(BC_global_forward_axis global_forward_axis, BC_global_up_axis global_up_axis) +{ + float mrot[3][3]; + float mat[4][4]; + mat3_from_axis_conversion( + BC_DEFAULT_FORWARD, + BC_DEFAULT_UP, + global_forward_axis, + global_up_axis, + mrot); + + transpose_m3(mrot); // Assume that mat3_from_axis_conversion() returns a transposed matrix + copy_m4_m3(mat, mrot); + set_transform(mat); +} + + void BCMatrix::set_transform(Matrix &mat) { copy_m4_m4(matrix, mat); @@ -129,14 +151,16 @@ void BCMatrix::sanitize(Matrix &mat, int precision) void BCMatrix::unit() { - unit_m4(matrix); + unit_m4(this->matrix); + mat4_decompose(this->loc, this->q, this->size, this->matrix); + quat_to_eul(this->rot, this->q); } /* We need double here because the OpenCollada API needs it. precision = -1 indicates to not limit the precision */ -void BCMatrix::get_matrix(double(&mat)[4][4], const bool transposed, const int precision) const +void BCMatrix::get_matrix(DMatrix &mat, const bool transposed, const int precision) const { for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) { @@ -147,6 +171,21 @@ void BCMatrix::get_matrix(double(&mat)[4][4], const bool transposed, const int p } } +void BCMatrix::get_matrix(Matrix &mat, const bool transposed, const int precision, const bool inverted) const +{ + for (int i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) { + float val = (transposed) ? matrix[j][i] : matrix[i][j]; + if (precision >= 0) + val = floor((val * pow(10, precision) + 0.5)) / pow(10, precision); + mat[i][j] = val; + } + + if (inverted) { + invert_m4(mat); + } +} + const bool BCMatrix::in_range(const BCMatrix &other, float distance) const { for (int i = 0; i < 4; i++) { diff --git a/source/blender/collada/BCSampleData.h b/source/blender/collada/BCSampleData.h index ec7f14f8c3a..81e0e514ae2 100644 --- a/source/blender/collada/BCSampleData.h +++ b/source/blender/collada/BCSampleData.h @@ -24,6 +24,8 @@ #include <map> #include <algorithm> +#include "ExportSettings.h" + extern "C" { #include "BKE_object.h" @@ -35,8 +37,6 @@ extern "C" #include "DNA_camera_types.h" } -typedef float(Matrix)[4][4]; - class BCMatrix { private: @@ -58,10 +58,13 @@ public: float(&scale() const)[3]; float(&quat() const)[4]; + BCMatrix(BC_global_forward_axis global_forward_axis, BC_global_up_axis global_up_axis); BCMatrix(Matrix &mat); BCMatrix(Object *ob); + BCMatrix(); - void get_matrix(double(&mat)[4][4], const bool transposed = false, const int precision = -1) const; + void get_matrix(DMatrix &matrix, const bool transposed=false, const int precision=-1) const; + void get_matrix(Matrix &matrix, const bool transposed=false, const int precision=-1, const bool inverted=false) const; const bool in_range(const BCMatrix &other, float distance) const; static void sanitize(Matrix &matrix, int precision); diff --git a/source/blender/collada/BlenderContext.h b/source/blender/collada/BlenderContext.h index c6c9063e253..64c10e04e9c 100644 --- a/source/blender/collada/BlenderContext.h +++ b/source/blender/collada/BlenderContext.h @@ -21,12 +21,42 @@ #ifndef __BLENDERCONTEXT_H__ #define __BLENDERCONTEXT_H__ +#ifdef __cplusplus extern "C" { +#endif + #include "DNA_object_types.h" #include "BKE_context.h" #include "BKE_main.h" #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" + +typedef float(Vector)[3]; +typedef float(Matrix)[4][4]; +typedef double(DMatrix)[4][4]; + +typedef enum BC_global_forward_axis { + BC_GLOBAL_FORWARD_X = 0, + BC_GLOBAL_FORWARD_Y = 1, + BC_GLOBAL_FORWARD_Z = 2, + BC_GLOBAL_FORWARD_MINUS_X = 3, + BC_GLOBAL_FORWARD_MINUS_Y = 4, + BC_GLOBAL_FORWARD_MINUS_Z = 5 +} BC_global_forward_axis; + +typedef enum BC_global_up_axis { + BC_GLOBAL_UP_X = 0, + BC_GLOBAL_UP_Y = 1, + BC_GLOBAL_UP_Z = 2, + BC_GLOBAL_UP_MINUS_X = 3, + BC_GLOBAL_UP_MINUS_Y = 4, + BC_GLOBAL_UP_MINUS_Z = 5 +} BC_global_up_axis; + +static const BC_global_forward_axis BC_DEFAULT_FORWARD = BC_GLOBAL_FORWARD_Y; +static const BC_global_up_axis BC_DEFAULT_UP = BC_GLOBAL_UP_Z; + +#ifdef __cplusplus } class BlenderContext @@ -48,5 +78,6 @@ public: ViewLayer *get_view_layer(); Main *get_main(); }; +#endif #endif diff --git a/source/blender/collada/ExportSettings.h b/source/blender/collada/ExportSettings.h index 7c73f6d7f29..19264520763 100644 --- a/source/blender/collada/ExportSettings.h +++ b/source/blender/collada/ExportSettings.h @@ -26,27 +26,7 @@ extern "C" { #endif #include "BLI_linklist.h" - -typedef enum BC_export_global_forward_axis { - BC_GLOBAL_FORWARD_X = 0, - BC_GLOBAL_FORWARD_Y = 1, - BC_GLOBAL_FORWARD_Z = 2, - BC_GLOBAL_FORWARD_MINUS_X = 3, - BC_GLOBAL_FORWARD_MINUS_Y = 4, - BC_GLOBAL_FORWARD_MINUS_Z = 5 -} BC_export_global_forward_axis; - -typedef enum BC_export_global_up_axis { - BC_GLOBAL_UP_X = 0, - BC_GLOBAL_UP_Y = 1, - BC_GLOBAL_UP_Z = 2, - BC_GLOBAL_UP_MINUS_X = 3, - BC_GLOBAL_UP_MINUS_Y = 4, - BC_GLOBAL_UP_MINUS_Z = 5 -} BC_export_global_up_axis; - -static const BC_export_global_forward_axis BC_DEFAULT_FORWARD = BC_GLOBAL_FORWARD_Y; -static const BC_export_global_up_axis BC_DEFAULT_UP = BC_GLOBAL_UP_Z; +#include "BlenderContext.h" typedef enum BC_export_mesh_type { BC_MESH_TYPE_VIEW, @@ -74,8 +54,8 @@ typedef enum BC_ui_export_section { typedef struct ExportSettings { bool apply_modifiers; - BC_export_global_forward_axis global_forward; - BC_export_global_up_axis global_up; + BC_global_forward_axis global_forward; + BC_global_up_axis global_up; bool apply_global_orientation; BC_export_mesh_type export_mesh_type; diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp index 0084ff84e4d..93b8b15076f 100644 --- a/source/blender/collada/collada_utils.cpp +++ b/source/blender/collada/collada_utils.cpp @@ -1050,6 +1050,32 @@ bool bc_has_animations(Scene *sce, LinkNode &export_set) return false; } +void bc_add_global_transform(Matrix &to_mat, const Matrix &from_mat, const BCMatrix &global_transform, const bool invert) +{ + copy_m4_m4(to_mat, from_mat); + bc_add_global_transform(to_mat, global_transform, invert); +} + +void bc_add_global_transform(Vector &to_vec, const Vector &from_vec, const BCMatrix &global_transform, const bool invert) +{ + copy_v3_v3(to_vec, from_vec); + bc_add_global_transform(to_vec, global_transform, invert); +} + +void bc_add_global_transform(Matrix &to_mat, const BCMatrix &global_transform, const bool invert) +{ + Matrix mat; + global_transform.get_matrix(mat, false, 6, invert); + mul_m4_m4m4(to_mat, mat, to_mat); +} + +void bc_add_global_transform(Vector &to_vec, const BCMatrix &global_transform, const bool invert) +{ + Matrix mat; + global_transform.get_matrix(mat, false, 6, invert); + mul_v3_m4v3(to_vec, mat, to_vec); +} + /** * Check if custom information about bind matrix exists and modify the from_mat * accordingly. diff --git a/source/blender/collada/collada_utils.h b/source/blender/collada/collada_utils.h index 99a805e8b19..2df53a661d7 100644 --- a/source/blender/collada/collada_utils.h +++ b/source/blender/collada/collada_utils.h @@ -223,8 +223,43 @@ extern bool bc_is_animated(BCMatrixSampleMap &values); extern bool bc_has_animations(Scene *sce, LinkNode &node); extern bool bc_has_animations(Object *ob); +void bc_add_global_transform(Matrix &to_mat, const Matrix &from_mat, const BCMatrix &global_transform, const bool invert = false); +void bc_add_global_transform(Vector &to_vec, const Vector &from_vec, const BCMatrix &global_transform, const bool invert = false); -extern void bc_create_restpose_mat(const ExportSettings *export_settings, Bone *bone, float to_mat[4][4], float world[4][4], bool use_local_space); +void bc_add_global_transform(Vector &to_vec, const BCMatrix &global_transform, const bool invert = false); +void bc_add_global_transform(Matrix &to_mat, const BCMatrix &global_transform, const bool invert = false); + +extern void bc_create_restpose_mat(const ExportSettings *export_settings, Bone *bone, float to_mat[4][4], float from_mat[4][4], bool use_local_space); + +class ColladaBaseNodes +{ +private: + std::vector<Object *> base_objects; + +public: + + void add(Object *ob) + { + base_objects.push_back(ob); + } + + bool contains(Object *ob) + { + std::vector<Object *>::iterator it = std::find(base_objects.begin(), base_objects.end(), ob); + return (it != base_objects.end()); + } + + int size() + { + return base_objects.size(); + } + + Object *get(int index) + { + return base_objects[index]; + } + +}; class BCPolygonNormalsIndices { _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs