This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/collada/TransformWriter.cpp
Gaia Clary 6be9d19951 Collada exporter update
Added new feature: Collada: global axis rotation upon export (UI)

The new feature allows to specify the target rest coordinate system upon export.
This allows for example to export a character that is in Blender orientation (Y forward)
to match the Secondlife orientation where (-X forward)

- Refactor:Added new utility methods to collada_utils
           Made BCMatrix class more powerfull
           moved Blender related structures into new BlenderContext class
           added class wrapper to encapsulate ExportSettings structure
           Added blender context getters to ExportSettings
           added access methods to BlenderContext into ExportSettings class
           Moved class BCMatrix into BlenderContext
           moved utility functions from collada_util into BlenderContext
           replace own function for parenting by a call to ED_object_parent_set()

- Cleanup: removed obsolete parameters from methods
           renamed parameters for better understanding
           cleanup whitespace and indentation
           removed obsolete comments
2019-05-23 12:29:20 +02:00

135 lines
4.4 KiB
C++

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/** \file
* \ingroup collada
*/
#include "BLI_math.h"
#include "BLI_sys_types.h"
#include "BKE_object.h"
#include "TransformWriter.h"
void TransformWriter::add_node_transform(COLLADASW::Node &node,
float mat[4][4],
float parent_mat[4][4],
BCExportSettings &export_settings
)
{
// bool limit_precision = export_settings.limit_precision;
float loc[3], rot[3], scale[3];
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 (export_settings.get_apply_global_orientation()) {
bc_apply_global_transform(local, export_settings.get_global_transform());
}
double dmat[4][4];
UnitConverter *converter = new UnitConverter();
converter->mat4_to_dae_double(dmat, local);
delete converter;
if (node.getType() == COLLADASW::Node::JOINT) {
// XXX Why are joints handled differently ?
// GC: I believe this is a mistake. Here we might want to
// export according to how the transformation type
// is set, see add_node_transform_ob()
node.addMatrix("transform", dmat);
}
else {
bc_decompose(local, loc, rot, NULL, scale);
add_transform(node, loc, rot, scale);
}
}
void TransformWriter::add_node_transform_ob(COLLADASW::Node &node,
Object *ob,
BCExportSettings &export_settings)
{
BC_export_transformation_type transformation_type =
export_settings.get_export_transformation_type();
bool limit_precision = export_settings.get_limit_precision();
/* Export the local Matrix (relative to the object parent,
* be it an object, bone or vertex(-tices)). */
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 (transformation_type) {
case BC_TRANSFORMATION_TYPE_MATRIX: {
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);
node.addMatrix("transform", d_obmat);
break;
}
case BC_TRANSFORMATION_TYPE_TRANSROTLOC: {
float loc[3], rot[3], scale[3];
bc_decompose(f_obmat, loc, rot, NULL, 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)
{
float loc[3] = {0.0f, 0.0f, 0.0f}, scale[3] = {1.0f, 1.0f, 1.0f}, rot[3] = {0.0f, 0.0f, 0.0f};
add_transform(node, loc, rot, scale);
}
void TransformWriter::add_transform(COLLADASW::Node &node,
float loc[3],
float rot[3],
float scale[3])
{
#if 0
node.addRotateZ("rotationZ", COLLADABU::Math::Utils::radToDegF(rot[2]));
node.addRotateY("rotationY", COLLADABU::Math::Utils::radToDegF(rot[1]));
node.addRotateX("rotationX", COLLADABU::Math::Utils::radToDegF(rot[0]));
#endif
node.addTranslate("location", loc[0], loc[1], loc[2]);
node.addRotateZ("rotationZ", RAD2DEGF(rot[2]));
node.addRotateY("rotationY", RAD2DEGF(rot[1]));
node.addRotateX("rotationX", RAD2DEGF(rot[0]));
node.addScale("scale", scale[0], scale[1], scale[2]);
}