Blender V4.3
rna_animviz.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <cstdlib>
10
11#include "DNA_action_types.h"
12#include "DNA_anim_types.h"
13#include "DNA_scene_types.h"
14
15#include "BLI_utildefines.h"
16
17#include "MEM_guardedalloc.h"
18
19#include "RNA_define.hh"
20#include "RNA_enum_types.hh"
21
22#include "rna_internal.hh"
23
24#include "WM_types.hh"
25
26/* Which part of bone(s) get baked */
27/* TODO: icons? */
29 {MOTIONPATH_BAKE_HEADS, "HEADS", 0, "Heads", "Calculate bone paths from heads"},
30 {0, "TAILS", 0, "Tails", "Calculate bone paths from tails"},
31#if 0
32 {MOTIONPATH_BAKE_CENTERS,
33 "CENTROID",
34 0,
35 "Centers",
36 "Calculate bone paths from center of mass"},
37#endif
38 {0, nullptr, 0, nullptr, nullptr},
39};
40
43 "CURRENT_FRAME",
44 0,
45 "Around Frame",
46 "Display Paths of poses within a fixed number of frames around the current frame"},
48 "RANGE",
49 0,
50 "In Range",
51 "Display Paths of poses within specified range"},
52 {0, nullptr, 0, nullptr, nullptr},
53};
54
56 {MOTIONPATH_RANGE_KEYS_ALL, "KEYS_ALL", 0, "All Keys", "From the first keyframe to the last"},
58 "KEYS_SELECTED",
59 0,
60 "Selected Keys",
61 "From the first selected keyframe to the last"},
62 {MOTIONPATH_RANGE_SCENE, "SCENE", 0, "Scene Frame Range", "The entire Scene / Preview range"},
63 {MOTIONPATH_RANGE_MANUAL, "MANUAL", 0, "Manual Range", "Manually determined frame range"},
64 {0, nullptr, 0, nullptr, nullptr},
65};
66
67#ifdef RNA_RUNTIME
68
69static PointerRNA rna_AnimViz_motion_paths_get(PointerRNA *ptr)
70{
71 return rna_pointer_inherit_refine(ptr, &RNA_AnimVizMotionPaths, ptr->data);
72}
73
74static void rna_AnimViz_path_start_frame_set(PointerRNA *ptr, int value)
75{
77
78 /* XXX: Watch it! Path Start > MAXFRAME/2 could be a problem. */
79 data->path_sf = value;
80 FRAMENUMBER_MIN_CLAMP(data->path_sf);
81
82 CLAMP(data->path_ef, data->path_sf + 1, MAXFRAME / 2);
83}
84
85static void rna_AnimViz_path_end_frame_set(PointerRNA *ptr, int value)
86{
88
89 data->path_ef = value;
90 CLAMP_MAX(data->path_sf, data->path_ef - 1);
91 if (U.flag & USER_NONEGFRAMES) {
92 CLAMP_MIN(data->path_sf, 0);
93 CLAMP_MIN(data->path_ef, 1);
94 }
95}
96
97#else
98
100{
101 PropertyRNA *prop;
102
103 prop = RNA_def_property(srna, "motion_path", PROP_POINTER, PROP_NONE);
104 RNA_def_property_pointer_sdna(prop, nullptr, "mpath");
105 RNA_def_property_ui_text(prop, "Motion Path", "Motion Path for this element");
106}
107
109{
110 StructRNA *srna;
111 PropertyRNA *prop;
112
113 srna = RNA_def_struct(brna, "MotionPathVert", nullptr);
114 RNA_def_struct_sdna(srna, "bMotionPathVert");
115 RNA_def_struct_ui_text(srna, "Motion Path Cache Point", "Cached location on path");
116
117 prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_XYZ);
118 RNA_def_property_array(prop, 3);
119 RNA_def_property_ui_text(prop, "Coordinates", "");
120
121 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
123 RNA_def_property_ui_text(prop, "Select", "Path point is selected for editing");
124}
125
127{
128 StructRNA *srna;
129 PropertyRNA *prop;
130
131 srna = RNA_def_struct(brna, "MotionPath", nullptr);
132 RNA_def_struct_sdna(srna, "bMotionPath");
134 srna, "Motion Path", "Cache of the world-space positions of an element over a frame range");
135
136 /* Collections */
137 prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
138 RNA_def_property_collection_sdna(prop, nullptr, "points", "length");
139 RNA_def_property_struct_type(prop, "MotionPathVert");
140 RNA_def_property_ui_text(prop, "Motion Path Points", "Cached positions per frame");
141
142 /* Playback Ranges */
143 prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
144 RNA_def_property_int_sdna(prop, nullptr, "start_frame");
146 RNA_def_property_ui_text(prop, "Start Frame", "Starting frame of the stored range");
147
148 prop = RNA_def_property(srna, "frame_end", PROP_INT, PROP_TIME);
149 RNA_def_property_int_sdna(prop, nullptr, "end_frame");
151 RNA_def_property_ui_text(prop, "End Frame", "End frame of the stored range");
152
153 prop = RNA_def_property(srna, "length", PROP_INT, PROP_TIME);
155 RNA_def_property_ui_text(prop, "Length", "Number of frames cached");
156
157 /* Custom Color */
158 prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA);
159 RNA_def_property_array(prop, 3);
161 prop, "Color Pre", "Custom color for motion path before the current frame");
164
165 prop = RNA_def_property(srna, "color_post", PROP_FLOAT, PROP_COLOR_GAMMA);
166 RNA_def_property_array(prop, 3);
168 prop, "Color Post", "Custom color for motion path after the current frame");
171
172 /* Line width */
173 prop = RNA_def_property(srna, "line_thickness", PROP_INT, PROP_NONE);
174 RNA_def_property_int_sdna(prop, nullptr, "line_thickness");
175 RNA_def_property_range(prop, 1, 6);
176 RNA_def_property_ui_text(prop, "Line Thickness", "Line thickness for motion path");
179
180 /* Settings */
181 prop = RNA_def_property(srna, "use_bone_head", PROP_BOOLEAN, PROP_NONE);
185 prop,
186 "Use Bone Heads",
187 "For PoseBone paths, use the bone head location when calculating this path");
188
189 /* FIXME: Motion Paths are not currently editable... */
190 prop = RNA_def_property(srna, "is_modified", PROP_BOOLEAN, PROP_NONE);
192 RNA_def_property_ui_text(prop, "Edit Path", "Path is being edited");
193
194 /* Use custom color */
195 prop = RNA_def_property(srna, "use_custom_color", PROP_BOOLEAN, PROP_NONE);
197 RNA_def_property_ui_text(prop, "Custom Colors", "Use custom color for this motion path");
200
201 /* Draw lines between keyframes */
202 prop = RNA_def_property(srna, "lines", PROP_BOOLEAN, PROP_NONE);
204 RNA_def_property_ui_text(prop, "Lines", "Use straight lines between keyframe points");
206}
207
208/* --- */
209
211{
212 StructRNA *srna;
213 PropertyRNA *prop;
214
215 srna = RNA_def_struct(brna, "AnimVizMotionPaths", nullptr);
216 RNA_def_struct_sdna(srna, "bAnimVizSettings");
217 RNA_def_struct_nested(brna, srna, "AnimViz");
219 srna, "Motion Path Settings", "Motion Path settings for animation visualization");
220
222
223 /* Enums */
224 prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
225 RNA_def_property_enum_sdna(prop, nullptr, "path_type");
227 RNA_def_property_ui_text(prop, "Paths Type", "Type of range to show for Motion Paths");
229
230 prop = RNA_def_property(srna, "range", PROP_ENUM, PROP_NONE);
231 RNA_def_property_enum_sdna(prop, nullptr, "path_range");
233 RNA_def_property_ui_text(prop, "Paths Range", "Type of range to calculate for Motion Paths");
235
236 prop = RNA_def_property(srna, "bake_location", PROP_ENUM, PROP_NONE);
237 RNA_def_property_enum_bitflag_sdna(prop, nullptr, "path_bakeflag");
239 RNA_def_property_ui_text(prop, "Bake Location", "When calculating Bone Paths, use Head or Tips");
241
242 /* Settings */
243 prop = RNA_def_property(srna, "show_frame_numbers", PROP_BOOLEAN, PROP_NONE);
244 RNA_def_property_boolean_sdna(prop, nullptr, "path_viewflag", MOTIONPATH_VIEW_FNUMS);
245 RNA_def_property_ui_text(prop, "Show Frame Numbers", "Show frame numbers on Motion Paths");
247
248 prop = RNA_def_property(srna, "show_keyframe_highlight", PROP_BOOLEAN, PROP_NONE);
249 RNA_def_property_boolean_sdna(prop, nullptr, "path_viewflag", MOTIONPATH_VIEW_KFRAS);
251 prop, "Highlight Keyframes", "Emphasize position of keyframes on Motion Paths");
253
254 prop = RNA_def_property(srna, "show_keyframe_numbers", PROP_BOOLEAN, PROP_NONE);
255 RNA_def_property_boolean_sdna(prop, nullptr, "path_viewflag", MOTIONPATH_VIEW_KFNOS);
257 prop, "Show Keyframe Numbers", "Show frame numbers of Keyframes on Motion Paths");
259
260 prop = RNA_def_property(srna, "show_keyframe_action_all", PROP_BOOLEAN, PROP_NONE);
261 RNA_def_property_boolean_sdna(prop, nullptr, "path_viewflag", MOTIONPATH_VIEW_KFACT);
263 prop,
264 "All Action Keyframes",
265 "For bone motion paths, search whole Action for keyframes instead of in group"
266 " with matching name only (is slower)");
268
269 prop = RNA_def_property(srna, "frame_step", PROP_INT, PROP_NONE);
270 RNA_def_property_int_sdna(prop, nullptr, "path_step");
271 RNA_def_property_range(prop, 1, 100);
273 prop,
274 "Frame Step",
275 "Number of frames between paths shown (not for 'On Keyframes' Onion-skinning method)");
277
278 /* Playback Ranges */
279 prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
280 RNA_def_property_int_sdna(prop, nullptr, "path_sf");
281 RNA_def_property_int_funcs(prop, nullptr, "rna_AnimViz_path_start_frame_set", nullptr);
283 "Start Frame",
284 "Starting frame of range of paths to display/calculate "
285 "(not for 'Around Frame' Onion-skinning method)");
287
288 prop = RNA_def_property(srna, "frame_end", PROP_INT, PROP_TIME);
289 RNA_def_property_int_sdna(prop, nullptr, "path_ef");
290 RNA_def_property_int_funcs(prop, nullptr, "rna_AnimViz_path_end_frame_set", nullptr);
292 "End Frame",
293 "End frame of range of paths to display/calculate "
294 "(not for 'Around Frame' Onion-skinning method)");
296
297 /* Around Current Ranges */
298 prop = RNA_def_property(srna, "frame_before", PROP_INT, PROP_TIME);
299 RNA_def_property_int_sdna(prop, nullptr, "path_bc");
300 RNA_def_property_range(prop, 1, MAXFRAMEF / 2);
302 "Before Current",
303 "Number of frames to show before the current frame "
304 "(only for 'Around Frame' Onion-skinning method)");
306
307 prop = RNA_def_property(srna, "frame_after", PROP_INT, PROP_TIME);
308 RNA_def_property_int_sdna(prop, nullptr, "path_ac");
309 RNA_def_property_range(prop, 1, MAXFRAMEF / 2);
311 "After Current",
312 "Number of frames to show after the current frame "
313 "(only for 'Around Frame' Onion-skinning method)");
315
316 /* Readonly Property - Do any motion paths exist/need updating? (Mainly for bone paths) */
317 prop = RNA_def_property(srna, "has_motion_paths", PROP_BOOLEAN, PROP_NONE);
318 RNA_def_property_boolean_sdna(prop, nullptr, "path_bakeflag", MOTIONPATH_BAKE_HAS_PATHS);
319 /* NOTE: This is really an internal state var for convenience, so don't allow edits! */
322 prop, "Has Motion Paths", "Are there any bone paths that will need updating (read-only)");
323
324 /* If enabled, bakes the motion paths into camera space. */
325 prop = RNA_def_property(srna, "use_camera_space_bake", PROP_BOOLEAN, PROP_NONE);
326 RNA_def_property_boolean_sdna(prop, nullptr, "path_bakeflag", MOTIONPATH_BAKE_CAMERA_SPACE);
328 prop,
329 "Bake to active Camera",
330 "Motion path points will be baked into the camera space of the active camera. This means "
331 "they will only look right when looking through that camera. Switching cameras using "
332 "markers is not supported.");
333
335}
336
337/* --- */
338
340{
341 PropertyRNA *prop;
342
343 prop = RNA_def_property(srna, "animation_visualization", PROP_POINTER, PROP_NONE);
345 RNA_def_property_pointer_sdna(prop, nullptr, "avs");
347 RNA_def_property_ui_text(prop, "Animation Visualization", "Animation data for this data-block");
348}
349
350static void rna_def_animviz(BlenderRNA *brna)
351{
352 StructRNA *srna;
353 PropertyRNA *prop;
354
355 srna = RNA_def_struct(brna, "AnimViz", nullptr);
356 RNA_def_struct_sdna(srna, "bAnimVizSettings");
358 srna, "Animation Visualization", "Settings for the visualization of motion");
359
360 /* motion path settings (nested struct) */
361 prop = RNA_def_property(srna, "motion_path", PROP_POINTER, PROP_NONE);
364 RNA_def_property_struct_type(prop, "AnimVizMotionPaths");
365 RNA_def_property_pointer_funcs(prop, "rna_AnimViz_motion_paths_get", nullptr, nullptr, nullptr);
366 RNA_def_property_ui_text(prop, "Motion Paths", "Motion Path settings for visualization");
367}
368
369/* --- */
370
379
380#endif
#define CLAMP(a, b, c)
#define CLAMP_MAX(a, c)
#define CLAMP_MIN(a, b)
@ MOTIONPATH_BAKE_CAMERA_SPACE
@ 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_RANGE_MANUAL
@ 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.
@ PROP_FLOAT
Definition RNA_types.hh:67
@ PROP_BOOLEAN
Definition RNA_types.hh:65
@ PROP_ENUM
Definition RNA_types.hh:69
@ PROP_INT
Definition RNA_types.hh:66
@ PROP_POINTER
Definition RNA_types.hh:70
@ PROP_COLLECTION
Definition RNA_types.hh:71
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:355
@ PROP_EDITABLE
Definition RNA_types.hh:207
@ PROP_NEVER_NULL
Definition RNA_types.hh:266
@ PROP_TIME
Definition RNA_types.hh:156
@ PROP_XYZ
Definition RNA_types.hh:172
@ PROP_NONE
Definition RNA_types.hh:136
@ PROP_COLOR_GAMMA
Definition RNA_types.hh:175
#define ND_DRAW_ANIMVIZ
Definition WM_types.hh:440
#define NC_OBJECT
Definition WM_types.hh:346
unsigned int U
Definition btGjkEpa3.h:78
PointerRNA rna_pointer_inherit_refine(const PointerRNA *ptr, StructRNA *type, void *data)
const EnumPropertyItem rna_enum_motionpath_display_type_items[]
static void rna_def_animviz_motionpath_vert(BlenderRNA *brna)
const EnumPropertyItem rna_enum_motionpath_range_items[]
void rna_def_animviz_common(StructRNA *srna)
const EnumPropertyItem rna_enum_motionpath_bake_location_items[]
void RNA_def_animviz(BlenderRNA *brna)
static void rna_def_animviz_motion_path(BlenderRNA *brna)
static void rna_def_animviz(BlenderRNA *brna)
void rna_def_motionpath_common(StructRNA *srna)
static void rna_def_animviz_paths(BlenderRNA *brna)
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_define_lib_overridable(const bool make_overridable)
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
void RNA_def_property_array(PropertyRNA *prop, int length)
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
void RNA_def_property_enum_bitflag_sdna(PropertyRNA *prop, const char *structname, const char *propname)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *structname)
void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
void * data
Definition RNA_types.hh:42
PointerRNA * ptr
Definition wm_files.cc:4126