Blender  V2.93
rna_nla.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include <stdlib.h>
22 
23 #include "DNA_action_types.h"
24 #include "DNA_anim_types.h"
25 #include "DNA_scene_types.h"
26 
27 #include "BLI_utildefines.h"
28 
29 #include "MEM_guardedalloc.h"
30 
31 #include "RNA_access.h"
32 #include "RNA_define.h"
33 #include "RNA_enum_types.h"
34 
35 #include "rna_internal.h"
36 
37 #include "WM_api.h"
38 #include "WM_types.h"
39 
40 #ifdef RNA_RUNTIME
41 
42 # include <math.h>
43 # include <stdio.h>
44 
45 /* needed for some of the validation stuff... */
46 # include "BKE_anim_data.h"
47 # include "BKE_fcurve.h"
48 # include "BKE_nla.h"
49 
50 # include "DNA_object_types.h"
51 
52 # include "ED_anim_api.h"
53 
54 # include "DEG_depsgraph.h"
55 # include "DEG_depsgraph_build.h"
56 
57 /* temp constant defined for these funcs only... */
58 # define NLASTRIP_MIN_LEN_THRESH 0.1f
59 
60 static void rna_NlaStrip_name_set(PointerRNA *ptr, const char *value)
61 {
62  NlaStrip *data = (NlaStrip *)ptr->data;
63 
64  /* copy the name first */
65  BLI_strncpy_utf8(data->name, value, sizeof(data->name));
66 
67  /* validate if there's enough info to do so */
68  if (ptr->owner_id) {
71  }
72 }
73 
74 static char *rna_NlaStrip_path(PointerRNA *ptr)
75 {
76  NlaStrip *strip = (NlaStrip *)ptr->data;
78 
79  /* if we're attached to AnimData, try to resolve path back to AnimData */
80  if (adt) {
81  NlaTrack *nlt;
82  NlaStrip *nls;
83 
84  for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) {
85  for (nls = nlt->strips.first; nls; nls = nls->next) {
86  if (nls == strip) {
87  /* XXX but if we animate like this, the control will never work... */
88  char name_esc_nlt[sizeof(nlt->name) * 2];
89  char name_esc_strip[sizeof(strip->name) * 2];
90 
91  BLI_str_escape(name_esc_nlt, nlt->name, sizeof(name_esc_nlt));
92  BLI_str_escape(name_esc_strip, strip->name, sizeof(name_esc_strip));
93  return BLI_sprintfN(
94  "animation_data.nla_tracks[\"%s\"].strips[\"%s\"]", name_esc_nlt, name_esc_strip);
95  }
96  }
97  }
98  }
99 
100  /* no path */
101  return BLI_strdup("");
102 }
103 
104 static void rna_NlaStrip_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
105 {
106  ID *id = ptr->owner_id;
107 
108  ANIM_id_update(bmain, id);
109 }
110 
111 static void rna_NlaStrip_dependency_update(Main *bmain, Scene *scene, PointerRNA *ptr)
112 {
114 
115  rna_NlaStrip_update(bmain, scene, ptr);
116 }
117 
118 static void rna_NlaStrip_transform_update(Main *bmain, Scene *scene, PointerRNA *ptr)
119 {
120  NlaStrip *strip = (NlaStrip *)ptr->data;
121 
123 
124  /* set the flag */
125  if ((strip->flag & NLASTRIP_FLAG_AUTO_BLENDS) && ptr->owner_id) {
126  /* validate state to ensure that auto-blend gets applied immediately */
128 
129  if (iat->adt) {
131  }
132  }
133 
134  rna_NlaStrip_update(bmain, scene, ptr);
135 }
136 
137 static void rna_NlaStrip_start_frame_set(PointerRNA *ptr, float value)
138 {
139  NlaStrip *data = (NlaStrip *)ptr->data;
140 
141  /* Clamp value to lie within valid limits:
142  * - Cannot start past the end of the strip + some flexibility threshold.
143  * - Cannot start before the previous strip (if present) ends.
144  * -> But if it was a transition,
145  * we could go up to the start of the strip + some flexibility threshold.
146  * as long as we re-adjust the transition afterwards.
147  * - Minimum frame is -MAXFRAME so that we don't get clipping on frame 0.
148  */
149  if (data->prev) {
150  if (data->prev->type == NLASTRIP_TYPE_TRANSITION) {
151  CLAMP(
152  value, data->prev->start + NLASTRIP_MIN_LEN_THRESH, data->end - NLASTRIP_MIN_LEN_THRESH);
153 
154  /* re-adjust the transition to stick to the endpoints of the action-clips */
155  data->prev->end = value;
156  }
157  else {
158  CLAMP(value, data->prev->end, data->end - NLASTRIP_MIN_LEN_THRESH);
159  }
160  }
161  else {
162  CLAMP(value, MINAFRAME, data->end);
163  }
164  data->start = value;
165 }
166 
167 static void rna_NlaStrip_end_frame_set(PointerRNA *ptr, float value)
168 {
169  NlaStrip *data = (NlaStrip *)ptr->data;
170 
171  /* clamp value to lie within valid limits
172  * - must not have zero or negative length strip, so cannot start before the first frame
173  * + some minimum-strip-length threshold
174  * - cannot end later than the start of the next strip (if present)
175  * -> but if it was a transition,
176  * we could go up to the start of the end - some flexibility threshold
177  * as long as we re-adjust the transition afterwards
178  */
179  if (data->next) {
180  if (data->next->type == NLASTRIP_TYPE_TRANSITION) {
181  CLAMP(
182  value, data->start + NLASTRIP_MIN_LEN_THRESH, data->next->end - NLASTRIP_MIN_LEN_THRESH);
183 
184  /* readjust the transition to stick to the endpoints of the action-clips */
185  data->next->start = value;
186  }
187  else {
188  CLAMP(value, data->start + NLASTRIP_MIN_LEN_THRESH, data->next->start);
189  }
190  }
191  else {
192  CLAMP(value, data->start + NLASTRIP_MIN_LEN_THRESH, MAXFRAME);
193  }
194  data->end = value;
195 
196  /* calculate the lengths the strip and its action (if applicable) */
197  if (data->type == NLASTRIP_TYPE_CLIP) {
198  float len, actlen;
199 
200  len = data->end - data->start;
201  actlen = data->actend - data->actstart;
202  if (IS_EQF(actlen, 0.0f)) {
203  actlen = 1.0f;
204  }
205 
206  /* now, adjust the 'scale' setting to reflect this (so that this change can be valid) */
207  data->scale = len / ((actlen)*data->repeat);
208  }
209 }
210 
211 static void rna_NlaStrip_scale_set(PointerRNA *ptr, float value)
212 {
213  NlaStrip *data = (NlaStrip *)ptr->data;
214 
215  /* set scale value */
216  /* NOTE: these need to be synced with the values in the
217  * property definition in rna_def_nlastrip() */
218  CLAMP(value, 0.0001f, 1000.0f);
219  data->scale = value;
220 
221  /* adjust the strip extents in response to this */
223 }
224 
225 static void rna_NlaStrip_repeat_set(PointerRNA *ptr, float value)
226 {
227  NlaStrip *data = (NlaStrip *)ptr->data;
228 
229  /* set repeat value */
230  /* NOTE: these need to be synced with the values in the
231  * property definition in rna_def_nlastrip() */
232  CLAMP(value, 0.01f, 1000.0f);
233  data->repeat = value;
234 
235  /* adjust the strip extents in response to this */
237 }
238 
239 static void rna_NlaStrip_blend_in_set(PointerRNA *ptr, float value)
240 {
241  NlaStrip *data = (NlaStrip *)ptr->data;
242  float len;
243 
244  /* blend-in is limited to the length of the strip, and also cannot overlap with blendout */
245  len = (data->end - data->start) - data->blendout;
246  CLAMP(value, 0, len);
247 
248  data->blendin = value;
249 }
250 
251 static void rna_NlaStrip_blend_out_set(PointerRNA *ptr, float value)
252 {
253  NlaStrip *data = (NlaStrip *)ptr->data;
254  float len;
255 
256  /* blend-out is limited to the length of the strip */
257  len = (data->end - data->start);
258  CLAMP(value, 0, len);
259 
260  /* it also cannot overlap with blendin */
261  if ((len - value) < data->blendin) {
262  value = len - data->blendin;
263  }
264 
265  data->blendout = value;
266 }
267 
268 static void rna_NlaStrip_use_auto_blend_set(PointerRNA *ptr, bool value)
269 {
270  NlaStrip *data = (NlaStrip *)ptr->data;
271 
272  if (value) {
273  /* set the flag */
275 
276  /* validate state to ensure that auto-blend gets applied immediately */
277  if (ptr->owner_id) {
279 
280  if (iat->adt) {
282  }
283  }
284  }
285  else {
286  /* clear the flag */
288 
289  /* clear the values too, so that it's clear that there has been an effect */
290  /* TODO: it's somewhat debatable whether it's better to leave these in instead... */
291  data->blendin = 0.0f;
292  data->blendout = 0.0f;
293  }
294 }
295 
296 static int rna_NlaStrip_action_editable(PointerRNA *ptr, const char **UNUSED(r_info))
297 {
298  NlaStrip *strip = (NlaStrip *)ptr->data;
299 
300  /* strip actions shouldn't be editable if NLA tweakmode is on */
301  if (ptr->owner_id) {
303 
304  if (adt) {
305  /* active action is only editable when it is not a tweaking strip */
306  if ((adt->flag & ADT_NLA_EDIT_ON) || (adt->actstrip) || (adt->tmpact)) {
307  return 0;
308  }
309  }
310  }
311 
312  /* check for clues that strip probably shouldn't be used... */
313  if (strip->flag & NLASTRIP_FLAG_TWEAKUSER) {
314  return 0;
315  }
316 
317  /* should be ok, though we may still miss some cases */
318  return PROP_EDITABLE;
319 }
320 
321 static void rna_NlaStrip_action_start_frame_set(PointerRNA *ptr, float value)
322 {
323  NlaStrip *data = (NlaStrip *)ptr->data;
324 
325  /* prevent start frame from occurring after end of action */
326  CLAMP(value, MINAFRAME, data->actend);
327  data->actstart = value;
328 
329  /* adjust the strip extents in response to this */
330  /* TODO: should the strip be moved backwards instead as a special case? */
332 }
333 
334 static void rna_NlaStrip_action_end_frame_set(PointerRNA *ptr, float value)
335 {
336  NlaStrip *data = (NlaStrip *)ptr->data;
337 
338  /* prevent end frame from starting before start of action */
339  CLAMP(value, data->actstart, MAXFRAME);
340  data->actend = value;
341 
342  /* adjust the strip extents in response to this */
344 }
345 
346 static void rna_NlaStrip_animated_influence_set(PointerRNA *ptr, bool value)
347 {
348  NlaStrip *data = (NlaStrip *)ptr->data;
349 
350  if (value) {
351  /* set the flag, then make sure a curve for this exists */
354  }
355  else {
357  }
358 }
359 
360 static void rna_NlaStrip_animated_time_set(PointerRNA *ptr, bool value)
361 {
362  NlaStrip *data = (NlaStrip *)ptr->data;
363 
364  if (value) {
365  /* set the flag, then make sure a curve for this exists */
366  data->flag |= NLASTRIP_FLAG_USR_TIME;
368  }
369  else {
370  data->flag &= ~NLASTRIP_FLAG_USR_TIME;
371  }
372 }
373 
374 static FCurve *rna_NlaStrip_fcurve_find(NlaStrip *strip,
375  ReportList *reports,
376  const char *data_path,
377  int index)
378 {
379  if (data_path[0] == '\0') {
380  BKE_report(reports, RPT_ERROR, "F-Curve data path empty, invalid argument");
381  return NULL;
382  }
383 
384  /* Returns NULL if not found. */
385  return BKE_fcurve_find(&strip->fcurves, data_path, index);
386 }
387 
388 static NlaStrip *rna_NlaStrip_new(ID *id,
389  NlaTrack *track,
390  Main *bmain,
391  bContext *C,
392  ReportList *reports,
393  const char *UNUSED(name),
394  int start,
395  bAction *action)
396 {
397  NlaStrip *strip = BKE_nlastrip_new(action);
398 
399  if (strip == NULL) {
400  BKE_report(reports, RPT_ERROR, "Unable to create new strip");
401  return NULL;
402  }
403 
404  strip->end += (start - strip->start);
405  strip->start = start;
406 
407  if (BKE_nlastrips_add_strip(&track->strips, strip) == 0) {
408  BKE_report(
409  reports,
410  RPT_ERROR,
411  "Unable to add strip (the track does not have any space to accommodate this new strip)");
412  BKE_nlastrip_free(NULL, strip, true);
413  return NULL;
414  }
415 
416  /* create dummy AnimData block so that BKE_nlastrip_validate_name()
417  * can be used to ensure a valid name, as we don't have one here...
418  * - only the nla_tracks list is needed there, which we aim to reverse engineer here...
419  */
420  {
421  AnimData adt = {NULL};
422  NlaTrack *nlt, *nlt_p;
423 
424  /* 'first' NLA track is found by going back up chain of given
425  * track's parents until we fall off. */
426  nlt_p = track;
427  nlt = track;
428  while ((nlt = nlt->prev) != NULL) {
429  nlt_p = nlt;
430  }
431  adt.nla_tracks.first = nlt_p;
432 
433  /* do the same thing to find the last track */
434  nlt_p = track;
435  nlt = track;
436  while ((nlt = nlt->next) != NULL) {
437  nlt_p = nlt;
438  }
439  adt.nla_tracks.last = nlt_p;
440 
441  /* now we can just auto-name as usual */
442  BKE_nlastrip_validate_name(&adt, strip);
443  }
444 
446 
449 
450  return strip;
451 }
452 
453 static void rna_NlaStrip_remove(
454  ID *id, NlaTrack *track, Main *bmain, bContext *C, ReportList *reports, PointerRNA *strip_ptr)
455 {
456  NlaStrip *strip = strip_ptr->data;
457  if (BLI_findindex(&track->strips, strip) == -1) {
458  BKE_reportf(
459  reports, RPT_ERROR, "NLA strip '%s' not found in track '%s'", strip->name, track->name);
460  return;
461  }
462 
463  BKE_nlastrip_free(&track->strips, strip, true);
464  RNA_POINTER_INVALIDATE(strip_ptr);
465 
467 
470 }
471 
472 /* Set the 'solo' setting for the given NLA-track, making sure that it is the only one
473  * that has this status in its AnimData block.
474  */
475 static void rna_NlaTrack_solo_set(PointerRNA *ptr, bool value)
476 {
477  NlaTrack *data = (NlaTrack *)ptr->data;
479  NlaTrack *nt;
480 
481  if (data == NULL) {
482  return;
483  }
484 
485  /* firstly, make sure 'solo' flag for all tracks is disabled */
486  for (nt = data; nt; nt = nt->next) {
487  nt->flag &= ~NLATRACK_SOLO;
488  }
489  for (nt = data; nt; nt = nt->prev) {
490  nt->flag &= ~NLATRACK_SOLO;
491  }
492 
493  /* now, enable 'solo' for the given track if appropriate */
494  if (value) {
495  /* set solo status */
496  data->flag |= NLATRACK_SOLO;
497 
498  /* set solo-status on AnimData */
499  adt->flag |= ADT_NLA_SOLO_TRACK;
500  }
501  else {
502  /* solo status was already cleared on track */
503 
504  /* clear solo-status on AnimData */
505  adt->flag &= ~ADT_NLA_SOLO_TRACK;
506  }
507 }
508 
509 #else
510 
511 /* enum defines exported for rna_animation.c */
514  "REPLACE",
515  0,
516  "Replace",
517  "The strip values replace the accumulated results by amount specified by influence"},
519  "COMBINE",
520  0,
521  "Combine",
522  "The strip values are combined with accumulated results by appropriately using addition, "
523  "multiplication, or quaternion math, based on channel type"},
524  {0, "", 0, NULL, NULL},
526  "ADD",
527  0,
528  "Add",
529  "Weighted result of strip is added to the accumulated results"},
531  "SUBTRACT",
532  0,
533  "Subtract",
534  "Weighted result of strip is removed from the accumulated results"},
536  "MULTIPLY",
537  0,
538  "Multiply",
539  "Weighted result of strip is multiplied with the accumulated results"},
540  {0, NULL, 0, NULL, NULL},
541 };
542 
544  {NLASTRIP_EXTEND_NOTHING, "NOTHING", 0, "Nothing", "Strip has no influence past its extents"},
546  "HOLD",
547  0,
548  "Hold",
549  "Hold the first frame if no previous strips in track, and always hold last frame"},
550  {NLASTRIP_EXTEND_HOLD_FORWARD, "HOLD_FORWARD", 0, "Hold Forward", "Only hold last frame"},
551  {0, NULL, 0, NULL, NULL},
552 };
553 
554 static void rna_def_strip_fcurves(BlenderRNA *brna, PropertyRNA *cprop)
555 {
556  StructRNA *srna;
557 
558  FunctionRNA *func;
559  PropertyRNA *parm;
560 
561  RNA_def_property_srna(cprop, "NlaStripFCurves");
562  srna = RNA_def_struct(brna, "NlaStripFCurves", NULL);
563  RNA_def_struct_sdna(srna, "NlaStrip");
564  RNA_def_struct_ui_text(srna, "NLA-Strip F-Curves", "Collection of NLA strip F-Curves");
565 
566  /* Strip.fcurves.find(...) */
567  func = RNA_def_function(srna, "find", "rna_NlaStrip_fcurve_find");
569  func,
570  "Find an F-Curve. Note that this function performs a linear scan "
571  "of all F-Curves in the NLA strip.");
573  parm = RNA_def_string(func, "data_path", NULL, 0, "Data Path", "F-Curve data path");
575  RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Array index", 0, INT_MAX);
576 
577  parm = RNA_def_pointer(
578  func, "fcurve", "FCurve", "", "The found F-Curve, or None if it doesn't exist");
579  RNA_def_function_return(func, parm);
580 }
581 
582 static void rna_def_nlastrip(BlenderRNA *brna)
583 {
584  StructRNA *srna;
585  PropertyRNA *prop;
586 
587  /* enum defs */
588  static const EnumPropertyItem prop_type_items[] = {
589  {NLASTRIP_TYPE_CLIP, "CLIP", 0, "Action Clip", "NLA Strip references some Action"},
591  "TRANSITION",
592  0,
593  "Transition",
594  "NLA Strip 'transitions' between adjacent strips"},
595  {NLASTRIP_TYPE_META, "META", 0, "Meta", "NLA Strip acts as a container for adjacent strips"},
597  "SOUND",
598  0,
599  "Sound Clip",
600  "NLA Strip representing a sound event for speakers"},
601  {0, NULL, 0, NULL, NULL},
602  };
603 
604  /* struct definition */
605  srna = RNA_def_struct(brna, "NlaStrip", NULL);
606  RNA_def_struct_ui_text(srna, "NLA Strip", "A container referencing an existing Action");
607  RNA_def_struct_path_func(srna, "rna_NlaStrip_path");
608  RNA_def_struct_ui_icon(srna, ICON_NLA); /* XXX */
609 
611 
612  /* name property */
613  prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
614  RNA_def_property_ui_text(prop, "Name", "");
615  RNA_def_property_string_funcs(prop, NULL, NULL, "rna_NlaStrip_name_set");
616  RNA_def_struct_name_property(srna, prop);
617  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
618 
619  /* Enums */
620  prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
621  RNA_def_property_enum_sdna(prop, NULL, "type");
623  prop, PROP_EDITABLE); /* XXX for now, not editable, since this is dangerous */
624  RNA_def_property_enum_items(prop, prop_type_items);
625  RNA_def_property_ui_text(prop, "Type", "Type of NLA Strip");
626  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
627 
628  prop = RNA_def_property(srna, "extrapolation", PROP_ENUM, PROP_NONE);
629  RNA_def_property_enum_sdna(prop, NULL, "extendmode");
632  prop, "Extrapolation", "Action to take for gaps past the strip extents");
633  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
634 
635  prop = RNA_def_property(srna, "blend_type", PROP_ENUM, PROP_NONE);
636  RNA_def_property_enum_sdna(prop, NULL, "blendmode");
639  prop, "Blending", "Method used for combining strip's result with accumulated result");
640  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
641 
642  /* Strip extents */
643  prop = RNA_def_property(srna, "frame_start", PROP_FLOAT, PROP_TIME);
644  RNA_def_property_float_sdna(prop, NULL, "start");
645  RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_start_frame_set", NULL);
646  RNA_def_property_ui_text(prop, "Start Frame", "");
648  prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update");
649 
650  prop = RNA_def_property(srna, "frame_end", PROP_FLOAT, PROP_TIME);
651  RNA_def_property_float_sdna(prop, NULL, "end");
652  RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_end_frame_set", NULL);
653  RNA_def_property_ui_text(prop, "End Frame", "");
655  prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update");
656 
657  /* Blending */
658  prop = RNA_def_property(srna, "blend_in", PROP_FLOAT, PROP_NONE);
659  RNA_def_property_float_sdna(prop, NULL, "blendin");
660  RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_blend_in_set", NULL);
662  prop, "Blend In", "Number of frames at start of strip to fade in influence");
663  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
664 
665  prop = RNA_def_property(srna, "blend_out", PROP_FLOAT, PROP_NONE);
666  RNA_def_property_float_sdna(prop, NULL, "blendout");
667  RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_blend_out_set", NULL);
668  RNA_def_property_ui_text(prop, "Blend Out", "");
669  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
670 
671  prop = RNA_def_property(srna, "use_auto_blend", PROP_BOOLEAN, PROP_NONE);
673  RNA_def_property_boolean_funcs(prop, NULL, "rna_NlaStrip_use_auto_blend_set");
675  "Auto Blend In/Out",
676  "Number of frames for Blending In/Out is automatically determined from "
677  "overlapping strips");
678  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
679 
680  /* Action */
681  prop = RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE);
682  RNA_def_property_pointer_sdna(prop, NULL, "act");
683  RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_Action_id_poll");
685  RNA_def_property_editable_func(prop, "rna_NlaStrip_action_editable");
686  RNA_def_property_ui_text(prop, "Action", "Action referenced by this strip");
688  prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_dependency_update");
689 
690  /* Action extents */
691  prop = RNA_def_property(srna, "action_frame_start", PROP_FLOAT, PROP_TIME);
692  RNA_def_property_float_sdna(prop, NULL, "actstart");
693  RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_action_start_frame_set", NULL);
694  RNA_def_property_ui_text(prop, "Action Start Frame", "First frame from action to use");
696  prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update");
697 
698  prop = RNA_def_property(srna, "action_frame_end", PROP_FLOAT, PROP_TIME);
699  RNA_def_property_float_sdna(prop, NULL, "actend");
700  RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_action_end_frame_set", NULL);
701  RNA_def_property_ui_text(prop, "Action End Frame", "Last frame from action to use");
703  prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update");
704 
705  /* Action Reuse */
706  prop = RNA_def_property(srna, "repeat", PROP_FLOAT, PROP_NONE);
707  RNA_def_property_float_sdna(prop, NULL, "repeat");
708  RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_repeat_set", NULL);
709  /* these limits have currently be chosen arbitrarily, but could be extended
710  * (minimum should still be > 0 though) if needed... */
711  RNA_def_property_range(prop, 0.1f, 1000.0f);
712  RNA_def_property_ui_text(prop, "Repeat", "Number of times to repeat the action range");
714  prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update");
715 
716  prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_NONE);
717  RNA_def_property_float_sdna(prop, NULL, "scale");
718  RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_scale_set", NULL);
719  /* these limits can be extended, but beyond this, we can get some crazy+annoying bugs
720  * due to numeric errors */
721  RNA_def_property_range(prop, 0.0001f, 1000.0f);
722  RNA_def_property_ui_text(prop, "Scale", "Scaling factor for action");
724  prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update");
725 
726  /* Strip's F-Curves */
727  prop = RNA_def_property(srna, "fcurves", PROP_COLLECTION, PROP_NONE);
728  RNA_def_property_collection_sdna(prop, NULL, "fcurves", NULL);
729  RNA_def_property_struct_type(prop, "FCurve");
731  prop, "F-Curves", "F-Curves for controlling the strip's influence and timing");
732  rna_def_strip_fcurves(brna, prop);
733 
734  /* Strip's F-Modifiers */
735  prop = RNA_def_property(srna, "modifiers", PROP_COLLECTION, PROP_NONE);
736  RNA_def_property_struct_type(prop, "FModifier");
738  prop, "Modifiers", "Modifiers affecting all the F-Curves in the referenced Action");
739 
740  /* Strip's Sub-Strips (for Meta-Strips) */
741  prop = RNA_def_property(srna, "strips", PROP_COLLECTION, PROP_NONE);
742  RNA_def_property_struct_type(prop, "NlaStrip");
744  prop,
745  "NLA Strips",
746  "NLA Strips that this strip acts as a container for (if it is of type Meta)");
747 
748  /* Settings - Values necessary for evaluation */
749  prop = RNA_def_property(srna, "influence", PROP_FLOAT, PROP_FACTOR);
750  RNA_def_property_range(prop, 0.0f, 1.0f);
752  prop, "Influence", "Amount the strip contributes to the current result");
753  /* XXX: Update temporarily disabled so that the property can be edited at all!
754  * Even autokey only applies after the curves have been re-evaluated,
755  * causing the unkeyed values to be lost. */
756  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, /*"rna_NlaStrip_update"*/ NULL);
757 
758  prop = RNA_def_property(srna, "strip_time", PROP_FLOAT, PROP_TIME);
759  RNA_def_property_ui_text(prop, "Strip Time", "Frame of referenced Action to evaluate");
760  /* XXX: Update temporarily disabled so that the property can be edited at all!
761  * Even autokey only applies after the curves have been re-evaluated,
762  * causing the unkeyed values to be lost. */
763  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, /*"rna_NlaStrip_update"*/ NULL);
764 
765  /* TODO: should the animated_influence/time settings be animatable themselves? */
766  prop = RNA_def_property(srna, "use_animated_influence", PROP_BOOLEAN, PROP_NONE);
768  RNA_def_property_boolean_funcs(prop, NULL, "rna_NlaStrip_animated_influence_set");
770  prop,
771  "Animated Influence",
772  "Influence setting is controlled by an F-Curve rather than automatically determined");
773  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
774 
775  prop = RNA_def_property(srna, "use_animated_time", PROP_BOOLEAN, PROP_NONE);
777  RNA_def_property_boolean_funcs(prop, NULL, "rna_NlaStrip_animated_time_set");
779  prop,
780  "Animated Strip Time",
781  "Strip time is controlled by an F-Curve rather than automatically determined");
782  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
783 
784  prop = RNA_def_property(srna, "use_animated_time_cyclic", PROP_BOOLEAN, PROP_NONE);
787  prop, "Cyclic Strip Time", "Cycle the animated time within the action start and end");
789  prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update");
790 
791  /* settings */
792  prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
793  /* can be made editable by hooking it up to the necessary NLA API methods */
796  RNA_def_property_ui_text(prop, "Active", "NLA Strip is active");
797  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
798 
799  prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
801  RNA_def_property_ui_text(prop, "Select", "NLA Strip is selected");
802  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
803 
804  prop = RNA_def_property(srna, "mute", PROP_BOOLEAN, PROP_NONE);
806  RNA_def_property_ui_icon(prop, ICON_CHECKBOX_HLT, -1);
807  RNA_def_property_ui_text(prop, "Mute", "Disable NLA Strip evaluation");
808  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
809 
810  prop = RNA_def_property(srna, "use_reverse", PROP_BOOLEAN, PROP_NONE);
813  "Reversed",
814  "NLA Strip is played back in reverse order (only when timing is "
815  "automatically determined)");
816  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
817 
818  prop = RNA_def_property(srna, "use_sync_length", PROP_BOOLEAN, PROP_NONE);
821  "Sync Action Length",
822  "Update range of frames referenced from action "
823  "after tweaking strip and its keyframes");
824  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
825 
827 }
828 
830 {
831  StructRNA *srna;
832  PropertyRNA *parm;
833  FunctionRNA *func;
834 
835  RNA_def_property_srna(cprop, "NlaStrips");
836  srna = RNA_def_struct(brna, "NlaStrips", NULL);
837  RNA_def_struct_sdna(srna, "NlaTrack");
838  RNA_def_struct_ui_text(srna, "Nla Strips", "Collection of Nla Strips");
839 
840  func = RNA_def_function(srna, "new", "rna_NlaStrip_new");
843  RNA_def_function_ui_description(func, "Add a new Action-Clip strip to the track");
844  parm = RNA_def_string(func, "name", "NlaStrip", 0, "", "Name for the NLA Strips");
846  parm = RNA_def_int(func,
847  "start",
848  0,
849  INT_MIN,
850  INT_MAX,
851  "Start Frame",
852  "Start frame for this strip",
853  INT_MIN,
854  INT_MAX);
856  parm = RNA_def_pointer(func, "action", "Action", "", "Action to assign to this strip");
858  /* return type */
859  parm = RNA_def_pointer(func, "strip", "NlaStrip", "", "New NLA Strip");
860  RNA_def_function_return(func, parm);
861 
862  func = RNA_def_function(srna, "remove", "rna_NlaStrip_remove");
865  RNA_def_function_ui_description(func, "Remove a NLA Strip");
866  parm = RNA_def_pointer(func, "strip", "NlaStrip", "", "NLA Strip to remove");
869 }
870 
871 static void rna_def_nlatrack(BlenderRNA *brna)
872 {
873  StructRNA *srna;
874  PropertyRNA *prop;
875 
876  srna = RNA_def_struct(brna, "NlaTrack", NULL);
878  srna, "NLA Track", "A animation layer containing Actions referenced as NLA strips");
879  RNA_def_struct_ui_icon(srna, ICON_NLA);
880 
881  /* strips collection */
882  prop = RNA_def_property(srna, "strips", PROP_COLLECTION, PROP_NONE);
883  RNA_def_property_struct_type(prop, "NlaStrip");
884  /* We do not support inserting or removing strips in overrides of tracks for now. */
886  RNA_def_property_ui_text(prop, "NLA Strips", "NLA Strips on this NLA-track");
887 
888  rna_api_nlatrack_strips(brna, prop);
889 
891 
892  /* name property */
893  prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
894  RNA_def_property_ui_text(prop, "Name", "");
895  RNA_def_struct_name_property(srna, prop);
896  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
897 
898  /* settings */
899  prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
900  /* can be made editable by hooking it up to the necessary NLA API methods */
903  RNA_def_property_ui_text(prop, "Active", "NLA Track is active");
904  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
905 
906  prop = RNA_def_property(srna, "is_solo", PROP_BOOLEAN, PROP_NONE);
907  /* can be made editable by hooking it up to the necessary NLA API methods */
910  prop,
911  "Solo",
912  "NLA Track is evaluated itself (i.e. active Action and all other NLA Tracks in the "
913  "same AnimData block are disabled)");
914  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
915  RNA_def_property_boolean_funcs(prop, NULL, "rna_NlaTrack_solo_set");
916 
917  prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
919  RNA_def_property_ui_text(prop, "Select", "NLA Track is selected");
920  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
921 
922  prop = RNA_def_property(srna, "mute", PROP_BOOLEAN, PROP_NONE);
924  RNA_def_property_ui_text(prop, "Muted", "Disable NLA Track evaluation");
925  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_update");
926 
927  prop = RNA_def_property(srna, "lock", PROP_BOOLEAN, PROP_NONE);
929  RNA_def_property_ui_text(prop, "Locked", "NLA Track is locked");
930  RNA_def_property_update(prop, NC_ANIMATION | ND_NLA, NULL); /* this will do? */
931 
933 }
934 
935 /* --------- */
936 
938 {
939  rna_def_nlatrack(brna);
940  rna_def_nlastrip(brna);
941 }
942 
943 #endif
struct AnimData * BKE_animdata_from_id(struct ID *id)
Definition: anim_data.c:96
struct FCurve * BKE_fcurve_find(ListBase *list, const char rna_path[], const int array_index)
Definition: fcurve.c:274
void BKE_nlastrip_validate_name(struct AnimData *adt, struct NlaStrip *strip)
Definition: nla.c:1626
void BKE_nlameta_flush_transforms(struct NlaStrip *mstrip)
Definition: nla.c:912
void BKE_nlastrip_recalculate_bounds(struct NlaStrip *strip)
Definition: nla.c:1409
bool BKE_nlastrips_add_strip(ListBase *strips, struct NlaStrip *strip)
Definition: nla.c:714
void BKE_nlastrip_validate_fcurves(struct NlaStrip *strip)
Definition: nla.c:1516
void BKE_nla_validate_state(struct AnimData *adt)
Definition: nla.c:1800
struct NlaStrip * BKE_nlastrip_new(struct bAction *act)
Definition: nla.c:327
void BKE_nlastrip_free(ListBase *strips, struct NlaStrip *strip, bool do_id_user)
Definition: nla.c:72
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
size_t size_t char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
size_t size_t char size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy) ATTR_NONNULL()
Definition: string.c:333
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:70
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string_utf8.c:258
#define UNUSED(x)
#define IS_EQF(a, b)
void DEG_id_tag_update_ex(struct Main *bmain, struct ID *id, int flag)
void DEG_relations_tag_update(struct Main *bmain)
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:654
@ ID_RECALC_ANIMATION
Definition: DNA_ID.h:614
@ NLASTRIP_FLAG_ACTIVE
@ NLASTRIP_FLAG_USR_INFLUENCE
@ NLASTRIP_FLAG_USR_TIME
@ NLASTRIP_FLAG_AUTO_BLENDS
@ NLASTRIP_FLAG_REVERSE
@ NLASTRIP_FLAG_MUTED
@ NLASTRIP_FLAG_USR_TIME_CYCLIC
@ NLASTRIP_FLAG_SELECT
@ NLASTRIP_FLAG_TWEAKUSER
@ NLASTRIP_FLAG_SYNC_LENGTH
@ ADT_NLA_SOLO_TRACK
@ ADT_NLA_EDIT_ON
@ NLASTRIP_EXTEND_HOLD_FORWARD
@ NLASTRIP_EXTEND_NOTHING
@ NLASTRIP_EXTEND_HOLD
@ NLASTRIP_MODE_REPLACE
@ NLASTRIP_MODE_ADD
@ NLASTRIP_MODE_SUBTRACT
@ NLASTRIP_MODE_COMBINE
@ NLASTRIP_MODE_MULTIPLY
@ NLASTRIP_TYPE_SOUND
@ NLASTRIP_TYPE_META
@ NLASTRIP_TYPE_TRANSITION
@ NLASTRIP_TYPE_CLIP
@ NLATRACK_SOLO
@ NLATRACK_ACTIVE
@ NLATRACK_MUTED
@ NLATRACK_SELECTED
@ NLATRACK_PROTECTED
Object is a sort of wrapper for general info.
#define MINAFRAME
#define MAXFRAME
Read Guarded memory(de)allocation.
Group RGB to Bright Vector Camera CLAMP
#define RNA_POINTER_INVALIDATE(ptr)
Definition: RNA_access.h:1425
@ PARM_RNAPTR
Definition: RNA_types.h:339
@ PARM_REQUIRED
Definition: RNA_types.h:337
@ FUNC_USE_REPORTS
Definition: RNA_types.h:578
@ FUNC_USE_MAIN
Definition: RNA_types.h:576
@ FUNC_USE_CONTEXT
Definition: RNA_types.h:577
@ FUNC_USE_SELF_ID
Definition: RNA_types.h:565
@ PROP_FLOAT
Definition: RNA_types.h:75
@ PROP_BOOLEAN
Definition: RNA_types.h:73
@ PROP_ENUM
Definition: RNA_types.h:77
@ PROP_STRING
Definition: RNA_types.h:76
@ PROP_POINTER
Definition: RNA_types.h:78
@ PROP_COLLECTION
Definition: RNA_types.h:79
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition: RNA_types.h:297
@ PROP_THICK_WRAP
Definition: RNA_types.h:270
@ PROP_EDITABLE
Definition: RNA_types.h:175
@ PROP_NEVER_NULL
Definition: RNA_types.h:225
@ PROP_ID_REFCOUNT
Definition: RNA_types.h:212
@ PROP_TIME
Definition: RNA_types.h:133
@ PROP_NONE
Definition: RNA_types.h:113
@ PROP_FACTOR
Definition: RNA_types.h:131
#define C
Definition: RandGen.cpp:39
#define NC_ANIMATION
Definition: WM_types.h:289
#define NA_ADDED
Definition: WM_types.h:464
#define NA_EDITED
Definition: WM_types.h:462
#define NA_REMOVED
Definition: WM_types.h:465
#define ND_NLA
Definition: WM_types.h:397
void ANIM_id_update(Main *bmain, ID *id)
Definition: anim_deps.c:119
Scene scene
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2762
void RNA_define_lib_overridable(const bool make_overridable)
Definition: rna_define.c:760
void RNA_def_struct_path_func(StructRNA *srna, const char *path)
Definition: rna_define.c:1212
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
Definition: rna_define.c:4159
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
Definition: rna_define.c:2257
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1555
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
Definition: rna_define.c:3312
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
Definition: rna_define.c:4302
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3153
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1676
void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
Definition: rna_define.c:1684
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4262
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
Definition: rna_define.c:3462
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
Definition: rna_define.c:1259
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
Definition: rna_define.c:2971
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
Definition: rna_define.c:1892
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
Definition: rna_define.c:1067
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
Definition: rna_define.c:1757
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1792
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
Definition: rna_define.c:2791
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4337
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
Definition: rna_define.c:2927
void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable)
Definition: rna_define.c:2877
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1279
void RNA_def_struct_name_property(struct StructRNA *srna, struct PropertyRNA *prop)
Definition: rna_define.c:1122
void RNA_def_function_flag(FunctionRNA *func, int flag)
Definition: rna_define.c:4332
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1517
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
Definition: rna_define.c:3373
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1047
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2623
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
Definition: rna_define.c:1267
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3675
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3585
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2515
void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
Definition: rna_define.c:1525
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1547
void RNA_def_nla(BlenderRNA *brna)
Definition: rna_nla.c:937
static void rna_def_nlastrip(BlenderRNA *brna)
Definition: rna_nla.c:582
static void rna_def_nlatrack(BlenderRNA *brna)
Definition: rna_nla.c:871
const EnumPropertyItem rna_enum_nla_mode_blend_items[]
Definition: rna_nla.c:512
static void rna_api_nlatrack_strips(BlenderRNA *brna, PropertyRNA *cprop)
Definition: rna_nla.c:829
static void rna_def_strip_fcurves(BlenderRNA *brna, PropertyRNA *cprop)
Definition: rna_nla.c:554
const EnumPropertyItem rna_enum_nla_mode_extend_items[]
Definition: rna_nla.c:543
NlaStrip * actstrip
bAction * tmpact
ListBase nla_tracks
Definition: DNA_ID.h:273
AnimData * adt
void * last
Definition: DNA_listBase.h:47
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
struct NlaStrip * next
ListBase fcurves
char name[64]
ListBase strips
struct NlaTrack * next
char name[64]
struct NlaTrack * prev
void * data
Definition: RNA_types.h:52
struct ID * owner_id
Definition: RNA_types.h:50
uint len
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3157