4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * Contributor(s): Blender Foundation (2008), Joshua Leung
22 * ***** END GPL LICENSE BLOCK *****
27 #include "RNA_define.h"
28 #include "RNA_types.h"
30 #include "rna_internal.h"
32 #include "DNA_armature_types.h"
33 #include "DNA_object_types.h"
34 #include "DNA_scene_types.h"
43 #include "BKE_context.h"
44 #include "BKE_depsgraph.h"
45 #include "BKE_idprop.h"
48 #include "ED_armature.h"
49 #include "BKE_armature.h"
51 static void rna_Armature_update_data(Main *bmain, Scene *scene, PointerRNA *ptr)
55 DAG_id_flush_update(id, OB_RECALC_DATA);
56 WM_main_add_notifier(NC_GEOM|ND_DATA, id);
57 //WM_main_add_notifier(NC_OBJECT|ND_POSE, NULL);
61 static void rna_Armature_act_bone_set(PointerRNA *ptr, PointerRNA value)
63 bArmature *arm= (bArmature*)ptr->data;
65 if(value.id.data==NULL && value.data==NULL) {
69 if(value.id.data != arm) {
73 arm->act_bone= value.data;
74 arm->act_bone->flag |= BONE_SELECTED;
79 static void rna_Armature_act_edit_bone_set(PointerRNA *ptr, PointerRNA value)
81 bArmature *arm= (bArmature*)ptr->data;
83 if(value.id.data==NULL && value.data==NULL) {
84 arm->act_edbone= NULL;
87 if(value.id.data != arm) {
91 arm->act_edbone= value.data;
92 ((EditBone *)arm->act_edbone)->flag |= BONE_SELECTED;
97 EditBone *rna_Armature_edit_bone_new(bArmature *arm, ReportList *reports, char *name)
100 BKE_reportf(reports, RPT_ERROR, "Armature '%s' not in editmode, cant add an editbone.", arm->id.name+2);
103 return ED_armature_edit_bone_add(arm, name);
106 void rna_Armature_edit_bone_remove(bArmature *arm, ReportList *reports, EditBone *ebone)
108 if(arm->edbo==NULL) {
109 BKE_reportf(reports, RPT_ERROR, "Armature '%s' not in editmode, cant remove an editbone.", arm->id.name+2);
112 ED_armature_edit_bone_remove(arm, ebone);
115 static void rna_Armature_redraw_data(Main *bmain, Scene *scene, PointerRNA *ptr)
117 ID *id= ptr->id.data;
119 WM_main_add_notifier(NC_GEOM|ND_DATA, id);
122 static char *rna_Bone_path(PointerRNA *ptr)
124 return BLI_sprintfN("bones[\"%s\"]", ((Bone*)ptr->data)->name);
127 static IDProperty *rna_Bone_idproperties(PointerRNA *ptr, int create)
129 Bone *bone= ptr->data;
131 if(create && !bone->prop) {
132 IDPropertyTemplate val = {0};
133 bone->prop= IDP_New(IDP_GROUP, val, "RNA_Bone ID properties");
139 static IDProperty *rna_EditBone_idproperties(PointerRNA *ptr, int create)
141 EditBone *ebone= ptr->data;
143 if(create && !ebone->prop) {
144 IDPropertyTemplate val = {0};
145 ebone->prop= IDP_New(IDP_GROUP, val, "RNA_EditBone ID properties");
151 static void rna_bone_layer_set(int *layer, const int *values)
155 /* ensure we always have some layer selected */
163 for(i=0; i<32; i++) {
164 if(values[i]) *layer |= (1<<i);
165 else *layer &= ~(1<<i);
169 static void rna_Bone_layer_set(PointerRNA *ptr, const int *values)
171 Bone *bone= (Bone*)ptr->data;
172 rna_bone_layer_set(&bone->layer, values);
175 static void rna_Armature_layer_set(PointerRNA *ptr, const int *values)
177 bArmature *arm= (bArmature*)ptr->data;
180 /* ensure we always have some layer selected */
188 for(i=0; i<32; i++) {
189 if(values[i]) arm->layer |= (1<<i);
190 else arm->layer &= ~(1<<i);
194 static void rna_Armature_ghost_start_frame_set(PointerRNA *ptr, int value)
196 bArmature *data= (bArmature*)ptr->data;
197 CLAMP(value, 1, data->ghostef);
198 data->ghostsf= value;
201 static void rna_Armature_ghost_end_frame_set(PointerRNA *ptr, int value)
203 bArmature *data= (bArmature*)ptr->data;
204 CLAMP(value, data->ghostsf, (int)(MAXFRAMEF/2));
205 data->ghostef= value;
208 static void rna_Armature_path_start_frame_set(PointerRNA *ptr, int value)
210 bArmature *data= (bArmature*)ptr->data;
211 CLAMP(value, 1, data->pathef);
215 static void rna_Armature_path_end_frame_set(PointerRNA *ptr, int value)
217 bArmature *data= (bArmature*)ptr->data;
218 CLAMP(value, data->pathsf, (int)(MAXFRAMEF/2));
222 static void rna_EditBone_name_set(PointerRNA *ptr, const char *value)
224 bArmature *arm= (bArmature*)ptr->id.data;
225 EditBone *ebone= (EditBone*)ptr->data;
226 char oldname[32], newname[32];
228 /* need to be on the stack */
229 BLI_strncpy(newname, value, 32);
230 BLI_strncpy(oldname, ebone->name, 32);
232 ED_armature_bone_rename(arm, oldname, newname);
235 static void rna_Bone_name_set(PointerRNA *ptr, const char *value)
237 bArmature *arm= (bArmature*)ptr->id.data;
238 Bone *bone= (Bone*)ptr->data;
239 char oldname[32], newname[32];
241 /* need to be on the stack */
242 BLI_strncpy(newname, value, 32);
243 BLI_strncpy(oldname, bone->name, 32);
245 ED_armature_bone_rename(arm, oldname, newname);
248 static void rna_EditBone_layer_set(PointerRNA *ptr, const int values[])
250 EditBone *data= (EditBone*)(ptr->data);
251 rna_bone_layer_set(&data->layer, values);
254 static void rna_EditBone_connected_check(EditBone *ebone)
257 if(ebone->flag & BONE_CONNECTED) {
258 /* Attach this bone to its parent */
259 VECCOPY(ebone->head, ebone->parent->tail);
261 if(ebone->flag & BONE_ROOTSEL)
262 ebone->parent->flag |= BONE_TIPSEL;
264 else if(!(ebone->parent->flag & BONE_ROOTSEL)) {
265 ebone->parent->flag &= ~BONE_TIPSEL;
270 static void rna_EditBone_connected_set(PointerRNA *ptr, int value)
272 EditBone *ebone= (EditBone*)(ptr->data);
274 if(value) ebone->flag |= BONE_CONNECTED;
275 else ebone->flag &= ~BONE_CONNECTED;
277 rna_EditBone_connected_check(ebone);
280 static PointerRNA rna_EditBone_parent_get(PointerRNA *ptr)
282 EditBone *data= (EditBone*)(ptr->data);
283 return rna_pointer_inherit_refine(ptr, &RNA_EditBone, data->parent);
286 static void rna_EditBone_parent_set(PointerRNA *ptr, PointerRNA value)
288 EditBone *ebone= (EditBone*)(ptr->data);
289 EditBone *pbone, *parbone= (EditBone*)value.data;
291 if(parbone == NULL) {
292 if(ebone->parent && !(ebone->parent->flag & BONE_ROOTSEL))
293 ebone->parent->flag &= ~BONE_TIPSEL;
295 ebone->parent = NULL;
296 ebone->flag &= ~BONE_CONNECTED;
299 /* within same armature */
300 if(value.id.data != ptr->id.data)
303 /* make sure this is a valid child */
307 for(pbone= parbone->parent; pbone; pbone=pbone->parent)
311 ebone->parent = parbone;
312 rna_EditBone_connected_check(ebone);
316 static void rna_EditBone_matrix_get(PointerRNA *ptr, float *values)
318 EditBone *ebone= (EditBone*)(ptr->data);
320 float delta[3], tmat[3][3], mat[4][4];
322 /* Find the current bone matrix */
323 sub_v3_v3v3(delta, ebone->tail, ebone->head);
324 vec_roll_to_mat3(delta, ebone->roll, tmat);
325 copy_m4_m3(mat, tmat);
326 VECCOPY(mat[3], ebone->head);
328 memcpy(values, mat, 16 * sizeof(float));
331 static void rna_Armature_editbone_transform_update(Main *bmain, Scene *scene, PointerRNA *ptr)
333 bArmature *arm= (bArmature*)ptr->id.data;
334 EditBone *ebone= (EditBone*)ptr->data;
335 EditBone *child, *eboflip;
337 /* update our parent */
338 if(ebone->parent && ebone->flag & BONE_CONNECTED)
339 VECCOPY(ebone->parent->tail, ebone->head)
341 /* update our children if necessary */
342 for(child = arm->edbo->first; child; child=child->next)
343 if(child->parent == ebone && (child->flag & BONE_CONNECTED))
344 VECCOPY(child->head, ebone->tail);
346 if(arm->flag & ARM_MIRROR_EDIT) {
347 eboflip= ED_armature_bone_get_mirrored(arm->edbo, ebone);
350 eboflip->roll= -ebone->roll;
352 eboflip->head[0]= -ebone->head[0];
353 eboflip->tail[0]= -ebone->tail[0];
355 /* update our parent */
356 if(eboflip->parent && eboflip->flag & BONE_CONNECTED)
357 VECCOPY(eboflip->parent->tail, eboflip->head);
359 /* update our children if necessary */
360 for(child = arm->edbo->first; child; child=child->next)
361 if(child->parent == eboflip && (child->flag & BONE_CONNECTED))
362 VECCOPY (child->head, eboflip->tail);
366 rna_Armature_update_data(bmain, scene, ptr);
369 static void rna_Armature_bones_next(CollectionPropertyIterator *iter)
371 ListBaseIterator *internal= iter->internal;
372 Bone *bone= (Bone*)internal->link;
374 if(bone->childbase.first)
375 internal->link= (Link*)bone->childbase.first;
377 internal->link= (Link*)bone->next;
379 internal->link= NULL;
383 if(bone && bone->next) {
384 internal->link= (Link*)bone->next;
390 iter->valid= (internal->link != NULL);
395 static void rna_def_bone_common(StructRNA *srna, int editbone)
400 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
401 RNA_def_property_string_sdna(prop, NULL, "name");
402 RNA_def_property_ui_text(prop, "Name", "");
403 RNA_def_struct_name_property(srna, prop);
404 if(editbone) RNA_def_property_string_funcs(prop, NULL, NULL, "rna_EditBone_name_set");
405 else RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Bone_name_set");
406 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
409 prop= RNA_def_property(srna, "layer", PROP_BOOLEAN, PROP_LAYER_MEMBER);
410 RNA_def_property_boolean_sdna(prop, NULL, "layer", 1);
411 RNA_def_property_array(prop, 32);
412 if(editbone) RNA_def_property_boolean_funcs(prop, NULL, "rna_EditBone_layer_set");
413 else RNA_def_property_boolean_funcs(prop, NULL, "rna_Bone_layer_set");
414 RNA_def_property_ui_text(prop, "Layers", "Layers bone exists in");
415 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
417 prop= RNA_def_property(srna, "connected", PROP_BOOLEAN, PROP_NONE);
418 RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_CONNECTED);
419 if(editbone) RNA_def_property_boolean_funcs(prop, NULL, "rna_EditBone_connected_set");
420 else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
421 RNA_def_property_ui_text(prop, "Connected", "When bone has a parent, bone's head is struck to the parent's tail.");
422 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
424 prop= RNA_def_property(srna, "hinge", PROP_BOOLEAN, PROP_NONE);
425 RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", BONE_HINGE);
426 RNA_def_property_ui_text(prop, "Inherit Rotation", "Bone inherits rotation or scale from parent bone.");
427 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
429 prop= RNA_def_property(srna, "multiply_vertexgroup_with_envelope", PROP_BOOLEAN, PROP_NONE);
430 RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_MULT_VG_ENV);
431 RNA_def_property_ui_text(prop, "Multiply Vertex Group with Envelope", "When deforming bone, multiply effects of Vertex Group weights with Envelope influence.");
432 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
434 prop= RNA_def_property(srna, "deform", PROP_BOOLEAN, PROP_NONE);
435 RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", BONE_NO_DEFORM);
436 RNA_def_property_ui_text(prop, "Deform", "Bone does not deform any geometry.");
437 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
439 prop= RNA_def_property(srna, "inherit_scale", PROP_BOOLEAN, PROP_NONE);
440 RNA_def_property_ui_text(prop, "Inherit Scale", "Bone inherits scaling from parent bone.");
441 RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", BONE_NO_SCALE);
442 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
444 prop= RNA_def_property(srna, "local_location", PROP_BOOLEAN, PROP_NONE);
445 RNA_def_property_ui_text(prop, "Local Location", "Bone location is set in local space.");
446 RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", BONE_NO_LOCAL_LOCATION);
447 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
449 prop= RNA_def_property(srna, "draw_wire", PROP_BOOLEAN, PROP_NONE);
450 RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_DRAWWIRE);
451 RNA_def_property_ui_text(prop, "Draw Wire", "Bone is always drawn as Wireframe regardless of viewport draw mode. Useful for non-obstructive custom bone shapes.");
452 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
454 prop= RNA_def_property(srna, "cyclic_offset", PROP_BOOLEAN, PROP_NONE);
455 RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", BONE_NO_CYCLICOFFSET);
456 RNA_def_property_ui_text(prop, "Cyclic Offset", "When bone doesn't have a parent, it receives cyclic offset effects.");
457 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
459 prop= RNA_def_property(srna, "restrict_select", PROP_BOOLEAN, PROP_NONE);
460 RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_UNSELECTABLE);
461 RNA_def_property_ui_text(prop, "Selectable", "Bone is able to be selected");
462 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
465 /* envelope deform settings */
466 prop= RNA_def_property(srna, "envelope_distance", PROP_FLOAT, PROP_NONE);
467 RNA_def_property_float_sdna(prop, NULL, "dist");
468 RNA_def_property_range(prop, 0.0f, 1000.0f);
469 RNA_def_property_ui_text(prop, "Envelope Deform Distance", "Bone deformation distance (for Envelope deform only).");
470 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
472 prop= RNA_def_property(srna, "envelope_weight", PROP_FLOAT, PROP_NONE);
473 RNA_def_property_float_sdna(prop, NULL, "weight");
474 RNA_def_property_range(prop, 0.0f, 1000.0f);
475 RNA_def_property_ui_text(prop, "Envelope Deform Weight", "Bone deformation weight (for Envelope deform only).");
476 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
478 prop= RNA_def_property(srna, "head_radius", PROP_FLOAT, PROP_NONE);
479 if(editbone) RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
480 RNA_def_property_float_sdna(prop, NULL, "rad_head");
481 //RNA_def_property_range(prop, 0, 1000); // XXX range is 0 to lim, where lim= 10000.0f*MAX2(1.0, view3d->grid);
482 RNA_def_property_ui_text(prop, "Envelope Head Radius", "Radius of head of bone (for Envelope deform only).");
484 prop= RNA_def_property(srna, "tail_radius", PROP_FLOAT, PROP_NONE);
485 if(editbone) RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
486 RNA_def_property_float_sdna(prop, NULL, "rad_tail");
487 //RNA_def_property_range(prop, 0, 1000); // XXX range is 0 to lim, where lim= 10000.0f*MAX2(1.0, view3d->grid);
488 RNA_def_property_ui_text(prop, "Envelope Tail Radius", "Radius of tail of bone (for Envelope deform only).");
490 /* b-bones deform settings */
491 prop= RNA_def_property(srna, "bbone_segments", PROP_INT, PROP_NONE);
492 RNA_def_property_int_sdna(prop, NULL, "segments");
493 RNA_def_property_range(prop, 1, 32);
494 RNA_def_property_ui_text(prop, "B-Bone Segments", "Number of subdivisions of bone (for B-Bones only).");
495 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
497 prop= RNA_def_property(srna, "bbone_in", PROP_FLOAT, PROP_NONE);
498 RNA_def_property_float_sdna(prop, NULL, "ease1");
499 RNA_def_property_range(prop, 0.0f, 2.0f);
500 RNA_def_property_ui_text(prop, "B-Bone Ease In", "Length of first Bezier Handle (for B-Bones only).");
501 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
503 prop= RNA_def_property(srna, "bbone_out", PROP_FLOAT, PROP_NONE);
504 RNA_def_property_float_sdna(prop, NULL, "ease2");
505 RNA_def_property_range(prop, 0.0f, 2.0f);
506 RNA_def_property_ui_text(prop, "B-Bone Ease Out", "Length of second Bezier Handle (for B-Bones only).");
507 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
510 // err... bones should not be directly edited (only editbones should be...)
511 static void rna_def_bone(BlenderRNA *brna)
516 srna= RNA_def_struct(brna, "Bone", NULL);
517 RNA_def_struct_ui_text(srna, "Bone", "Bone in an Armature datablock.");
518 RNA_def_struct_ui_icon(srna, ICON_BONE_DATA);
519 RNA_def_struct_path_func(srna, "rna_Bone_path");
520 RNA_def_struct_idproperties_func(srna, "rna_Bone_idproperties");
522 /* pointers/collections */
523 /* parent (pointer) */
524 prop= RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
525 RNA_def_property_struct_type(prop, "Bone");
526 RNA_def_property_pointer_sdna(prop, NULL, "parent");
527 RNA_def_property_ui_text(prop, "Parent", "Parent bone (in same Armature).");
528 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
530 /* children (collection) */
531 prop= RNA_def_property(srna, "children", PROP_COLLECTION, PROP_NONE);
532 RNA_def_property_collection_sdna(prop, NULL, "childbase", NULL);
533 RNA_def_property_struct_type(prop, "Bone");
534 RNA_def_property_ui_text(prop, "Children", "Bones which are children of this bone");
536 rna_def_bone_common(srna, 0);
538 // XXX should we define this in PoseChannel wrapping code instead? but PoseChannels directly get some of their flags from here...
539 prop= RNA_def_property(srna, "hidden", PROP_BOOLEAN, PROP_NONE);
540 RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_HIDDEN_P);
541 RNA_def_property_ui_text(prop, "Hidden", "Bone is not visible when it is not in Edit Mode (i.e. in Object or Pose Modes).");
542 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
544 prop= RNA_def_property(srna, "selected", PROP_BOOLEAN, PROP_NONE);
545 RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_SELECTED);
546 RNA_def_property_ui_text(prop, "Selected", "");
547 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
549 /* XXX better matrix descriptions possible (Arystan) */
550 prop= RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX);
551 RNA_def_property_float_sdna(prop, NULL, "bone_mat");
552 RNA_def_property_array(prop, 9);
553 RNA_def_property_ui_text(prop, "Bone Matrix", "3x3 bone matrix.");
555 prop= RNA_def_property(srna, "matrix_local", PROP_FLOAT, PROP_MATRIX);
556 RNA_def_property_float_sdna(prop, NULL, "arm_mat");
557 RNA_def_property_array(prop, 16);
558 RNA_def_property_ui_text(prop, "Bone Armature-Relative Matrix", "4x4 bone matrix relative to armature.");
560 prop= RNA_def_property(srna, "tail", PROP_FLOAT, PROP_TRANSLATION);
561 RNA_def_property_float_sdna(prop, NULL, "tail");
562 RNA_def_property_array(prop, 3);
563 RNA_def_property_ui_text(prop, "Tail", "Location of tail end of the bone.");
565 prop= RNA_def_property(srna, "tail_local", PROP_FLOAT, PROP_TRANSLATION);
566 RNA_def_property_float_sdna(prop, NULL, "arm_tail");
567 RNA_def_property_array(prop, 3);
568 RNA_def_property_ui_text(prop, "Armature-Relative Tail", "Location of tail end of the bone relative to armature.");
570 prop= RNA_def_property(srna, "head", PROP_FLOAT, PROP_TRANSLATION);
571 RNA_def_property_float_sdna(prop, NULL, "head");
572 RNA_def_property_array(prop, 3);
573 RNA_def_property_ui_text(prop, "Head", "Location of head end of the bone relative to its parent.");
575 prop= RNA_def_property(srna, "head_local", PROP_FLOAT, PROP_TRANSLATION);
576 RNA_def_property_float_sdna(prop, NULL, "arm_head");
577 RNA_def_property_array(prop, 3);
578 RNA_def_property_ui_text(prop, "Armature-Relative Head", "Location of head end of the bone relative to armature.");
581 static void rna_def_edit_bone(BlenderRNA *brna)
586 srna= RNA_def_struct(brna, "EditBone", NULL);
587 RNA_def_struct_sdna(srna, "EditBone");
588 RNA_def_struct_idproperties_func(srna, "rna_EditBone_idproperties");
589 RNA_def_struct_ui_text(srna, "Edit Bone", "Editmode bone in an Armature datablock.");
590 RNA_def_struct_ui_icon(srna, ICON_BONE_DATA);
592 RNA_define_verify_sdna(0); // not in sdna
594 prop= RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
595 RNA_def_property_struct_type(prop, "EditBone");
596 RNA_def_property_pointer_funcs(prop, "rna_EditBone_parent_get", "rna_EditBone_parent_set", NULL);
597 RNA_def_property_flag(prop, PROP_EDITABLE);
598 RNA_def_property_ui_text(prop, "Parent", "Parent edit bone (in same Armature).");
599 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
601 prop= RNA_def_property(srna, "roll", PROP_FLOAT, PROP_NONE);
602 RNA_def_property_float_sdna(prop, NULL, "roll");
603 RNA_def_property_ui_text(prop, "Roll", "Bone rotation around head-tail axis.");
604 RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
606 prop= RNA_def_property(srna, "head", PROP_FLOAT, PROP_TRANSLATION);
607 RNA_def_property_float_sdna(prop, NULL, "head");
608 RNA_def_property_array(prop, 3);
609 RNA_def_property_ui_text(prop, "Head", "Location of head end of the bone.");
610 RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
612 prop= RNA_def_property(srna, "tail", PROP_FLOAT, PROP_TRANSLATION);
613 RNA_def_property_float_sdna(prop, NULL, "tail");
614 RNA_def_property_array(prop, 3);
615 RNA_def_property_ui_text(prop, "Tail", "Location of tail end of the bone.");
616 RNA_def_property_update(prop, 0, "rna_Armature_editbone_transform_update");
618 rna_def_bone_common(srna, 1);
620 prop= RNA_def_property(srna, "hidden", PROP_BOOLEAN, PROP_NONE);
621 RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_HIDDEN_A);
622 RNA_def_property_ui_text(prop, "Hidden", "Bone is not visible when in Edit Mode");
623 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
625 prop= RNA_def_property(srna, "locked", PROP_BOOLEAN, PROP_NONE);
626 RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_EDITMODE_LOCKED);
627 RNA_def_property_ui_text(prop, "Locked", "Bone is not able to be transformed when in Edit Mode.");
628 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
630 prop= RNA_def_property(srna, "selected", PROP_BOOLEAN, PROP_NONE);
631 RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_SELECTED);
632 RNA_def_property_ui_text(prop, "Selected", "");
633 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
635 prop= RNA_def_property(srna, "selected_head", PROP_BOOLEAN, PROP_NONE);
636 RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_ROOTSEL);
637 RNA_def_property_ui_text(prop, "Head Selected", "");
638 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
640 prop= RNA_def_property(srna, "selected_tail", PROP_BOOLEAN, PROP_NONE);
641 RNA_def_property_boolean_sdna(prop, NULL, "flag", BONE_TIPSEL);
642 RNA_def_property_ui_text(prop, "Tail Selected", "");
643 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
645 /* calculated and read only, not actual data access */
646 prop= RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX);
647 //RNA_def_property_float_sdna(prop, NULL, ""); // doesnt access any real data
648 RNA_def_property_array(prop, 16);
649 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
650 RNA_def_property_ui_text(prop, "Editbone Matrix", "Read-only matrix calculated from the roll (armature space).");
651 RNA_def_property_float_funcs(prop, "rna_EditBone_matrix_get", NULL, NULL); // TODO - this could be made writable also
653 RNA_api_armature_edit_bone(srna);
655 RNA_define_verify_sdna(1);
659 /* armature.bones.* */
660 static void rna_def_armature_bones(BlenderRNA *brna, PropertyRNA *cprop)
665 // FunctionRNA *func;
666 // PropertyRNA *parm;
668 RNA_def_property_srna(cprop, "ArmatureBones");
669 srna= RNA_def_struct(brna, "ArmatureBones", NULL);
670 RNA_def_struct_sdna(srna, "bArmature");
671 RNA_def_struct_ui_text(srna, "Armature Bones", "Collection of armature bones.");
674 prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
675 RNA_def_property_struct_type(prop, "Bone");
676 RNA_def_property_pointer_sdna(prop, NULL, "act_bone");
677 RNA_def_property_flag(prop, PROP_EDITABLE);
678 RNA_def_property_ui_text(prop, "Active Bone", "Armatures active bone.");
679 RNA_def_property_pointer_funcs(prop, NULL, "rna_Armature_act_bone_set", NULL);
682 // RNA_def_property_collection_active(prop, prop_act);
685 /* armature.bones.* */
686 static void rna_def_armature_edit_bones(BlenderRNA *brna, PropertyRNA *cprop)
694 RNA_def_property_srna(cprop, "ArmatureEditBones");
695 srna= RNA_def_struct(brna, "ArmatureEditBones", NULL);
696 RNA_def_struct_sdna(srna, "bArmature");
697 RNA_def_struct_ui_text(srna, "Armature EditBones", "Collection of armature edit bones.");
699 prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
700 RNA_def_property_struct_type(prop, "EditBone");
701 RNA_def_property_pointer_sdna(prop, NULL, "act_edbone");
702 RNA_def_property_flag(prop, PROP_EDITABLE);
703 RNA_def_property_ui_text(prop, "Active EditBone", "Armatures active edit bone.");
704 //RNA_def_property_update(prop, 0, "rna_Armature_act_editbone_update");
705 RNA_def_property_pointer_funcs(prop, NULL, "rna_Armature_act_edit_bone_set", NULL);
708 // RNA_def_property_collection_active(prop, prop_act);
711 func= RNA_def_function(srna, "new", "rna_Armature_edit_bone_new");
712 RNA_def_function_flag(func, FUNC_USE_REPORTS);
713 RNA_def_function_ui_description(func, "Add a new bone.");
714 parm= RNA_def_string(func, "name", "Object", 0, "", "New name for the bone.");
715 RNA_def_property_flag(parm, PROP_REQUIRED);
718 parm= RNA_def_pointer(func, "bone", "EditBone", "", "Newly created edit bone.");
719 RNA_def_function_return(func, parm);
722 func= RNA_def_function(srna, "remove", "rna_Armature_edit_bone_remove");
723 RNA_def_function_flag(func, FUNC_USE_REPORTS);
724 RNA_def_function_ui_description(func, "Remove an existing bone from the armature.");
725 /* target to remove*/
726 parm= RNA_def_pointer(func, "bone", "EditBone", "", "EditBone to remove.");
727 RNA_def_property_flag(parm, PROP_REQUIRED);
730 static void rna_def_armature(BlenderRNA *brna)
735 static EnumPropertyItem prop_drawtype_items[] = {
736 {ARM_OCTA, "OCTAHEDRAL", 0, "Octahedral", "Display bones as octahedral shape (default)."},
737 {ARM_LINE, "STICK", 0, "Stick", "Display bones as simple 2D lines with dots."},
738 {ARM_B_BONE, "BBONE", 0, "B-Bone", "Display bones as boxes, showing subdivision and B-Splines"},
739 {ARM_ENVELOPE, "ENVELOPE", 0, "Envelope", "Display bones as extruded spheres, showing defomation influence volume."},
740 {0, NULL, 0, NULL, NULL}};
741 static EnumPropertyItem prop_ghost_type_items[] = {
742 {ARM_GHOST_CUR, "CURRENT_FRAME", 0, "Around Frame", "Display Ghosts of poses within a fixed number of frames around the current frame."},
743 {ARM_GHOST_RANGE, "RANGE", 0, "In Range", "Display Ghosts of poses within specified range."},
744 {ARM_GHOST_KEYS, "KEYS", 0, "On Keyframes", "Display Ghosts of poses on Keyframes."},
745 {0, NULL, 0, NULL, NULL}};
746 static const EnumPropertyItem prop_paths_type_items[]= {
747 {ARM_PATH_ACFRA, "CURRENT_FRAME", 0, "Around Frame", "Display Paths of poses within a fixed number of frames around the current frame."},
748 {0, "RANGE", 0, "In Range", "Display Paths of poses within specified range."},
749 {0, NULL, 0, NULL, NULL}};
750 static const EnumPropertyItem prop_paths_location_items[]= {
751 {ARM_PATH_HEADS, "HEADS", 0, "Heads", "Calculate bone paths from heads"},
752 {0, "TAILS", 0, "Tails", "Calculate bone paths from tails"},
753 {0, NULL, 0, NULL, NULL}};
754 static const EnumPropertyItem prop_pose_position_items[]= {
755 {0, "POSE", 0, "Pose Position", "Show armature in posed state."},
756 {ARM_RESTPOS, "REST", 0, "Rest Position", "Show Armature in binding pose state. No posing possible."},
757 {0, NULL, 0, NULL, NULL}};
759 srna= RNA_def_struct(brna, "Armature", "ID");
760 RNA_def_struct_ui_text(srna, "Armature", "Armature datablock containing a hierarchy of bones, usually used for rigging characters.");
761 RNA_def_struct_ui_icon(srna, ICON_ARMATURE_DATA);
762 RNA_def_struct_sdna(srna, "bArmature");
765 rna_def_animdata_common(srna);
768 prop= RNA_def_property(srna, "bones", PROP_COLLECTION, PROP_NONE);
769 RNA_def_property_collection_sdna(prop, NULL, "bonebase", NULL);
770 RNA_def_property_collection_funcs(prop, 0, "rna_Armature_bones_next", 0, 0, 0, 0, 0);
771 RNA_def_property_struct_type(prop, "Bone");
772 RNA_def_property_ui_text(prop, "Bones", "");
773 rna_def_armature_bones(brna, prop);
775 prop= RNA_def_property(srna, "edit_bones", PROP_COLLECTION, PROP_NONE);
776 RNA_def_property_collection_sdna(prop, NULL, "edbo", NULL);
777 RNA_def_property_struct_type(prop, "EditBone");
778 RNA_def_property_ui_text(prop, "Edit Bones", "");
779 rna_def_armature_edit_bones(brna, prop);
782 prop= RNA_def_property(srna, "pose_position", PROP_ENUM, PROP_NONE);
783 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
784 RNA_def_property_enum_items(prop, prop_pose_position_items);
785 RNA_def_property_ui_text(prop, "Pose Position", "Show armature in binding pose or final posed state.");
786 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
788 prop= RNA_def_property(srna, "drawtype", PROP_ENUM, PROP_NONE);
789 RNA_def_property_enum_items(prop, prop_drawtype_items);
790 RNA_def_property_ui_text(prop, "Draw Type", "");
791 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
793 prop= RNA_def_property(srna, "ghost_type", PROP_ENUM, PROP_NONE);
794 RNA_def_property_enum_sdna(prop, NULL, "ghosttype");
795 RNA_def_property_enum_items(prop, prop_ghost_type_items);
796 RNA_def_property_ui_text(prop, "Ghost Type", "Method of Onion-skinning for active Action");
797 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
799 prop= RNA_def_property(srna, "paths_type", PROP_ENUM, PROP_NONE);
800 RNA_def_property_enum_bitflag_sdna(prop, NULL, "pathflag");
801 RNA_def_property_enum_items(prop, prop_paths_type_items);
802 RNA_def_property_ui_text(prop, "Paths Type", "Type of range to show for Bone Paths");
803 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
805 prop= RNA_def_property(srna, "paths_location", PROP_ENUM, PROP_NONE);
806 RNA_def_property_enum_bitflag_sdna(prop, NULL, "pathflag");
807 RNA_def_property_enum_items(prop, prop_paths_location_items);
808 RNA_def_property_ui_text(prop, "Paths Location", "When calculating Bone Paths, use Head or Tips");
809 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
813 prop= RNA_def_property(srna, "layer", PROP_BOOLEAN, PROP_LAYER_MEMBER);
814 RNA_def_property_boolean_sdna(prop, NULL, "layer", 1);
815 RNA_def_property_array(prop, 32);
816 RNA_def_property_ui_text(prop, "Visible Layers", "Armature layer visibility.");
817 RNA_def_property_boolean_funcs(prop, NULL, "rna_Armature_layer_set");
818 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Armature_redraw_data");
819 RNA_def_property_flag(prop, PROP_LIB_EXCEPTION);
821 /* layer protection */
822 prop= RNA_def_property(srna, "layer_protection", PROP_BOOLEAN, PROP_LAYER);
823 RNA_def_property_boolean_sdna(prop, NULL, "layer_protected", 1);
824 RNA_def_property_array(prop, 32);
825 RNA_def_property_ui_text(prop, "Layer Proxy Protection", "Protected layers in Proxy Instances are restored to Proxy settings on file reload and undo.");
826 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
831 prop= RNA_def_property(srna, "draw_axes", PROP_BOOLEAN, PROP_NONE);
832 RNA_def_property_boolean_sdna(prop, NULL, "flag", ARM_DRAWAXES);
833 RNA_def_property_ui_text(prop, "Draw Axes", "Draw bone axes.");
834 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
836 prop= RNA_def_property(srna, "draw_names", PROP_BOOLEAN, PROP_NONE);
837 RNA_def_property_boolean_sdna(prop, NULL, "flag", ARM_DRAWNAMES);
838 RNA_def_property_ui_text(prop, "Draw Names", "Draw bone names.");
839 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
841 prop= RNA_def_property(srna, "delay_deform", PROP_BOOLEAN, PROP_NONE);
842 RNA_def_property_boolean_sdna(prop, NULL, "flag", ARM_DELAYDEFORM);
843 RNA_def_property_ui_text(prop, "Delay Deform", "Don't deform children when manipulating bones in Pose Mode");
844 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
846 prop= RNA_def_property(srna, "x_axis_mirror", PROP_BOOLEAN, PROP_NONE);
847 RNA_def_property_boolean_sdna(prop, NULL, "flag", ARM_MIRROR_EDIT);
848 RNA_def_property_ui_text(prop, "X-Axis Mirror", "Apply changes to matching bone on opposite side of X-Axis.");
849 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
851 prop= RNA_def_property(srna, "auto_ik", PROP_BOOLEAN, PROP_NONE);
852 RNA_def_property_boolean_sdna(prop, NULL, "flag", ARM_AUTO_IK);
853 RNA_def_property_ui_text(prop, "Auto IK", "Add temporaral IK constraints while grabbing bones in Pose Mode.");
854 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
856 prop= RNA_def_property(srna, "draw_custom_bone_shapes", PROP_BOOLEAN, PROP_NONE);
857 RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", ARM_NO_CUSTOM);
858 RNA_def_property_ui_text(prop, "Draw Custom Bone Shapes", "Draw bones with their custom shapes.");
859 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
861 prop= RNA_def_property(srna, "draw_group_colors", PROP_BOOLEAN, PROP_NONE);
862 RNA_def_property_boolean_sdna(prop, NULL, "flag", ARM_COL_CUSTOM);
863 RNA_def_property_ui_text(prop, "Draw Bone Group Colors", "Draw bone group colors.");
864 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
866 prop= RNA_def_property(srna, "ghost_only_selected", PROP_BOOLEAN, PROP_NONE);
867 RNA_def_property_boolean_sdna(prop, NULL, "flag", ARM_GHOST_ONLYSEL);
868 RNA_def_property_ui_text(prop, "Draw Ghosts on Selected Bones Only", "");
869 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
872 prop= RNA_def_property(srna, "deform_vertexgroups", PROP_BOOLEAN, PROP_NONE);
873 RNA_def_property_boolean_sdna(prop, NULL, "deformflag", ARM_DEF_VGROUP);
874 RNA_def_property_ui_text(prop, "Deform Vertex Groups", "Enable Vertex Groups when defining deform");
875 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
877 prop= RNA_def_property(srna, "deform_envelope", PROP_BOOLEAN, PROP_NONE);
878 RNA_def_property_boolean_sdna(prop, NULL, "deformflag", ARM_DEF_ENVELOPE);
879 RNA_def_property_ui_text(prop, "Deform Envelopes", "Enable Bone Envelopes when defining deform");
880 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
882 prop= RNA_def_property(srna, "deform_quaternion", PROP_BOOLEAN, PROP_NONE);
883 RNA_def_property_boolean_sdna(prop, NULL, "deformflag", ARM_DEF_QUATERNION);
884 RNA_def_property_ui_text(prop, "Use Dual Quaternion Deformation", "Enable deform rotation with Quaternions");
885 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
887 prop= RNA_def_property(srna, "deform_bbone_rest", PROP_BOOLEAN, PROP_NONE);
888 RNA_def_property_boolean_sdna(prop, NULL, "deformflag", ARM_DEF_B_BONE_REST);
889 RNA_def_property_ui_text(prop, "B-Bones Deform in Rest Position", "Make B-Bones deform already in Rest Position");
890 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
892 //prop= RNA_def_property(srna, "deform_invert_vertexgroups", PROP_BOOLEAN, PROP_NONE);
893 //RNA_def_property_boolean_negative_sdna(prop, NULL, "deformflag", ARM_DEF_INVERT_VGROUP);
894 //RNA_def_property_ui_text(prop, "Invert Vertex Group Influence", "Invert Vertex Group influence (only for Modifiers)");
895 //RNA_def_property_update(prop, 0, "rna_Armature_update_data");
898 prop= RNA_def_property(srna, "paths_show_frame_numbers", PROP_BOOLEAN, PROP_NONE);
899 RNA_def_property_boolean_sdna(prop, NULL, "pathflag", ARM_PATH_FNUMS);
900 RNA_def_property_ui_text(prop, "Paths Show Frame Numbers", "When drawing Armature in Pose Mode, show frame numbers on Bone Paths");
901 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
903 prop= RNA_def_property(srna, "paths_highlight_keyframes", PROP_BOOLEAN, PROP_NONE);
904 RNA_def_property_boolean_sdna(prop, NULL, "pathflag", ARM_PATH_KFRAS);
905 RNA_def_property_ui_text(prop, "Paths Highlight Keyframes", "When drawing Armature in Pose Mode, emphasize position of keyframes on Bone Paths");
906 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
908 prop= RNA_def_property(srna, "paths_show_keyframe_numbers", PROP_BOOLEAN, PROP_NONE);
909 RNA_def_property_boolean_sdna(prop, NULL, "pathflag", ARM_PATH_KFNOS);
910 RNA_def_property_ui_text(prop, "Paths Show Keyframe Numbers", "When drawing Armature in Pose Mode, show frame numbers of Keyframes on Bone Paths");
911 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
915 /* ghost/onionskining settings */
916 prop= RNA_def_property(srna, "ghost_step", PROP_INT, PROP_NONE);
917 RNA_def_property_int_sdna(prop, NULL, "ghostep");
918 RNA_def_property_range(prop, 0, 30);
919 RNA_def_property_ui_text(prop, "Ghosting Step", "Number of frame steps on either side of current frame to show as ghosts (only for 'Around Current Frame' Onion-skining method).");
920 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
922 prop= RNA_def_property(srna, "ghost_size", PROP_INT, PROP_NONE);
923 RNA_def_property_int_sdna(prop, NULL, "ghostsize");
924 RNA_def_property_range(prop, 1, 20);
925 RNA_def_property_ui_text(prop, "Ghosting Frame Step", "Frame step for Ghosts (not for 'On Keyframes' Onion-skining method).");
926 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
928 prop= RNA_def_property(srna, "ghost_start_frame", PROP_INT, PROP_TIME);
929 RNA_def_property_int_sdna(prop, NULL, "ghostsf");
930 RNA_def_property_int_funcs(prop, NULL, "rna_Armature_ghost_start_frame_set", NULL);
931 RNA_def_property_ui_text(prop, "Ghosting Start Frame", "Starting frame of range of Ghosts to display (not for 'Around Current Frame' Onion-skinning method).");
932 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
934 prop= RNA_def_property(srna, "ghost_end_frame", PROP_INT, PROP_TIME);
935 RNA_def_property_int_sdna(prop, NULL, "ghostef");
936 RNA_def_property_int_funcs(prop, NULL, "rna_Armature_ghost_end_frame_set", NULL);
937 RNA_def_property_ui_text(prop, "Ghosting End Frame", "End frame of range of Ghosts to display (not for 'Around Current Frame' Onion-skinning method).");
938 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
940 /* bone path settings */
941 prop= RNA_def_property(srna, "path_size", PROP_INT, PROP_NONE);
942 RNA_def_property_int_sdna(prop, NULL, "pathsize");
943 RNA_def_property_range(prop, 1, 100);
944 RNA_def_property_ui_text(prop, "Paths Frame Step", "Number of frames between 'dots' on Bone Paths (when drawing).");
945 RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
947 prop= RNA_def_property(srna, "path_start_frame", PROP_INT, PROP_TIME);
948 RNA_def_property_int_sdna(prop, NULL, "pathsf");
949 RNA_def_property_int_funcs(prop, NULL, "rna_Armature_path_start_frame_set", NULL);
950 RNA_def_property_ui_text(prop, "Paths Calculation Start Frame", "Starting frame of range of frames to use for Bone Path calculations.");
951 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
953 prop= RNA_def_property(srna, "path_end_frame", PROP_INT, PROP_TIME);
954 RNA_def_property_int_sdna(prop, NULL, "pathef");
955 RNA_def_property_int_funcs(prop, NULL, "rna_Armature_path_end_frame_set", NULL);
956 RNA_def_property_ui_text(prop, "Paths Calculation End Frame", "End frame of range of frames to use for Bone Path calculations.");
957 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
959 prop= RNA_def_property(srna, "path_before_current", PROP_INT, PROP_NONE);
960 RNA_def_property_int_sdna(prop, NULL, "pathbc");
961 RNA_def_property_range(prop, 1, MAXFRAMEF/2);
962 RNA_def_property_ui_text(prop, "Paths Frames Before Current", "Number of frames before current frame to show on Bone Paths (only for 'Around Current' option).");
963 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
965 prop= RNA_def_property(srna, "path_after_current", PROP_INT, PROP_NONE);
966 RNA_def_property_int_sdna(prop, NULL, "pathac");
967 RNA_def_property_range(prop, 1, MAXFRAMEF/2);
968 RNA_def_property_ui_text(prop, "Paths Frames After Current", "Number of frames after current frame to show on Bone Paths (only for 'Around Current' option).");
969 RNA_def_property_update(prop, 0, "rna_Armature_update_data");
972 void RNA_def_armature(BlenderRNA *brna)
974 rna_def_armature(brna);
976 rna_def_edit_bone(brna);