fix: collada transformtype must be identical for animation export and object export

When exporting an object we can choose the transformation type 'Matrix'
or 'trans/rot/scale' When exporting an animation we have the same choice
regarding the used transformation type.

However we must make sure that animations and objects use the same
transformation type within one colleda export. The user interface is
now reworked such that the correct settings are always guaranteed.

I also reworked the tool tips
This commit is contained in:
Gaia Clary 2019-05-27 15:34:05 +02:00
parent 4db3916b60
commit bc055258d5
6 changed files with 110 additions and 45 deletions

View File

@ -133,7 +133,7 @@ void AnimationExporter::exportAnimation(Object *ob, BCAnimationSampler &sampler)
* Note: For Armatures the skeletal animation has already been exported (see above)
* However Armatures also can have Object animation.
*/
bool export_as_matrix = this->export_settings.get_export_transformation_type() ==
bool export_as_matrix = this->export_settings.get_animation_transformation_type() ==
BC_TRANSFORMATION_TYPE_MATRIX;
if (export_as_matrix) {

View File

@ -81,7 +81,8 @@ typedef struct ExportSettings {
bool use_object_instantiation;
bool use_blender_profile;
bool sort_by_name;
BC_export_transformation_type export_transformation_type;
BC_export_transformation_type object_transformation_type;
BC_export_transformation_type animation_transformation_type;
bool open_sim;
bool limit_precision;
@ -232,9 +233,14 @@ class BCExportSettings {
return export_settings.sort_by_name;
}
BC_export_transformation_type get_export_transformation_type()
BC_export_transformation_type get_object_transformation_type()
{
return export_settings.export_transformation_type;
return export_settings.object_transformation_type;
}
BC_export_transformation_type get_animation_transformation_type()
{
return export_settings.animation_transformation_type;
}
bool get_open_sim()

View File

@ -128,7 +128,7 @@ void SceneExporter::writeNode(Object *ob)
colladaNode.start();
if (ob->type == OB_MESH && armature_exported) {
/* for skinned mesh we write obmat in <bind_shape_matrix> */
TransformWriter::add_node_transform_identity(colladaNode);
TransformWriter::add_node_transform_identity(colladaNode, this->export_settings);
}
else {
TransformWriter::add_node_transform_ob(colladaNode, ob, this->export_settings);

View File

@ -30,11 +30,8 @@ void TransformWriter::add_joint_transform(COLLADASW::Node &node,
float parent_mat[4][4],
BCExportSettings &export_settings,
bool has_restmat
)
{
// bool limit_precision = export_settings.limit_precision;
float loc[3], rot[3], scale[3];
float local[4][4];
if (parent_mat) {
@ -55,14 +52,11 @@ void TransformWriter::add_joint_transform(COLLADASW::Node &node,
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()
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, NULL, scale);
add_transform(node, loc, rot, scale);
}
@ -73,7 +67,7 @@ void TransformWriter::add_node_transform_ob(COLLADASW::Node &node,
BCExportSettings &export_settings)
{
BC_export_transformation_type transformation_type =
export_settings.get_export_transformation_type();
export_settings.get_object_transformation_type();
bool limit_precision = export_settings.get_limit_precision();
/* Export the local Matrix (relative to the object parent,
@ -112,10 +106,28 @@ void TransformWriter::add_node_transform_ob(COLLADASW::Node &node,
}
}
void TransformWriter::add_node_transform_identity(COLLADASW::Node &node)
void TransformWriter::add_node_transform_identity(
COLLADASW::Node &node,
BCExportSettings &export_settings)
{
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);
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,

View File

@ -39,7 +39,7 @@ class TransformWriter {
void add_node_transform_ob(COLLADASW::Node &node, Object *ob, BCExportSettings &export_settings);
void add_node_transform_identity(COLLADASW::Node &node);
void add_node_transform_identity(COLLADASW::Node &node, BCExportSettings &export_settings);
private:
void add_transform(COLLADASW::Node &node, float loc[3], float rot[3], float scale[3]);

View File

@ -106,7 +106,8 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
int use_object_instantiation;
int use_blender_profile;
int sort_by_name;
int export_transformation_type;
int export_object_transformation_type;
int export_animation_transformation_type;
int open_sim;
int limit_precision;
@ -170,9 +171,13 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation");
use_blender_profile = RNA_boolean_get(op->ptr, "use_blender_profile");
sort_by_name = RNA_boolean_get(op->ptr, "sort_by_name");
export_transformation_type = RNA_enum_get(op->ptr, "export_transformation_type_selection");
open_sim = RNA_boolean_get(op->ptr, "open_sim");
export_object_transformation_type = RNA_enum_get(
op->ptr, "export_object_transformation_type_selection");
export_animation_transformation_type = RNA_enum_get(
op->ptr, "export_animation_transformation_type_selection");
open_sim = RNA_boolean_get(op->ptr, "open_sim");
limit_precision = RNA_boolean_get(op->ptr, "limit_precision");
keep_bind_info = RNA_boolean_get(op->ptr, "keep_bind_info");
@ -192,7 +197,6 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
export_settings.global_up = global_up;
export_settings.apply_global_orientation = apply_global_orientation != 0;
export_settings.export_mesh_type = export_mesh_type;
export_settings.export_mesh_type = export_mesh_type;
export_settings.selected = selected != 0;
export_settings.include_children = include_children != 0;
@ -213,23 +217,24 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
export_settings.use_object_instantiation = use_object_instantiation != 0;
export_settings.use_blender_profile = use_blender_profile != 0;
export_settings.sort_by_name = sort_by_name != 0;
export_settings.object_transformation_type = export_object_transformation_type;
export_settings.animation_transformation_type = export_animation_transformation_type;
export_settings.keep_smooth_curves = keep_smooth_curves != 0;
if (export_animation_type == BC_ANIMATION_EXPORT_SAMPLES) {
export_settings.export_transformation_type = export_transformation_type;
}
else {
if (export_animation_type != BC_ANIMATION_EXPORT_SAMPLES) {
// When curves are exported then we can not export as matrix
export_settings.export_transformation_type = BC_TRANSFORMATION_TYPE_TRANSROTLOC;
export_settings.animation_transformation_type = BC_TRANSFORMATION_TYPE_TRANSROTLOC;
}
if (export_settings.export_transformation_type == BC_TRANSFORMATION_TYPE_TRANSROTLOC) {
export_settings.keep_smooth_curves = keep_smooth_curves != 0;
}
else {
if (export_settings.animation_transformation_type != BC_TRANSFORMATION_TYPE_TRANSROTLOC) {
// Can not export smooth curves when Matrix export is enabled.
export_settings.keep_smooth_curves = false;
}
if (include_animations) {
export_settings.object_transformation_type = export_settings.animation_transformation_type;
}
export_settings.open_sim = open_sim != 0;
export_settings.limit_precision = limit_precision != 0;
export_settings.keep_bind_info = keep_bind_info != 0;
@ -266,10 +271,11 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
bool include_animations = RNA_boolean_get(imfptr, "include_animations");
int ui_section = RNA_enum_get(imfptr, "prop_bc_export_ui_section");
BC_export_animation_type animation_type = RNA_enum_get(imfptr,
"export_animation_type_selection");
BC_export_transformation_type transformation_type = RNA_enum_get(
imfptr, "export_transformation_type_selection");
BC_export_animation_type animation_type = RNA_enum_get(
imfptr, "export_animation_type_selection");
BC_export_transformation_type animation_transformation_type = RNA_enum_get(
imfptr, "export_animation_transformation_type_selection");
bool sampling = animation_type == BC_ANIMATION_EXPORT_SAMPLES;
@ -330,13 +336,26 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
row = uiLayoutRow(box, false);
split = uiLayoutSplit(row, 0.6f, UI_LAYOUT_ALIGN_RIGHT);
col = uiLayoutColumn(split, false);
uiItemR(col, imfptr, "apply_modifiers", 0, NULL, ICON_NONE);
col = uiLayoutColumn(split, false);
uiItemR(col, imfptr, "export_mesh_type_selection", 0, "", ICON_NONE);
uiLayoutSetEnabled(col, RNA_boolean_get(imfptr, "apply_modifiers"));
col = uiLayoutColumn(box, false);
uiItemR(col, imfptr, "triangulate", 1, NULL, ICON_NONE);
row = uiLayoutRow(box, false);
uiItemR(row, imfptr, "triangulate", 1, NULL, ICON_NONE);
split = uiLayoutSplit(row, 0.6f, UI_LAYOUT_ALIGN_RIGHT);
uiItemL(split, IFACE_("Transformation Type"), ICON_NONE);
if (RNA_boolean_get(imfptr, "include_animations")) {
uiItemR(split, imfptr, "export_animation_transformation_type_selection", 0, "", ICON_NONE);
}
else {
uiItemR(split, imfptr, "export_object_transformation_type_selection", 0, "", ICON_NONE);
}
}
else if (ui_section == BC_UI_SECTION_ARMATURE) {
/* Armature options */
@ -361,18 +380,24 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
row = uiLayoutRow(box, false);
uiItemR(row, imfptr, "export_animation_type_selection", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
uiLayoutSetEnabled(row, include_animations);
row = uiLayoutRow(box, false);
split = uiLayoutSplit(row, 0.6f, UI_LAYOUT_ALIGN_RIGHT);
uiItemL(split, IFACE_("Transformation Type"), ICON_NONE);
uiItemR(split, imfptr, "export_transformation_type_selection", 0, "", ICON_NONE);
uiLayoutSetEnabled(row, animation_type == BC_ANIMATION_EXPORT_SAMPLES);
if (RNA_boolean_get(imfptr, "include_animations")) {
uiItemR(split, imfptr, "export_animation_transformation_type_selection", 0, "", ICON_NONE);
}
else {
uiItemR(split, imfptr, "export_object_transformation_type_selection", 0, "", ICON_NONE);
}
uiLayoutSetEnabled(row, include_animations && animation_type == BC_ANIMATION_EXPORT_SAMPLES);
row = uiLayoutColumn(box, false);
uiItemR(row, imfptr, "keep_smooth_curves", 0, NULL, ICON_NONE);
uiLayoutSetEnabled(row,
include_animations &&
(transformation_type == BC_TRANSFORMATION_TYPE_TRANSROTLOC ||
(animation_transformation_type == BC_TRANSFORMATION_TYPE_TRANSROTLOC ||
animation_type == BC_ANIMATION_EXPORT_KEYS));
row = uiLayoutColumn(box, false);
@ -385,6 +410,7 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
row = uiLayoutColumn(box, false);
uiItemR(row, imfptr, "keep_flat_curves", 0, NULL, ICON_NONE);
uiLayoutSetEnabled(row, include_animations);
row = uiLayoutRow(box, false);
uiItemR(row, imfptr, "include_all_actions", 0, NULL, ICON_NONE);
@ -469,12 +495,12 @@ void WM_OT_collada_export(wmOperatorType *ot)
"matrix",
0,
"Matrix",
"Use <matrix> to specify transformations"},
"Use <matrix> representation for exported transformations"},
{BC_TRANSFORMATION_TYPE_TRANSROTLOC,
"transrotloc",
0,
"TransRotLoc",
"Use <translate>, <rotate>, <scale> to specify transformations"},
"Use <translate>, <rotate>, <scale> representation for exported transformations"},
{0, NULL, 0, NULL, NULL}};
static const EnumPropertyItem prop_bc_export_animation_type[] = {
@ -678,21 +704,42 @@ void WM_OT_collada_export(wmOperatorType *ot)
func, "sort_by_name", 0, "Sort by Object name", "Sort exported data by Object name");
RNA_def_int(func,
"export_transformation_type",
"export_object_transformation_type",
0,
INT_MIN,
INT_MAX,
"Transform",
"Transformation type for translation, scale and rotation",
"Object Transformation type for translation, scale and rotation",
INT_MIN,
INT_MAX);
RNA_def_enum(func,
"export_transformation_type_selection",
"export_object_transformation_type_selection",
prop_bc_export_transformation_type,
0,
"Transform",
"Transformation type for translation, scale and rotation");
"Object Transformation type for translation, scale and rotation");
RNA_def_int(func,
"export_animation_transformation_type",
0,
INT_MIN,
INT_MAX,
"Transform",
"Transformation type for translation, scale and rotation\n"
"Note: The Animation transformation type in the Anim Tab\n"\
"is always equal to the Object transformation type in the Geom tab",
INT_MIN,
INT_MAX);
RNA_def_enum(func,
"export_animation_transformation_type_selection",
prop_bc_export_transformation_type,
0,
"Transform",
"Transformation type for translation, scale and rotation\n"
"Note: The Animation transformation type in the Anim Tab\n"
"is always equal to the Object transformation type in the Geom tab");
RNA_def_boolean(func,
"open_sim",