Files
test2/source/blender/io/collada/TransformWriter.cpp
Campbell Barton e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00

127 lines
3.8 KiB
C++

/* SPDX-FileCopyrightText: 2010-2022 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup collada
*/
#include "BLI_math_matrix.h"
#include "BLI_sys_types.h"
#include "BKE_object.h"
#include "TransformWriter.h"
void TransformWriter::add_joint_transform(COLLADASW::Node &node,
float mat[4][4],
float parent_mat[4][4],
BCExportSettings &export_settings,
bool has_restmat)
{
float local[4][4];
if (parent_mat) {
float invpar[4][4];
invert_m4_m4(invpar, parent_mat);
mul_m4_m4m4(local, invpar, mat);
}
else {
copy_m4_m4(local, mat);
}
if (!has_restmat && export_settings.get_apply_global_orientation()) {
bc_apply_global_transform(local, export_settings.get_global_transform());
}
double dmat[4][4];
UnitConverter::mat4_to_dae_double(dmat, local);
if (export_settings.get_object_transformation_type() == BC_TRANSFORMATION_TYPE_MATRIX) {
node.addMatrix("transform", dmat);
}
else {
float loc[3], rot[3], scale[3];
bc_decompose(local, loc, rot, nullptr, scale);
add_transform(node, loc, rot, scale);
}
}
void TransformWriter::add_node_transform_ob(COLLADASW::Node &node,
Object *ob,
BCExportSettings &export_settings)
{
bool limit_precision = export_settings.get_limit_precision();
/* Export the local Matrix (relative to the object parent,
* be it an object, bone or vertices (one or more)). */
Matrix f_obmat;
BKE_object_matrix_local_get(ob, f_obmat);
if (export_settings.get_apply_global_orientation()) {
bc_apply_global_transform(f_obmat, export_settings.get_global_transform());
}
else {
bc_add_global_transform(f_obmat, export_settings.get_global_transform());
}
switch (export_settings.get_object_transformation_type()) {
case BC_TRANSFORMATION_TYPE_MATRIX: {
double d_obmat[4][4];
UnitConverter::mat4_to_dae_double(d_obmat, f_obmat);
if (limit_precision) {
BCMatrix::sanitize(d_obmat, LIMITTED_PRECISION);
}
node.addMatrix("transform", d_obmat);
break;
}
case BC_TRANSFORMATION_TYPE_DECOMPOSED: {
float loc[3], rot[3], scale[3];
bc_decompose(f_obmat, loc, rot, nullptr, scale);
if (limit_precision) {
bc_sanitize_v3(loc, LIMITTED_PRECISION);
bc_sanitize_v3(rot, LIMITTED_PRECISION);
bc_sanitize_v3(scale, LIMITTED_PRECISION);
}
add_transform(node, loc, rot, scale);
break;
}
}
}
void TransformWriter::add_node_transform_identity(COLLADASW::Node &node,
BCExportSettings &export_settings)
{
BC_export_transformation_type transformation_type =
export_settings.get_object_transformation_type();
switch (transformation_type) {
case BC_TRANSFORMATION_TYPE_MATRIX: {
BCMatrix mat;
DMatrix d_obmat;
mat.get_matrix(d_obmat);
node.addMatrix("transform", d_obmat);
break;
}
default: {
float loc[3] = {0.0f, 0.0f, 0.0f};
float scale[3] = {1.0f, 1.0f, 1.0f};
float rot[3] = {0.0f, 0.0f, 0.0f};
add_transform(node, loc, rot, scale);
break;
}
}
}
void TransformWriter::add_transform(COLLADASW::Node &node,
const float loc[3],
const float rot[3],
const float scale[3])
{
node.addScale("scale", scale[0], scale[1], scale[2]);
node.addRotateZ("rotationZ", RAD2DEGF(rot[2]));
node.addRotateY("rotationY", RAD2DEGF(rot[1]));
node.addRotateX("rotationX", RAD2DEGF(rot[0]));
node.addTranslate("location", loc[0], loc[1], loc[2]);
}