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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * Contributor(s): Blender Foundation (2008), Roland Hess, Joshua Leung
22 * ***** END GPL LICENSE BLOCK *****
25 /** \file blender/makesrna/intern/rna_pose.c
33 #include "RNA_define.h"
34 #include "RNA_enum_types.h"
36 #include "rna_internal.h"
38 #include "DNA_action_types.h"
39 #include "DNA_armature_types.h"
40 #include "DNA_constraint_types.h"
41 #include "DNA_object_types.h"
42 #include "DNA_scene_types.h"
51 #include "BKE_action.h"
52 #include "BKE_armature.h"
54 #include "DNA_userdef_types.h"
56 #include "MEM_guardedalloc.h"
58 #include "BLI_ghash.h"
60 #include "BKE_context.h"
61 #include "BKE_constraint.h"
62 #include "BKE_depsgraph.h"
63 #include "BKE_idprop.h"
65 #include "ED_object.h"
66 #include "ED_armature.h"
68 #include "MEM_guardedalloc.h"
72 #include "RNA_access.h"
74 static void rna_Pose_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
76 // XXX when to use this? ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
78 DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
81 static void rna_Pose_IK_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
83 // XXX when to use this? ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
84 Object *ob= ptr->id.data;
86 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
87 BIK_clear_data(ob->pose);
90 static char *rna_PoseBone_path(PointerRNA *ptr)
92 return BLI_sprintfN("pose.bones[\"%s\"]", ((bPoseChannel*)ptr->data)->name);
95 static void rna_BoneGroup_color_set_set(PointerRNA *ptr, int value)
97 bActionGroup *grp= ptr->data;
99 /* if valid value, set the new enum value, then copy the relevant colors? */
100 if ((value >= -1) && (value < 21))
101 grp->customCol= value;
105 /* only do color copying if using a custom color (i.e. not default color) */
106 if (grp->customCol) {
107 if (grp->customCol > 0) {
108 /* copy theme colors on-to group's custom color in case user tries to edit color */
109 bTheme *btheme= U.themes.first;
110 ThemeWireColor *col_set= &btheme->tarm[(grp->customCol - 1)];
112 memcpy(&grp->cs, col_set, sizeof(ThemeWireColor));
115 /* init custom colors with a generic multi-color rgb set, if not initialised already (for custom color set) */
116 if (grp->cs.solid[0] == 0) {
117 /* define for setting colors in theme below */
118 #define SETCOL(col, r, g, b, a) col[0]=r; col[1]=g; col[2]= b; col[3]= a;
120 SETCOL(grp->cs.solid, 0xff, 0x00, 0x00, 255);
121 SETCOL(grp->cs.select, 0x81, 0xe6, 0x14, 255);
122 SETCOL(grp->cs.active, 0x18, 0xb6, 0xe0, 255);
130 static IDProperty *rna_PoseBone_idprops(PointerRNA *ptr, int create)
132 bPoseChannel *pchan= ptr->data;
134 if(create && !pchan->prop) {
135 IDPropertyTemplate val = {0};
136 pchan->prop= IDP_New(IDP_GROUP, val, "RNA_PoseBone group");
142 static void rna_Pose_ik_solver_set(struct PointerRNA *ptr, int value)
144 bPose *pose= (bPose*)ptr->data;
146 if (pose->iksolver != value) {
147 // the solver has changed, must clean any temporary structures
148 BIK_clear_data(pose);
150 MEM_freeN(pose->ikparam);
151 pose->ikparam = NULL;
153 pose->iksolver = value;
154 init_pose_ikparam(pose);
158 static void rna_Pose_ik_solver_update(Main *bmain, Scene *scene, PointerRNA *ptr)
160 Object *ob= ptr->id.data;
161 bPose *pose = ptr->data;
163 pose->flag |= POSE_RECALC; // checks & sorts pose channels
164 DAG_scene_sort(bmain, scene);
166 update_pose_constraint_flags(pose);
168 object_test_constraints(ob);
170 DAG_id_tag_update(&ob->id, OB_RECALC_DATA|OB_RECALC_OB);
173 /* rotation - axis-angle */
174 static void rna_PoseChannel_rotation_axis_angle_get(PointerRNA *ptr, float *value)
176 bPoseChannel *pchan= ptr->data;
178 /* for now, assume that rotation mode is axis-angle */
179 value[0]= pchan->rotAngle;
180 copy_v3_v3(&value[1], pchan->rotAxis);
183 /* rotation - axis-angle */
184 static void rna_PoseChannel_rotation_axis_angle_set(PointerRNA *ptr, const float *value)
186 bPoseChannel *pchan= ptr->data;
188 /* for now, assume that rotation mode is axis-angle */
189 pchan->rotAngle= value[0];
190 copy_v3_v3(pchan->rotAxis, (float *)&value[1]);
192 // TODO: validate axis?
195 static void rna_PoseChannel_rotation_mode_set(PointerRNA *ptr, int value)
197 bPoseChannel *pchan= ptr->data;
199 /* use API Method for conversions... */
200 BKE_rotMode_change_values(pchan->quat, pchan->eul, pchan->rotAxis, &pchan->rotAngle, pchan->rotmode, (short)value);
202 /* finally, set the new rotation type */
203 pchan->rotmode= value;
206 static void rna_PoseChannel_name_set(PointerRNA *ptr, const char *value)
208 Object *ob= (Object*)ptr->id.data;
209 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
210 char oldname[sizeof(pchan->name)], newname[sizeof(pchan->name)];
212 /* need to be on the stack */
213 BLI_strncpy(newname, value, sizeof(pchan->name));
214 BLI_strncpy(oldname, pchan->name, sizeof(pchan->name));
216 ED_armature_bone_rename(ob->data, oldname, newname);
219 static int rna_PoseChannel_has_ik_get(PointerRNA *ptr)
221 Object *ob= (Object*)ptr->id.data;
222 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
224 return ED_pose_channel_in_IK_chain(ob, pchan);
227 StructRNA *rna_IKParam_refine(PointerRNA *ptr)
229 bIKParam *param = (bIKParam *)ptr->data;
231 switch (param->iksolver) {
239 PointerRNA rna_Pose_ikparam_get(struct PointerRNA *ptr)
241 bPose *pose= (bPose*)ptr->data;
242 return rna_pointer_inherit_refine(ptr, &RNA_IKParam, pose->ikparam);
245 static StructRNA *rna_Pose_ikparam_typef(PointerRNA *ptr)
247 bPose *pose= (bPose*)ptr->data;
249 switch (pose->iksolver) {
257 static void rna_Itasc_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
259 Object *ob = ptr->id.data;
260 bItasc *itasc = ptr->data;
263 if (itasc->precision < 0.0001f)
264 itasc->precision = 0.0001f;
265 if (itasc->minstep < 0.001f)
266 itasc->minstep = 0.001f;
267 if (itasc->maxstep < itasc->minstep)
268 itasc->maxstep = itasc->minstep;
269 if (itasc->feedback < 0.01f)
270 itasc->feedback = 0.01f;
271 if (itasc->feedback > 100.f)
272 itasc->feedback = 100.f;
273 if (itasc->maxvel < 0.01f)
274 itasc->maxvel = 0.01f;
275 if (itasc->maxvel > 100.f)
276 itasc->maxvel = 100.f;
277 BIK_update_param(ob->pose);
279 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
282 static void rna_Itasc_update_rebuild(Main *bmain, Scene *scene, PointerRNA *ptr)
284 Object *ob= ptr->id.data;
285 bPose *pose = ob->pose;
287 pose->flag |= POSE_RECALC; // checks & sorts pose channels
288 rna_Itasc_update(bmain, scene, ptr);
291 static void rna_PoseChannel_bone_custom_set(PointerRNA *ptr, PointerRNA value)
293 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
297 id_us_min(&pchan->custom->id);
298 pchan->custom = NULL;
301 pchan->custom = value.data;
303 id_us_plus(&pchan->custom->id);
306 static PointerRNA rna_PoseChannel_bone_group_get(PointerRNA *ptr)
308 Object *ob= (Object*)ptr->id.data;
309 bPose *pose= (ob) ? ob->pose : NULL;
310 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
314 grp= BLI_findlink(&pose->agroups, pchan->agrp_index-1);
318 return rna_pointer_inherit_refine(ptr, &RNA_BoneGroup, grp);
321 static void rna_PoseChannel_bone_group_set(PointerRNA *ptr, PointerRNA value)
323 Object *ob= (Object*)ptr->id.data;
324 bPose *pose= (ob) ? ob->pose : NULL;
325 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
328 pchan->agrp_index= BLI_findindex(&pose->agroups, value.data) + 1;
330 pchan->agrp_index= 0;
333 static int rna_PoseChannel_bone_group_index_get(PointerRNA *ptr)
335 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
336 return MAX2(pchan->agrp_index-1, 0);
339 static void rna_PoseChannel_bone_group_index_set(PointerRNA *ptr, int value)
341 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
342 pchan->agrp_index= value+1;
345 static void rna_PoseChannel_bone_group_index_range(PointerRNA *ptr, int *min, int *max)
347 Object *ob= (Object*)ptr->id.data;
348 bPose *pose= (ob) ? ob->pose : NULL;
353 *max= BLI_countlist(&pose->agroups)-1;
360 static PointerRNA rna_Pose_active_bone_group_get(PointerRNA *ptr)
362 bPose *pose= (bPose*)ptr->data;
363 return rna_pointer_inherit_refine(ptr, &RNA_BoneGroup, BLI_findlink(&pose->agroups, pose->active_group-1));
366 static void rna_Pose_active_bone_group_set(PointerRNA *ptr, PointerRNA value)
368 bPose *pose= (bPose*)ptr->data;
369 pose->active_group= BLI_findindex(&pose->agroups, value.data) + 1;
372 static int rna_Pose_active_bone_group_index_get(PointerRNA *ptr)
374 bPose *pose= (bPose*)ptr->data;
375 return MAX2(pose->active_group-1, 0);
378 static void rna_Pose_active_bone_group_index_set(PointerRNA *ptr, int value)
380 bPose *pose= (bPose*)ptr->data;
381 pose->active_group= value+1;
384 static void rna_Pose_active_bone_group_index_range(PointerRNA *ptr, int *min, int *max)
386 bPose *pose= (bPose*)ptr->data;
389 *max= BLI_countlist(&pose->agroups)-1;
394 static void rna_pose_bgroup_name_index_get(PointerRNA *ptr, char *value, int index)
396 bPose *pose= (bPose*)ptr->data;
399 grp= BLI_findlink(&pose->agroups, index-1);
401 if(grp) BLI_strncpy(value, grp->name, sizeof(grp->name));
402 else BLI_strncpy(value, "", sizeof(grp->name)); // XXX if invalid pointer, won't this crash?
405 static int rna_pose_bgroup_name_index_length(PointerRNA *ptr, int index)
407 bPose *pose= (bPose*)ptr->data;
410 grp= BLI_findlink(&pose->agroups, index-1);
411 return (grp)? strlen(grp->name): 0;
414 static void rna_pose_bgroup_name_index_set(PointerRNA *ptr, const char *value, short *index)
416 bPose *pose= (bPose*)ptr->data;
420 for (a=1, grp=pose->agroups.first; grp; grp=grp->next, a++) {
421 if (strcmp(grp->name, value) == 0) {
430 static void rna_pose_pgroup_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen)
432 bPose *pose= (bPose*)ptr->data;
435 for (grp= pose->agroups.first; grp; grp= grp->next) {
436 if (strcmp(grp->name, value) == 0) {
437 BLI_strncpy(result, value, maxlen);
442 BLI_strncpy(result, "", maxlen);
446 static PointerRNA rna_PoseChannel_active_constraint_get(PointerRNA *ptr)
448 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
449 bConstraint *con= constraints_get_active(&pchan->constraints);
450 return rna_pointer_inherit_refine(ptr, &RNA_Constraint, con);
453 static void rna_PoseChannel_active_constraint_set(PointerRNA *ptr, PointerRNA value)
455 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
456 constraints_set_active(&pchan->constraints, (bConstraint *)value.data);
459 static bConstraint *rna_PoseChannel_constraints_new(bPoseChannel *pchan, int type)
461 //WM_main_add_notifier(NC_OBJECT|ND_CONSTRAINT|NA_ADDED, object);
462 // TODO, pass object also
463 // TODO, new pose bones don't have updated draw flags
464 return add_pose_constraint(NULL, pchan, NULL, type);
467 static void rna_PoseChannel_constraints_remove(ID *id, bPoseChannel *pchan, ReportList *reports, bConstraint *con)
469 if(BLI_findindex(&pchan->constraints, con) == -1) {
470 BKE_reportf(reports, RPT_ERROR, "Constraint '%s' not found in pose bone '%s'.", con->name, pchan->name);
474 Object *ob= (Object *)id;
475 const short is_ik= ELEM(con->type, CONSTRAINT_TYPE_KINEMATIC, CONSTRAINT_TYPE_SPLINEIK);
477 remove_constraint(&pchan->constraints, con);
478 ED_object_constraint_update(ob);
479 constraints_set_active(&pchan->constraints, NULL);
480 WM_main_add_notifier(NC_OBJECT|ND_CONSTRAINT|NA_REMOVED, id);
483 BIK_clear_data(ob->pose);
488 static int rna_PoseChannel_proxy_editable(PointerRNA *ptr)
490 Object *ob= (Object*)ptr->id.data;
491 bArmature *arm= ob->data;
492 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
494 return (ob->proxy && pchan->bone && (pchan->bone->layer & arm->layer_protected))? 0: PROP_EDITABLE;
497 static int rna_PoseChannel_location_editable(PointerRNA *ptr, int index)
499 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
501 /* only if the axis in question is locked, not editable... */
502 if ((index == 0) && (pchan->protectflag & OB_LOCK_LOCX))
504 else if ((index == 1) && (pchan->protectflag & OB_LOCK_LOCY))
506 else if ((index == 2) && (pchan->protectflag & OB_LOCK_LOCZ))
509 return PROP_EDITABLE;
512 static int rna_PoseChannel_scale_editable(PointerRNA *ptr, int index)
514 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
516 /* only if the axis in question is locked, not editable... */
517 if ((index == 0) && (pchan->protectflag & OB_LOCK_SCALEX))
519 else if ((index == 1) && (pchan->protectflag & OB_LOCK_SCALEY))
521 else if ((index == 2) && (pchan->protectflag & OB_LOCK_SCALEZ))
524 return PROP_EDITABLE;
527 static int rna_PoseChannel_rotation_euler_editable(PointerRNA *ptr, int index)
529 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
531 /* only if the axis in question is locked, not editable... */
532 if ((index == 0) && (pchan->protectflag & OB_LOCK_ROTX))
534 else if ((index == 1) && (pchan->protectflag & OB_LOCK_ROTY))
536 else if ((index == 2) && (pchan->protectflag & OB_LOCK_ROTZ))
539 return PROP_EDITABLE;
542 static int rna_PoseChannel_rotation_4d_editable(PointerRNA *ptr, int index)
544 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
546 /* only consider locks if locking components individually... */
547 if (pchan->protectflag & OB_LOCK_ROT4D) {
548 /* only if the axis in question is locked, not editable... */
549 if ((index == 0) && (pchan->protectflag & OB_LOCK_ROTW))
551 else if ((index == 1) && (pchan->protectflag & OB_LOCK_ROTX))
553 else if ((index == 2) && (pchan->protectflag & OB_LOCK_ROTY))
555 else if ((index == 3) && (pchan->protectflag & OB_LOCK_ROTZ))
559 return PROP_EDITABLE;
562 /* not essential, but much faster then the default lookup function */
563 int rna_PoseBones_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
565 bPose *pose= (bPose*)ptr->data;
566 bPoseChannel *pchan= get_pose_channel(pose, key);
568 RNA_pointer_create(ptr->id.data, &RNA_PoseBone, pchan, r_ptr);
576 static void rna_PoseChannel_matrix_basis_get(PointerRNA *ptr, float *values)
578 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
579 pchan_to_mat4(pchan, (float (*)[4])values);
582 static void rna_PoseChannel_matrix_basis_set(PointerRNA *ptr, const float *values)
584 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
585 pchan_apply_mat4(pchan, (float (*)[4])values, FALSE); /* no compat for predictable result */
588 static void rna_PoseChannel_matrix_set(PointerRNA *ptr, const float *values)
590 bPoseChannel *pchan= (bPoseChannel*)ptr->data;
591 Object *ob= (Object*)ptr->id.data;
592 float umat[4][4]= MAT4_UNITY;
595 /* recalculate pose matrix with only parent transformations,
596 * bone loc/sca/rot is ignored, scene and frame are not used. */
597 where_is_pose_bone(NULL, ob, pchan, 0.0f, FALSE);
599 /* find the matrix, need to remove the bone transforms first so this is
600 * calculated as a matrix to set rather then a difference ontop of whats
602 pchan_apply_mat4(pchan, umat, FALSE);
603 armature_mat_pose_to_bone(pchan, (float (*)[4])values, tmat);
604 pchan_apply_mat4(pchan, tmat, FALSE); /* no compat for predictable result */
609 static void rna_def_bone_group(BlenderRNA *brna)
611 static EnumPropertyItem prop_colorSets_items[] = {
612 {0, "DEFAULT", 0, "Default Colors", ""},
613 {1, "THEME01", 0, "01 - Theme Color Set", ""},
614 {2, "THEME02", 0, "02 - Theme Color Set", ""},
615 {3, "THEME03", 0, "03 - Theme Color Set", ""},
616 {4, "THEME04", 0, "04 - Theme Color Set", ""},
617 {5, "THEME05", 0, "05 - Theme Color Set", ""},
618 {6, "THEME06", 0, "06 - Theme Color Set", ""},
619 {7, "THEME07", 0, "07 - Theme Color Set", ""},
620 {8, "THEME08", 0, "08 - Theme Color Set", ""},
621 {9, "THEME09", 0, "09 - Theme Color Set", ""},
622 {10, "THEME10", 0, "10 - Theme Color Set", ""},
623 {11, "THEME11", 0, "11 - Theme Color Set", ""},
624 {12, "THEME12", 0, "12 - Theme Color Set", ""},
625 {13, "THEME13", 0, "13 - Theme Color Set", ""},
626 {14, "THEME14", 0, "14 - Theme Color Set", ""},
627 {15, "THEME15", 0, "15 - Theme Color Set", ""},
628 {16, "THEME16", 0, "16 - Theme Color Set", ""},
629 {17, "THEME17", 0, "17 - Theme Color Set", ""},
630 {18, "THEME18", 0, "18 - Theme Color Set", ""},
631 {19, "THEME19", 0, "19 - Theme Color Set", ""},
632 {20, "THEME20", 0, "20 - Theme Color Set", ""},
633 {-1, "CUSTOM", 0, "Custom Color Set", ""},
634 {0, NULL, 0, NULL, NULL}};
640 srna= RNA_def_struct(brna, "BoneGroup", NULL);
641 RNA_def_struct_sdna(srna, "bActionGroup");
642 RNA_def_struct_ui_text(srna, "Bone Group", "Groups of Pose Channels (Bones)");
643 RNA_def_struct_ui_icon(srna, ICON_GROUP_BONE);
646 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
647 RNA_def_property_ui_text(prop, "Name", "");
648 RNA_def_struct_name_property(srna, prop);
650 // TODO: add some runtime-collections stuff to access grouped bones
652 /* color set + colors */
653 prop= RNA_def_property(srna, "color_set", PROP_ENUM, PROP_NONE);
654 RNA_def_property_enum_sdna(prop, NULL, "customCol");
655 RNA_def_property_enum_items(prop, prop_colorSets_items);
656 RNA_def_property_enum_funcs(prop, NULL, "rna_BoneGroup_color_set_set", NULL);
657 RNA_def_property_ui_text(prop, "Color Set", "Custom color set to use");
658 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
660 // TODO: editing the colors for this should result in changes to the color type...
661 prop= RNA_def_property(srna, "colors", PROP_POINTER, PROP_NONE);
662 RNA_def_property_flag(prop, PROP_NEVER_NULL);
663 RNA_def_property_struct_type(prop, "ThemeBoneColorSet");
664 RNA_def_property_pointer_sdna(prop, NULL, "cs"); /* NOTE: the DNA data is not really a pointer, but this code works :) */
665 RNA_def_property_ui_text(prop, "Colors", "Copy of the colors associated with the group's color set");
666 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
669 static EnumPropertyItem prop_iksolver_items[] = {
670 {IKSOLVER_LEGACY, "LEGACY", 0, "Legacy", "Original IK solver"},
671 {IKSOLVER_ITASC, "ITASC", 0, "iTaSC", "Multi constraint, stateful IK solver"},
672 {0, NULL, 0, NULL, NULL}};
674 static EnumPropertyItem prop_solver_items[] = {
675 {ITASC_SOLVER_SDLS, "SDLS", 0, "SDLS", "Selective Damped Least Square"},
676 {ITASC_SOLVER_DLS, "DLS", 0, "DLS", "Damped Least Square with Numerical Filtering"},
677 {0, NULL, 0, NULL, NULL}};
680 static void rna_def_pose_channel_constraints(BlenderRNA *brna, PropertyRNA *cprop)
688 RNA_def_property_srna(cprop, "PoseBoneConstraints");
689 srna= RNA_def_struct(brna, "PoseBoneConstraints", NULL);
690 RNA_def_struct_sdna(srna, "bPoseChannel");
691 RNA_def_struct_ui_text(srna, "PoseBone Constraints", "Collection of pose bone constraints");
693 /* Collection active property */
694 prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
695 RNA_def_property_struct_type(prop, "Constraint");
696 RNA_def_property_pointer_funcs(prop, "rna_PoseChannel_active_constraint_get", "rna_PoseChannel_active_constraint_set", NULL, NULL);
697 RNA_def_property_flag(prop, PROP_EDITABLE);
698 RNA_def_property_ui_text(prop, "Active Constraint", "Active PoseChannel constraint");
701 /* Constraint collection */
702 func= RNA_def_function(srna, "new", "rna_PoseChannel_constraints_new");
703 RNA_def_function_ui_description(func, "Add a constraint to this object");
705 parm= RNA_def_pointer(func, "constraint", "Constraint", "", "New constraint.");
706 RNA_def_function_return(func, parm);
707 /* constraint to add */
708 parm= RNA_def_enum(func, "type", constraint_type_items, 1, "", "Constraint type to add.");
709 RNA_def_property_flag(parm, PROP_REQUIRED);
711 func= RNA_def_function(srna, "remove", "rna_PoseChannel_constraints_remove");
712 RNA_def_function_ui_description(func, "Remove a constraint from this object.");
713 RNA_def_function_flag(func, FUNC_USE_REPORTS|FUNC_USE_SELF_ID); /* ID needed for refresh */
714 /* constraint to remove */
715 parm= RNA_def_pointer(func, "constraint", "Constraint", "", "Removed constraint.");
716 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
719 static void rna_def_pose_channel(BlenderRNA *brna)
721 // XXX: this RNA enum define is currently duplicated for objects, since there is some text here which is not applicable
722 static EnumPropertyItem prop_rotmode_items[] = {
723 {ROT_MODE_QUAT, "QUATERNION", 0, "Quaternion (WXYZ)", "No Gimbal Lock (default)"},
724 {ROT_MODE_XYZ, "XYZ", 0, "XYZ Euler", "XYZ Rotation Order. Prone to Gimbal Lock"},
725 {ROT_MODE_XZY, "XZY", 0, "XZY Euler", "XZY Rotation Order. Prone to Gimbal Lock"},
726 {ROT_MODE_YXZ, "YXZ", 0, "YXZ Euler", "YXZ Rotation Order. Prone to Gimbal Lock"},
727 {ROT_MODE_YZX, "YZX", 0, "YZX Euler", "YZX Rotation Order. Prone to Gimbal Lock"},
728 {ROT_MODE_ZXY, "ZXY", 0, "ZXY Euler", "ZXY Rotation Order. Prone to Gimbal Lock"},
729 {ROT_MODE_ZYX, "ZYX", 0, "ZYX Euler", "ZYX Rotation Order. Prone to Gimbal Lock"},
730 {ROT_MODE_AXISANGLE, "AXIS_ANGLE", 0, "Axis Angle", "Axis Angle (W+XYZ). Defines a rotation around some axis defined by 3D-Vector"},
731 {0, NULL, 0, NULL, NULL}};
733 static float default_quat[4] = {1,0,0,0}; /* default quaternion values */
734 static float default_axisAngle[4] = {0,0,1,0}; /* default axis-angle rotation values */
735 static float default_scale[3] = {1,1,1}; /* default scale values */
737 const int matrix_dimsize[]= {4, 4};
742 srna= RNA_def_struct(brna, "PoseBone", NULL);
743 RNA_def_struct_sdna(srna, "bPoseChannel");
744 RNA_def_struct_ui_text(srna, "Pose Bone", "Channel defining pose data for a bone in a Pose");
745 RNA_def_struct_path_func(srna, "rna_PoseBone_path");
746 RNA_def_struct_idprops_func(srna, "rna_PoseBone_idprops");
748 /* Bone Constraints */
749 prop= RNA_def_property(srna, "constraints", PROP_COLLECTION, PROP_NONE);
750 RNA_def_property_struct_type(prop, "Constraint");
751 RNA_def_property_ui_text(prop, "Constraints", "Constraints that act on this PoseChannel");
753 rna_def_pose_channel_constraints(brna, prop);
755 /* Name + Selection Status */
756 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
757 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_PoseChannel_name_set");
758 RNA_def_property_ui_text(prop, "Name", "");
759 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
760 RNA_def_struct_name_property(srna, prop);
762 /* Baked Bone Path cache data */
763 rna_def_motionpath_common(srna);
765 /* Relationships to other bones */
766 prop= RNA_def_property(srna, "bone", PROP_POINTER, PROP_NONE);
767 RNA_def_property_flag(prop, PROP_NEVER_NULL);
768 RNA_def_property_struct_type(prop, "Bone");
769 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
770 RNA_def_property_ui_text(prop, "Bone", "Bone associated with this PoseBone");
772 prop= RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
773 RNA_def_property_struct_type(prop, "PoseBone");
774 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
775 RNA_def_property_ui_text(prop, "Parent", "Parent of this pose bone");
777 prop= RNA_def_property(srna, "child", PROP_POINTER, PROP_NONE);
778 RNA_def_property_struct_type(prop, "PoseBone");
779 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
780 RNA_def_property_ui_text(prop, "Child", "Child of this pose bone");
782 /* Transformation settings */
783 prop= RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION);
784 RNA_def_property_float_sdna(prop, NULL, "loc");
785 RNA_def_property_editable_array_func(prop, "rna_PoseChannel_location_editable");
786 RNA_def_property_ui_text(prop, "Location", "");
787 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable"); // XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too
788 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
790 prop= RNA_def_property(srna, "scale", PROP_FLOAT, PROP_XYZ);
791 RNA_def_property_float_sdna(prop, NULL, "size");
792 RNA_def_property_editable_array_func(prop, "rna_PoseChannel_scale_editable");
793 RNA_def_property_float_array_default(prop, default_scale);
794 RNA_def_property_ui_text(prop, "Scale", "");
795 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable"); // XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too
796 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
798 prop= RNA_def_property(srna, "rotation_quaternion", PROP_FLOAT, PROP_QUATERNION);
799 RNA_def_property_float_sdna(prop, NULL, "quat");
800 RNA_def_property_editable_array_func(prop, "rna_PoseChannel_rotation_4d_editable");
801 RNA_def_property_float_array_default(prop, default_quat);
802 RNA_def_property_ui_text(prop, "Quaternion Rotation", "Rotation in Quaternions");
803 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable"); // XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too
804 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
806 /* XXX: for axis-angle, it would have been nice to have 2 separate fields for UI purposes, but
807 * having a single one is better for Keyframing and other property-management situations...
809 prop= RNA_def_property(srna, "rotation_axis_angle", PROP_FLOAT, PROP_AXISANGLE);
810 RNA_def_property_array(prop, 4); // TODO: maybe we'll need to define the 'default value' getter too...
811 RNA_def_property_float_funcs(prop, "rna_PoseChannel_rotation_axis_angle_get", "rna_PoseChannel_rotation_axis_angle_set", NULL);
812 RNA_def_property_editable_array_func(prop, "rna_PoseChannel_rotation_4d_editable");
813 RNA_def_property_float_array_default(prop, default_axisAngle);
814 RNA_def_property_ui_text(prop, "Axis-Angle Rotation", "Angle of Rotation for Axis-Angle rotation representation");
815 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable"); // XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too
816 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
818 prop= RNA_def_property(srna, "rotation_euler", PROP_FLOAT, PROP_EULER);
819 RNA_def_property_float_sdna(prop, NULL, "eul");
820 RNA_def_property_editable_array_func(prop, "rna_PoseChannel_rotation_euler_editable");
821 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable"); // XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too
822 RNA_def_property_ui_text(prop, "Euler Rotation", "Rotation in Eulers");
823 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
825 prop= RNA_def_property(srna, "rotation_mode", PROP_ENUM, PROP_NONE);
826 RNA_def_property_enum_sdna(prop, NULL, "rotmode");
827 RNA_def_property_enum_items(prop, prop_rotmode_items); // XXX move to using a single define of this someday
828 RNA_def_property_enum_funcs(prop, NULL, "rna_PoseChannel_rotation_mode_set", NULL);
829 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable"); // XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too
830 RNA_def_property_ui_text(prop, "Rotation Mode", "");
831 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
833 /* transform matrices - should be read-only since these are set directly by AnimSys evaluation */
834 prop= RNA_def_property(srna, "matrix_channel", PROP_FLOAT, PROP_MATRIX);
835 RNA_def_property_float_sdna(prop, NULL, "chan_mat");
836 RNA_def_property_multi_array(prop, 2, matrix_dimsize);
837 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
838 RNA_def_property_ui_text(prop, "Channel Matrix", "4x4 matrix, before constraints");
840 /* writable because it touches loc/scale/rot directly */
841 prop= RNA_def_property(srna, "matrix_basis", PROP_FLOAT, PROP_MATRIX);
842 RNA_def_property_multi_array(prop, 2, matrix_dimsize);
843 RNA_def_property_ui_text(prop, "Basis Matrix", "Provides an alternative access to loc/scale/rotation relative to the parent and own rest bone.");
844 RNA_def_property_float_funcs(prop, "rna_PoseChannel_matrix_basis_get", "rna_PoseChannel_matrix_basis_set", NULL);
845 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
846 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
849 prop= RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX);
850 RNA_def_property_float_sdna(prop, NULL, "pose_mat");
851 RNA_def_property_multi_array(prop, 2, matrix_dimsize);
852 RNA_def_property_float_funcs(prop, NULL, "rna_PoseChannel_matrix_set", NULL);
853 RNA_def_property_ui_text(prop, "Pose Matrix", "Final 4x4 matrix after constraints and drivers are applied (object space)");
854 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
856 /* Head/Tail Coordinates (in Pose Space) - Automatically calculated... */
857 prop= RNA_def_property(srna, "head", PROP_FLOAT, PROP_TRANSLATION);
858 RNA_def_property_float_sdna(prop, NULL, "pose_head");
859 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
860 RNA_def_property_ui_text(prop, "Pose Head Position", "Location of head of the channel's bone");
862 prop= RNA_def_property(srna, "tail", PROP_FLOAT, PROP_TRANSLATION);
863 RNA_def_property_float_sdna(prop, NULL, "pose_tail");
864 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
865 RNA_def_property_ui_text(prop, "Pose Tail Position", "Location of tail of the channel's bone");
868 prop= RNA_def_property(srna, "is_in_ik_chain", PROP_BOOLEAN, PROP_NONE);
869 RNA_def_property_boolean_funcs(prop, "rna_PoseChannel_has_ik_get", NULL);
870 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
871 RNA_def_property_ui_text(prop, "Has IK", "Is part of an IK chain");
872 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
874 prop= RNA_def_property(srna, "lock_ik_x", PROP_BOOLEAN, PROP_NONE);
875 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_NO_XDOF);
876 RNA_def_property_ui_text(prop, "IK X Lock", "Disallow movement around the X axis");
877 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
878 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
880 prop= RNA_def_property(srna, "lock_ik_y", PROP_BOOLEAN, PROP_NONE);
881 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_NO_YDOF);
882 RNA_def_property_ui_text(prop, "IK Y Lock", "Disallow movement around the Y axis");
883 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
884 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
886 prop= RNA_def_property(srna, "lock_ik_z", PROP_BOOLEAN, PROP_NONE);
887 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_NO_ZDOF);
888 RNA_def_property_ui_text(prop, "IK Z Lock", "Disallow movement around the Z axis");
889 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
890 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
892 prop= RNA_def_property(srna, "use_ik_limit_x", PROP_BOOLEAN, PROP_NONE);
893 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_XLIMIT);
894 RNA_def_property_ui_text(prop, "IK X Limit", "Limit movement around the X axis");
895 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
896 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
898 prop= RNA_def_property(srna, "use_ik_limit_y", PROP_BOOLEAN, PROP_NONE);
899 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_YLIMIT);
900 RNA_def_property_ui_text(prop, "IK Y Limit", "Limit movement around the Y axis");
901 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
902 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
904 prop= RNA_def_property(srna, "use_ik_limit_z", PROP_BOOLEAN, PROP_NONE);
905 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_ZLIMIT);
906 RNA_def_property_ui_text(prop, "IK Z Limit", "Limit movement around the Z axis");
907 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
908 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
910 prop= RNA_def_property(srna, "use_ik_rotation_control", PROP_BOOLEAN, PROP_NONE);
911 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_ROTCTL);
912 RNA_def_property_ui_text(prop, "IK rot control", "Apply channel rotation as IK constraint");
913 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
914 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
916 prop= RNA_def_property(srna, "use_ik_linear_control", PROP_BOOLEAN, PROP_NONE);
917 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_LINCTL);
918 RNA_def_property_ui_text(prop, "IK rot control", "Apply channel size as IK constraint if stretching is enabled");
919 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
920 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
922 prop= RNA_def_property(srna, "ik_min_x", PROP_FLOAT, PROP_ANGLE);
923 RNA_def_property_float_sdna(prop, NULL, "limitmin[0]");
924 RNA_def_property_range(prop, -M_PI, 0.0f);
925 RNA_def_property_ui_text(prop, "IK X Minimum", "Minimum angles for IK Limit");
926 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
927 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
929 prop= RNA_def_property(srna, "ik_max_x", PROP_FLOAT, PROP_ANGLE);
930 RNA_def_property_float_sdna(prop, NULL, "limitmax[0]");
931 RNA_def_property_range(prop, 0.0f, M_PI);
932 RNA_def_property_ui_text(prop, "IK X Maximum", "Maximum angles for IK Limit");
933 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
934 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
936 prop= RNA_def_property(srna, "ik_min_y", PROP_FLOAT, PROP_ANGLE);
937 RNA_def_property_float_sdna(prop, NULL, "limitmin[1]");
938 RNA_def_property_range(prop, -M_PI, 0.0f);
939 RNA_def_property_ui_text(prop, "IK Y Minimum", "Minimum angles for IK Limit");
940 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
941 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
943 prop= RNA_def_property(srna, "ik_max_y", PROP_FLOAT, PROP_ANGLE);
944 RNA_def_property_float_sdna(prop, NULL, "limitmax[1]");
945 RNA_def_property_range(prop, 0.0f, M_PI);
946 RNA_def_property_ui_text(prop, "IK Y Maximum", "Maximum angles for IK Limit");
947 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
948 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
950 prop= RNA_def_property(srna, "ik_min_z", PROP_FLOAT, PROP_ANGLE);
951 RNA_def_property_float_sdna(prop, NULL, "limitmin[2]");
952 RNA_def_property_range(prop, -M_PI, 0.0f);
953 RNA_def_property_ui_text(prop, "IK Z Minimum", "Minimum angles for IK Limit");
954 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
955 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
957 prop= RNA_def_property(srna, "ik_max_z", PROP_FLOAT, PROP_ANGLE);
958 RNA_def_property_float_sdna(prop, NULL, "limitmax[2]");
959 RNA_def_property_range(prop, 0.0f, M_PI);
960 RNA_def_property_ui_text(prop, "IK Z Maximum", "Maximum angles for IK Limit");
961 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
962 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
964 prop= RNA_def_property(srna, "ik_stiffness_x", PROP_FLOAT, PROP_NONE);
965 RNA_def_property_float_sdna(prop, NULL, "stiffness[0]");
966 RNA_def_property_range(prop, 0.0f, 0.99f);
967 RNA_def_property_ui_text(prop, "IK X Stiffness", "IK stiffness around the X axis");
968 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
969 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
971 prop= RNA_def_property(srna, "ik_stiffness_y", PROP_FLOAT, PROP_NONE);
972 RNA_def_property_float_sdna(prop, NULL, "stiffness[1]");
973 RNA_def_property_range(prop, 0.0f, 0.99f);
974 RNA_def_property_ui_text(prop, "IK Y Stiffness", "IK stiffness around the Y axis");
975 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
976 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
978 prop= RNA_def_property(srna, "ik_stiffness_z", PROP_FLOAT, PROP_NONE);
979 RNA_def_property_float_sdna(prop, NULL, "stiffness[2]");
980 RNA_def_property_range(prop, 0.0f, 0.99f);
981 RNA_def_property_ui_text(prop, "IK Z Stiffness", "IK stiffness around the Z axis");
982 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
983 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
985 prop= RNA_def_property(srna, "ik_stretch", PROP_FLOAT, PROP_NONE);
986 RNA_def_property_float_sdna(prop, NULL, "ikstretch");
987 RNA_def_property_range(prop, 0.0f,1.0f);
988 RNA_def_property_ui_text(prop, "IK Stretch", "Allow scaling of the bone for IK");
989 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
990 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
992 prop= RNA_def_property(srna, "ik_rotation_weight", PROP_FLOAT, PROP_NONE);
993 RNA_def_property_float_sdna(prop, NULL, "ikrotweight");
994 RNA_def_property_range(prop, 0.0f,1.0f);
995 RNA_def_property_ui_text(prop, "IK Rot Weight", "Weight of rotation constraint for IK");
996 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
997 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
999 prop= RNA_def_property(srna, "ik_linear_weight", PROP_FLOAT, PROP_NONE);
1000 RNA_def_property_float_sdna(prop, NULL, "iklinweight");
1001 RNA_def_property_range(prop, 0.0f,1.0f);
1002 RNA_def_property_ui_text(prop, "IK Lin Weight", "Weight of scale constraint for IK");
1003 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1004 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1006 /* custom bone shapes */
1007 prop= RNA_def_property(srna, "custom_shape", PROP_POINTER, PROP_NONE);
1008 RNA_def_property_pointer_sdna(prop, NULL, "custom");
1009 RNA_def_property_struct_type(prop, "Object");
1010 RNA_def_property_flag(prop, PROP_EDITABLE);
1011 RNA_def_property_pointer_funcs(prop, NULL, "rna_PoseChannel_bone_custom_set", NULL, NULL);
1012 RNA_def_property_ui_text(prop, "Custom Object", "Object that defines custom draw type for this bone");
1013 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1014 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1016 prop= RNA_def_property(srna, "custom_shape_transform", PROP_POINTER, PROP_NONE);
1017 RNA_def_property_pointer_sdna(prop, NULL, "custom_tx");
1018 RNA_def_property_struct_type(prop, "PoseBone");
1019 RNA_def_property_flag(prop, PROP_EDITABLE);
1020 RNA_def_property_ui_text(prop, "Custom Shape Transform", "Bone that defines the display transform of this custom shape");
1021 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1022 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1025 prop= RNA_def_property(srna, "bone_group_index", PROP_INT, PROP_NONE);
1026 RNA_def_property_int_sdna(prop, NULL, "agrp_index");
1027 RNA_def_property_flag(prop, PROP_EDITABLE);
1028 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
1029 RNA_def_property_int_funcs(prop, "rna_PoseChannel_bone_group_index_get", "rna_PoseChannel_bone_group_index_set", "rna_PoseChannel_bone_group_index_range");
1030 RNA_def_property_ui_text(prop, "Bone Group Index", "Bone Group this pose channel belongs to (0=no group)");
1031 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1032 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1034 prop= RNA_def_property(srna, "bone_group", PROP_POINTER, PROP_NONE);
1035 RNA_def_property_struct_type(prop, "BoneGroup");
1036 RNA_def_property_flag(prop, PROP_EDITABLE);
1037 RNA_def_property_pointer_funcs(prop, "rna_PoseChannel_bone_group_get", "rna_PoseChannel_bone_group_set", NULL, NULL);
1038 RNA_def_property_ui_text(prop, "Bone Group", "Bone Group this pose channel belongs to");
1039 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1040 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1042 /* transform locks */
1043 prop= RNA_def_property(srna, "lock_location", PROP_BOOLEAN, PROP_XYZ);
1044 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_LOCX);
1045 RNA_def_property_array(prop, 3);
1046 RNA_def_property_ui_text(prop, "Lock Location", "Lock editing of location in the interface");
1047 RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
1048 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1049 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1051 prop= RNA_def_property(srna, "lock_rotation", PROP_BOOLEAN, PROP_XYZ);
1052 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_ROTX);
1053 RNA_def_property_array(prop, 3);
1054 RNA_def_property_ui_text(prop, "Lock Rotation", "Lock editing of rotation in the interface");
1055 RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
1056 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1057 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1059 // XXX this is sub-optimal - it really should be included above, but due to technical reasons we can't do this!
1060 prop= RNA_def_property(srna, "lock_rotation_w", PROP_BOOLEAN, PROP_NONE);
1061 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_ROTW);
1062 RNA_def_property_ui_text(prop, "Lock Rotation (4D Angle)", "Lock editing of 'angle' component of four-component rotations in the interface");
1063 RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
1064 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1065 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1067 // XXX this needs a better name
1068 prop= RNA_def_property(srna, "lock_rotations_4d", PROP_BOOLEAN, PROP_NONE);
1069 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_ROT4D);
1070 RNA_def_property_ui_text(prop, "Lock Rotations (4D)", "Lock editing of four component rotations by components (instead of as Eulers)");
1071 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1072 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1074 prop= RNA_def_property(srna, "lock_scale", PROP_BOOLEAN, PROP_XYZ);
1075 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_SCALEX);
1076 RNA_def_property_array(prop, 3);
1077 RNA_def_property_ui_text(prop, "Lock Scale", "Lock editing of scale in the interface");
1078 RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
1079 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1080 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1082 RNA_api_pose_channel(srna);
1085 static void rna_def_pose_itasc(BlenderRNA *brna)
1087 static const EnumPropertyItem prop_itasc_mode_items[]= {
1088 {0, "ANIMATION", 0, "Animation", "Stateless solver computing pose starting from current action and non-IK constraints"},
1089 {ITASC_SIMULATION, "SIMULATION", 0, "Simulation", "Statefull solver running in real-time context and ignoring actions and non-IK constraints"},
1090 {0, NULL, 0, NULL, NULL}};
1091 static const EnumPropertyItem prop_itasc_reiteration_items[]= {
1092 {0, "NEVER", 0, "Never", "The solver does not reiterate, not even on first frame (starts from rest pose)"},
1093 {ITASC_INITIAL_REITERATION, "INITIAL", 0, "Initial", "The solver reiterates (converges) on the first frame but not on subsequent frame"},
1094 {ITASC_INITIAL_REITERATION|ITASC_REITERATION, "ALWAYS", 0, "Always", "The solver reiterates (converges) on all frames"},
1095 {0, NULL, 0, NULL, NULL}};
1100 srna= RNA_def_struct(brna, "Itasc", "IKParam");
1101 RNA_def_struct_sdna(srna, "bItasc");
1102 RNA_def_struct_ui_text(srna, "bItasc", "Parameters for the iTaSC IK solver");
1104 prop= RNA_def_property(srna, "precision", PROP_FLOAT, PROP_NONE);
1105 RNA_def_property_float_sdna(prop, NULL, "precision");
1106 RNA_def_property_range(prop, 0.0f,0.1f);
1107 RNA_def_property_ui_text(prop, "Precision", "Precision of convergence in case of reiteration");
1108 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1110 prop= RNA_def_property(srna, "iterations", PROP_INT, PROP_NONE);
1111 RNA_def_property_int_sdna(prop, NULL, "numiter");
1112 RNA_def_property_range(prop, 1.f,1000.f);
1113 RNA_def_property_ui_text(prop, "Iterations", "Maximum number of iterations for convergence in case of reiteration");
1114 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1116 prop= RNA_def_property(srna, "step_count", PROP_INT, PROP_NONE);
1117 RNA_def_property_int_sdna(prop, NULL, "numstep");
1118 RNA_def_property_range(prop, 1.f, 50.f);
1119 RNA_def_property_ui_text(prop, "Num steps", "Divides the frame interval into this many steps");
1120 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1122 prop= RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
1123 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
1124 RNA_def_property_enum_items(prop, prop_itasc_mode_items);
1125 RNA_def_property_ui_text(prop, "Mode", NULL);
1126 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update_rebuild");
1128 prop= RNA_def_property(srna, "reiteration_method", PROP_ENUM, PROP_NONE);
1129 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
1130 RNA_def_property_enum_items(prop, prop_itasc_reiteration_items);
1131 RNA_def_property_ui_text(prop, "Reiteration", "Defines if the solver is allowed to reiterate (converges until precision is met) on none, first or all frames");
1132 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1134 prop= RNA_def_property(srna, "use_auto_step", PROP_BOOLEAN, PROP_NONE);
1135 RNA_def_property_boolean_sdna(prop, NULL, "flag", ITASC_AUTO_STEP);
1136 RNA_def_property_ui_text(prop, "Auto step", "Automatically determine the optimal number of steps for best performance/accuracy trade off");
1137 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1139 prop= RNA_def_property(srna, "step_min", PROP_FLOAT, PROP_NONE);
1140 RNA_def_property_float_sdna(prop, NULL, "minstep");
1141 RNA_def_property_range(prop, 0.0f,0.1f);
1142 RNA_def_property_ui_text(prop, "Min step", "Lower bound for timestep in second in case of automatic substeps");
1143 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1145 prop= RNA_def_property(srna, "step_max", PROP_FLOAT, PROP_NONE);
1146 RNA_def_property_float_sdna(prop, NULL, "maxstep");
1147 RNA_def_property_range(prop, 0.0f,1.0f);
1148 RNA_def_property_ui_text(prop, "Max step", "Higher bound for timestep in second in case of automatic substeps");
1149 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1151 prop= RNA_def_property(srna, "feedback", PROP_FLOAT, PROP_NONE);
1152 RNA_def_property_float_sdna(prop, NULL, "feedback");
1153 RNA_def_property_range(prop, 0.0f,100.0f);
1154 RNA_def_property_ui_text(prop, "Feedback", "Feedback coefficient for error correction. Average response time=1/feedback. Default=20");
1155 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1157 prop= RNA_def_property(srna, "velocity_max", PROP_FLOAT, PROP_NONE);
1158 RNA_def_property_float_sdna(prop, NULL, "maxvel");
1159 RNA_def_property_range(prop, 0.0f,100.0f);
1160 RNA_def_property_ui_text(prop, "Max Velocity", "Maximum joint velocity in rad/s. Default=50");
1161 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1163 prop= RNA_def_property(srna, "solver", PROP_ENUM, PROP_NONE);
1164 RNA_def_property_enum_sdna(prop, NULL, "solver");
1165 RNA_def_property_enum_items(prop, prop_solver_items);
1166 RNA_def_property_ui_text(prop, "Solver", "Solving method selection: Automatic damping or manual damping");
1167 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update_rebuild");
1169 prop= RNA_def_property(srna, "damping_max", PROP_FLOAT, PROP_NONE);
1170 RNA_def_property_float_sdna(prop, NULL, "dampmax");
1171 RNA_def_property_range(prop, 0.0f,1.0f);
1172 RNA_def_property_ui_text(prop, "Damp", "Maximum damping coefficient when singular value is nearly 0. Higher values=more stability, less reactivity. Default=0.5");
1173 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1175 prop= RNA_def_property(srna, "damping_epsilon", PROP_FLOAT, PROP_NONE);
1176 RNA_def_property_float_sdna(prop, NULL, "dampeps");
1177 RNA_def_property_range(prop, 0.0f,1.0f);
1178 RNA_def_property_ui_text(prop, "Epsilon", "Singular value under which damping is progressively applied. Higher values=more stability, less reactivity. Default=0.1");
1179 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1182 static void rna_def_pose_ikparam(BlenderRNA *brna)
1187 srna= RNA_def_struct(brna, "IKParam", NULL);
1188 RNA_def_struct_sdna(srna, "bIKParam");
1189 RNA_def_struct_ui_text(srna, "IKParam", "Base type for IK solver parameters");
1190 RNA_def_struct_refine_func(srna, "rna_IKParam_refine");
1192 prop= RNA_def_property(srna, "ik_solver", PROP_ENUM, PROP_NONE);
1193 RNA_def_property_enum_sdna(prop, NULL, "iksolver");
1194 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1195 RNA_def_property_enum_items(prop, prop_iksolver_items);
1196 RNA_def_property_ui_text(prop, "IK Solver", "IK solver for which these parameters are defined, 0 for Legacy, 1 for iTaSC");
1199 /* pose.bone_groups */
1200 static void rna_def_bone_groups(BlenderRNA *brna, PropertyRNA *cprop)
1205 // FunctionRNA *func;
1206 // PropertyRNA *parm;
1208 RNA_def_property_srna(cprop, "BoneGroups");
1209 srna= RNA_def_struct(brna, "BoneGroups", NULL);
1210 RNA_def_struct_sdna(srna, "bPose");
1211 RNA_def_struct_ui_text(srna, "Bone Groups", "Collection of bone groups");
1213 prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
1214 RNA_def_property_struct_type(prop, "BoneGroup");
1215 RNA_def_property_flag(prop, PROP_EDITABLE);
1216 RNA_def_property_pointer_funcs(prop, "rna_Pose_active_bone_group_get", "rna_Pose_active_bone_group_set", NULL, NULL);
1217 RNA_def_property_ui_text(prop, "Active Bone Group", "Active bone group for this pose");
1218 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1220 prop= RNA_def_property(srna, "active_index", PROP_INT, PROP_NONE);
1221 RNA_def_property_int_sdna(prop, NULL, "active_group");
1222 RNA_def_property_int_funcs(prop, "rna_Pose_active_bone_group_index_get", "rna_Pose_active_bone_group_index_set", "rna_Pose_active_bone_group_index_range");
1223 RNA_def_property_ui_text(prop, "Active Bone Group Index", "Active index in bone groups array");
1224 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1227 static void rna_def_pose(BlenderRNA *brna)
1232 /* struct definition */
1233 srna= RNA_def_struct(brna, "Pose", NULL);
1234 RNA_def_struct_sdna(srna, "bPose");
1235 RNA_def_struct_ui_text(srna, "Pose", "A collection of pose channels, including settings for animating bones");
1238 prop= RNA_def_property(srna, "bones", PROP_COLLECTION, PROP_NONE);
1239 RNA_def_property_collection_sdna(prop, NULL, "chanbase", NULL);
1240 RNA_def_property_struct_type(prop, "PoseBone");
1241 RNA_def_property_ui_text(prop, "Pose Bones", "Individual pose bones for the armature");
1242 RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, NULL, NULL, NULL, "rna_PoseBones_lookup_string"); /* can be removed, only for fast lookup */
1244 prop= RNA_def_property(srna, "bone_groups", PROP_COLLECTION, PROP_NONE);
1245 RNA_def_property_collection_sdna(prop, NULL, "agroups", NULL);
1246 RNA_def_property_struct_type(prop, "BoneGroup");
1247 RNA_def_property_ui_text(prop, "Bone Groups", "Groups of the bones");
1248 rna_def_bone_groups(brna, prop);
1251 prop= RNA_def_property(srna, "ik_solver", PROP_ENUM, PROP_NONE);
1252 RNA_def_property_enum_sdna(prop, NULL, "iksolver");
1253 RNA_def_property_enum_funcs(prop, NULL, "rna_Pose_ik_solver_set", NULL);
1254 RNA_def_property_enum_items(prop, prop_iksolver_items);
1255 RNA_def_property_ui_text(prop, "IK Solver", "Selection of IK solver for IK chain, current choice is 0 for Legacy, 1 for iTaSC");
1256 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_ik_solver_update");
1258 prop= RNA_def_property(srna, "ik_param", PROP_POINTER, PROP_NONE);
1259 RNA_def_property_struct_type(prop, "IKParam");
1260 RNA_def_property_pointer_funcs(prop, "rna_Pose_ikparam_get", NULL, "rna_Pose_ikparam_typef", NULL);
1261 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1262 RNA_def_property_ui_text(prop, "IK Param", "Parameters for IK solver");
1265 rna_def_animviz_common(srna);
1267 /* RNA_api_pose(srna); */
1270 void RNA_def_pose(BlenderRNA *brna)
1273 rna_def_pose_channel(brna);
1274 rna_def_pose_ikparam(brna);
1275 rna_def_pose_itasc(brna);
1276 rna_def_bone_group(brna);