2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Blender Foundation (2008).
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file blender/makesrna/intern/rna_key.c
30 #include "DNA_scene_types.h"
31 #include "DNA_curve_types.h"
32 #include "DNA_key_types.h"
33 #include "DNA_lattice_types.h"
34 #include "DNA_mesh_types.h"
36 #include "BLI_string_utils.h"
37 #include "BLI_utildefines.h"
39 #include "BLT_translation.h"
41 #include "RNA_access.h"
42 #include "RNA_define.h"
43 #include "RNA_enum_types.h"
45 #include "rna_internal.h"
51 #include "DNA_object_types.h"
53 #include "BKE_animsys.h"
57 #include "DEG_depsgraph.h"
62 static Key *rna_ShapeKey_find_key(ID *id)
64 switch (GS(id->name)) {
65 case ID_CU: return ((Curve *)id)->key;
66 case ID_KE: return (Key *)id;
67 case ID_LT: return ((Lattice *)id)->key;
68 case ID_ME: return ((Mesh *)id)->key;
69 case ID_OB: return BKE_key_from_object((Object *)id);
74 static void rna_ShapeKey_name_set(PointerRNA *ptr, const char *value)
76 KeyBlock *kb = ptr->data;
77 char oldname[sizeof(kb->name)];
79 /* make a copy of the old name first */
80 BLI_strncpy(oldname, kb->name, sizeof(kb->name));
82 /* copy the new name into the name slot */
83 BLI_strncpy_utf8(kb->name, value, sizeof(kb->name));
85 /* make sure the name is truly unique */
87 Key *key = rna_ShapeKey_find_key(ptr->id.data);
88 BLI_uniquename(&key->block, kb, CTX_DATA_(BLT_I18NCONTEXT_ID_SHAPEKEY, "Key"), '.',
89 offsetof(KeyBlock, name), sizeof(kb->name));
92 /* fix all the animation data which may link to this */
93 BKE_animdata_fix_paths_rename_all(NULL, "key_blocks", oldname, kb->name);
96 static float rna_ShapeKey_frame_get(PointerRNA *ptr)
98 KeyBlock *kb = (KeyBlock *)ptr->data;
99 return kb->pos * 100.0f; /* Because pos is ctime/100... */
102 static void rna_ShapeKey_value_set(PointerRNA *ptr, float value)
104 KeyBlock *data = (KeyBlock *)ptr->data;
105 CLAMP(value, data->slidermin, data->slidermax);
106 data->curval = value;
109 static void rna_ShapeKey_value_range(PointerRNA *ptr, float *min, float *max,
110 float *UNUSED(softmin), float *UNUSED(softmax))
112 KeyBlock *data = (KeyBlock *)ptr->data;
114 *min = data->slidermin;
115 *max = data->slidermax;
118 /* epsilon for how close one end of shapekey range can get to the other */
119 #define SHAPEKEY_SLIDER_TOL 0.001f
121 static void rna_ShapeKey_slider_min_range(PointerRNA *ptr, float *min, float *max,
122 float *UNUSED(softmin), float *UNUSED(softmax))
124 KeyBlock *data = (KeyBlock *)ptr->data;
127 *max = data->slidermax - SHAPEKEY_SLIDER_TOL;
130 static void rna_ShapeKey_slider_min_set(PointerRNA *ptr, float value)
132 KeyBlock *data = (KeyBlock *)ptr->data;
133 float min, max, softmin, softmax;
135 rna_ShapeKey_slider_min_range(ptr, &min, &max, &softmin, &softmax);
136 CLAMP(value, min, max);
137 data->slidermin = value;
140 static void rna_ShapeKey_slider_max_range(PointerRNA *ptr, float *min, float *max,
141 float *UNUSED(softmin), float *UNUSED(softmax))
143 KeyBlock *data = (KeyBlock *)ptr->data;
145 *min = data->slidermin + SHAPEKEY_SLIDER_TOL;
149 static void rna_ShapeKey_slider_max_set(PointerRNA *ptr, float value)
151 KeyBlock *data = (KeyBlock *)ptr->data;
152 float min, max, softmin, softmax;
154 rna_ShapeKey_slider_max_range(ptr, &min, &max, &softmin, &softmax);
155 CLAMP(value, min, max);
156 data->slidermax = value;
159 #undef SHAPEKEY_SLIDER_TOL
161 /* ***** Normals accessors for shapekeys. ***** */
162 /* Note: with this we may recompute several times the same data, should we want to access verts, then polys, then loops
163 * normals... However, such case looks rather unlikely - and not worth adding some kind of caching in KeyBlocks.
166 static Mesh *rna_KeyBlock_normals_get_mesh(PointerRNA *ptr, ID *id)
168 Key *key = rna_ShapeKey_find_key((id == NULL && ptr != NULL) ? ptr->id.data : id);
169 id = key ? key->from : NULL;
172 switch (GS(id->name)) {
177 Object *ob = (Object *)id;
178 if (ob->type == OB_MESH) {
190 static int rna_KeyBlock_normals_vert_len(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
192 Mesh *me = rna_KeyBlock_normals_get_mesh(ptr, NULL);
194 length[0] = me ? me->totvert : 0;
197 return (length[0] * length[1]);
200 static void rna_KeyBlock_normals_vert_calc(ID *id, KeyBlock *data, int *normals_len, float **normals)
202 Mesh *me = rna_KeyBlock_normals_get_mesh(NULL, id);
204 *normals_len = (me ? me->totvert : 0) * 3;
206 if (ELEM(NULL, me, data) || (me->totvert == 0)) {
211 *normals = MEM_mallocN(sizeof(**normals) * (size_t)(*normals_len), __func__);
213 BKE_keyblock_mesh_calc_normals(data, me, (float (*)[3])(*normals), NULL, NULL);
216 static int rna_KeyBlock_normals_poly_len(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
218 Mesh *me = rna_KeyBlock_normals_get_mesh(ptr, NULL);
220 length[0] = me ? me->totpoly : 0;
223 return (length[0] * length[1]);
226 static void rna_KeyBlock_normals_poly_calc(ID *id, KeyBlock *data, int *normals_len, float **normals)
228 Mesh *me = rna_KeyBlock_normals_get_mesh(NULL, id);
230 *normals_len = (me ? me->totpoly : 0) * 3;
232 if (ELEM(NULL, me, data) || (me->totpoly == 0)) {
237 *normals = MEM_mallocN(sizeof(**normals) * (size_t)(*normals_len), __func__);
239 BKE_keyblock_mesh_calc_normals(data, me, NULL, (float (*)[3])(*normals), NULL);
242 static int rna_KeyBlock_normals_loop_len(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
244 Mesh *me = rna_KeyBlock_normals_get_mesh(ptr, NULL);
246 length[0] = me ? me->totloop : 0;
249 return (length[0] * length[1]);
252 static void rna_KeyBlock_normals_loop_calc(ID *id, KeyBlock *data, int *normals_len, float **normals)
254 Mesh *me = rna_KeyBlock_normals_get_mesh(NULL, id);
256 *normals_len = (me ? me->totloop : 0) * 3;
258 if (ELEM(NULL, me, data) || (me->totloop == 0)) {
263 *normals = MEM_mallocN(sizeof(**normals) * (size_t)(*normals_len), __func__);
265 BKE_keyblock_mesh_calc_normals(data, me, NULL, NULL, (float (*)[3])(*normals));
269 PointerRNA rna_object_shapekey_index_get(ID *id, int value)
271 Key *key = rna_ShapeKey_find_key(id);
275 if (key && value < key->totkey)
276 kb = BLI_findlink(&key->block, value);
278 RNA_pointer_create(id, &RNA_ShapeKey, kb, &ptr);
283 int rna_object_shapekey_index_set(ID *id, PointerRNA value, int current)
285 Key *key = rna_ShapeKey_find_key(id);
288 int a = BLI_findindex(&key->block, value.data);
289 if (a != -1) return a;
295 static PointerRNA rna_ShapeKey_relative_key_get(PointerRNA *ptr)
297 KeyBlock *kb = (KeyBlock *)ptr->data;
299 return rna_object_shapekey_index_get(ptr->id.data, kb->relative);
302 static void rna_ShapeKey_relative_key_set(PointerRNA *ptr, PointerRNA value)
304 KeyBlock *kb = (KeyBlock *)ptr->data;
306 kb->relative = rna_object_shapekey_index_set(ptr->id.data, value, kb->relative);
309 static void rna_ShapeKeyPoint_co_get(PointerRNA *ptr, float *values)
311 float *vec = (float *)ptr->data;
318 static void rna_ShapeKeyPoint_co_set(PointerRNA *ptr, const float *values)
320 float *vec = (float *)ptr->data;
327 static float rna_ShapeKeyCurvePoint_tilt_get(PointerRNA *ptr)
329 float *vec = (float *)ptr->data;
333 static void rna_ShapeKeyCurvePoint_tilt_set(PointerRNA *ptr, float value)
335 float *vec = (float *)ptr->data;
339 static void rna_ShapeKeyBezierPoint_co_get(PointerRNA *ptr, float *values)
341 float *vec = (float *)ptr->data;
343 values[0] = vec[0 + 3];
344 values[1] = vec[1 + 3];
345 values[2] = vec[2 + 3];
348 static void rna_ShapeKeyBezierPoint_co_set(PointerRNA *ptr, const float *values)
350 float *vec = (float *)ptr->data;
352 vec[0 + 3] = values[0];
353 vec[1 + 3] = values[1];
354 vec[2 + 3] = values[2];
357 static void rna_ShapeKeyBezierPoint_handle_1_co_get(PointerRNA *ptr, float *values)
359 float *vec = (float *)ptr->data;
366 static void rna_ShapeKeyBezierPoint_handle_1_co_set(PointerRNA *ptr, const float *values)
368 float *vec = (float *)ptr->data;
375 static void rna_ShapeKeyBezierPoint_handle_2_co_get(PointerRNA *ptr, float *values)
377 float *vec = (float *)ptr->data;
379 values[0] = vec[6 + 0];
380 values[1] = vec[6 + 1];
381 values[2] = vec[6 + 2];
384 static void rna_ShapeKeyBezierPoint_handle_2_co_set(PointerRNA *ptr, const float *values)
386 float *vec = (float *)ptr->data;
388 vec[6 + 0] = values[0];
389 vec[6 + 1] = values[1];
390 vec[6 + 2] = values[2];
394 static float rna_ShapeKeyBezierPoint_tilt_get(PointerRNA *ptr)
396 float *vec = (float *)ptr->data;
400 static void rna_ShapeKeyBezierPoint_tilt_set(PointerRNA *ptr, float value)
402 float *vec = (float *)ptr->data;
407 static void rna_ShapeKey_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
409 Key *key = rna_ShapeKey_find_key(ptr->id.data);
410 KeyBlock *kb = (KeyBlock *)ptr->data;
413 int tot = kb->totelem, size = key->elemsize;
415 if (GS(key->from->name) == ID_CU) {
416 cu = (Curve *)key->from;
425 rna_iterator_array_begin(iter, (void *)kb->data, size, tot, 0, NULL);
428 static int rna_ShapeKey_data_length(PointerRNA *ptr)
430 Key *key = rna_ShapeKey_find_key(ptr->id.data);
431 KeyBlock *kb = (KeyBlock *)ptr->data;
434 int tot = kb->totelem;
436 if (GS(key->from->name) == ID_CU) {
437 cu = (Curve *)key->from;
447 static PointerRNA rna_ShapeKey_data_get(CollectionPropertyIterator *iter)
449 Key *key = rna_ShapeKey_find_key(iter->parent.id.data);
454 if (GS(key->from->name) == ID_CU) {
455 cu = (Curve *)key->from;
459 type = &RNA_ShapeKeyBezierPoint;
461 type = &RNA_ShapeKeyCurvePoint;
464 type = &RNA_ShapeKeyPoint;
466 return rna_pointer_inherit_refine(&iter->parent, type, rna_iterator_array_get(iter));
469 static char *rna_ShapeKey_path(PointerRNA *ptr)
471 KeyBlock *kb = (KeyBlock *)ptr->data;
472 ID *id = ptr->id.data;
473 char name_esc[sizeof(kb->name) * 2];
475 BLI_strescape(name_esc, kb->name, sizeof(name_esc));
477 if ((id) && (GS(id->name) != ID_KE))
478 return BLI_sprintfN("shape_keys.key_blocks[\"%s\"]", name_esc);
480 return BLI_sprintfN("key_blocks[\"%s\"]", name_esc);
483 static void rna_Key_update_data(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
485 Key *key = ptr->id.data;
488 for (ob = bmain->object.first; ob; ob = ob->id.next) {
489 if (BKE_key_from_object(ob) == key) {
490 DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
491 WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ob);
496 static KeyBlock *rna_ShapeKeyData_find_keyblock(Key *key, float *point)
501 if (ELEM(NULL, key, point))
504 /* we'll need to manually search through the keyblocks and check
505 * if the point is somewhere in the middle of each block's data
507 for (kb = key->block.first; kb; kb = kb->next) {
509 float *start = (float *)kb->data;
512 /* easy cases first */
513 if ((start == NULL) || (start > point)) {
514 /* there's no chance point is in array */
517 else if (start == point) {
518 /* exact match - point is first in array */
522 /* determine where end of array is
523 * - elemsize is in bytes, so use (char *) cast to get array in terms of bytes
525 end = (float *)((char *)start + (key->elemsize * kb->totelem));
527 /* if point's address is less than the end, then it is somewhere between start and end, so in array */
529 /* we've found the owner of the point data */
538 static int rna_ShapeKeyPoint_get_index(Key *key, KeyBlock *kb, float *point)
540 /* if we frame the data array and point pointers as (char *), then the difference between
541 * them will be in bytes. Thus, dividing through by key->elemsize (number of bytes per point)
542 * gives us the offset of point from start of array.
544 char *start = (char *)kb->data;
545 char *pt = (char *)point;
547 return (int)(pt - start) / key->elemsize;
550 static int rna_ShapeKeyBezierPoint_get_index(KeyBlock *kb, float *point)
552 float *start = (float *)kb->data;
554 /* Unlike with rna_ShapeKeyPoint_get_index(), we cannot use key->elemsize here
555 * since the default value for curves (16) is actually designed for BPoints
556 * (i.e. NURBS Surfaces). The magic number "12" here was found by empirical
557 * testing on a 64-bit system, and is similar to what's used for meshes and
558 * lattices. For more details, see T38013
560 return (int)(point - start) / 12;
563 static char *rna_ShapeKeyPoint_path(PointerRNA *ptr)
565 ID *id = (ID *)ptr->id.data;
566 Key *key = rna_ShapeKey_find_key(ptr->id.data);
568 float *point = (float *)ptr->data;
570 /* if we can get a key block, we can construct a path */
571 kb = rna_ShapeKeyData_find_keyblock(key, point);
574 char name_esc_kb[sizeof(kb->name) * 2];
577 if (ptr->type == &RNA_ShapeKeyBezierPoint)
578 index = rna_ShapeKeyBezierPoint_get_index(kb, point);
580 index = rna_ShapeKeyPoint_get_index(key, kb, point);
582 BLI_strescape(name_esc_kb, kb->name, sizeof(name_esc_kb));
584 if (GS(id->name) == ID_KE)
585 return BLI_sprintfN("key_blocks[\"%s\"].data[%d]", name_esc_kb, index);
587 return BLI_sprintfN("shape_keys.key_blocks[\"%s\"].data[%d]", name_esc_kb, index);
590 return NULL; /* XXX: there's really no way to resolve this... */
595 EnumPropertyItem rna_enum_keyblock_type_items[] = {
596 {KEY_LINEAR, "KEY_LINEAR", 0, "Linear", ""},
597 {KEY_CARDINAL, "KEY_CARDINAL", 0, "Cardinal", ""},
598 {KEY_CATMULL_ROM, "KEY_CATMULL_ROM", 0, "Catmull-Rom", ""},
599 {KEY_BSPLINE, "KEY_BSPLINE", 0, "BSpline", ""},
600 {0, NULL, 0, NULL, NULL}
603 static void rna_def_keydata(BlenderRNA *brna)
608 srna = RNA_def_struct(brna, "ShapeKeyPoint", NULL);
609 RNA_def_struct_ui_text(srna, "Shape Key Point", "Point in a shape key");
610 RNA_def_struct_path_func(srna, "rna_ShapeKeyPoint_path");
612 prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION);
613 RNA_def_property_array(prop, 3);
614 RNA_def_property_float_funcs(prop, "rna_ShapeKeyPoint_co_get", "rna_ShapeKeyPoint_co_set", NULL);
615 RNA_def_property_ui_text(prop, "Location", "");
616 RNA_def_property_update(prop, 0, "rna_Key_update_data");
618 srna = RNA_def_struct(brna, "ShapeKeyCurvePoint", NULL);
619 RNA_def_struct_ui_text(srna, "Shape Key Curve Point", "Point in a shape key for curves");
620 /* there's nothing type specific here, so this is fine for now */
621 RNA_def_struct_path_func(srna, "rna_ShapeKeyPoint_path");
623 prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION);
624 RNA_def_property_array(prop, 3);
625 RNA_def_property_float_funcs(prop, "rna_ShapeKeyPoint_co_get", "rna_ShapeKeyPoint_co_set", NULL);
626 RNA_def_property_ui_text(prop, "Location", "");
627 RNA_def_property_update(prop, 0, "rna_Key_update_data");
629 prop = RNA_def_property(srna, "tilt", PROP_FLOAT, PROP_NONE);
630 RNA_def_property_float_funcs(prop, "rna_ShapeKeyCurvePoint_tilt_get", "rna_ShapeKeyCurvePoint_tilt_set", NULL);
631 RNA_def_property_ui_text(prop, "Tilt", "");
632 RNA_def_property_update(prop, 0, "rna_Key_update_data");
634 srna = RNA_def_struct(brna, "ShapeKeyBezierPoint", NULL);
635 RNA_def_struct_ui_text(srna, "Shape Key Bezier Point", "Point in a shape key for Bezier curves");
636 /* there's nothing type specific here, so this is fine for now */
637 RNA_def_struct_path_func(srna, "rna_ShapeKeyPoint_path");
639 prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION);
640 RNA_def_property_array(prop, 3);
641 RNA_def_property_float_funcs(prop, "rna_ShapeKeyBezierPoint_co_get", "rna_ShapeKeyBezierPoint_co_set", NULL);
642 RNA_def_property_ui_text(prop, "Location", "");
643 RNA_def_property_update(prop, 0, "rna_Key_update_data");
645 prop = RNA_def_property(srna, "handle_left", PROP_FLOAT, PROP_TRANSLATION);
646 RNA_def_property_array(prop, 3);
647 RNA_def_property_float_funcs(prop, "rna_ShapeKeyBezierPoint_handle_1_co_get",
648 "rna_ShapeKeyBezierPoint_handle_1_co_set", NULL);
649 RNA_def_property_ui_text(prop, "Handle 1 Location", "");
650 RNA_def_property_update(prop, 0, "rna_Key_update_data");
652 prop = RNA_def_property(srna, "handle_right", PROP_FLOAT, PROP_TRANSLATION);
653 RNA_def_property_array(prop, 3);
654 RNA_def_property_float_funcs(prop, "rna_ShapeKeyBezierPoint_handle_2_co_get",
655 "rna_ShapeKeyBezierPoint_handle_2_co_set", NULL);
656 RNA_def_property_ui_text(prop, "Handle 2 Location", "");
657 RNA_def_property_update(prop, 0, "rna_Key_update_data");
659 /* appears to be unused currently */
661 prop = RNA_def_property(srna, "tilt", PROP_FLOAT, PROP_NONE);
662 RNA_def_property_float_funcs(prop, "rna_ShapeKeyBezierPoint_tilt_get", "rna_ShapeKeyBezierPoint_tilt_set", NULL);
663 RNA_def_property_ui_text(prop, "Tilt", "");
664 RNA_def_property_update(prop, 0, "rna_Key_update_data");
668 static void rna_def_keyblock(BlenderRNA *brna)
671 PropertyRNA *prop, *parm;
674 srna = RNA_def_struct(brna, "ShapeKey", NULL);
675 RNA_def_struct_ui_text(srna, "Shape Key", "Shape key in a shape keys data-block");
676 RNA_def_struct_sdna(srna, "KeyBlock");
677 RNA_def_struct_path_func(srna, "rna_ShapeKey_path");
678 RNA_def_struct_ui_icon(srna, ICON_SHAPEKEY_DATA);
680 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
681 RNA_def_property_ui_text(prop, "Name", "Name of Shape Key");
682 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_ShapeKey_name_set");
683 RNA_def_property_update(prop, 0, "rna_Key_update_data");
684 RNA_def_struct_name_property(srna, prop);
686 /* keys need to be sorted to edit this */
687 prop = RNA_def_property(srna, "frame", PROP_FLOAT, PROP_TIME);
688 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
689 RNA_def_property_float_sdna(prop, NULL, "pos");
690 RNA_def_property_float_funcs(prop, "rna_ShapeKey_frame_get", NULL, NULL);
691 RNA_def_property_ui_text(prop, "Frame", "Frame for absolute keys");
692 RNA_def_property_update(prop, 0, "rna_Key_update_data");
694 /* for now, this is editable directly, as users can set this even if they're not animating them
695 * (to test results) */
696 prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_FACTOR);
697 RNA_def_property_float_sdna(prop, NULL, "curval");
698 RNA_def_property_float_funcs(prop, NULL, "rna_ShapeKey_value_set", "rna_ShapeKey_value_range");
699 RNA_def_property_ui_range(prop, -10.0f, 10.0f, 10, 3);
700 RNA_def_property_ui_text(prop, "Value", "Value of shape key at the current frame");
701 RNA_def_property_update(prop, 0, "rna_Key_update_data");
703 prop = RNA_def_property(srna, "interpolation", PROP_ENUM, PROP_NONE);
704 RNA_def_property_enum_sdna(prop, NULL, "type");
705 RNA_def_property_enum_items(prop, rna_enum_keyblock_type_items);
706 RNA_def_property_ui_text(prop, "Interpolation", "Interpolation type for absolute shape keys");
707 RNA_def_property_update(prop, 0, "rna_Key_update_data");
709 prop = RNA_def_property(srna, "vertex_group", PROP_STRING, PROP_NONE);
710 RNA_def_property_string_sdna(prop, NULL, "vgroup");
711 RNA_def_property_ui_text(prop, "Vertex Group", "Vertex weight group, to blend with basis shape");
712 RNA_def_property_update(prop, 0, "rna_Key_update_data");
714 prop = RNA_def_property(srna, "relative_key", PROP_POINTER, PROP_NONE);
715 RNA_def_property_struct_type(prop, "ShapeKey");
716 RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
717 RNA_def_property_pointer_funcs(prop, "rna_ShapeKey_relative_key_get",
718 "rna_ShapeKey_relative_key_set", NULL, NULL);
719 RNA_def_property_ui_text(prop, "Relative Key", "Shape used as a relative key");
720 RNA_def_property_update(prop, 0, "rna_Key_update_data");
722 prop = RNA_def_property(srna, "mute", PROP_BOOLEAN, PROP_NONE);
723 RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYBLOCK_MUTE);
724 RNA_def_property_ui_text(prop, "Mute", "Mute this shape key");
725 RNA_def_property_ui_icon(prop, ICON_RESTRICT_VIEW_OFF, 1);
726 RNA_def_property_update(prop, 0, "rna_Key_update_data");
728 prop = RNA_def_property(srna, "slider_min", PROP_FLOAT, PROP_NONE);
729 RNA_def_property_float_sdna(prop, NULL, "slidermin");
730 RNA_def_property_range(prop, -10.0f, 10.0f);
731 RNA_def_property_float_funcs(prop, NULL, "rna_ShapeKey_slider_min_set", "rna_ShapeKey_slider_min_range");
732 RNA_def_property_ui_text(prop, "Slider Min", "Minimum for slider");
734 prop = RNA_def_property(srna, "slider_max", PROP_FLOAT, PROP_NONE);
735 RNA_def_property_float_sdna(prop, NULL, "slidermax");
736 RNA_def_property_range(prop, -10.0f, 10.0f);
737 RNA_def_property_float_default(prop, 1.0f);
738 RNA_def_property_float_funcs(prop, NULL, "rna_ShapeKey_slider_max_set", "rna_ShapeKey_slider_max_range");
739 RNA_def_property_ui_text(prop, "Slider Max", "Maximum for slider");
741 prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
742 RNA_def_property_collection_sdna(prop, NULL, "data", "totelem");
743 RNA_def_property_struct_type(prop, "UnknownType");
744 RNA_def_property_ui_text(prop, "Data", "");
745 RNA_def_property_collection_funcs(prop, "rna_ShapeKey_data_begin", NULL, NULL, "rna_ShapeKey_data_get",
746 "rna_ShapeKey_data_length", NULL, NULL, NULL);
748 /* XXX multi-dim dynamic arrays are very badly supported by (py)rna currently, those are defined for the day
749 * it works better, for now user will get a 1D tuple...
751 func = RNA_def_function(srna, "normals_vertex_get", "rna_KeyBlock_normals_vert_calc");
752 RNA_def_function_ui_description(func, "Compute local space vertices' normals for this shape key");
753 RNA_def_function_flag(func, FUNC_USE_SELF_ID);
754 parm = RNA_def_property(func, "normals", PROP_FLOAT, /* PROP_DIRECTION */ PROP_NONE);
755 RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_OUTPUT);
756 RNA_def_property_multi_array(parm, 2, NULL);
757 RNA_def_property_range(parm, -1.0f, 1.0f);
758 RNA_def_property_dynamic_array_funcs(parm, "rna_KeyBlock_normals_vert_len");
760 func = RNA_def_function(srna, "normals_polygon_get", "rna_KeyBlock_normals_poly_calc");
761 RNA_def_function_ui_description(func, "Compute local space faces' normals for this shape key");
762 RNA_def_function_flag(func, FUNC_USE_SELF_ID);
763 parm = RNA_def_property(func, "normals", PROP_FLOAT, /* PROP_DIRECTION */ PROP_NONE);
764 RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_OUTPUT);
765 RNA_def_property_multi_array(parm, 2, NULL);
766 RNA_def_property_range(parm, -1.0f, 1.0f);
767 RNA_def_property_dynamic_array_funcs(parm, "rna_KeyBlock_normals_poly_len");
769 func = RNA_def_function(srna, "normals_split_get", "rna_KeyBlock_normals_loop_calc");
770 RNA_def_function_ui_description(func, "Compute local space face corners' normals for this shape key");
771 RNA_def_function_flag(func, FUNC_USE_SELF_ID);
772 parm = RNA_def_property(func, "normals", PROP_FLOAT, /* PROP_DIRECTION */ PROP_NONE);
773 RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_OUTPUT);
774 RNA_def_property_multi_array(parm, 2, NULL);
775 RNA_def_property_range(parm, -1.0f, 1.0f);
776 RNA_def_property_dynamic_array_funcs(parm, "rna_KeyBlock_normals_loop_len");
779 static void rna_def_key(BlenderRNA *brna)
784 srna = RNA_def_struct(brna, "Key", "ID");
785 RNA_def_struct_ui_text(srna, "Key", "Shape keys data-block containing different shapes of geometric data-blocks");
786 RNA_def_struct_ui_icon(srna, ICON_SHAPEKEY_DATA);
788 prop = RNA_def_property(srna, "reference_key", PROP_POINTER, PROP_NONE);
789 RNA_def_property_flag(prop, PROP_NEVER_NULL);
790 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
791 RNA_def_property_pointer_sdna(prop, NULL, "refkey");
792 RNA_def_property_ui_text(prop, "Reference Key", "");
794 prop = RNA_def_property(srna, "key_blocks", PROP_COLLECTION, PROP_NONE);
795 RNA_def_property_collection_sdna(prop, NULL, "block", NULL);
796 RNA_def_property_struct_type(prop, "ShapeKey");
797 RNA_def_property_ui_text(prop, "Key Blocks", "Shape keys");
799 rna_def_animdata_common(srna);
801 prop = RNA_def_property(srna, "user", PROP_POINTER, PROP_NONE);
802 RNA_def_property_flag(prop, PROP_NEVER_NULL);
803 RNA_def_property_pointer_sdna(prop, NULL, "from");
804 RNA_def_property_ui_text(prop, "User", "Data-block using these shape keys");
806 prop = RNA_def_property(srna, "use_relative", PROP_BOOLEAN, PROP_NONE);
807 RNA_def_property_boolean_sdna(prop, NULL, "type", KEY_RELATIVE);
808 RNA_def_property_ui_text(prop, "Relative",
809 "Make shape keys relative, "
810 "otherwise play through shapes as a sequence using the evaluation time");
811 RNA_def_property_update(prop, 0, "rna_Key_update_data");
813 prop = RNA_def_property(srna, "eval_time", PROP_FLOAT, PROP_NONE);
814 RNA_def_property_float_sdna(prop, NULL, "ctime");
815 RNA_def_property_range(prop, MINFRAME, MAXFRAME);
816 RNA_def_property_ui_text(prop, "Evaluation Time", "Evaluation time for absolute shape keys");
817 RNA_def_property_update(prop, 0, "rna_Key_update_data");
820 void RNA_def_key(BlenderRNA *brna)
823 rna_def_keyblock(brna);
824 rna_def_keydata(brna);