Blender  V2.93
rna_animviz.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_define.h"
32 #include "RNA_enum_types.h"
33 
34 #include "rna_internal.h"
35 
36 #include "WM_types.h"
37 
38 /* Which part of bone(s) get baked */
39 // TODO: icons?
41  {MOTIONPATH_BAKE_HEADS, "HEADS", 0, "Heads", "Calculate bone paths from heads"},
42  {0, "TAILS", 0, "Tails", "Calculate bone paths from tails"},
43 #if 0
44  {MOTIONPATH_BAKE_CENTERS,
45  "CENTROID",
46  0,
47  "Centers",
48  "Calculate bone paths from center of mass"},
49 #endif
50  {0, NULL, 0, NULL, NULL},
51 };
52 
53 #ifdef RNA_RUNTIME
54 
55 static PointerRNA rna_AnimViz_motion_paths_get(PointerRNA *ptr)
56 {
58 }
59 
60 static void rna_AnimViz_path_start_frame_set(PointerRNA *ptr, int value)
61 {
63 
64  /* XXX: Watch it! Path Start > MAXFRAME/2 could be a problem. */
65  data->path_sf = value;
66  FRAMENUMBER_MIN_CLAMP(data->path_sf);
67 
68  CLAMP(data->path_ef, data->path_sf + 1, MAXFRAME / 2);
69 }
70 
71 static void rna_AnimViz_path_end_frame_set(PointerRNA *ptr, int value)
72 {
74 
75  data->path_ef = value;
76  CLAMP_MAX(data->path_sf, data->path_ef - 1);
77  if (U.flag & USER_NONEGFRAMES) {
78  CLAMP_MIN(data->path_sf, 0);
79  CLAMP_MIN(data->path_ef, 1);
80  }
81 }
82 
83 #else
84 
86 {
87  PropertyRNA *prop;
88 
89  prop = RNA_def_property(srna, "motion_path", PROP_POINTER, PROP_NONE);
90  RNA_def_property_pointer_sdna(prop, NULL, "mpath");
91  RNA_def_property_ui_text(prop, "Motion Path", "Motion Path for this element");
92 }
93 
95 {
96  StructRNA *srna;
97  PropertyRNA *prop;
98 
99  srna = RNA_def_struct(brna, "MotionPathVert", NULL);
100  RNA_def_struct_sdna(srna, "bMotionPathVert");
101  RNA_def_struct_ui_text(srna, "Motion Path Cache Point", "Cached location on path");
102 
103  prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_XYZ);
104  RNA_def_property_array(prop, 3);
105  RNA_def_property_ui_text(prop, "Coordinates", "");
106 
107  prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
109  RNA_def_property_ui_text(prop, "Select", "Path point is selected for editing");
110 }
111 
113 {
114  StructRNA *srna;
115  PropertyRNA *prop;
116 
117  srna = RNA_def_struct(brna, "MotionPath", NULL);
118  RNA_def_struct_sdna(srna, "bMotionPath");
120  srna, "Motion Path", "Cache of the worldspace positions of an element over a frame range");
121 
122  /* Collections */
123  prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
124  RNA_def_property_collection_sdna(prop, NULL, "points", "length");
125  RNA_def_property_struct_type(prop, "MotionPathVert");
126  RNA_def_property_ui_text(prop, "Motion Path Points", "Cached positions per frame");
127 
128  /* Playback Ranges */
129  prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
130  RNA_def_property_int_sdna(prop, NULL, "start_frame");
132  RNA_def_property_ui_text(prop, "Start Frame", "Starting frame of the stored range");
133 
134  prop = RNA_def_property(srna, "frame_end", PROP_INT, PROP_TIME);
135  RNA_def_property_int_sdna(prop, NULL, "end_frame");
137  RNA_def_property_ui_text(prop, "End Frame", "End frame of the stored range");
138 
139  prop = RNA_def_property(srna, "length", PROP_INT, PROP_TIME);
141  RNA_def_property_ui_text(prop, "Length", "Number of frames cached");
142 
143  /* Custom Color */
144  prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA);
145  RNA_def_property_array(prop, 3);
146  RNA_def_property_ui_text(prop, "Color", "Custom color for motion path");
148 
149  /* Line width */
150  prop = RNA_def_property(srna, "line_thickness", PROP_INT, PROP_NONE);
151  RNA_def_property_int_sdna(prop, NULL, "line_thickness");
152  RNA_def_property_range(prop, 1, 6);
153  RNA_def_property_ui_text(prop, "Line Thickness", "Line thickness for motion path");
155 
156  /* Settings */
157  prop = RNA_def_property(srna, "use_bone_head", PROP_BOOLEAN, PROP_NONE);
161  prop,
162  "Use Bone Heads",
163  "For PoseBone paths, use the bone head location when calculating this path");
164 
165  /* FIXME: Motion Paths are not currently editable... */
166  prop = RNA_def_property(srna, "is_modified", PROP_BOOLEAN, PROP_NONE);
168  RNA_def_property_ui_text(prop, "Edit Path", "Path is being edited");
169 
170  /* Use custom color */
171  prop = RNA_def_property(srna, "use_custom_color", PROP_BOOLEAN, PROP_NONE);
173  RNA_def_property_ui_text(prop, "Custom Colors", "Use custom color for this motion path");
175 
176  /* Draw lines between keyframes */
177  prop = RNA_def_property(srna, "lines", PROP_BOOLEAN, PROP_NONE);
179  RNA_def_property_ui_text(prop, "Lines", "Use straight lines between keyframe points");
181 }
182 
183 /* --- */
184 
186 {
187  StructRNA *srna;
188  PropertyRNA *prop;
189 
190  static const EnumPropertyItem prop_type_items[] = {
192  "CURRENT_FRAME",
193  0,
194  "Around Frame",
195  "Display Paths of poses within a fixed number of frames around the current frame"},
197  "RANGE",
198  0,
199  "In Range",
200  "Display Paths of poses within specified range"},
201  {0, NULL, 0, NULL, NULL},
202  };
203 
204  srna = RNA_def_struct(brna, "AnimVizMotionPaths", NULL);
205  RNA_def_struct_sdna(srna, "bAnimVizSettings");
206  RNA_def_struct_nested(brna, srna, "AnimViz");
208  srna, "Motion Path Settings", "Motion Path settings for animation visualization");
209 
210  /* Enums */
211  prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
212  RNA_def_property_enum_sdna(prop, NULL, "path_type");
213  RNA_def_property_enum_items(prop, prop_type_items);
214  RNA_def_property_ui_text(prop, "Paths Type", "Type of range to show for Motion Paths");
216 
217  prop = RNA_def_property(srna, "bake_location", PROP_ENUM, PROP_NONE);
218  RNA_def_property_enum_bitflag_sdna(prop, NULL, "path_bakeflag");
220  RNA_def_property_ui_text(prop, "Bake Location", "When calculating Bone Paths, use Head or Tips");
222 
223  /* Settings */
224  prop = RNA_def_property(srna, "show_frame_numbers", PROP_BOOLEAN, PROP_NONE);
226  RNA_def_property_ui_text(prop, "Show Frame Numbers", "Show frame numbers on Motion Paths");
228 
229  prop = RNA_def_property(srna, "show_keyframe_highlight", PROP_BOOLEAN, PROP_NONE);
232  prop, "Highlight Keyframes", "Emphasize position of keyframes on Motion Paths");
234 
235  prop = RNA_def_property(srna, "show_keyframe_numbers", PROP_BOOLEAN, PROP_NONE);
238  prop, "Show Keyframe Numbers", "Show frame numbers of Keyframes on Motion Paths");
240 
241  prop = RNA_def_property(srna, "show_keyframe_action_all", PROP_BOOLEAN, PROP_NONE);
244  prop,
245  "All Action Keyframes",
246  "For bone motion paths, search whole Action for keyframes instead of in group"
247  " with matching name only (is slower)");
249 
250  prop = RNA_def_property(srna, "frame_step", PROP_INT, PROP_NONE);
251  RNA_def_property_int_sdna(prop, NULL, "path_step");
252  RNA_def_property_range(prop, 1, 100);
254  prop,
255  "Frame Step",
256  "Number of frames between paths shown (not for 'On Keyframes' Onion-skinning method)");
258 
259  /* Playback Ranges */
260  prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
261  RNA_def_property_int_sdna(prop, NULL, "path_sf");
262  RNA_def_property_int_funcs(prop, NULL, "rna_AnimViz_path_start_frame_set", NULL);
264  "Start Frame",
265  "Starting frame of range of paths to display/calculate "
266  "(not for 'Around Current Frame' Onion-skinning method)");
268 
269  prop = RNA_def_property(srna, "frame_end", PROP_INT, PROP_TIME);
270  RNA_def_property_int_sdna(prop, NULL, "path_ef");
271  RNA_def_property_int_funcs(prop, NULL, "rna_AnimViz_path_end_frame_set", NULL);
273  "End Frame",
274  "End frame of range of paths to display/calculate "
275  "(not for 'Around Current Frame' Onion-skinning method)");
277 
278  /* Around Current Ranges */
279  prop = RNA_def_property(srna, "frame_before", PROP_INT, PROP_TIME);
280  RNA_def_property_int_sdna(prop, NULL, "path_bc");
281  RNA_def_property_range(prop, 1, MAXFRAMEF / 2);
283  "Before Current",
284  "Number of frames to show before the current frame "
285  "(only for 'Around Current Frame' Onion-skinning method)");
287 
288  prop = RNA_def_property(srna, "frame_after", PROP_INT, PROP_TIME);
289  RNA_def_property_int_sdna(prop, NULL, "path_ac");
290  RNA_def_property_range(prop, 1, MAXFRAMEF / 2);
292  "After Current",
293  "Number of frames to show after the current frame "
294  "(only for 'Around Current Frame' Onion-skinning method)");
296 
297  /* Readonly Property - Do any motion paths exist/need updating? (Mainly for bone paths) */
298  prop = RNA_def_property(srna, "has_motion_paths", PROP_BOOLEAN, PROP_NONE);
300  /* NOTE: This is really an internal state var for convenience, so don't allow edits! */
303  prop, "Has Motion Paths", "Are there any bone paths that will need updating (read-only)");
304 }
305 
306 /* --- */
307 
309 {
310  PropertyRNA *prop;
311 
312  prop = RNA_def_property(srna, "animation_visualization", PROP_POINTER, PROP_NONE);
314  RNA_def_property_pointer_sdna(prop, NULL, "avs");
315  RNA_def_property_ui_text(prop, "Animation Visualization", "Animation data for this data-block");
316 }
317 
318 static void rna_def_animviz(BlenderRNA *brna)
319 {
320  StructRNA *srna;
321  PropertyRNA *prop;
322 
323  srna = RNA_def_struct(brna, "AnimViz", NULL);
324  RNA_def_struct_sdna(srna, "bAnimVizSettings");
326  srna, "Animation Visualization", "Settings for the visualization of motion");
327 
328  /* motion path settings (nested struct) */
329  prop = RNA_def_property(srna, "motion_path", PROP_POINTER, PROP_NONE);
331  RNA_def_property_struct_type(prop, "AnimVizMotionPaths");
332  RNA_def_property_pointer_funcs(prop, "rna_AnimViz_motion_paths_get", NULL, NULL, NULL);
333  RNA_def_property_ui_text(prop, "Motion Paths", "Motion Path settings for visualization");
334 }
335 
336 /* --- */
337 
339 {
340  rna_def_animviz(brna);
341  rna_def_animviz_paths(brna);
342 
345 }
346 
347 #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_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 RGB to Bright Vector Camera CLAMP
StructRNA RNA_AnimVizMotionPaths
@ PROP_FLOAT
Definition: RNA_types.h:75
@ PROP_BOOLEAN
Definition: RNA_types.h:73
@ PROP_ENUM
Definition: RNA_types.h:77
@ PROP_INT
Definition: RNA_types.h:74
@ PROP_POINTER
Definition: RNA_types.h:78
@ PROP_COLLECTION
Definition: RNA_types.h:79
@ PROP_EDITABLE
Definition: RNA_types.h:175
@ PROP_NEVER_NULL
Definition: RNA_types.h:225
@ PROP_TIME
Definition: RNA_types.h:133
@ PROP_XYZ
Definition: RNA_types.h:148
@ PROP_NONE
Definition: RNA_types.h:113
@ PROP_COLOR_GAMMA
Definition: RNA_types.h:151
#define ND_DRAW_ANIMVIZ
Definition: WM_types.h:374
#define NC_OBJECT
Definition: WM_types.h:280
unsigned int U
Definition: btGjkEpa3.h:78
PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *data)
Definition: rna_access.c:196
static void rna_def_animviz_motionpath_vert(BlenderRNA *brna)
Definition: rna_animviz.c:94
void rna_def_animviz_common(StructRNA *srna)
Definition: rna_animviz.c:308
const EnumPropertyItem rna_enum_motionpath_bake_location_items[]
Definition: rna_animviz.c:40
void RNA_def_animviz(BlenderRNA *brna)
Definition: rna_animviz.c:338
static void rna_def_animviz_motion_path(BlenderRNA *brna)
Definition: rna_animviz.c:112
static void rna_def_animviz(BlenderRNA *brna)
Definition: rna_animviz.c:318
void rna_def_motionpath_common(StructRNA *srna)
Definition: rna_animviz.c:85
static void rna_def_animviz_paths(BlenderRNA *brna)
Definition: rna_animviz.c:185
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2762
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_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1676
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
Definition: rna_define.c:1259
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_array(PropertyRNA *prop, int length)
Definition: rna_define.c:1568
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_property_update(PropertyRNA *prop, int noteflag, const char *func)
Definition: rna_define.c:2927
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1279
void RNA_def_property_enum_bitflag_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2691
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_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
Definition: rna_define.c:3055
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2364
void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *structname)
Definition: rna_define.c:1138
void * data
Definition: RNA_types.h:52
PointerRNA * ptr
Definition: wm_files.c:3157