From 8664d4b98ba6cdcde44a6878dbdf4d8327a1f96e Mon Sep 17 00:00:00 2001 From: Gaia Clary Date: Wed, 6 Mar 2013 23:21:52 +0000 Subject: Collada: Added option for how rot,loc,trans data is exported (improves flexibility for support of other 3D tools) --- source/blender/collada/AnimationExporter.cpp | 6 +++-- source/blender/collada/AnimationExporter.h | 2 +- source/blender/collada/DocumentExporter.cpp | 15 +++++++++++- source/blender/collada/ExportSettings.h | 2 ++ source/blender/collada/SceneExporter.cpp | 13 ++++++++--- source/blender/collada/SceneExporter.h | 2 ++ source/blender/collada/TransformWriter.cpp | 32 ++++++++++++++++++++------ source/blender/collada/TransformWriter.h | 3 ++- source/blender/collada/collada.cpp | 10 ++++---- source/blender/collada/collada.h | 7 ++++++ source/blender/editors/io/io_collada.c | 30 ++++++++++++++++++++---- source/blender/makesrna/intern/rna_scene_api.c | 7 +++++- 12 files changed, 105 insertions(+), 24 deletions(-) diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp index a69f7918e40..983e0fece5f 100644 --- a/source/blender/collada/AnimationExporter.cpp +++ b/source/blender/collada/AnimationExporter.cpp @@ -36,9 +36,10 @@ void forEachObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set) } } -void AnimationExporter::exportAnimations(Scene *sce) +bool AnimationExporter::exportAnimations(Scene *sce) { - if (hasAnimations(sce)) { + bool has_animations = hasAnimations(sce); + if (has_animations) { this->scene = sce; openLibrary(); @@ -47,6 +48,7 @@ void AnimationExporter::exportAnimations(Scene *sce) closeLibrary(); } + return has_animations; } // called for each exported object diff --git a/source/blender/collada/AnimationExporter.h b/source/blender/collada/AnimationExporter.h index d2f50b22d02..59c338b6b64 100644 --- a/source/blender/collada/AnimationExporter.h +++ b/source/blender/collada/AnimationExporter.h @@ -98,7 +98,7 @@ public: { this->sw = sw; } - void exportAnimations(Scene *sce); + bool exportAnimations(Scene *sce); // called for each exported object void operator() (Object *ob); diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp index 09aec2a43a7..c03316e1fe5 100644 --- a/source/blender/collada/DocumentExporter.cpp +++ b/source/blender/collada/DocumentExporter.cpp @@ -266,7 +266,7 @@ void DocumentExporter::exportCurrentScene(Scene *sce) // AnimationExporter ae(&sw, this->export_settings); - ae.exportAnimations(sce); + bool has_animations = ae.exportAnimations(sce); // ArmatureExporter arm_exporter(&sw, this->export_settings); @@ -279,6 +279,19 @@ void DocumentExporter::exportCurrentScene(Scene *sce) // SceneExporter se(&sw, &arm_exporter, this->export_settings); + + if (has_animations && this->export_settings->export_transformation_type == BC_TRANSFORMATION_TYPE_MATRIX) { + // channels adressing objects is not (yet) supported + // So we force usage of , and + fprintf(stdout, + "For animated Ojects we must use decomposed elements,\n" \ + "Forcing usage of TransLocRot transformation type."); + se.setExportTransformationType(BC_TRANSFORMATION_TYPE_TRANSROTLOC); + } + else { + se.setExportTransformationType(this->export_settings->export_transformation_type); + } + se.exportScene(sce); // diff --git a/source/blender/collada/ExportSettings.h b/source/blender/collada/ExportSettings.h index ec71fb2747c..f9eb4cbc26f 100644 --- a/source/blender/collada/ExportSettings.h +++ b/source/blender/collada/ExportSettings.h @@ -27,6 +27,7 @@ #ifndef __EXPORTSETTINGS_H__ #define __EXPORTSETTINGS_H__ +#include "collada.h" #include "collada.h" struct ExportSettings { @@ -48,6 +49,7 @@ public: bool triangulate; bool use_object_instantiation; bool sort_by_name; + BC_export_transformation_type export_transformation_type; bool second_life; char *filepath; diff --git a/source/blender/collada/SceneExporter.cpp b/source/blender/collada/SceneExporter.cpp index dbf7d40b373..f3844be525e 100644 --- a/source/blender/collada/SceneExporter.cpp +++ b/source/blender/collada/SceneExporter.cpp @@ -36,7 +36,12 @@ SceneExporter::SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm, : COLLADASW::LibraryVisualScenes(sw), arm_exporter(arm), export_settings(export_settings) { } - + +void SceneExporter::setExportTransformationType(BC_export_transformation_type transformation_type) +{ + this->transformation_type = transformation_type; +} + void SceneExporter::exportScene(Scene *sce) { // @@ -84,6 +89,7 @@ void SceneExporter::exportHierarchy(Scene *sce) } } + void SceneExporter::writeNodes(Object *ob, Scene *sce) { // Add associated armature first if available @@ -130,8 +136,9 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce) if (ob->type == OB_MESH && armature_exported) // for skinned mesh we write obmat in TransformWriter::add_node_transform_identity(colladaNode); - else - TransformWriter::add_node_transform_ob(colladaNode, ob); + else { + TransformWriter::add_node_transform_ob(colladaNode, ob, this->transformation_type); + } // if (ob->type == OB_MESH) { diff --git a/source/blender/collada/SceneExporter.h b/source/blender/collada/SceneExporter.h index f438c002f91..c7c15dba2cb 100644 --- a/source/blender/collada/SceneExporter.h +++ b/source/blender/collada/SceneExporter.h @@ -97,8 +97,10 @@ class SceneExporter: COLLADASW::LibraryVisualScenes, protected TransformWriter, public: SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm, const ExportSettings *export_settings); void exportScene(Scene *sce); + void setExportTransformationType(BC_export_transformation_type transformation_type); private: + BC_export_transformation_type transformation_type; // required for writeNodes() for bone-parented objects friend class ArmatureExporter; void exportHierarchy(Scene *sce); diff --git a/source/blender/collada/TransformWriter.cpp b/source/blender/collada/TransformWriter.cpp index fa813e0b961..aa78d8b9e5d 100644 --- a/source/blender/collada/TransformWriter.cpp +++ b/source/blender/collada/TransformWriter.cpp @@ -51,13 +51,16 @@ void TransformWriter::add_node_transform(COLLADASW::Node& node, float mat[4][4], converter->mat4_to_dae_double(dmat, local); TransformBase::decompose(local, loc, rot, NULL, scale); - //if (node.getType() == COLLADASW::Node::JOINT) - node.addMatrix("transform", dmat); - //else - //add_transform(node, loc, rot, scale); + + if (node.getType() == COLLADASW::Node::JOINT) { + // XXX Why are joints handled differently ? + node.addMatrix("transform", dmat); + } + else + add_transform(node, loc, rot, scale); } -void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob) +void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob, BC_export_transformation_type transformation_type) { #if 0 float rot[3], loc[3], scale[3]; @@ -114,8 +117,23 @@ void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob) double d_obmat[4][4]; converter.mat4_to_dae_double(d_obmat, ob->obmat); - node.addMatrix("transform",d_obmat); - //add_transform(node, ob->loc, ob->rot, ob->size); + + switch (transformation_type) { + case BC_TRANSFORMATION_TYPE_MATRIX : { + node.addMatrix("transform",d_obmat); + break; + } + case BC_TRANSFORMATION_TYPE_TRANSROTLOC: { + add_transform(node, ob->loc, ob->rot, ob->size); + break; + } + case BC_TRANSFORMATION_TYPE_BOTH : { + node.addMatrix("transform",d_obmat); + add_transform(node, ob->loc, ob->rot, ob->size); + break; + } + } + } void TransformWriter::add_node_transform_identity(COLLADASW::Node& node) diff --git a/source/blender/collada/TransformWriter.h b/source/blender/collada/TransformWriter.h index d2a4b54a570..7f69a4b9c95 100644 --- a/source/blender/collada/TransformWriter.h +++ b/source/blender/collada/TransformWriter.h @@ -33,13 +33,14 @@ #include "DNA_object_types.h" #include "collada_internal.h" +#include "collada.h" class TransformWriter : protected TransformBase { protected: void add_node_transform(COLLADASW::Node& node, float mat[4][4], float parent_mat[4][4]); - void add_node_transform_ob(COLLADASW::Node& node, Object *ob); + void add_node_transform_ob(COLLADASW::Node& node, Object *ob, BC_export_transformation_type transformation_type); void add_node_transform_identity(COLLADASW::Node& node); diff --git a/source/blender/collada/collada.cpp b/source/blender/collada/collada.cpp index fc6c848ef49..1eb5ac6ca4d 100644 --- a/source/blender/collada/collada.cpp +++ b/source/blender/collada/collada.cpp @@ -78,6 +78,7 @@ int collada_export(Scene *sce, int triangulate, int use_object_instantiation, int sort_by_name, + BC_export_transformation_type export_transformation_type, int second_life) { ExportSettings export_settings; @@ -107,10 +108,11 @@ int collada_export(Scene *sce, export_settings.include_material_textures= include_material_textures != 0; export_settings.use_texture_copies = use_texture_copies != 0; - export_settings.triangulate = triangulate != 0; - export_settings.use_object_instantiation = use_object_instantiation != 0; - export_settings.sort_by_name = sort_by_name != 0; - export_settings.second_life = second_life != 0; + export_settings.triangulate = triangulate != 0; + export_settings.use_object_instantiation = use_object_instantiation != 0; + export_settings.sort_by_name = sort_by_name != 0; + export_settings.export_transformation_type = export_transformation_type; + export_settings.second_life = second_life != 0; int includeFilter = OB_REL_NONE; diff --git a/source/blender/collada/collada.h b/source/blender/collada/collada.h index 642259da7fc..305e5a69a31 100644 --- a/source/blender/collada/collada.h +++ b/source/blender/collada/collada.h @@ -41,6 +41,12 @@ typedef enum BC_export_mesh_type { BC_MESH_TYPE_RENDER } BC_export_mesh_type; +typedef enum BC_export_transformation_type { + BC_TRANSFORMATION_TYPE_MATRIX, + BC_TRANSFORMATION_TYPE_TRANSROTLOC, + BC_TRANSFORMATION_TYPE_BOTH +} BC_export_transformation_type; + struct bContext; struct Scene; @@ -70,6 +76,7 @@ int collada_export(Scene *sce, int triangulate, int use_object_instantiation, int sort_by_name, + BC_export_transformation_type export_transformation_type, int second_life); diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c index 4908c101a7c..7c47bc62aaa 100644 --- a/source/blender/editors/io/io_collada.c +++ b/source/blender/editors/io/io_collada.c @@ -95,6 +95,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) int triangulate; int use_object_instantiation; int sort_by_name; + int export_transformation_type; int second_life; if (!RNA_struct_property_is_set(op->ptr, "filepath")) { @@ -119,10 +120,11 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) use_texture_copies = RNA_boolean_get(op->ptr, "use_texture_copies"); active_uv_only = RNA_boolean_get(op->ptr, "active_uv_only"); - triangulate = RNA_boolean_get(op->ptr, "triangulate"); - use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation"); - sort_by_name = RNA_boolean_get(op->ptr, "sort_by_name"); - second_life = RNA_boolean_get(op->ptr, "second_life"); + triangulate = RNA_boolean_get(op->ptr, "triangulate"); + use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation"); + sort_by_name = RNA_boolean_get(op->ptr, "sort_by_name"); + export_transformation_type = RNA_enum_get(op->ptr, "export_transformation_type_selection"); + second_life = RNA_boolean_get(op->ptr, "second_life"); /* get editmode results */ ED_object_exit_editmode(C, 0); /* 0 = does not exit editmode */ @@ -145,6 +147,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) triangulate, use_object_instantiation, sort_by_name, + export_transformation_type, second_life)) { return OPERATOR_FINISHED; @@ -224,6 +227,12 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr) uiItemR(row, imfptr, "triangulate", 0, NULL, ICON_NONE); row = uiLayoutRow(box, FALSE); uiItemR(row, imfptr, "use_object_instantiation", 0, NULL, ICON_NONE); + + 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); + row = uiLayoutRow(box, FALSE); uiItemR(row, imfptr, "sort_by_name", 0, NULL, ICON_NONE); @@ -245,6 +254,13 @@ void WM_OT_collada_export(wmOperatorType *ot) {0, NULL, 0, NULL, NULL} }; + static EnumPropertyItem prop_bc_export_transformation_type[] = { + {BC_TRANSFORMATION_TYPE_MATRIX, "matrix", 0, "Matrix", "Use to specify transformations"}, + {BC_TRANSFORMATION_TYPE_TRANSROTLOC, "transrotloc", 0, "TransRotLoc", "Use , , to specify transformations"}, + {BC_TRANSFORMATION_TYPE_BOTH, "both", 0, "Both", "Use AND , , to specify transformations"}, + {0, NULL, 0, NULL, NULL} + }; + ot->name = "Export COLLADA"; ot->description = "Save a Collada file"; ot->idname = "WM_OT_collada_export"; @@ -308,6 +324,12 @@ void WM_OT_collada_export(wmOperatorType *ot) RNA_def_boolean(ot->srna, "sort_by_name", 0, "Sort by Object name", "Sort exported data by Object name"); + RNA_def_int(ot->srna, "export_transformation_type", 0, INT_MIN, INT_MAX, + "Transform", "Transformation type for translation, scale and rotation", INT_MIN, INT_MAX); + + RNA_def_enum(ot->srna, "export_transformation_type_selection", prop_bc_export_transformation_type, 0, + "Transform", "Transformation type for translation, scale and rotation"); + RNA_def_boolean(ot->srna, "second_life", 0, "Export for Second Life", "Compatibility mode for Second Life"); } diff --git a/source/blender/makesrna/intern/rna_scene_api.c b/source/blender/makesrna/intern/rna_scene_api.c index 54b008d0787..82f054e62e0 100644 --- a/source/blender/makesrna/intern/rna_scene_api.c +++ b/source/blender/makesrna/intern/rna_scene_api.c @@ -115,12 +115,13 @@ static void rna_Scene_collada_export( int use_ngons, int use_object_instantiation, int sort_by_name, + int export_transformation_type, int second_life) { collada_export(scene, filepath, apply_modifiers, export_mesh_type, selected, include_children, include_armatures, include_shapekeys, deform_bones_only, active_uv_only, include_uv_textures, include_material_textures, - use_texture_copies, use_ngons, use_object_instantiation, sort_by_name, second_life); + use_texture_copies, use_ngons, use_object_instantiation, sort_by_name, export_transformation_type, second_life); } #endif @@ -166,6 +167,10 @@ void RNA_api_scene(StructRNA *srna) parm = RNA_def_boolean(func, "use_object_instantiation", 1, "Use Object Instances", "Instantiate multiple Objects from same Data"); parm = RNA_def_boolean(func, "sort_by_name", 0, "Sort by Object name", "Sort exported data by Object name"); parm = RNA_def_boolean(func, "second_life", 0, "Export for Second Life", "Compatibility mode for Second Life"); + + parm = RNA_def_int(func, "export_transformation_type", 0, INT_MIN, INT_MAX, + "Transformation", "Transformation type for translation, scale and rotation", INT_MIN, INT_MAX); + RNA_def_function_ui_description(func, "Export to collada file"); #endif } -- cgit v1.2.3