merged collada rework from master into blender 2.8
authorGaia Clary <gaia.clary@machinimatrix.org>
Sat, 24 Feb 2018 23:06:41 +0000 (00:06 +0100)
committerGaia Clary <gaia.clary@machinimatrix.org>
Sat, 24 Feb 2018 23:06:41 +0000 (00:06 +0100)
12 files changed:
1  2 
source/blender/collada/AnimationExporter.cpp
source/blender/collada/AnimationExporter.h
source/blender/collada/AnimationImporter.cpp
source/blender/collada/ExportSettings.h
source/blender/collada/collada.cpp
source/blender/collada/collada.h
source/blender/collada/collada_utils.cpp
source/blender/collada/collada_utils.h
source/blender/editors/io/io_collada.c
source/blender/makesrna/intern/rna_scene_api.c
source/blenderplayer/bad_level_call_stubs/stubs.c
tests/python/CMakeLists.txt

index cc772535e37b469d66e6e48a35ec5fc62724ed90,759fb1546c7da2ddba544f6f822a5a60ea250051..24e5ecb8d1030a14cefb806586511ab1bf097072
@@@ -756,14 -943,60 +944,60 @@@ void AnimationExporter::get_source_valu
        }
  }
  
+ // old function to keep compatibility for calls where offset and object are not needed
  std::string AnimationExporter::create_source_from_fcurve(COLLADASW::InputSemantic::Semantics semantic, FCurve *fcu, const std::string& anim_id, const char *axis_name)
  {
-       std::string source_id = anim_id + get_semantic_suffix(semantic);
+       return create_source_from_fcurve(semantic, fcu, anim_id, axis_name, NULL);
+ }
  
-       //bool is_angle = STREQ(fcu->rna_path, "rotation");
-       bool is_angle = false;
+ void AnimationExporter::evaluate_anim_with_constraints(Object *ob, float ctime)
+ {
+       BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, ctime, ADT_RECALC_ALL);
 -      ListBase *conlist = get_active_constraints(ob);
++      ListBase *conlist = get_active_constraints(this->eval_ctx, ob);
+       bConstraint *con;
+       for (con = (bConstraint *)conlist->first; con; con = con->next) {
+               ListBase targets = { NULL, NULL };
  
-       if (strstr(fcu->rna_path, "rotation") || strstr(fcu->rna_path,"spot_size")) is_angle = true;
+               const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
+               if (cti && cti->get_constraint_targets) {
+                       bConstraintTarget *ct;
+                       Object *obtar;
+                       cti->get_constraint_targets(con, &targets);
+                       for (ct = (bConstraintTarget *)targets.first; ct; ct = ct->next) {
+                               obtar = ct->tar;
+                               if (obtar) {
+                                       BKE_animsys_evaluate_animdata(scene, &obtar->id, obtar->adt, ctime, ADT_RECALC_ANIM);
 -                                      BKE_object_where_is_calc_time(scene, obtar, ctime);
++                                      BKE_object_where_is_calc_time(this->eval_ctx, scene, obtar, ctime);
+                               }
+                       }
+                       if (cti->flush_constraint_targets)
+                               cti->flush_constraint_targets(con, &targets, 1);
+               }
+       }
 -      BKE_object_where_is_calc_time(scene, ob, ctime);
++      BKE_object_where_is_calc_time(this->eval_ctx, scene, ob, ctime);
+ }
+ /*
+  * ob is needed to aply parent inverse information to fcurve.
+  * TODO: Here we have to step over all keyframes for each object and for each fcurve.
+  * Instead of processing each fcurve one by one, 
+  * step over the animation from keyframe to keyframe, 
+  * then create adjusted fcurves (and entries) for all affected objects.
+  * Then we would need to step through the scene only once.
+  */
+ std::string AnimationExporter::create_source_from_fcurve(COLLADASW::InputSemantic::Semantics semantic, FCurve *fcu, const std::string& anim_id, const char *axis_name, Object *ob)
+ {
+       std::string source_id = anim_id + get_semantic_suffix(semantic);
+       bool is_angle = (strstr(fcu->rna_path, "rotation") || strstr(fcu->rna_path, "spot_size"));
+       bool is_euler = strstr(fcu->rna_path, "rotation_euler");
+       bool is_translation = strstr(fcu->rna_path, "location");
+       bool is_scale = strstr(fcu->rna_path, "scale");
+       bool is_tangent = false;
+       int offset_index = 0;
  
        COLLADASW::FloatSourceF source(mSW);
        source.setId(source_id);
@@@ -936,10 -1221,11 +1222,11 @@@ std::string AnimationExporter::create_4
        int j = 0;
        for (it = frames.begin(); it != frames.end(); it++) {
                float mat[4][4], ipar[4][4];
+               float frame = *it;
  
 -              float ctime = BKE_scene_frame_get_from_ctime(scene, frame);
 -              CFRA = BKE_scene_frame_get_from_ctime(scene, frame);
 -              //BKE_scene_update_for_newframe(G.main->eval_ctx, G.main,scene,scene->lay);
 +              float ctime = BKE_scene_frame_get_from_ctime(scene, *it);
 +              CFRA = BKE_scene_frame_get_from_ctime(scene, *it);
 +              //BKE_scene_graph_update_for_newframe(G.main->eval_ctx, depsgraph, G.main,scene);
                BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, ctime, ADT_RECALC_ALL);
                                
                if (bone) {
  
                }
                else {
-                       calc_ob_mat_at_time(ob, ctime, mat);
+                       BKE_scene_frame_set(scene, ctime);
+                       Main *bmain = bc_get_main();
 -                      EvaluationContext *ev_context = bc_get_evaluation_context();
 -                      BKE_scene_update_for_newframe(ev_context, bmain, scene, scene->lay);
++                      BKE_animsys_evaluate_all_animation(bmain, scene, ctime);
+                       copy_m4_m4(mat, ob->obmat);
                }
                
                UnitConverter converter;
@@@ -1540,9 -1855,24 +1855,28 @@@ bool AnimationExporter::validateConstra
        return valid;
  }
  
- void AnimationExporter::calc_ob_mat_at_time(Object *ob, float ctime , float mat[][4])
+ #if 0
+ /*
+  * Needed for sampled animations. 
+  * This function calculates the object matrix at a given time,
+  * also taking constraints into account.
+  *
+  * XXX: Why looking at the constraints here is necessary?
+  *      Maybe this can be done better?
+  */
+ void AnimationExporter::calc_obmat_at_time(Object *ob, float ctime )
  {
++<<<<<<< HEAD
 +      ListBase *conlist = get_active_constraints(this->eval_ctx, ob);
++=======
+       BKE_scene_frame_set(scene, ctime);
+       Main *bmain = bc_get_main();
+       EvaluationContext *ev_context = bc_get_evaluation_context();
+       BKE_scene_update_for_newframe(ev_context, bmain, scene, scene->lay);
+       ListBase *conlist = get_active_constraints(ob);
++>>>>>>> master
        bConstraint *con;
        for (con = (bConstraint *)conlist->first; con; con = con->next) {
                ListBase targets = {NULL, NULL};
                                cti->flush_constraint_targets(con, &targets, 1);
                }
        }
++<<<<<<< HEAD
 +      BKE_object_where_is_calc_time(eval_ctx, scene, ob, ctime);
 +      copy_m4_m4(mat, ob->obmat);
++=======
+       BKE_object_where_is_calc_time(scene, ob, ctime);
++>>>>>>> master
  }
+ #endif
  
index 5af5d8844551c9d5756a4a8f75d702c4db2107f2,b26b0427f33665de6ae69c61948990044e3bd0d7..3bb510e51d699f8852e76f212a74705f62a4ab34
@@@ -91,11 -90,13 +91,13 @@@ private
  public:
  
        AnimationExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings):
-                       COLLADASW::LibraryAnimations(sw), export_settings(export_settings)
-                       { this->sw = sw; }
-       
+               COLLADASW::LibraryAnimations(sw),
+               export_settings(export_settings)
+       {
+               this->sw = sw;
+       }
  
 -      bool exportAnimations(Scene *sce);
 +      bool exportAnimations(const struct EvaluationContext *eval_ctx, Scene *sce);
  
        // called for each exported object
        void operator() (Object *ob); 
index 33a7527f38306a245ed1a3368f1bf1c6de1c7a0a,3b0b5708c7ce291370ad8961d7c43142f5948d95..0483449e5130c9c6ff7b19f32eb8d9d2d39eda55
@@@ -40,9 -39,10 +40,10 @@@ public
        bool include_armatures;
        bool include_shapekeys;
        bool deform_bones_only;
+       int sampling_rate;
  
        bool active_uv_only;
 -      BC_export_texture_type export_texture_type;
 +      bool include_material_textures;
        bool use_texture_copies;
  
        bool triangulate;
index 6c5fb0b33f397a1a53b62f98d9133251ab09e133,718ae1d876b4bacdde44b51322cf6d2cd20987ea..286444882e407685c935d6f53139fe2a8914e6ad
@@@ -37,6 -37,6 +37,7 @@@ extern "C
  {
  #include "BKE_scene.h"
  #include "BKE_context.h"
++#include "DEG_depsgraph.h"
  
  /* make dummy file */
  #include "BLI_fileops.h"
@@@ -80,9 -78,10 +79,10 @@@ int collada_export(bContext *C
                     int include_armatures,
                                   int include_shapekeys,
                     int deform_bones_only,
+                    int sampling_rate,
  
                                   int active_uv_only,
 -                                 BC_export_texture_type export_texture_type,
 +                                 int include_material_textures,
                                   int use_texture_copies,
  
                     int triangulate,
  {
        ExportSettings export_settings;
  
++      EvaluationContext eval_ctx;
++      CTX_data_eval_ctx(C, &eval_ctx);
++      Scene *sce = CTX_data_scene(C);
++      ViewLayer *view_layer = CTX_data_view_layer(C);
++
        export_settings.filepath                 = (char *)filepath;
  
        export_settings.apply_modifiers          = apply_modifiers != 0;
        export_settings.include_armatures        = include_armatures != 0;
        export_settings.include_shapekeys        = include_shapekeys != 0;
        export_settings.deform_bones_only        = deform_bones_only != 0;
+       export_settings.sampling_rate            = sampling_rate;
  
        export_settings.active_uv_only           = active_uv_only != 0;
 -      export_settings.export_texture_type      = export_texture_type;
 +      export_settings.include_material_textures= include_material_textures != 0;
        export_settings.use_texture_copies       = use_texture_copies != 0;
  
        export_settings.triangulate                = triangulate != 0;
        if (export_settings.include_children) includeFilter |= OB_REL_CHILDREN_RECURSIVE;
  
        eObjectSet objectSet = (export_settings.selected) ? OB_SET_SELECTED : OB_SET_ALL;
 -      Scene *sce = CTX_data_scene(C);
 -      export_settings.export_set = BKE_object_relational_superset(sce, objectSet, (eObRelationTypes)includeFilter);
++
 +      export_settings.export_set = BKE_object_relational_superset(view_layer, objectSet, (eObRelationTypes)includeFilter);
++
        int export_count = BLI_linklist_count(export_settings.export_set);
  
        if (export_count == 0) {
        }
  
        DocumentExporter exporter(&export_settings);
-       int status = exporter.exportCurrentScene(eval_ctx, sce);
 -      int status = exporter.exportCurrentScene(sce);
++      int status = exporter.exportCurrentScene(&eval_ctx, sce);
  
        BLI_linklist_free(export_settings.export_set, NULL);
  
index eb3964f9cb7b377853ffa2e8b1239f1c58d9cdbf,e546e1f10567d3da8c218a0538e7b7997cf7e2ff..89853b8849f3db2c4d2581be1333d75de8d8a469
@@@ -76,9 -77,10 +74,10 @@@ int collada_export(struct bContext *C
                     int include_armatures,
                     int include_shapekeys,
                     int deform_bones_only,
+                    int sampling_rate,
  
                     int active_uv_only,
 -                   BC_export_texture_type export_texture_type,
 +                   int include_material_textures,
                     int use_texture_copies,
  
                     int triangulate,
index 117e2ef7f76f74d85901f04227e94f8c028e5d7d,9f984a33ed12502f605fa0cf1c766c228d36b15a..99eca373e4e4ed99e7935368d7cc23cbc53c9c84
@@@ -135,7 -133,18 +136,23 @@@ int bc_set_parent(Object *ob, Object *p
        return true;
  }
  
 -Object *bc_add_object(Scene *scene, int type, const char *name)
++Scene *bc_get_scene(bContext *C)
++{
++      return CTX_data_scene(C);
++}
++
+ Main *bc_get_main()
+ {
+       return G.main;
+ }
+ EvaluationContext *bc_get_evaluation_context()
+ {
+       Main *bmain = G.main;
+       return bmain->eval_ctx;
+ }
 +Object *bc_add_object(Scene *scene, ViewLayer *view_layer, int type, const char *name)
  {
        Object *ob = BKE_object_add_only_object(G.main, type, name);
  
index e3a1610586104db32f9edc32929c59afc2aa5abb,8b5903b9746c78b7fe34ca27537403e8146bcfd7..43fcdf66dce4a13885c89cb5b67acc6dcd74f967
@@@ -60,10 -61,11 +60,14 @@@ extern "C" 
  #include "ExportSettings.h"
  #include "collada_internal.h"
  
 +struct EvaluationContext;
 +
  typedef std::map<COLLADAFW::TextureMapId, std::vector<MTex *> > TexIndexTextureArrayMap;
  
++extern Scene *bc_get_scene(bContext *C);
+ extern Main *bc_get_main();
+ extern EvaluationContext *bc_get_evaluation_context();
  extern float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray& array, unsigned int index);
  extern int bc_test_parent_loop(Object *par, Object *ob);
  extern int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space = true);
index 1b7fd319da0ba239054a6987be6eeeb94d10a87e,7f5442bbca4cd257e7413d4ae5d25ee04bda040d..98c88ba5fc9a522b7224603bd199a6f290246cd2
@@@ -91,8 -86,9 +91,9 @@@ static int wm_collada_export_exec(bCont
        int include_armatures;
        int include_shapekeys;
        int deform_bones_only;
+       int sampling_rate;
  
 -      int export_texture_type;
 +      int include_material_textures;
        int use_texture_copies;
        int active_uv_only;
  
        include_children         = RNA_boolean_get(op->ptr, "include_children");
        include_armatures        = RNA_boolean_get(op->ptr, "include_armatures");
        include_shapekeys        = RNA_boolean_get(op->ptr, "include_shapekeys");
+       sampling_rate             = RNA_int_get(op->ptr,     "sampling_rate");
        deform_bones_only        = RNA_boolean_get(op->ptr, "deform_bones_only");
  
 -      export_texture_type      = RNA_enum_get(op->ptr, "export_texture_type_selection");
 +      include_material_textures = RNA_boolean_get(op->ptr, "include_material_textures");
        use_texture_copies       = RNA_boolean_get(op->ptr, "use_texture_copies");
        active_uv_only           = RNA_boolean_get(op->ptr, "active_uv_only");
  
        /* get editmode results */
        ED_object_editmode_load(CTX_data_edit_object(C));
  
--
-       export_count = collada_export(&eval_ctx,
-               CTX_data_scene(C),
-               CTX_data_view_layer(C),
+       export_count = collada_export(C,
                filepath,
                apply_modifiers,
                export_mesh_type,
                include_armatures,
                include_shapekeys,
                deform_bones_only,
+               sampling_rate,
  
                active_uv_only,
 -              export_texture_type,
 +              include_material_textures,
                use_texture_copies,
  
                triangulate,
@@@ -369,9 -374,11 +374,12 @@@ void WM_OT_collada_export(wmOperatorTyp
                        "Export all Shape Keys from Mesh Objects");
  
        RNA_def_boolean(func, "deform_bones_only", 0, "Deform Bones only",
-                       "Only export deforming bones with armatures");
+                       "Only export deforming bones with armatures");
+       RNA_def_int(func, "sampling_rate", 0, -1, INT_MAX,
+               "Samplintg Rate", "The maximum distance of frames between 2 keyframes. Disabled when value is -1", -1, INT_MAX);
  
 +
        RNA_def_boolean(func, "active_uv_only", 0, "Only Selected UV Map",
                        "Export only the selected UV Map");
  
index f99803a1d99844f8ffd461ba5642f07e49b8635d,d641ee123668168945101a86ac9d0b99507ed64f..580b4d3410674374fd3113a203ecccc6def17fdc
@@@ -307,8 -278,9 +306,9 @@@ static void rna_Scene_collada_export
          int include_armatures,
          int include_shapekeys,
          int deform_bones_only,
+         int sampling_rate,
          int active_uv_only,
 -        int export_texture_type,
 +        int include_material_textures,
          int use_texture_copies,
          int triangulate,
          int use_object_instantiation,
                include_armatures,
                include_shapekeys,
                deform_bones_only,
+               sampling_rate,
  
                active_uv_only,
 -              export_texture_type,
 +              include_material_textures,
                use_texture_copies,
  
                triangulate,
@@@ -438,10 -403,13 +434,13 @@@ void RNA_api_scene(StructRNA *srna
        RNA_def_boolean(func, "deform_bones_only", false,
                        "Deform Bones only", "Only export deforming bones with armatures");
  
+       RNA_def_int(func, "sampling_rate", 0, -1, INT_MAX,
+               "Samplintg Rate", "The maximum distance of frames between 2 keyframes. Disabled when value is -1", -1, INT_MAX);
        RNA_def_boolean(func, "active_uv_only", false, "Only Selected UV Map", "Export only the selected UV Map");
  
 -      RNA_def_int(func, "export_texture_type", 0, INT_MIN, INT_MAX,
 -              "Texture Type", "Type for exported Textures (UV or MAT)", INT_MIN, INT_MAX);
 +      RNA_def_boolean(func, "include_material_textures", false,
 +                      "Include Material Textures", "Export textures assigned to the object Materials");
  
        RNA_def_boolean(func, "use_texture_copies", true,
                        "Copy", "Copy textures to same folder where the .dae file is exported");
index a0cb8ed8c98a6d815136cfa526b9f83ec5497ad2,85ed589dd78a0e716ab9001387eb88646e883e53..28f413299a53d9730c59d28faf8be279a3cc58e2
@@@ -838,9 -739,10 +838,10 @@@ int collada_export(const struct Evaluat
                     int include_armatures,
                     int include_shapekeys,
                     int deform_bones_only,
+                    int sampling_rate,
  
                     int active_uv_only,
 -                   BC_export_texture_type export_texture_type,
 +                   int include_material_textures,
                     int use_texture_copies,
  
                     int triangulate,
index f973488d6573c8b8cef6e0bf3e8b0f1b089761c2,6419c3f36e2aa70bca608044ef33c82dce6e06ef..20b65889c2bf83f7c1f161c753a4f04a9edc60ae
@@@ -617,4 -617,4 +617,5 @@@ if(WITH_ALEMBIC
        )
  endif()
  
 +add_subdirectory(view_layer)
+ add_subdirectory(collada)