Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rna_animviz.c « intern « makesrna « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0453b327b453fe6d96040752b82e351f6be1f010 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/* SPDX-License-Identifier: GPL-2.0-or-later */

/** \file
 * \ingroup RNA
 */

#include <stdlib.h>

#include "DNA_action_types.h"
#include "DNA_anim_types.h"
#include "DNA_scene_types.h"

#include "BLI_utildefines.h"

#include "MEM_guardedalloc.h"

#include "RNA_define.h"
#include "RNA_enum_types.h"

#include "rna_internal.h"

#include "WM_types.h"

/* Which part of bone(s) get baked */
// TODO: icons?
const EnumPropertyItem rna_enum_motionpath_bake_location_items[] = {
    {MOTIONPATH_BAKE_HEADS, "HEADS", 0, "Heads", "Calculate bone paths from heads"},
    {0, "TAILS", 0, "Tails", "Calculate bone paths from tails"},
#if 0
    {MOTIONPATH_BAKE_CENTERS,
     "CENTROID",
     0,
     "Centers",
     "Calculate bone paths from center of mass"},
#endif
    {0, NULL, 0, NULL, NULL},
};

const EnumPropertyItem rna_enum_motionpath_display_type_items[] = {
    {MOTIONPATH_TYPE_ACFRA,
     "CURRENT_FRAME",
     0,
     "Around Frame",
     "Display Paths of poses within a fixed number of frames around the current frame"},
    {MOTIONPATH_TYPE_RANGE,
     "RANGE",
     0,
     "In Range",
     "Display Paths of poses within specified range"},
    {0, NULL, 0, NULL, NULL},
};

const EnumPropertyItem rna_enum_motionpath_range_items[] = {
    {MOTIONPATH_RANGE_KEYS_ALL, "KEYS_ALL", 0, "All keys range", ""},
    {MOTIONPATH_RANGE_KEYS_SELECTED, "KEYS_SELECTED", 0, "Selected keys range", ""},
    {MOTIONPATH_RANGE_SCENE, "SCENE", 0, "Scene frame range", ""},
    {0, NULL, 0, NULL, NULL},
};

#ifdef RNA_RUNTIME

static PointerRNA rna_AnimViz_motion_paths_get(PointerRNA *ptr)
{
  return rna_pointer_inherit_refine(ptr, &RNA_AnimVizMotionPaths, ptr->data);
}

static void rna_AnimViz_path_start_frame_set(PointerRNA *ptr, int value)
{
  bAnimVizSettings *data = (bAnimVizSettings *)ptr->data;

  /* XXX: Watch it! Path Start > MAXFRAME/2 could be a problem. */
  data->path_sf = value;
  FRAMENUMBER_MIN_CLAMP(data->path_sf);

  CLAMP(data->path_ef, data->path_sf + 1, MAXFRAME / 2);
}

static void rna_AnimViz_path_end_frame_set(PointerRNA *ptr, int value)
{
  bAnimVizSettings *data = (bAnimVizSettings *)ptr->data;

  data->path_ef = value;
  CLAMP_MAX(data->path_sf, data->path_ef - 1);
  if (U.flag & USER_NONEGFRAMES) {
    CLAMP_MIN(data->path_sf, 0);
    CLAMP_MIN(data->path_ef, 1);
  }
}

#else

void rna_def_motionpath_common(StructRNA *srna)
{
  PropertyRNA *prop;

  prop = RNA_def_property(srna, "motion_path", PROP_POINTER, PROP_NONE);
  RNA_def_property_pointer_sdna(prop, NULL, "mpath");
  RNA_def_property_ui_text(prop, "Motion Path", "Motion Path for this element");
}

static void rna_def_animviz_motionpath_vert(BlenderRNA *brna)
{
  StructRNA *srna;
  PropertyRNA *prop;

  srna = RNA_def_struct(brna, "MotionPathVert", NULL);
  RNA_def_struct_sdna(srna, "bMotionPathVert");
  RNA_def_struct_ui_text(srna, "Motion Path Cache Point", "Cached location on path");

  prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_XYZ);
  RNA_def_property_array(prop, 3);
  RNA_def_property_ui_text(prop, "Coordinates", "");

  prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
  RNA_def_property_boolean_sdna(prop, NULL, "flag", MOTIONPATH_VERT_SEL);
  RNA_def_property_ui_text(prop, "Select", "Path point is selected for editing");
}

static void rna_def_animviz_motion_path(BlenderRNA *brna)
{
  StructRNA *srna;
  PropertyRNA *prop;

  srna = RNA_def_struct(brna, "MotionPath", NULL);
  RNA_def_struct_sdna(srna, "bMotionPath");
  RNA_def_struct_ui_text(
      srna, "Motion Path", "Cache of the world-space positions of an element over a frame range");

  /* Collections */
  prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
  RNA_def_property_collection_sdna(prop, NULL, "points", "length");
  RNA_def_property_struct_type(prop, "MotionPathVert");
  RNA_def_property_ui_text(prop, "Motion Path Points", "Cached positions per frame");

  /* Playback Ranges */
  prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
  RNA_def_property_int_sdna(prop, NULL, "start_frame");
  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
  RNA_def_property_ui_text(prop, "Start Frame", "Starting frame of the stored range");

  prop = RNA_def_property(srna, "frame_end", PROP_INT, PROP_TIME);
  RNA_def_property_int_sdna(prop, NULL, "end_frame");
  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
  RNA_def_property_ui_text(prop, "End Frame", "End frame of the stored range");

  prop = RNA_def_property(srna, "length", PROP_INT, PROP_TIME);
  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
  RNA_def_property_ui_text(prop, "Length", "Number of frames cached");

  /* Custom Color */
  prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA);
  RNA_def_property_array(prop, 3);
  RNA_def_property_ui_text(prop, "Color", "Custom color for motion path");
  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW_ANIMVIZ, NULL);

  /* Line width */
  prop = RNA_def_property(srna, "line_thickness", PROP_INT, PROP_NONE);
  RNA_def_property_int_sdna(prop, NULL, "line_thickness");
  RNA_def_property_range(prop, 1, 6);
  RNA_def_property_ui_text(prop, "Line Thickness", "Line thickness for motion path");
  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW_ANIMVIZ, NULL);

  /* Settings */
  prop = RNA_def_property(srna, "use_bone_head", PROP_BOOLEAN, PROP_NONE);
  RNA_def_property_boolean_sdna(prop, NULL, "flag", MOTIONPATH_FLAG_BHEAD);
  RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* xxx */
  RNA_def_property_ui_text(
      prop,
      "Use Bone Heads",
      "For PoseBone paths, use the bone head location when calculating this path");

  /* FIXME: Motion Paths are not currently editable... */
  prop = RNA_def_property(srna, "is_modified", PROP_BOOLEAN, PROP_NONE);
  RNA_def_property_boolean_sdna(prop, NULL, "flag", MOTIONPATH_FLAG_EDIT);
  RNA_def_property_ui_text(prop, "Edit Path", "Path is being edited");

  /* Use custom color */
  prop = RNA_def_property(srna, "use_custom_color", PROP_BOOLEAN, PROP_NONE);
  RNA_def_property_boolean_sdna(prop, NULL, "flag", MOTIONPATH_FLAG_CUSTOM);
  RNA_def_property_ui_text(prop, "Custom Colors", "Use custom color for this motion path");
  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW_ANIMVIZ, NULL);

  /* Draw lines between keyframes */
  prop = RNA_def_property(srna, "lines", PROP_BOOLEAN, PROP_NONE);
  RNA_def_property_boolean_sdna(prop, NULL, "flag", MOTIONPATH_FLAG_LINES);
  RNA_def_property_ui_text(prop, "Lines", "Use straight lines between keyframe points");
  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW_ANIMVIZ, NULL);
}

/* --- */

static void rna_def_animviz_paths(BlenderRNA *brna)
{
  StructRNA *srna;
  PropertyRNA *prop;

  srna = RNA_def_struct(brna, "AnimVizMotionPaths", NULL);
  RNA_def_struct_sdna(srna, "bAnimVizSettings");
  RNA_def_struct_nested(brna, srna, "AnimViz");
  RNA_def_struct_ui_text(
      srna, "Motion Path Settings", "Motion Path settings for animation visualization");

  RNA_define_lib_overridable(true);

  /* Enums */
  prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
  RNA_def_property_enum_sdna(prop, NULL, "path_type");
  RNA_def_property_enum_items(prop, rna_enum_motionpath_display_type_items);
  RNA_def_property_ui_text(prop, "Paths Type", "Type of range to show for Motion Paths");
  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW_ANIMVIZ, NULL);

  prop = RNA_def_property(srna, "range", PROP_ENUM, PROP_NONE);
  RNA_def_property_enum_sdna(prop, NULL, "path_range");
  RNA_def_property_enum_items(prop, rna_enum_motionpath_range_items);
  RNA_def_property_ui_text(prop, "Paths Range", "Type of range to calculate for Motion Paths");
  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW_ANIMVIZ, NULL);

  prop = RNA_def_property(srna, "bake_location", PROP_ENUM, PROP_NONE);
  RNA_def_property_enum_bitflag_sdna(prop, NULL, "path_bakeflag");
  RNA_def_property_enum_items(prop, rna_enum_motionpath_bake_location_items);
  RNA_def_property_ui_text(prop, "Bake Location", "When calculating Bone Paths, use Head or Tips");
  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW_ANIMVIZ, NULL);

  /* Settings */
  prop = RNA_def_property(srna, "show_frame_numbers", PROP_BOOLEAN, PROP_NONE);
  RNA_def_property_boolean_sdna(prop, NULL, "path_viewflag", MOTIONPATH_VIEW_FNUMS);
  RNA_def_property_ui_text(prop, "Show Frame Numbers", "Show frame numbers on Motion Paths");
  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW_ANIMVIZ, NULL);

  prop = RNA_def_property(srna, "show_keyframe_highlight", PROP_BOOLEAN, PROP_NONE);
  RNA_def_property_boolean_sdna(prop, NULL, "path_viewflag", MOTIONPATH_VIEW_KFRAS);
  RNA_def_property_ui_text(
      prop, "Highlight Keyframes", "Emphasize position of keyframes on Motion Paths");
  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW_ANIMVIZ, NULL);

  prop = RNA_def_property(srna, "show_keyframe_numbers", PROP_BOOLEAN, PROP_NONE);
  RNA_def_property_boolean_sdna(prop, NULL, "path_viewflag", MOTIONPATH_VIEW_KFNOS);
  RNA_def_property_ui_text(
      prop, "Show Keyframe Numbers", "Show frame numbers of Keyframes on Motion Paths");
  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW_ANIMVIZ, NULL);

  prop = RNA_def_property(srna, "show_keyframe_action_all", PROP_BOOLEAN, PROP_NONE);
  RNA_def_property_boolean_sdna(prop, NULL, "path_viewflag", MOTIONPATH_VIEW_KFACT);
  RNA_def_property_ui_text(
      prop,
      "All Action Keyframes",
      "For bone motion paths, search whole Action for keyframes instead of in group"
      " with matching name only (is slower)");
  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW_ANIMVIZ, NULL);

  prop = RNA_def_property(srna, "frame_step", PROP_INT, PROP_NONE);
  RNA_def_property_int_sdna(prop, NULL, "path_step");
  RNA_def_property_range(prop, 1, 100);
  RNA_def_property_ui_text(
      prop,
      "Frame Step",
      "Number of frames between paths shown (not for 'On Keyframes' Onion-skinning method)");
  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW_ANIMVIZ, NULL);

  /* Playback Ranges */
  prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
  RNA_def_property_int_sdna(prop, NULL, "path_sf");
  RNA_def_property_int_funcs(prop, NULL, "rna_AnimViz_path_start_frame_set", NULL);
  RNA_def_property_ui_text(prop,
                           "Start Frame",
                           "Starting frame of range of paths to display/calculate "
                           "(not for 'Around Current Frame' Onion-skinning method)");
  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW_ANIMVIZ, NULL);

  prop = RNA_def_property(srna, "frame_end", PROP_INT, PROP_TIME);
  RNA_def_property_int_sdna(prop, NULL, "path_ef");
  RNA_def_property_int_funcs(prop, NULL, "rna_AnimViz_path_end_frame_set", NULL);
  RNA_def_property_ui_text(prop,
                           "End Frame",
                           "End frame of range of paths to display/calculate "
                           "(not for 'Around Current Frame' Onion-skinning method)");
  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW_ANIMVIZ, NULL);

  /* Around Current Ranges */
  prop = RNA_def_property(srna, "frame_before", PROP_INT, PROP_TIME);
  RNA_def_property_int_sdna(prop, NULL, "path_bc");
  RNA_def_property_range(prop, 1, MAXFRAMEF / 2);
  RNA_def_property_ui_text(prop,
                           "Before Current",
                           "Number of frames to show before the current frame "
                           "(only for 'Around Current Frame' Onion-skinning method)");
  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW_ANIMVIZ, NULL);

  prop = RNA_def_property(srna, "frame_after", PROP_INT, PROP_TIME);
  RNA_def_property_int_sdna(prop, NULL, "path_ac");
  RNA_def_property_range(prop, 1, MAXFRAMEF / 2);
  RNA_def_property_ui_text(prop,
                           "After Current",
                           "Number of frames to show after the current frame "
                           "(only for 'Around Current Frame' Onion-skinning method)");
  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW_ANIMVIZ, NULL);

  /* Readonly Property - Do any motion paths exist/need updating? (Mainly for bone paths) */
  prop = RNA_def_property(srna, "has_motion_paths", PROP_BOOLEAN, PROP_NONE);
  RNA_def_property_boolean_sdna(prop, NULL, "path_bakeflag", MOTIONPATH_BAKE_HAS_PATHS);
  /* NOTE: This is really an internal state var for convenience, so don't allow edits! */
  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
  RNA_def_property_ui_text(
      prop, "Has Motion Paths", "Are there any bone paths that will need updating (read-only)");

  RNA_define_lib_overridable(false);
}

/* --- */

void rna_def_animviz_common(StructRNA *srna)
{
  PropertyRNA *prop;

  prop = RNA_def_property(srna, "animation_visualization", PROP_POINTER, PROP_NONE);
  RNA_def_property_flag(prop, PROP_NEVER_NULL);
  RNA_def_property_pointer_sdna(prop, NULL, "avs");
  RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
  RNA_def_property_ui_text(prop, "Animation Visualization", "Animation data for this data-block");
}

static void rna_def_animviz(BlenderRNA *brna)
{
  StructRNA *srna;
  PropertyRNA *prop;

  srna = RNA_def_struct(brna, "AnimViz", NULL);
  RNA_def_struct_sdna(srna, "bAnimVizSettings");
  RNA_def_struct_ui_text(
      srna, "Animation Visualization", "Settings for the visualization of motion");

  /* motion path settings (nested struct) */
  prop = RNA_def_property(srna, "motion_path", PROP_POINTER, PROP_NONE);
  RNA_def_property_flag(prop, PROP_NEVER_NULL);
  RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
  RNA_def_property_struct_type(prop, "AnimVizMotionPaths");
  RNA_def_property_pointer_funcs(prop, "rna_AnimViz_motion_paths_get", NULL, NULL, NULL);
  RNA_def_property_ui_text(prop, "Motion Paths", "Motion Path settings for visualization");
}

/* --- */

void RNA_def_animviz(BlenderRNA *brna)
{
  rna_def_animviz(brna);
  rna_def_animviz_paths(brna);

  rna_def_animviz_motion_path(brna);
  rna_def_animviz_motionpath_vert(brna);
}

#endif