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