Blender  V3.3
rna_animviz.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <stdlib.h>
8 
9 #include "DNA_action_types.h"
10 #include "DNA_anim_types.h"
11 #include "DNA_scene_types.h"
12 
13 #include "BLI_utildefines.h"
14 
15 #include "MEM_guardedalloc.h"
16 
17 #include "RNA_define.h"
18 #include "RNA_enum_types.h"
19 
20 #include "rna_internal.h"
21 
22 #include "WM_types.h"
23 
24 /* Which part of bone(s) get baked */
25 // TODO: icons?
27  {MOTIONPATH_BAKE_HEADS, "HEADS", 0, "Heads", "Calculate bone paths from heads"},
28  {0, "TAILS", 0, "Tails", "Calculate bone paths from tails"},
29 #if 0
30  {MOTIONPATH_BAKE_CENTERS,
31  "CENTROID",
32  0,
33  "Centers",
34  "Calculate bone paths from center of mass"},
35 #endif
36  {0, NULL, 0, NULL, NULL},
37 };
38 
41  "CURRENT_FRAME",
42  0,
43  "Around Frame",
44  "Display Paths of poses within a fixed number of frames around the current frame"},
46  "RANGE",
47  0,
48  "In Range",
49  "Display Paths of poses within specified range"},
50  {0, NULL, 0, NULL, NULL},
51 };
52 
54  {MOTIONPATH_RANGE_KEYS_ALL, "KEYS_ALL", 0, "All Keys", "From the first keyframe to the last"},
56  "KEYS_SELECTED",
57  0,
58  "Selected Keys",
59  "From the first selected keyframe to the last"},
60  {MOTIONPATH_RANGE_SCENE, "SCENE", 0, "Scene Frame Range", "The entire Scene / Preview range"},
61  {0, NULL, 0, NULL, NULL},
62 };
63 
64 #ifdef RNA_RUNTIME
65 
66 static PointerRNA rna_AnimViz_motion_paths_get(PointerRNA *ptr)
67 {
68  return rna_pointer_inherit_refine(ptr, &RNA_AnimVizMotionPaths, ptr->data);
69 }
70 
71 static void rna_AnimViz_path_start_frame_set(PointerRNA *ptr, int value)
72 {
74 
75  /* XXX: Watch it! Path Start > MAXFRAME/2 could be a problem. */
76  data->path_sf = value;
77  FRAMENUMBER_MIN_CLAMP(data->path_sf);
78 
79  CLAMP(data->path_ef, data->path_sf + 1, MAXFRAME / 2);
80 }
81 
82 static void rna_AnimViz_path_end_frame_set(PointerRNA *ptr, int value)
83 {
85 
86  data->path_ef = value;
87  CLAMP_MAX(data->path_sf, data->path_ef - 1);
88  if (U.flag & USER_NONEGFRAMES) {
89  CLAMP_MIN(data->path_sf, 0);
90  CLAMP_MIN(data->path_ef, 1);
91  }
92 }
93 
94 #else
95 
97 {
98  PropertyRNA *prop;
99 
100  prop = RNA_def_property(srna, "motion_path", PROP_POINTER, PROP_NONE);
101  RNA_def_property_pointer_sdna(prop, NULL, "mpath");
102  RNA_def_property_ui_text(prop, "Motion Path", "Motion Path for this element");
103 }
104 
106 {
107  StructRNA *srna;
108  PropertyRNA *prop;
109 
110  srna = RNA_def_struct(brna, "MotionPathVert", NULL);
111  RNA_def_struct_sdna(srna, "bMotionPathVert");
112  RNA_def_struct_ui_text(srna, "Motion Path Cache Point", "Cached location on path");
113 
114  prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_XYZ);
115  RNA_def_property_array(prop, 3);
116  RNA_def_property_ui_text(prop, "Coordinates", "");
117 
118  prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
120  RNA_def_property_ui_text(prop, "Select", "Path point is selected for editing");
121 }
122 
124 {
125  StructRNA *srna;
126  PropertyRNA *prop;
127 
128  srna = RNA_def_struct(brna, "MotionPath", NULL);
129  RNA_def_struct_sdna(srna, "bMotionPath");
131  srna, "Motion Path", "Cache of the world-space positions of an element over a frame range");
132 
133  /* Collections */
134  prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
135  RNA_def_property_collection_sdna(prop, NULL, "points", "length");
136  RNA_def_property_struct_type(prop, "MotionPathVert");
137  RNA_def_property_ui_text(prop, "Motion Path Points", "Cached positions per frame");
138 
139  /* Playback Ranges */
140  prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
141  RNA_def_property_int_sdna(prop, NULL, "start_frame");
143  RNA_def_property_ui_text(prop, "Start Frame", "Starting frame of the stored range");
144 
145  prop = RNA_def_property(srna, "frame_end", PROP_INT, PROP_TIME);
146  RNA_def_property_int_sdna(prop, NULL, "end_frame");
148  RNA_def_property_ui_text(prop, "End Frame", "End frame of the stored range");
149 
150  prop = RNA_def_property(srna, "length", PROP_INT, PROP_TIME);
152  RNA_def_property_ui_text(prop, "Length", "Number of frames cached");
153 
154  /* Custom Color */
155  prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA);
156  RNA_def_property_array(prop, 3);
157  RNA_def_property_ui_text(prop, "Color", "Custom color for motion path");
159 
160  /* Line width */
161  prop = RNA_def_property(srna, "line_thickness", PROP_INT, PROP_NONE);
162  RNA_def_property_int_sdna(prop, NULL, "line_thickness");
163  RNA_def_property_range(prop, 1, 6);
164  RNA_def_property_ui_text(prop, "Line Thickness", "Line thickness for motion path");
166 
167  /* Settings */
168  prop = RNA_def_property(srna, "use_bone_head", PROP_BOOLEAN, PROP_NONE);
172  prop,
173  "Use Bone Heads",
174  "For PoseBone paths, use the bone head location when calculating this path");
175 
176  /* FIXME: Motion Paths are not currently editable... */
177  prop = RNA_def_property(srna, "is_modified", PROP_BOOLEAN, PROP_NONE);
179  RNA_def_property_ui_text(prop, "Edit Path", "Path is being edited");
180 
181  /* Use custom color */
182  prop = RNA_def_property(srna, "use_custom_color", PROP_BOOLEAN, PROP_NONE);
184  RNA_def_property_ui_text(prop, "Custom Colors", "Use custom color for this motion path");
186 
187  /* Draw lines between keyframes */
188  prop = RNA_def_property(srna, "lines", PROP_BOOLEAN, PROP_NONE);
190  RNA_def_property_ui_text(prop, "Lines", "Use straight lines between keyframe points");
192 }
193 
194 /* --- */
195 
197 {
198  StructRNA *srna;
199  PropertyRNA *prop;
200 
201  srna = RNA_def_struct(brna, "AnimVizMotionPaths", NULL);
202  RNA_def_struct_sdna(srna, "bAnimVizSettings");
203  RNA_def_struct_nested(brna, srna, "AnimViz");
205  srna, "Motion Path Settings", "Motion Path settings for animation visualization");
206 
208 
209  /* Enums */
210  prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
211  RNA_def_property_enum_sdna(prop, NULL, "path_type");
213  RNA_def_property_ui_text(prop, "Paths Type", "Type of range to show for Motion Paths");
215 
216  prop = RNA_def_property(srna, "range", PROP_ENUM, PROP_NONE);
217  RNA_def_property_enum_sdna(prop, NULL, "path_range");
219  RNA_def_property_ui_text(prop, "Paths Range", "Type of range to calculate for Motion Paths");
221 
222  prop = RNA_def_property(srna, "bake_location", PROP_ENUM, PROP_NONE);
223  RNA_def_property_enum_bitflag_sdna(prop, NULL, "path_bakeflag");
225  RNA_def_property_ui_text(prop, "Bake Location", "When calculating Bone Paths, use Head or Tips");
227 
228  /* Settings */
229  prop = RNA_def_property(srna, "show_frame_numbers", PROP_BOOLEAN, PROP_NONE);
231  RNA_def_property_ui_text(prop, "Show Frame Numbers", "Show frame numbers on Motion Paths");
233 
234  prop = RNA_def_property(srna, "show_keyframe_highlight", PROP_BOOLEAN, PROP_NONE);
237  prop, "Highlight Keyframes", "Emphasize position of keyframes on Motion Paths");
239 
240  prop = RNA_def_property(srna, "show_keyframe_numbers", PROP_BOOLEAN, PROP_NONE);
243  prop, "Show Keyframe Numbers", "Show frame numbers of Keyframes on Motion Paths");
245 
246  prop = RNA_def_property(srna, "show_keyframe_action_all", PROP_BOOLEAN, PROP_NONE);
249  prop,
250  "All Action Keyframes",
251  "For bone motion paths, search whole Action for keyframes instead of in group"
252  " with matching name only (is slower)");
254 
255  prop = RNA_def_property(srna, "frame_step", PROP_INT, PROP_NONE);
256  RNA_def_property_int_sdna(prop, NULL, "path_step");
257  RNA_def_property_range(prop, 1, 100);
259  prop,
260  "Frame Step",
261  "Number of frames between paths shown (not for 'On Keyframes' Onion-skinning method)");
263 
264  /* Playback Ranges */
265  prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
266  RNA_def_property_int_sdna(prop, NULL, "path_sf");
267  RNA_def_property_int_funcs(prop, NULL, "rna_AnimViz_path_start_frame_set", NULL);
269  "Start Frame",
270  "Starting frame of range of paths to display/calculate "
271  "(not for 'Around Current Frame' Onion-skinning method)");
273 
274  prop = RNA_def_property(srna, "frame_end", PROP_INT, PROP_TIME);
275  RNA_def_property_int_sdna(prop, NULL, "path_ef");
276  RNA_def_property_int_funcs(prop, NULL, "rna_AnimViz_path_end_frame_set", NULL);
278  "End Frame",
279  "End frame of range of paths to display/calculate "
280  "(not for 'Around Current Frame' Onion-skinning method)");
282 
283  /* Around Current Ranges */
284  prop = RNA_def_property(srna, "frame_before", PROP_INT, PROP_TIME);
285  RNA_def_property_int_sdna(prop, NULL, "path_bc");
286  RNA_def_property_range(prop, 1, MAXFRAMEF / 2);
288  "Before Current",
289  "Number of frames to show before the current frame "
290  "(only for 'Around Current Frame' Onion-skinning method)");
292 
293  prop = RNA_def_property(srna, "frame_after", PROP_INT, PROP_TIME);
294  RNA_def_property_int_sdna(prop, NULL, "path_ac");
295  RNA_def_property_range(prop, 1, MAXFRAMEF / 2);
297  "After Current",
298  "Number of frames to show after the current frame "
299  "(only for 'Around Current Frame' Onion-skinning method)");
301 
302  /* Readonly Property - Do any motion paths exist/need updating? (Mainly for bone paths) */
303  prop = RNA_def_property(srna, "has_motion_paths", PROP_BOOLEAN, PROP_NONE);
305  /* NOTE: This is really an internal state var for convenience, so don't allow edits! */
308  prop, "Has Motion Paths", "Are there any bone paths that will need updating (read-only)");
309 
311 }
312 
313 /* --- */
314 
316 {
317  PropertyRNA *prop;
318 
319  prop = RNA_def_property(srna, "animation_visualization", PROP_POINTER, PROP_NONE);
321  RNA_def_property_pointer_sdna(prop, NULL, "avs");
323  RNA_def_property_ui_text(prop, "Animation Visualization", "Animation data for this data-block");
324 }
325 
326 static void rna_def_animviz(BlenderRNA *brna)
327 {
328  StructRNA *srna;
329  PropertyRNA *prop;
330 
331  srna = RNA_def_struct(brna, "AnimViz", NULL);
332  RNA_def_struct_sdna(srna, "bAnimVizSettings");
334  srna, "Animation Visualization", "Settings for the visualization of motion");
335 
336  /* motion path settings (nested struct) */
337  prop = RNA_def_property(srna, "motion_path", PROP_POINTER, PROP_NONE);
340  RNA_def_property_struct_type(prop, "AnimVizMotionPaths");
341  RNA_def_property_pointer_funcs(prop, "rna_AnimViz_motion_paths_get", NULL, NULL, NULL);
342  RNA_def_property_ui_text(prop, "Motion Paths", "Motion Path settings for visualization");
343 }
344 
345 /* --- */
346 
348 {
349  rna_def_animviz(brna);
350  rna_def_animviz_paths(brna);
351 
354 }
355 
356 #endif
#define CLAMP_MAX(a, c)
#define CLAMP_MIN(a, b)
@ MOTIONPATH_BAKE_HEADS
@ MOTIONPATH_BAKE_HAS_PATHS
@ MOTIONPATH_TYPE_ACFRA
@ MOTIONPATH_TYPE_RANGE
@ MOTIONPATH_VERT_SEL
@ MOTIONPATH_VIEW_KFACT
@ MOTIONPATH_VIEW_KFNOS
@ MOTIONPATH_VIEW_FNUMS
@ MOTIONPATH_VIEW_KFRAS
@ MOTIONPATH_RANGE_KEYS_ALL
@ MOTIONPATH_RANGE_KEYS_SELECTED
@ MOTIONPATH_RANGE_SCENE
@ MOTIONPATH_FLAG_LINES
@ MOTIONPATH_FLAG_CUSTOM
@ MOTIONPATH_FLAG_EDIT
@ MOTIONPATH_FLAG_BHEAD
#define MAXFRAMEF
#define MAXFRAME
#define FRAMENUMBER_MIN_CLAMP(cfra)
@ USER_NONEGFRAMES
Read Guarded memory(de)allocation.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
@ PROP_FLOAT
Definition: RNA_types.h:61
@ PROP_BOOLEAN
Definition: RNA_types.h:59
@ PROP_ENUM
Definition: RNA_types.h:63
@ PROP_INT
Definition: RNA_types.h:60
@ PROP_POINTER
Definition: RNA_types.h:64
@ PROP_COLLECTION
Definition: RNA_types.h:65
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition: RNA_types.h:312
@ PROP_EDITABLE
Definition: RNA_types.h:189
@ PROP_NEVER_NULL
Definition: RNA_types.h:239
@ PROP_TIME
Definition: RNA_types.h:146
@ PROP_XYZ
Definition: RNA_types.h:162
@ PROP_NONE
Definition: RNA_types.h:126
@ PROP_COLOR_GAMMA
Definition: RNA_types.h:165
#define ND_DRAW_ANIMVIZ
Definition: WM_types.h:422
#define NC_OBJECT
Definition: WM_types.h:329
unsigned int U
Definition: btGjkEpa3.h:78
PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *data)
Definition: rna_access.c:186
const EnumPropertyItem rna_enum_motionpath_display_type_items[]
Definition: rna_animviz.c:39
static void rna_def_animviz_motionpath_vert(BlenderRNA *brna)
Definition: rna_animviz.c:105
const EnumPropertyItem rna_enum_motionpath_range_items[]
Definition: rna_animviz.c:53
void rna_def_animviz_common(StructRNA *srna)
Definition: rna_animviz.c:315
const EnumPropertyItem rna_enum_motionpath_bake_location_items[]
Definition: rna_animviz.c:26
void RNA_def_animviz(BlenderRNA *brna)
Definition: rna_animviz.c:347
static void rna_def_animviz_motion_path(BlenderRNA *brna)
Definition: rna_animviz.c:123
static void rna_def_animviz(BlenderRNA *brna)
Definition: rna_animviz.c:326
void rna_def_motionpath_common(StructRNA *srna)
Definition: rna_animviz.c:96
static void rna_def_animviz_paths(BlenderRNA *brna)
Definition: rna_animviz.c:196
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2740
void RNA_define_lib_overridable(const bool make_overridable)
Definition: rna_define.c:742
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
Definition: rna_define.c:2236
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1645
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
Definition: rna_define.c:1237
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
Definition: rna_define.c:1872
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
Definition: rna_define.c:1048
void RNA_def_property_array(PropertyRNA *prop, int length)
Definition: rna_define.c:1539
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
Definition: rna_define.c:1737
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1772
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
Definition: rna_define.c:2769
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
Definition: rna_define.c:2900
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1257
void RNA_def_property_enum_bitflag_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2669
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1495
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:3385
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1028
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2601
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3028
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1490
void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2343
void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *structname)
Definition: rna_define.c:1119
void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
Definition: rna_define.c:1503
void * data
Definition: RNA_types.h:38
PointerRNA * ptr
Definition: wm_files.c:3480