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 
17 /** \file
18  * \ingroup RNA
19  */
20 
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?
40 const EnumPropertyItem rna_enum_motionpath_bake_location_items[] = {
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 
rna_AnimViz_motion_paths_get(PointerRNA * ptr)55 static PointerRNA rna_AnimViz_motion_paths_get(PointerRNA *ptr)
56 {
57   return rna_pointer_inherit_refine(ptr, &RNA_AnimVizMotionPaths, ptr->data);
58 }
59 
rna_AnimViz_path_start_frame_set(PointerRNA * ptr,int value)60 static void rna_AnimViz_path_start_frame_set(PointerRNA *ptr, int value)
61 {
62   bAnimVizSettings *data = (bAnimVizSettings *)ptr->data;
63 
64   /* XXX: watchit! 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 
rna_AnimViz_path_end_frame_set(PointerRNA * ptr,int value)71 static void rna_AnimViz_path_end_frame_set(PointerRNA *ptr, int value)
72 {
73   bAnimVizSettings *data = (bAnimVizSettings *)ptr->data;
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 
rna_def_motionpath_common(StructRNA * srna)85 void rna_def_motionpath_common(StructRNA *srna)
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 
rna_def_animviz_motionpath_vert(BlenderRNA * brna)94 static void rna_def_animviz_motionpath_vert(BlenderRNA *brna)
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);
108   RNA_def_property_boolean_sdna(prop, NULL, "flag", MOTIONPATH_VERT_SEL);
109   RNA_def_property_ui_text(prop, "Select", "Path point is selected for editing");
110 }
111 
rna_def_animviz_motion_path(BlenderRNA * brna)112 static void rna_def_animviz_motion_path(BlenderRNA *brna)
113 {
114   StructRNA *srna;
115   PropertyRNA *prop;
116 
117   srna = RNA_def_struct(brna, "MotionPath", NULL);
118   RNA_def_struct_sdna(srna, "bMotionPath");
119   RNA_def_struct_ui_text(
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");
131   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
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");
136   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
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);
140   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
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");
147   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
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 drawing path");
154   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
155 
156   /* Settings */
157   prop = RNA_def_property(srna, "use_bone_head", PROP_BOOLEAN, PROP_NONE);
158   RNA_def_property_boolean_sdna(prop, NULL, "flag", MOTIONPATH_FLAG_BHEAD);
159   RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* xxx */
160   RNA_def_property_ui_text(
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);
167   RNA_def_property_boolean_sdna(prop, NULL, "flag", MOTIONPATH_FLAG_EDIT);
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);
172   RNA_def_property_boolean_sdna(prop, NULL, "flag", MOTIONPATH_FLAG_CUSTOM);
173   RNA_def_property_ui_text(prop, "Custom Colors", "Use custom color for this motion path");
174   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
175 
176   /* Draw lines between keyframes */
177   prop = RNA_def_property(srna, "lines", PROP_BOOLEAN, PROP_NONE);
178   RNA_def_property_boolean_sdna(prop, NULL, "flag", MOTIONPATH_FLAG_LINES);
179   RNA_def_property_ui_text(prop, "Lines", "Draw straight lines between keyframe points");
180   RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
181 }
182 
183 /* --- */
184 
rna_def_animviz_paths(BlenderRNA * brna)185 static void rna_def_animviz_paths(BlenderRNA *brna)
186 {
187   StructRNA *srna;
188   PropertyRNA *prop;
189 
190   static const EnumPropertyItem prop_type_items[] = {
191       {MOTIONPATH_TYPE_ACFRA,
192        "CURRENT_FRAME",
193        0,
194        "Around Frame",
195        "Display Paths of poses within a fixed number of frames around the current frame"},
196       {MOTIONPATH_TYPE_RANGE,
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");
207   RNA_def_struct_ui_text(
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");
215   RNA_def_property_update(
216       prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
217 
218   prop = RNA_def_property(srna, "bake_location", PROP_ENUM, PROP_NONE);
219   RNA_def_property_enum_bitflag_sdna(prop, NULL, "path_bakeflag");
220   RNA_def_property_enum_items(prop, rna_enum_motionpath_bake_location_items);
221   RNA_def_property_ui_text(prop, "Bake Location", "When calculating Bone Paths, use Head or Tips");
222   RNA_def_property_update(
223       prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
224 
225   /* Settings */
226   prop = RNA_def_property(srna, "show_frame_numbers", PROP_BOOLEAN, PROP_NONE);
227   RNA_def_property_boolean_sdna(prop, NULL, "path_viewflag", MOTIONPATH_VIEW_FNUMS);
228   RNA_def_property_ui_text(prop, "Show Frame Numbers", "Show frame numbers on Motion Paths");
229   RNA_def_property_update(
230       prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
231 
232   prop = RNA_def_property(srna, "show_keyframe_highlight", PROP_BOOLEAN, PROP_NONE);
233   RNA_def_property_boolean_sdna(prop, NULL, "path_viewflag", MOTIONPATH_VIEW_KFRAS);
234   RNA_def_property_ui_text(
235       prop, "Highlight Keyframes", "Emphasize position of keyframes on Motion Paths");
236   RNA_def_property_update(
237       prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
238 
239   prop = RNA_def_property(srna, "show_keyframe_numbers", PROP_BOOLEAN, PROP_NONE);
240   RNA_def_property_boolean_sdna(prop, NULL, "path_viewflag", MOTIONPATH_VIEW_KFNOS);
241   RNA_def_property_ui_text(
242       prop, "Show Keyframe Numbers", "Show frame numbers of Keyframes on Motion Paths");
243   RNA_def_property_update(
244       prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
245 
246   prop = RNA_def_property(srna, "show_keyframe_action_all", PROP_BOOLEAN, PROP_NONE);
247   RNA_def_property_boolean_sdna(prop, NULL, "path_viewflag", MOTIONPATH_VIEW_KFACT);
248   RNA_def_property_ui_text(
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)");
253   RNA_def_property_update(
254       prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
255 
256   prop = RNA_def_property(srna, "frame_step", PROP_INT, PROP_NONE);
257   RNA_def_property_int_sdna(prop, NULL, "path_step");
258   RNA_def_property_range(prop, 1, 100);
259   RNA_def_property_ui_text(
260       prop,
261       "Frame Step",
262       "Number of frames between paths shown (not for 'On Keyframes' Onion-skinning method)");
263   RNA_def_property_update(
264       prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
265 
266   /* Playback Ranges */
267   prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
268   RNA_def_property_int_sdna(prop, NULL, "path_sf");
269   RNA_def_property_int_funcs(prop, NULL, "rna_AnimViz_path_start_frame_set", NULL);
270   RNA_def_property_ui_text(prop,
271                            "Start Frame",
272                            "Starting frame of range of paths to display/calculate "
273                            "(not for 'Around Current Frame' Onion-skinning method)");
274   RNA_def_property_update(
275       prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
276 
277   prop = RNA_def_property(srna, "frame_end", PROP_INT, PROP_TIME);
278   RNA_def_property_int_sdna(prop, NULL, "path_ef");
279   RNA_def_property_int_funcs(prop, NULL, "rna_AnimViz_path_end_frame_set", NULL);
280   RNA_def_property_ui_text(prop,
281                            "End Frame",
282                            "End frame of range of paths to display/calculate "
283                            "(not for 'Around Current Frame' Onion-skinning method)");
284   RNA_def_property_update(
285       prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
286 
287   /* Around Current Ranges */
288   prop = RNA_def_property(srna, "frame_before", PROP_INT, PROP_TIME);
289   RNA_def_property_int_sdna(prop, NULL, "path_bc");
290   RNA_def_property_range(prop, 1, MAXFRAMEF / 2);
291   RNA_def_property_ui_text(prop,
292                            "Before Current",
293                            "Number of frames to show before the current frame "
294                            "(only for 'Around Current Frame' Onion-skinning method)");
295   RNA_def_property_update(
296       prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
297 
298   prop = RNA_def_property(srna, "frame_after", PROP_INT, PROP_TIME);
299   RNA_def_property_int_sdna(prop, NULL, "path_ac");
300   RNA_def_property_range(prop, 1, MAXFRAMEF / 2);
301   RNA_def_property_ui_text(prop,
302                            "After Current",
303                            "Number of frames to show after the current frame "
304                            "(only for 'Around Current Frame' Onion-skinning method)");
305   RNA_def_property_update(
306       prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); /* XXX since this is only for 3d-view drawing */
307 
308   /* Readonly Property - Do any motion paths exist/need updating? (Mainly for bone paths) */
309   prop = RNA_def_property(srna, "has_motion_paths", PROP_BOOLEAN, PROP_NONE);
310   RNA_def_property_boolean_sdna(prop, NULL, "path_bakeflag", MOTIONPATH_BAKE_HAS_PATHS);
311   /* NOTE: This is really an internal state var for convenience, so don't allow edits! */
312   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
313   RNA_def_property_ui_text(
314       prop, "Has Motion Paths", "Are there any bone paths that will need updating (read-only)");
315 }
316 
317 /* --- */
318 
rna_def_animviz_common(StructRNA * srna)319 void rna_def_animviz_common(StructRNA *srna)
320 {
321   PropertyRNA *prop;
322 
323   prop = RNA_def_property(srna, "animation_visualization", PROP_POINTER, PROP_NONE);
324   RNA_def_property_flag(prop, PROP_NEVER_NULL);
325   RNA_def_property_pointer_sdna(prop, NULL, "avs");
326   RNA_def_property_ui_text(prop, "Animation Visualization", "Animation data for this data-block");
327 }
328 
rna_def_animviz(BlenderRNA * brna)329 static void rna_def_animviz(BlenderRNA *brna)
330 {
331   StructRNA *srna;
332   PropertyRNA *prop;
333 
334   srna = RNA_def_struct(brna, "AnimViz", NULL);
335   RNA_def_struct_sdna(srna, "bAnimVizSettings");
336   RNA_def_struct_ui_text(
337       srna, "Animation Visualization", "Settings for the visualization of motion");
338 
339   /* motion path settings (nested struct) */
340   prop = RNA_def_property(srna, "motion_path", PROP_POINTER, PROP_NONE);
341   RNA_def_property_flag(prop, PROP_NEVER_NULL);
342   RNA_def_property_struct_type(prop, "AnimVizMotionPaths");
343   RNA_def_property_pointer_funcs(prop, "rna_AnimViz_motion_paths_get", NULL, NULL, NULL);
344   RNA_def_property_ui_text(prop, "Motion Paths", "Motion Path settings for visualization");
345 }
346 
347 /* --- */
348 
RNA_def_animviz(BlenderRNA * brna)349 void RNA_def_animviz(BlenderRNA *brna)
350 {
351   rna_def_animviz(brna);
352   rna_def_animviz_paths(brna);
353 
354   rna_def_animviz_motion_path(brna);
355   rna_def_animviz_motionpath_vert(brna);
356 }
357 
358 #endif
359