From 0c8b0771f26120d557c80df1a30905c8228fd702 Mon Sep 17 00:00:00 2001 From: Gaia Clary Date: Sat, 24 Nov 2018 14:24:36 +0100 Subject: [PATCH] refactor: Collada reorganize class constructors - Class constructors without body (only attribute initialisations) can safely be kept in the class header files - Constructor variables should be initialized in the order of their definition in the header files This change is also aimed to remove a couple of build warnings from the linux builds. --- source/blender/collada/AnimationClipExporter.h | 8 ++++---- source/blender/collada/AnimationExporter.h | 9 ++++----- source/blender/collada/AnimationImporter.cpp | 5 ----- source/blender/collada/AnimationImporter.h | 6 +++++- source/blender/collada/ArmatureExporter.cpp | 9 --------- source/blender/collada/ArmatureExporter.h | 13 ++++++++++--- source/blender/collada/ControllerExporter.cpp | 12 ++---------- source/blender/collada/ControllerExporter.h | 10 ++++++++-- source/blender/collada/GeometryExporter.cpp | 6 ------ source/blender/collada/GeometryExporter.h | 8 +++++++- source/blender/collada/Materials.cpp | 4 ++-- source/blender/collada/Materials.h | 1 + source/blender/collada/SceneExporter.cpp | 6 ------ source/blender/collada/SceneExporter.h | 16 ++++++++++++---- source/blender/collada/collada_internal.h | 8 +++----- 15 files changed, 58 insertions(+), 63 deletions(-) diff --git a/source/blender/collada/AnimationClipExporter.h b/source/blender/collada/AnimationClipExporter.h index d76a3fa1380..8a9394ce88a 100644 --- a/source/blender/collada/AnimationClipExporter.h +++ b/source/blender/collada/AnimationClipExporter.h @@ -38,13 +38,13 @@ private: public: AnimationClipExporter(Depsgraph *depsgraph , COLLADASW::StreamWriter *sw, const ExportSettings *export_settings, std::vector> anim_meta) : - depsgraph(depsgraph), COLLADASW::LibraryAnimationClips(sw), + depsgraph(depsgraph), + scene(nullptr), + sw(sw), export_settings(export_settings), anim_meta(anim_meta) - { - this->sw = sw; - } + {} void exportAnimationClips(Scene *sce); }; diff --git a/source/blender/collada/AnimationExporter.h b/source/blender/collada/AnimationExporter.h index a5d3780af63..2240449f7ba 100644 --- a/source/blender/collada/AnimationExporter.h +++ b/source/blender/collada/AnimationExporter.h @@ -98,16 +98,16 @@ class AnimationExporter: COLLADASW::LibraryAnimations private: BlenderContext &blender_context; COLLADASW::StreamWriter *sw; + const ExportSettings *export_settings; public: AnimationExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): - blender_context(blender_context), COLLADASW::LibraryAnimations(sw), + blender_context(blender_context), + sw(sw), export_settings(export_settings) - { - this->sw = sw; - } + {} bool exportAnimations(); @@ -115,7 +115,6 @@ public: void operator() (Object *ob); protected: - const ExportSettings *export_settings; void export_object_constraint_animation(Object *ob); diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index b581c6647ba..e3a8e517352 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -244,11 +244,6 @@ void AnimationImporter::add_fcurves_to_object(Main *bmain, Object *ob, std::vect } } -AnimationImporter::AnimationImporter(bContext *C, UnitConverter *conv, ArmatureImporter *arm, Scene *scene) : - mContext(C), - TransformReader(conv), armature_importer(arm), scene(scene) { -} - AnimationImporter::~AnimationImporter() { // free unused FCurves diff --git a/source/blender/collada/AnimationImporter.h b/source/blender/collada/AnimationImporter.h index 2e9f69ea8cb..d6d5ad03a88 100644 --- a/source/blender/collada/AnimationImporter.h +++ b/source/blender/collada/AnimationImporter.h @@ -139,7 +139,11 @@ private: }; public: - AnimationImporter(bContext *C, UnitConverter *conv, ArmatureImporter *arm, Scene *scene); + AnimationImporter(bContext *C, UnitConverter *conv, ArmatureImporter *arm, Scene *scene) : + TransformReader(conv), + mContext(C), + armature_importer(arm), + scene(scene) {} ~AnimationImporter(); diff --git a/source/blender/collada/ArmatureExporter.cpp b/source/blender/collada/ArmatureExporter.cpp index efeca5aec35..2aa7b483110 100644 --- a/source/blender/collada/ArmatureExporter.cpp +++ b/source/blender/collada/ArmatureExporter.cpp @@ -53,15 +53,6 @@ extern "C" { #include "collada_utils.h" -// XXX exporter writes wrong data for shared armatures. A separate -// controller should be written for each armature-mesh binding how do -// we make controller ids then? -ArmatureExporter::ArmatureExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : - blender_context(blender_context), - COLLADASW::LibraryControllers(sw), export_settings(export_settings) -{ -} - // write bone nodes void ArmatureExporter::add_armature_bones( Object *ob_arm, diff --git a/source/blender/collada/ArmatureExporter.h b/source/blender/collada/ArmatureExporter.h index 977a8b9b4a5..1a8080ad613 100644 --- a/source/blender/collada/ArmatureExporter.h +++ b/source/blender/collada/ArmatureExporter.h @@ -57,7 +57,15 @@ class SceneExporter; class ArmatureExporter : public COLLADASW::LibraryControllers, protected TransformWriter, protected InstanceWriter { public: - ArmatureExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings); + + // XXX exporter writes wrong data for shared armatures. A separate + // controller should be written for each armature-mesh binding how do + // we make controller ids then? + ArmatureExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : + COLLADASW::LibraryControllers(sw), + blender_context(blender_context), + export_settings(export_settings) + {} void add_armature_bones( Object *ob_arm, @@ -68,9 +76,8 @@ public: bool add_instance_controller(Object *ob); private: - UnitConverter converter; - const ExportSettings *export_settings; BlenderContext &blender_context; + const ExportSettings *export_settings; #if 0 std::vector written_armatures; diff --git a/source/blender/collada/ControllerExporter.cpp b/source/blender/collada/ControllerExporter.cpp index 0aed3440620..7685a2b09a0 100644 --- a/source/blender/collada/ControllerExporter.cpp +++ b/source/blender/collada/ControllerExporter.cpp @@ -55,13 +55,6 @@ extern "C" { #include "collada_utils.h" -// XXX exporter writes wrong data for shared armatures. A separate -// controller should be written for each armature-mesh binding how do -// we make controller ids then? -ControllerExporter::ControllerExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : - blender_context(blender_context), - COLLADASW::LibraryControllers(sw), export_settings(export_settings) { -} bool ControllerExporter::is_skinned_mesh(Object *ob) { @@ -428,8 +421,7 @@ void ControllerExporter::add_joints_element(ListBase *defbase, void ControllerExporter::add_bind_shape_mat(Object *ob) { double bind_mat[4][4]; - - converter.mat4_to_dae_double(bind_mat, ob->obmat); + UnitConverter::mat4_to_dae_double(bind_mat, ob->obmat); addBindShapeTransform(bind_mat); } @@ -539,7 +531,7 @@ std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm, ListBas mul_m4_m4m4(world, ob_arm->obmat, bind_mat); invert_m4_m4(mat, world); - converter.mat4_to_dae(inv_bind_mat, mat); + UnitConverter::mat4_to_dae(inv_bind_mat, mat); if (this->export_settings->limit_precision) bc_sanitize_mat(inv_bind_mat, 6); source.appendValues(inv_bind_mat); diff --git a/source/blender/collada/ControllerExporter.h b/source/blender/collada/ControllerExporter.h index 6a3ea7cc023..309bdbd37f0 100644 --- a/source/blender/collada/ControllerExporter.h +++ b/source/blender/collada/ControllerExporter.h @@ -60,7 +60,14 @@ class SceneExporter; class ControllerExporter : public COLLADASW::LibraryControllers, protected TransformWriter, protected InstanceWriter { public: - ControllerExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings); + // XXX exporter writes wrong data for shared armatures. A separate + // controller should be written for each armature-mesh binding how do + // we make controller ids then? + ControllerExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : + COLLADASW::LibraryControllers(sw), + blender_context(blender_context), + export_settings(export_settings) { + } bool is_skinned_mesh(Object *ob); @@ -72,7 +79,6 @@ public: private: BlenderContext &blender_context; - UnitConverter converter; const ExportSettings *export_settings; #if 0 diff --git a/source/blender/collada/GeometryExporter.cpp b/source/blender/collada/GeometryExporter.cpp index f4ea82044a3..8b4302f3470 100644 --- a/source/blender/collada/GeometryExporter.cpp +++ b/source/blender/collada/GeometryExporter.cpp @@ -50,12 +50,6 @@ extern "C" { #include "collada_internal.h" #include "collada_utils.h" -// TODO: optimize UV sets by making indexed list with duplicates removed -GeometryExporter::GeometryExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : - blender_context(blender_context), - COLLADASW::LibraryGeometries(sw), export_settings(export_settings) -{ -} void GeometryExporter::exportGeom() { diff --git a/source/blender/collada/GeometryExporter.h b/source/blender/collada/GeometryExporter.h index a48319d778c..bd629946d01 100644 --- a/source/blender/collada/GeometryExporter.h +++ b/source/blender/collada/GeometryExporter.h @@ -75,7 +75,13 @@ class GeometryExporter : COLLADASW::LibraryGeometries Normal n; public: - GeometryExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings); + + // TODO: optimize UV sets by making indexed list with duplicates removed + GeometryExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : + COLLADASW::LibraryGeometries(sw), + blender_context(blender_context), + export_settings(export_settings) + {} void exportGeom(); diff --git a/source/blender/collada/Materials.cpp b/source/blender/collada/Materials.cpp index de0405da93a..3173c2592c4 100644 --- a/source/blender/collada/Materials.cpp +++ b/source/blender/collada/Materials.cpp @@ -24,8 +24,8 @@ MaterialNode::MaterialNode(bContext *C, Material *ma, KeyImageMap &key_image_map) : mContext(C), - effect(nullptr), material(ma), + effect(nullptr), key_image_map(&key_image_map) { ntree = prepare_material_nodetree(); @@ -34,8 +34,8 @@ MaterialNode::MaterialNode(bContext *C, Material *ma, KeyImageMap &key_image_map MaterialNode::MaterialNode(bContext *C, COLLADAFW::EffectCommon *ef, Material *ma, UidImageMap &uid_image_map) : mContext(C), - effect(ef), material(ma), + effect(ef), uid_image_map(&uid_image_map) { ntree = prepare_material_nodetree(); diff --git a/source/blender/collada/Materials.h b/source/blender/collada/Materials.h index 68a75db3481..69f64a6280d 100644 --- a/source/blender/collada/Materials.h +++ b/source/blender/collada/Materials.h @@ -53,6 +53,7 @@ private: COLLADAFW::EffectCommon *effect; UidImageMap *uid_image_map = nullptr; KeyImageMap *key_image_map = nullptr; + NodeMap node_map; bNodeTree *ntree; diff --git a/source/blender/collada/SceneExporter.cpp b/source/blender/collada/SceneExporter.cpp index 7a815e7d3e3..defeec9a52d 100644 --- a/source/blender/collada/SceneExporter.cpp +++ b/source/blender/collada/SceneExporter.cpp @@ -34,12 +34,6 @@ extern "C" { #include "SceneExporter.h" #include "collada_utils.h" -SceneExporter::SceneExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, ArmatureExporter *arm, const ExportSettings *export_settings): - blender_context(blender_context), - COLLADASW::LibraryVisualScenes(sw), arm_exporter(arm), export_settings(export_settings) -{ -} - void SceneExporter::exportScene() { ViewLayer *view_layer = blender_context.get_view_layer(); diff --git a/source/blender/collada/SceneExporter.h b/source/blender/collada/SceneExporter.h index f4868f527ab..f6525d5438d 100644 --- a/source/blender/collada/SceneExporter.h +++ b/source/blender/collada/SceneExporter.h @@ -94,18 +94,26 @@ extern "C" { class SceneExporter: COLLADASW::LibraryVisualScenes, protected TransformWriter, protected InstanceWriter { public: - SceneExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, ArmatureExporter *arm, const ExportSettings *export_settings); + + SceneExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, ArmatureExporter *arm, const ExportSettings *export_settings) : + COLLADASW::LibraryVisualScenes(sw), + blender_context(blender_context), + arm_exporter(arm), + export_settings(export_settings) + {} + void exportScene(); private: - friend class ArmatureExporter; BlenderContext &blender_context; + friend class ArmatureExporter; + ArmatureExporter *arm_exporter; + const ExportSettings *export_settings; + void exportHierarchy(); void writeNodeList(std::vector &child_objects, Object *parent); void writeNodes(Object *ob); - ArmatureExporter *arm_exporter; - const ExportSettings *export_settings; }; #endif diff --git a/source/blender/collada/collada_internal.h b/source/blender/collada/collada_internal.h index a84457f75e7..f16e3a7cf4a 100644 --- a/source/blender/collada/collada_internal.h +++ b/source/blender/collada/collada_internal.h @@ -73,11 +73,9 @@ public: // TODO need also for angle conversion, time conversion... - void dae_matrix_to_mat4_(float out[4][4], const COLLADABU::Math::Matrix4& in); - - void mat4_to_dae(float out[4][4], float in[4][4]); - - void mat4_to_dae_double(double out[4][4], float in[4][4]); + static void dae_matrix_to_mat4_(float out[4][4], const COLLADABU::Math::Matrix4& in); + static void mat4_to_dae(float out[4][4], float in[4][4]); + static void mat4_to_dae_double(double out[4][4], float in[4][4]); float(&get_rotation())[4][4]; float(&get_scale())[4][4];