refactor collada: replace bc_sanitize_mat() by static class method in BCMatrix
This commit is contained in:
parent
70bc179c45
commit
122b9478c6
|
@ -315,7 +315,7 @@ void ArmatureExporter::add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW:
|
|||
}
|
||||
|
||||
if (this->export_settings.get_limit_precision()) {
|
||||
bc_sanitize_mat(mat, LIMITTED_PRECISION);
|
||||
BCMatrix::sanitize(mat, LIMITTED_PRECISION);
|
||||
}
|
||||
|
||||
TransformWriter::add_joint_transform(node, mat, NULL, this->export_settings, has_restmat);
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
#include "BCMath.h"
|
||||
#include "BlenderContext.h"
|
||||
#include "collada_utils.h"
|
||||
|
||||
BCMatrix::BCMatrix(const BCMatrix &mat)
|
||||
{
|
||||
|
@ -134,7 +133,19 @@ void BCMatrix::transpose(Matrix &mat)
|
|||
|
||||
void BCMatrix::sanitize(Matrix &mat, int precision)
|
||||
{
|
||||
bc_sanitize_mat(mat, precision);
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (int j = 0; j < 4; j++) {
|
||||
double val = (double)mat[i][j];
|
||||
val = double_round(val, precision);
|
||||
mat[i][j] = (float)val;
|
||||
}
|
||||
}
|
||||
|
||||
void BCMatrix::sanitize(DMatrix &mat, int precision)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (int j = 0; j < 4; j++)
|
||||
mat[i][j] = double_round(mat[i][j], precision);
|
||||
}
|
||||
|
||||
void BCMatrix::unit()
|
||||
|
|
|
@ -32,9 +32,6 @@ class BCQuat {
|
|||
private:
|
||||
mutable Quat q;
|
||||
|
||||
void unit();
|
||||
void copy(Quat &r, Quat &a);
|
||||
|
||||
public:
|
||||
BCQuat(const BCQuat &other)
|
||||
{
|
||||
|
@ -102,7 +99,9 @@ class BCMatrix {
|
|||
void apply_transform(const BCMatrix &matrix, const bool inverted = false);
|
||||
|
||||
const bool in_range(const BCMatrix &other, float distance) const;
|
||||
|
||||
static void sanitize(Matrix &matrix, int precision);
|
||||
static void sanitize(DMatrix &matrix, int precision);
|
||||
static void transpose(Matrix &matrix);
|
||||
};
|
||||
|
||||
|
|
|
@ -75,193 +75,3 @@ const BCMatrix &BCSample::get_matrix() const
|
|||
{
|
||||
return obmat;
|
||||
}
|
||||
|
||||
BCMatrix::BCMatrix(const BCMatrix &mat)
|
||||
{
|
||||
set_transform(mat.matrix);
|
||||
}
|
||||
|
||||
BCMatrix::BCMatrix(Matrix &mat)
|
||||
{
|
||||
set_transform(mat);
|
||||
}
|
||||
|
||||
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); // TODO: Verify that mat3_from_axis_conversion() returns a transposed matrix
|
||||
copy_m4_m3(mat, mrot);
|
||||
set_transform(mat);
|
||||
}
|
||||
|
||||
void BCMatrix::add_transform(const Matrix &mat, bool inverse)
|
||||
{
|
||||
add_transform(this->matrix, mat, this->matrix, inverse);
|
||||
}
|
||||
|
||||
void BCMatrix::add_transform(const BCMatrix &mat, bool inverse)
|
||||
{
|
||||
add_transform(this->matrix, mat.matrix, this->matrix, inverse);
|
||||
}
|
||||
|
||||
void BCMatrix::apply_transform(const BCMatrix &mat, bool inverse)
|
||||
{
|
||||
apply_transform(this->matrix, mat.matrix, this->matrix, inverse);
|
||||
}
|
||||
|
||||
void BCMatrix::add_transform(Matrix &to, const Matrix &transform, const Matrix &from, bool inverse)
|
||||
{
|
||||
if (inverse) {
|
||||
Matrix globinv;
|
||||
invert_m4_m4(globinv, transform);
|
||||
add_transform(to, globinv, from, /*inverse=*/false);
|
||||
}
|
||||
else {
|
||||
mul_m4_m4m4(to, transform, from);
|
||||
}
|
||||
}
|
||||
|
||||
void BCMatrix::apply_transform(Matrix &to,
|
||||
const Matrix &transform,
|
||||
const Matrix &from,
|
||||
bool inverse)
|
||||
{
|
||||
Matrix globinv;
|
||||
invert_m4_m4(globinv, transform);
|
||||
if (inverse) {
|
||||
add_transform(to, globinv, from, /*inverse=*/false);
|
||||
}
|
||||
else {
|
||||
mul_m4_m4m4(to, transform, from);
|
||||
mul_m4_m4m4(to, to, globinv);
|
||||
}
|
||||
}
|
||||
|
||||
void BCMatrix::add_inverted_transform(Matrix &to, const Matrix &transform, const Matrix &from)
|
||||
{
|
||||
Matrix workmat;
|
||||
invert_m4_m4(workmat, transform);
|
||||
mul_m4_m4m4(to, workmat, from);
|
||||
}
|
||||
|
||||
void BCMatrix::set_transform(Object *ob)
|
||||
{
|
||||
Matrix lmat;
|
||||
|
||||
BKE_object_matrix_local_get(ob, lmat);
|
||||
copy_m4_m4(matrix, lmat);
|
||||
|
||||
mat4_decompose(this->loc, this->q, this->size, lmat);
|
||||
quat_to_compatible_eul(this->rot, ob->rot, this->q);
|
||||
}
|
||||
|
||||
void BCMatrix::set_transform(Matrix &mat)
|
||||
{
|
||||
copy_m4_m4(matrix, mat);
|
||||
mat4_decompose(this->loc, this->q, this->size, mat);
|
||||
quat_to_eul(this->rot, this->q);
|
||||
}
|
||||
|
||||
void BCMatrix::copy(Matrix &out, Matrix &in)
|
||||
{
|
||||
/* destination comes first: */
|
||||
memcpy(out, in, sizeof(Matrix));
|
||||
}
|
||||
|
||||
void BCMatrix::transpose(Matrix &mat)
|
||||
{
|
||||
transpose_m4(mat);
|
||||
}
|
||||
|
||||
void BCMatrix::sanitize(Matrix &mat, int precision)
|
||||
{
|
||||
bc_sanitize_mat(mat, precision);
|
||||
}
|
||||
|
||||
void BCMatrix::unit()
|
||||
{
|
||||
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(DMatrix &mat, const bool transposed, const int precision) 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (fabs(other.matrix[i][j] - matrix[i][j]) > distance) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
float (&BCMatrix::location() const)[3]
|
||||
{
|
||||
return loc;
|
||||
}
|
||||
|
||||
float (&BCMatrix::rotation() const)[3]
|
||||
{
|
||||
return rot;
|
||||
}
|
||||
|
||||
float (&BCMatrix::scale() const)[3]
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
float (&BCMatrix::quat() const)[4]
|
||||
{
|
||||
return q;
|
||||
}
|
||||
|
|
|
@ -50,55 +50,6 @@ void bc_set_mark(Object *ob);
|
|||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
class BCMatrix {
|
||||
|
||||
private:
|
||||
mutable float matrix[4][4];
|
||||
mutable float size[3];
|
||||
mutable float rot[3];
|
||||
mutable float loc[3];
|
||||
mutable float q[4];
|
||||
|
||||
void unit();
|
||||
void copy(Matrix &r, Matrix &a);
|
||||
|
||||
public:
|
||||
float (&location() const)[3];
|
||||
float (&rotation() const)[3];
|
||||
float (&scale() const)[3];
|
||||
float (&quat() const)[4];
|
||||
|
||||
BCMatrix(BC_global_forward_axis global_forward_axis, BC_global_up_axis global_up_axis);
|
||||
BCMatrix(const BCMatrix &mat);
|
||||
BCMatrix(Matrix &mat);
|
||||
BCMatrix(Object *ob);
|
||||
BCMatrix();
|
||||
|
||||
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;
|
||||
void set_transform(Object *ob);
|
||||
void set_transform(Matrix &mat);
|
||||
void add_transform(Matrix &to,
|
||||
const Matrix &transform,
|
||||
const Matrix &from,
|
||||
const bool inverted = false);
|
||||
void apply_transform(Matrix &to,
|
||||
const Matrix &transform,
|
||||
const Matrix &from,
|
||||
const bool inverted = false);
|
||||
void add_inverted_transform(Matrix &to, const Matrix &transform, const Matrix &from);
|
||||
void add_transform(const Matrix &matrix, const bool inverted = false);
|
||||
void add_transform(const BCMatrix &matrix, const bool inverted = false);
|
||||
void apply_transform(const BCMatrix &matrix, const bool inverted = false);
|
||||
|
||||
const bool in_range(const BCMatrix &other, float distance) const;
|
||||
static void sanitize(Matrix &matrix, int precision);
|
||||
static void transpose(Matrix &matrix);
|
||||
};
|
||||
|
||||
class BlenderContext {
|
||||
private:
|
||||
bContext *context;
|
||||
|
|
|
@ -444,7 +444,7 @@ void ControllerExporter::add_bind_shape_mat(Object *ob)
|
|||
// UnitConverter::mat4_to_dae_double(bind_mat, ob->obmat);
|
||||
UnitConverter::mat4_to_dae_double(bind_mat, f_obmat);
|
||||
if (this->export_settings.get_limit_precision()) {
|
||||
bc_sanitize_mat(bind_mat, LIMITTED_PRECISION);
|
||||
BCMatrix::sanitize(bind_mat, LIMITTED_PRECISION);
|
||||
}
|
||||
|
||||
addBindShapeTransform(bind_mat);
|
||||
|
@ -569,7 +569,7 @@ std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm,
|
|||
invert_m4_m4(mat, world);
|
||||
UnitConverter::mat4_to_dae(inv_bind_mat, mat);
|
||||
if (this->export_settings.get_limit_precision()) {
|
||||
bc_sanitize_mat(inv_bind_mat, LIMITTED_PRECISION);
|
||||
BCMatrix::sanitize(inv_bind_mat, LIMITTED_PRECISION);
|
||||
}
|
||||
source.appendValues(inv_bind_mat);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#ifdef __cplusplus
|
||||
# include <vector>
|
||||
# include "BCMath.h"
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
@ -86,8 +86,9 @@ void TransformWriter::add_node_transform_ob(COLLADASW::Node &node,
|
|||
UnitConverter converter;
|
||||
double d_obmat[4][4];
|
||||
converter.mat4_to_dae_double(d_obmat, f_obmat);
|
||||
|
||||
if (limit_precision) {
|
||||
bc_sanitize_mat(d_obmat, LIMITTED_PRECISION);
|
||||
BCMatrix::sanitize(d_obmat, LIMITTED_PRECISION);
|
||||
}
|
||||
node.addMatrix("transform", d_obmat);
|
||||
break;
|
||||
|
|
|
@ -1085,20 +1085,6 @@ void bc_create_restpose_mat(BCExportSettings &export_settings,
|
|||
loc_eulO_size_to_mat4(to_mat, loc, rot, scale, 6);
|
||||
}
|
||||
|
||||
/*
|
||||
* Make 4*4 matrices better readable
|
||||
*/
|
||||
void bc_sanitize_mat(float mat[4][4], int precision)
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
double val = (double)mat[i][j];
|
||||
val = double_round(val, precision);
|
||||
mat[i][j] = (float)val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void bc_sanitize_v3(float v[3], int precision)
|
||||
{
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
@ -1108,15 +1094,6 @@ void bc_sanitize_v3(float v[3], int precision)
|
|||
}
|
||||
}
|
||||
|
||||
void bc_sanitize_mat(double mat[4][4], int precision)
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
mat[i][j] = double_round(mat[i][j], precision);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void bc_sanitize_v3(double v[3], int precision)
|
||||
{
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
|
|
@ -217,8 +217,6 @@ void bc_copy_darray_m4d(double *r, double a[4][4]);
|
|||
void bc_copy_m4d_v44(double (&r)[4][4], std::vector<std::vector<double>> &a);
|
||||
void bc_copy_v44_m4d(std::vector<std::vector<double>> &a, double (&r)[4][4]);
|
||||
|
||||
void bc_sanitize_mat(float mat[4][4], int precision);
|
||||
void bc_sanitize_mat(double mat[4][4], int precision);
|
||||
void bc_sanitize_v3(double v[3], int precision);
|
||||
void bc_sanitize_v3(float v[3], int precision);
|
||||
|
||||
|
|
Loading…
Reference in New Issue