~ubuntu-branches/ubuntu/trusty/blender/trusty-proposed

« back to all changes in this revision

Viewing changes to source/blender/collada/AnimationExporter.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2013-08-14 10:43:49 UTC
  • mfrom: (14.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20130814104349-t1d5mtwkphp12dyj
Tags: 2.68a-3
* Upload to unstable
* debian/: python3.3 Depends simplified
  - debian/control: python3.3 Depends dropped
    for blender-data package
  - 0001-blender_thumbnailer.patch refreshed
* debian/control: libavcodec b-dep versioning dropped

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
        }
37
37
}
38
38
 
39
 
void AnimationExporter::exportAnimations(Scene *sce)
 
39
bool AnimationExporter::exportAnimations(Scene *sce)
40
40
{
41
 
        if (hasAnimations(sce)) {
 
41
        bool has_animations = hasAnimations(sce);
 
42
        if (has_animations) {
42
43
                this->scene = sce;
43
44
 
44
45
                openLibrary();
47
48
 
48
49
                closeLibrary();
49
50
        }
 
51
        return has_animations;
50
52
}
51
53
 
52
54
// called for each exported object
182
184
        ListBase *conlist = get_active_constraints(ob);
183
185
        if (conlist == NULL) return;
184
186
        bConstraint *con;
185
 
        for (con = (bConstraint*)conlist->first; con; con = con->next) {
 
187
        for (con = (bConstraint *)conlist->first; con; con = con->next) {
186
188
                ListBase targets = {NULL, NULL};
187
189
                
188
190
                bConstraintTypeInfo *cti = BKE_constraint_get_typeinfo(con);
197
199
                         *      - ct->matrix members have not yet been calculated here! 
198
200
                         */
199
201
                        cti->get_constraint_targets(con, &targets);
200
 
                        if (cti) {
201
 
                                for (ct = (bConstraintTarget*)targets.first; ct; ct = ct->next) {
202
 
                                        obtar = ct->tar;
 
202
 
 
203
                        for (ct = (bConstraintTarget *)targets.first; ct; ct = ct->next) {
 
204
                                obtar = ct->tar;
 
205
 
 
206
                                if (obtar)
203
207
                                        find_frames(obtar, frames);
204
 
                                }
205
208
                        }
 
209
 
 
210
                        if (cti->flush_constraint_targets)
 
211
                                cti->flush_constraint_targets(con, &targets, 1);
206
212
                }
207
213
        }
208
214
}
257
263
                return id_name(ob);
258
264
}
259
265
 
 
266
std::string AnimationExporter::getAnimationPathId(const FCurve *fcu)
 
267
{
 
268
        std::string rna_path = std::string(fcu->rna_path);
 
269
        return translate_id(rna_path);
 
270
}
 
271
 
260
272
//convert f-curves to animation curves and write
261
273
void AnimationExporter::dae_animation(Object *ob, FCurve *fcu, char *transformName, bool is_param, Material *ma)
262
274
{
303
315
        //Create anim Id
304
316
        if (ob->type == OB_ARMATURE) {
305
317
                ob_name =  getObjectBoneName(ob, fcu);
306
 
                BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s.%s", (char *)translate_id(ob_name).c_str(),
307
 
                             transformName, axis_name);
 
318
                BLI_snprintf(
 
319
                                anim_id,
 
320
                                sizeof(anim_id),
 
321
                                "%s_%s.%s",
 
322
                                (char *)translate_id(ob_name).c_str(),
 
323
                                (char *)translate_id(transformName).c_str(),
 
324
                                axis_name);
308
325
        }
309
326
        else {
310
327
                if (ma)
311
328
                        ob_name = id_name(ob) + "_material";
312
329
                else
313
330
                        ob_name = id_name(ob);
314
 
                BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char *)translate_id(ob_name).c_str(),
315
 
                             fcu->rna_path, axis_name);
 
331
 
 
332
                BLI_snprintf(
 
333
                                anim_id,
 
334
                                sizeof(anim_id),
 
335
                                "%s_%s_%s",
 
336
                                (char *)translate_id(ob_name).c_str(),
 
337
                                (char *)getAnimationPathId(fcu).c_str(),
 
338
                                axis_name);
316
339
        }
317
340
 
318
341
        openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
525
548
        if (!fra.size())
526
549
                return;
527
550
 
528
 
        BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s", (char*)translate_id(ob_name).c_str(),
 
551
        BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s", (char *)translate_id(ob_name).c_str(),
529
552
                     "object_matrix");
530
553
 
531
554
        openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
882
905
}
883
906
 
884
907
 
885
 
std::string AnimationExporter::create_4x4_source(std::vector<float> &frames, Object * ob, Bone *bone, const std::string& anim_id)
 
908
std::string AnimationExporter::create_4x4_source(std::vector<float> &frames, Object *ob, Bone *bone, const std::string &anim_id)
886
909
{
887
910
        COLLADASW::InputSemantic::Semantics semantic = COLLADASW::InputSemantic::OUTPUT;
888
911
        std::string source_id = anim_id + get_semantic_suffix(semantic);
901
924
        bPoseChannel *parchan = NULL;
902
925
        bPoseChannel *pchan = NULL;
903
926
 
904
 
        if (ob->type == OB_ARMATURE ) {
 
927
        if (ob->type == OB_ARMATURE && bone) {
905
928
                bPose *pose = ob->pose;
906
929
                pchan = BKE_pose_channel_find_name(pose, bone->name);
907
930
                if (!pchan)
935
958
                        // compute bone local mat
936
959
                        if (bone->parent) {
937
960
                                invert_m4_m4(ipar, parchan->pose_mat);
938
 
                                mult_m4_m4m4(mat, ipar, pchan->pose_mat);
 
961
                                mul_m4_m4m4(mat, ipar, pchan->pose_mat);
939
962
                        }
940
963
                        else
941
964
                                copy_m4_m4(mat, pchan->pose_mat);
949
972
                                temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
950
973
                                invert_m4(temp);
951
974
 
952
 
                                mult_m4_m4m4(mat, mat, temp);
 
975
                                mul_m4_m4m4(mat, mat, temp);
953
976
 
954
977
                                if (bone->parent) {
955
978
                                        copy_m4_m4(temp, bone->parent->arm_mat);
956
979
                                        temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
957
980
 
958
 
                                        mult_m4_m4m4(mat, temp, mat);
 
981
                                        mul_m4_m4m4(mat, temp, mat);
959
982
                                }
960
983
                        }
961
984
 
1474
1497
                // compute bone local mat
1475
1498
                if (bone->parent) {
1476
1499
                        invert_m4_m4(ipar, parchan->pose_mat);
1477
 
                        mult_m4_m4m4(mat, ipar, pchan->pose_mat);
 
1500
                        mul_m4_m4m4(mat, ipar, pchan->pose_mat);
1478
1501
                }
1479
1502
                else
1480
1503
                        copy_m4_m4(mat, pchan->pose_mat);
1516
1539
{
1517
1540
        ListBase *conlist = get_active_constraints(ob);
1518
1541
        bConstraint *con;
1519
 
        for (con = (bConstraint*)conlist->first; con; con = con->next) {
 
1542
        for (con = (bConstraint *)conlist->first; con; con = con->next) {
1520
1543
                ListBase targets = {NULL, NULL};
1521
1544
                
1522
1545
                bConstraintTypeInfo *cti = BKE_constraint_get_typeinfo(con);
1525
1548
                        bConstraintTarget *ct;
1526
1549
                        Object *obtar;
1527
1550
                        cti->get_constraint_targets(con, &targets);
1528
 
                        for (ct = (bConstraintTarget*)targets.first; ct; ct = ct->next) {
 
1551
                        for (ct = (bConstraintTarget *)targets.first; ct; ct = ct->next) {
1529
1552
                                obtar = ct->tar;
1530
 
                                BKE_animsys_evaluate_animdata(scene, &obtar->id, obtar->adt, ctime, ADT_RECALC_ANIM);
1531
 
                                BKE_object_where_is_calc_time(scene, obtar, ctime);
 
1553
 
 
1554
                                if (obtar) {
 
1555
                                        BKE_animsys_evaluate_animdata(scene, &obtar->id, obtar->adt, ctime, ADT_RECALC_ANIM);
 
1556
                                        BKE_object_where_is_calc_time(scene, obtar, ctime);
 
1557
                                }
1532
1558
                        }
 
1559
 
 
1560
                        if (cti->flush_constraint_targets)
 
1561
                                cti->flush_constraint_targets(con, &targets, 1);
1533
1562
                }
1534
1563
        }
1535
1564
        BKE_object_where_is_calc_time(scene, ob, ctime);