~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/editors/armature/poseUtils.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: poseUtils.c 27676 2010-03-23 14:09:09Z campbellbarton $
3
 
 *
 
1
/*
4
2
 * ***** BEGIN GPL LICENSE BLOCK *****
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or
25
23
 * ***** END GPL LICENSE BLOCK *****
26
24
 */
27
25
 
 
26
/** \file blender/editors/armature/poseUtils.c
 
27
 *  \ingroup edarmature
 
28
 */
 
29
 
 
30
 
28
31
#include <stdlib.h>
29
32
#include <stdio.h>
30
33
#include <stddef.h>
38
41
#include "BLI_blenlib.h"
39
42
#include "BLI_dynstr.h"
40
43
#include "BLI_dlrbTree.h"
 
44
#include "BLI_utildefines.h"
41
45
 
42
46
#include "DNA_anim_types.h"
43
47
#include "DNA_armature_types.h"
44
48
#include "DNA_object_types.h"
45
49
#include "DNA_scene_types.h"
46
50
 
47
 
#include "BKE_animsys.h"
48
51
#include "BKE_action.h"
49
52
#include "BKE_armature.h"
50
53
#include "BKE_depsgraph.h"
51
 
#include "BKE_fcurve.h"
52
 
#include "BKE_object.h"
 
54
#include "BKE_idprop.h"
53
55
 
54
 
#include "BKE_global.h"
55
56
#include "BKE_context.h"
56
 
#include "BKE_report.h"
57
 
#include "BKE_utildefines.h"
58
57
 
59
58
#include "RNA_access.h"
60
59
 
62
61
#include "WM_types.h"
63
62
 
64
63
 
65
 
#include "BIF_gl.h"
66
64
 
67
65
#include "ED_armature.h"
68
66
#include "ED_keyframing.h"
113
111
                        pchan->flag |= POSE_SIZE;
114
112
                        
115
113
                /* store current transforms */
116
 
                // TODO: store axis-angle too?
117
 
                VECCOPY(pfl->oldloc, pchan->loc);
118
 
                VECCOPY(pfl->oldrot, pchan->eul);
119
 
                VECCOPY(pfl->oldscale, pchan->size);
120
 
                QUATCOPY(pfl->oldquat, pchan->quat);
 
114
                copy_v3_v3(pfl->oldloc, pchan->loc);
 
115
                copy_v3_v3(pfl->oldrot, pchan->eul);
 
116
                copy_v3_v3(pfl->oldscale, pchan->size);
 
117
                copy_qt_qt(pfl->oldquat, pchan->quat);
 
118
                copy_v3_v3(pfl->oldaxis, pchan->rotAxis);
 
119
                pfl->oldangle = pchan->rotAngle;
 
120
                
 
121
                /* make copy of custom properties */
 
122
                if (pchan->prop && (transFlags & ACT_TRANS_PROP))
 
123
                        pfl->oldprops = IDP_CopyProperty(pchan->prop);
121
124
        }
122
125
123
126
 
124
127
 
125
128
/* get sets of F-Curves providing transforms for the bones in the Pose  */
126
 
// TODO: separate the inner workings out to another helper func, since we need option of whether to take selected or visible bones...
127
129
void poseAnim_mapping_get (bContext *C, ListBase *pfLinks, Object *ob, bAction *act)
128
130
{       
129
131
        /* for each Pose-Channel which gets affected, get the F-Curves for that channel 
134
136
                fcurves_to_pchan_links_get(pfLinks, ob, act, pchan);
135
137
        }
136
138
        CTX_DATA_END;
 
139
        
 
140
        /* if no PoseChannels were found, try a second pass, doing visible ones instead
 
141
         * i.e. if nothing selected, do whole pose
 
142
         */
 
143
        if (pfLinks->first == NULL) {
 
144
                CTX_DATA_BEGIN(C, bPoseChannel*, pchan, visible_pose_bones)
 
145
                {
 
146
                        fcurves_to_pchan_links_get(pfLinks, ob, act, pchan);
 
147
                }
 
148
                CTX_DATA_END;
 
149
        }
137
150
}
138
151
 
139
152
/* free F-Curve <-> PoseChannel links  */
145
158
        for (pfl= pfLinks->first; pfl; pfl= pfln) {
146
159
                pfln= pfl->next;
147
160
                
 
161
                /* free custom properties */
 
162
                if (pfl->oldprops) {
 
163
                        IDP_FreeProperty(pfl->oldprops);
 
164
                        MEM_freeN(pfl->oldprops);
 
165
                }
 
166
                
148
167
                /* free list of F-Curve reference links */
149
168
                BLI_freelistN(&pfl->fcurves);
150
169
                
168
187
         */
169
188
        // FIXME: shouldn't this use the builtin stuff?
170
189
        if ((arm->flag & ARM_DELAYDEFORM)==0)
171
 
                DAG_id_flush_update(&ob->id, OB_RECALC_DATA);  /* sets recalc flags */
 
190
                DAG_id_tag_update(&ob->id, OB_RECALC_DATA);  /* sets recalc flags */
172
191
        else
173
192
                where_is_pose(scene, ob);
174
193
        
186
205
                bPoseChannel *pchan= pfl->pchan;
187
206
                
188
207
                /* just copy all the values over regardless of whether they changed or not */
189
 
                // TODO; include axis-angle here too?
190
 
                VECCOPY(pchan->loc, pfl->oldloc);
191
 
                VECCOPY(pchan->eul, pfl->oldrot);
192
 
                VECCOPY(pchan->size, pfl->oldscale);
193
 
                QUATCOPY(pchan->quat, pfl->oldquat);
 
208
                copy_v3_v3(pchan->loc, pfl->oldloc);
 
209
                copy_v3_v3(pchan->eul, pfl->oldrot);
 
210
                copy_v3_v3(pchan->size, pfl->oldscale);
 
211
                copy_qt_qt(pchan->quat, pfl->oldquat);
 
212
                copy_v3_v3(pchan->rotAxis, pfl->oldaxis);
 
213
                pchan->rotAngle = pfl->oldangle;
 
214
                
 
215
                /* just overwrite values of properties from the stored copies (there should be some) */
 
216
                if (pfl->oldprops)
 
217
                        IDP_SyncGroupValues(pfl->pchan->prop, pfl->oldprops);
194
218
        }
195
219
}
196
220
 
197
221
/* perform autokeyframing after changes were made + confirmed */
198
222
void poseAnim_mapping_autoKeyframe (bContext *C, Scene *scene, Object *ob, ListBase *pfLinks, float cframe)
199
223
{
200
 
        static short keyingsets_need_init = 1;
201
 
        static KeyingSet *ks_loc = NULL;
202
 
        static KeyingSet *ks_rot = NULL;
203
 
        static KeyingSet *ks_scale = NULL;
204
 
        
205
 
        /* get keyingsets the first time this is run? 
206
 
         * NOTE: it should be safe to store these static, since they're currently builtin ones
207
 
         * but maybe later this may change, in which case this code needs to be revised!
208
 
         */
209
 
        if (keyingsets_need_init) {
210
 
                ks_loc= ANIM_builtin_keyingset_get_named(NULL, "Location");
211
 
                ks_rot= ANIM_builtin_keyingset_get_named(NULL, "Rotation");
212
 
                ks_scale= ANIM_builtin_keyingset_get_named(NULL, "Scaling");
213
 
                
214
 
                keyingsets_need_init = 0;
215
 
        }
216
 
        
217
224
        /* insert keyframes as necessary if autokeyframing */
218
225
        if (autokeyframe_cfra_can_key(scene, &ob->id)) {
 
226
                KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, ANIM_KS_WHOLE_CHARACTER_ID);
 
227
                ListBase dsources = {NULL, NULL};
219
228
                tPChanFCurveLink *pfl;
220
229
                
221
 
                /* iterate over each pose-channel affected, applying the changes */
 
230
                /* iterate over each pose-channel affected, tagging bones to be keyed */
 
231
                /* XXX: here we already have the information about what transforms exist, though 
 
232
                 * it might be easier to just overwrite all using normal mechanisms
 
233
                 */
222
234
                for (pfl= pfLinks->first; pfl; pfl= pfl->next) {
223
 
                        ListBase dsources = {NULL, NULL};
224
235
                        bPoseChannel *pchan= pfl->pchan;
225
236
                        
226
 
                        /* add datasource override for the PoseChannel so KeyingSet will do right thing */
 
237
                        /* add datasource override for the PoseChannel, to be used later */
227
238
                        ANIM_relative_keyingset_add_source(&dsources, &ob->id, &RNA_PoseBone, pchan); 
228
239
                        
229
 
                        /* insert keyframes 
230
 
                         *      - these keyingsets here use dsources, since we need to specify exactly which keyframes get affected
231
 
                         */
232
 
                        if (pchan->flag & POSE_LOC)
233
 
                                ANIM_apply_keyingset(C, &dsources, NULL, ks_loc, MODIFYKEY_MODE_INSERT, cframe);
234
 
                        if (pchan->flag & POSE_ROT)
235
 
                                ANIM_apply_keyingset(C, &dsources, NULL, ks_rot, MODIFYKEY_MODE_INSERT, cframe);
236
 
                        if (pchan->flag & POSE_SIZE)
237
 
                                ANIM_apply_keyingset(C, &dsources, NULL, ks_scale, MODIFYKEY_MODE_INSERT, cframe);
238
 
                                
239
 
                        /* free the temp info */
240
 
                        BLI_freelistN(&dsources);
 
240
                        /* clear any unkeyed tags */
 
241
                        if (pchan->bone)
 
242
                                pchan->bone->flag &= ~BONE_UNKEYED;
 
243
                }
 
244
                
 
245
                /* insert keyframes for all relevant bones in one go */
 
246
                ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cframe);
 
247
                BLI_freelistN(&dsources);
 
248
                
 
249
                /* do the bone paths
 
250
                 *      - only do this if keyframes should have been added
 
251
                 *      - do not calculate unless there are paths already to update...
 
252
                 */
 
253
                if (C && (ob->pose->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS)) {
 
254
                        //ED_pose_clear_paths(C, ob); // XXX for now, don't need to clear
 
255
                        ED_pose_recalculate_paths(scene, ob);
241
256
                }
242
257
        }
243
258
}
247
262
/* find the next F-Curve for a PoseChannel with matching path... 
248
263
 *      - path is not just the pfl rna_path, since that path doesn't have property info yet
249
264
 */
250
 
LinkData *poseAnim_mapping_getNextFCurve (ListBase *fcuLinks, LinkData *prev, char *path)
 
265
LinkData *poseAnim_mapping_getNextFCurve (ListBase *fcuLinks, LinkData *prev, const char *path)
251
266
{
252
267
        LinkData *first= (prev)? prev->next : (fcuLinks)? fcuLinks->first : NULL;
253
268
        LinkData *ld;