2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Blender Foundation (2008), Roland Hess, Joshua Leung
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file blender/makesrna/intern/rna_pose.c
31 #include "RNA_define.h"
32 #include "RNA_enum_types.h"
34 #include "rna_internal.h"
36 #include "DNA_action_types.h"
37 #include "DNA_armature_types.h"
38 #include "DNA_constraint_types.h"
39 #include "DNA_object_types.h"
40 #include "DNA_scene_types.h"
48 /* XXX: this RNA enum define is currently duplicated for objects,
49 * since there is some text here which is not applicable */
50 EnumPropertyItem posebone_rotmode_items[] = {
51 {ROT_MODE_QUAT, "QUATERNION", 0, "Quaternion (WXYZ)", "No Gimbal Lock (default)"},
52 {ROT_MODE_XYZ, "XYZ", 0, "XYZ Euler", "XYZ Rotation Order (prone to Gimbal Lock)"},
53 {ROT_MODE_XZY, "XZY", 0, "XZY Euler", "XZY Rotation Order (prone to Gimbal Lock)"},
54 {ROT_MODE_YXZ, "YXZ", 0, "YXZ Euler", "YXZ Rotation Order (prone to Gimbal Lock)"},
55 {ROT_MODE_YZX, "YZX", 0, "YZX Euler", "YZX Rotation Order (prone to Gimbal Lock)"},
56 {ROT_MODE_ZXY, "ZXY", 0, "ZXY Euler", "ZXY Rotation Order (prone to Gimbal Lock)"},
57 {ROT_MODE_ZYX, "ZYX", 0, "ZYX Euler", "ZYX Rotation Order (prone to Gimbal Lock)"},
58 {ROT_MODE_AXISANGLE, "AXIS_ANGLE", 0, "Axis Angle",
59 "Axis Angle (W+XYZ), defines a rotation around some axis defined by 3D-Vector"},
60 {0, NULL, 0, NULL, NULL}};
65 #include "BKE_action.h"
66 #include "BKE_armature.h"
68 #include "DNA_userdef_types.h"
70 #include "MEM_guardedalloc.h"
72 #include "BLI_ghash.h"
74 #include "BKE_context.h"
75 #include "BKE_constraint.h"
76 #include "BKE_depsgraph.h"
77 #include "BKE_idprop.h"
79 #include "ED_object.h"
80 #include "ED_armature.h"
82 #include "MEM_guardedalloc.h"
86 #include "RNA_access.h"
88 static void rna_Pose_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
90 /* XXX when to use this? ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK); */
92 DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
95 static void rna_Pose_IK_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
97 /* XXX when to use this? ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK); */
98 Object *ob = ptr->id.data;
100 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
101 BIK_clear_data(ob->pose);
104 static char *rna_PoseBone_path(PointerRNA *ptr)
106 return BLI_sprintfN("pose.bones[\"%s\"]", ((bPoseChannel*)ptr->data)->name);
109 static void rna_BoneGroup_color_set_set(PointerRNA *ptr, int value)
111 bActionGroup *grp = ptr->data;
113 /* if valid value, set the new enum value, then copy the relevant colors? */
114 if ((value >= -1) && (value < 21))
115 grp->customCol = value;
119 /* only do color copying if using a custom color (i.e. not default color) */
120 if (grp->customCol) {
121 if (grp->customCol > 0) {
122 /* copy theme colors on-to group's custom color in case user tries to edit color */
123 bTheme *btheme = U.themes.first;
124 ThemeWireColor *col_set = &btheme->tarm[(grp->customCol - 1)];
126 memcpy(&grp->cs, col_set, sizeof(ThemeWireColor));
129 /* init custom colors with a generic multi-color rgb set, if not initialized already
130 * (for custom color set) */
131 if (grp->cs.solid[0] == 0) {
132 /* define for setting colors in theme below */
133 #define SETCOL(col, r, g, b, a) col[0] = r; col[1] = g; col[2] = b; col[3] = a;
135 SETCOL(grp->cs.solid, 0xff, 0x00, 0x00, 255);
136 SETCOL(grp->cs.select, 0x81, 0xe6, 0x14, 255);
137 SETCOL(grp->cs.active, 0x18, 0xb6, 0xe0, 255);
145 void rna_BoneGroup_name_set(PointerRNA *ptr, const char *value)
147 Object *ob = ptr->id.data;
148 bActionGroup *agrp = ptr->data;
150 /* copy the new name into the name slot */
151 BLI_strncpy_utf8(agrp->name, value, sizeof(agrp->name));
153 BLI_uniquename(&ob->pose->agroups, agrp, "Group", '.', offsetof(bActionGroup, name), sizeof(agrp->name));
156 static IDProperty *rna_PoseBone_idprops(PointerRNA *ptr, int create)
158 bPoseChannel *pchan = ptr->data;
160 if (create && !pchan->prop) {
161 IDPropertyTemplate val = {0};
162 pchan->prop = IDP_New(IDP_GROUP, &val, "RNA_PoseBone group");
168 static void rna_Pose_ik_solver_set(struct PointerRNA *ptr, int value)
170 bPose *pose = (bPose*)ptr->data;
172 if (pose->iksolver != value) {
173 /* the solver has changed, must clean any temporary structures */
174 BIK_clear_data(pose);
176 MEM_freeN(pose->ikparam);
177 pose->ikparam = NULL;
179 pose->iksolver = value;
180 init_pose_ikparam(pose);
184 static void rna_Pose_ik_solver_update(Main *bmain, Scene *scene, PointerRNA *ptr)
186 Object *ob = ptr->id.data;
187 bPose *pose = ptr->data;
189 pose->flag |= POSE_RECALC; /* checks & sorts pose channels */
190 DAG_scene_sort(bmain, scene);
192 update_pose_constraint_flags(pose);
194 object_test_constraints(ob);
196 DAG_id_tag_update(&ob->id, OB_RECALC_DATA|OB_RECALC_OB);
199 /* rotation - axis-angle */
200 static void rna_PoseChannel_rotation_axis_angle_get(PointerRNA *ptr, float *value)
202 bPoseChannel *pchan = ptr->data;
204 /* for now, assume that rotation mode is axis-angle */
205 value[0] = pchan->rotAngle;
206 copy_v3_v3(&value[1], pchan->rotAxis);
209 /* rotation - axis-angle */
210 static void rna_PoseChannel_rotation_axis_angle_set(PointerRNA *ptr, const float *value)
212 bPoseChannel *pchan = ptr->data;
214 /* for now, assume that rotation mode is axis-angle */
215 pchan->rotAngle = value[0];
216 copy_v3_v3(pchan->rotAxis, (float *)&value[1]);
218 /* TODO: validate axis? */
221 static void rna_PoseChannel_rotation_mode_set(PointerRNA *ptr, int value)
223 bPoseChannel *pchan = ptr->data;
225 /* use API Method for conversions... */
226 BKE_rotMode_change_values(pchan->quat, pchan->eul, pchan->rotAxis, &pchan->rotAngle,
227 pchan->rotmode, (short)value);
229 /* finally, set the new rotation type */
230 pchan->rotmode = value;
233 static void rna_PoseChannel_name_set(PointerRNA *ptr, const char *value)
235 Object *ob = (Object*)ptr->id.data;
236 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
237 char oldname[sizeof(pchan->name)], newname[sizeof(pchan->name)];
239 /* need to be on the stack */
240 BLI_strncpy_utf8(newname, value, sizeof(pchan->name));
241 BLI_strncpy(oldname, pchan->name, sizeof(pchan->name));
243 ED_armature_bone_rename(ob->data, oldname, newname);
246 static int rna_PoseChannel_has_ik_get(PointerRNA *ptr)
248 Object *ob = (Object*)ptr->id.data;
249 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
251 return ED_pose_channel_in_IK_chain(ob, pchan);
254 StructRNA *rna_IKParam_refine(PointerRNA *ptr)
256 bIKParam *param = (bIKParam *)ptr->data;
258 switch (param->iksolver) {
266 PointerRNA rna_Pose_ikparam_get(struct PointerRNA *ptr)
268 bPose *pose = (bPose*)ptr->data;
269 return rna_pointer_inherit_refine(ptr, &RNA_IKParam, pose->ikparam);
272 static StructRNA *rna_Pose_ikparam_typef(PointerRNA *ptr)
274 bPose *pose = (bPose*)ptr->data;
276 switch (pose->iksolver) {
284 static void rna_Itasc_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
286 Object *ob = ptr->id.data;
287 bItasc *itasc = ptr->data;
290 if (itasc->precision < 0.0001f)
291 itasc->precision = 0.0001f;
292 if (itasc->minstep < 0.001f)
293 itasc->minstep = 0.001f;
294 if (itasc->maxstep < itasc->minstep)
295 itasc->maxstep = itasc->minstep;
296 if (itasc->feedback < 0.01f)
297 itasc->feedback = 0.01f;
298 if (itasc->feedback > 100.f)
299 itasc->feedback = 100.f;
300 if (itasc->maxvel < 0.01f)
301 itasc->maxvel = 0.01f;
302 if (itasc->maxvel > 100.f)
303 itasc->maxvel = 100.f;
304 BIK_update_param(ob->pose);
306 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
309 static void rna_Itasc_update_rebuild(Main *bmain, Scene *scene, PointerRNA *ptr)
311 Object *ob = ptr->id.data;
312 bPose *pose = ob->pose;
314 pose->flag |= POSE_RECALC; /* checks & sorts pose channels */
315 rna_Itasc_update(bmain, scene, ptr);
318 static void rna_PoseChannel_bone_custom_set(PointerRNA *ptr, PointerRNA value)
320 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
324 id_us_min(&pchan->custom->id);
325 pchan->custom = NULL;
328 pchan->custom = value.data;
330 id_us_plus(&pchan->custom->id);
333 static PointerRNA rna_PoseChannel_bone_group_get(PointerRNA *ptr)
335 Object *ob = (Object*)ptr->id.data;
336 bPose *pose = (ob) ? ob->pose : NULL;
337 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
341 grp = BLI_findlink(&pose->agroups, pchan->agrp_index-1);
345 return rna_pointer_inherit_refine(ptr, &RNA_BoneGroup, grp);
348 static void rna_PoseChannel_bone_group_set(PointerRNA *ptr, PointerRNA value)
350 Object *ob = (Object*)ptr->id.data;
351 bPose *pose = (ob) ? ob->pose : NULL;
352 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
355 pchan->agrp_index = BLI_findindex(&pose->agroups, value.data) + 1;
357 pchan->agrp_index = 0;
360 static int rna_PoseChannel_bone_group_index_get(PointerRNA *ptr)
362 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
363 return MAX2(pchan->agrp_index-1, 0);
366 static void rna_PoseChannel_bone_group_index_set(PointerRNA *ptr, int value)
368 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
369 pchan->agrp_index = value+1;
372 static void rna_PoseChannel_bone_group_index_range(PointerRNA *ptr, int *min, int *max)
374 Object *ob = (Object*)ptr->id.data;
375 bPose *pose = (ob) ? ob->pose : NULL;
380 *max = BLI_countlist(&pose->agroups)-1;
381 *max = MAX2(0, *max);
387 static PointerRNA rna_Pose_active_bone_group_get(PointerRNA *ptr)
389 bPose *pose = (bPose*)ptr->data;
390 return rna_pointer_inherit_refine(ptr, &RNA_BoneGroup, BLI_findlink(&pose->agroups, pose->active_group-1));
393 static void rna_Pose_active_bone_group_set(PointerRNA *ptr, PointerRNA value)
395 bPose *pose = (bPose*)ptr->data;
396 pose->active_group = BLI_findindex(&pose->agroups, value.data) + 1;
399 static int rna_Pose_active_bone_group_index_get(PointerRNA *ptr)
401 bPose *pose = (bPose*)ptr->data;
402 return MAX2(pose->active_group-1, 0);
405 static void rna_Pose_active_bone_group_index_set(PointerRNA *ptr, int value)
407 bPose *pose = (bPose*)ptr->data;
408 pose->active_group = value+1;
411 static void rna_Pose_active_bone_group_index_range(PointerRNA *ptr, int *min, int *max)
413 bPose *pose = (bPose*)ptr->data;
416 *max = BLI_countlist(&pose->agroups)-1;
417 *max = MAX2(0, *max);
421 static void rna_pose_bgroup_name_index_get(PointerRNA *ptr, char *value, int index)
423 bPose *pose = (bPose*)ptr->data;
426 grp = BLI_findlink(&pose->agroups, index-1);
428 if (grp) BLI_strncpy(value, grp->name, sizeof(grp->name));
429 else value[0] = '\0';
432 static int rna_pose_bgroup_name_index_length(PointerRNA *ptr, int index)
434 bPose *pose = (bPose*)ptr->data;
437 grp = BLI_findlink(&pose->agroups, index-1);
438 return (grp)? strlen(grp->name): 0;
441 static void rna_pose_bgroup_name_index_set(PointerRNA *ptr, const char *value, short *index)
443 bPose *pose = (bPose*)ptr->data;
447 for (a = 1, grp = pose->agroups.first; grp; grp = grp->next, a++) {
448 if (strcmp(grp->name, value) == 0) {
457 static void rna_pose_pgroup_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen)
459 bPose *pose = (bPose*)ptr->data;
462 for (grp = pose->agroups.first; grp; grp = grp->next) {
463 if (strcmp(grp->name, value) == 0) {
464 BLI_strncpy(result, value, maxlen);
473 static PointerRNA rna_PoseChannel_active_constraint_get(PointerRNA *ptr)
475 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
476 bConstraint *con = constraints_get_active(&pchan->constraints);
477 return rna_pointer_inherit_refine(ptr, &RNA_Constraint, con);
480 static void rna_PoseChannel_active_constraint_set(PointerRNA *ptr, PointerRNA value)
482 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
483 constraints_set_active(&pchan->constraints, (bConstraint *)value.data);
486 static bConstraint *rna_PoseChannel_constraints_new(bPoseChannel *pchan, int type)
488 /*WM_main_add_notifier(NC_OBJECT|ND_CONSTRAINT|NA_ADDED, object); */
489 /* TODO, pass object also */
490 /* TODO, new pose bones don't have updated draw flags */
491 return add_pose_constraint(NULL, pchan, NULL, type);
494 static void rna_PoseChannel_constraints_remove(ID *id, bPoseChannel *pchan, ReportList *reports, bConstraint *con)
496 if (BLI_findindex(&pchan->constraints, con) == -1) {
497 BKE_reportf(reports, RPT_ERROR, "Constraint '%s' not found in pose bone '%s'", con->name, pchan->name);
501 Object *ob = (Object *)id;
502 const short is_ik = ELEM(con->type, CONSTRAINT_TYPE_KINEMATIC, CONSTRAINT_TYPE_SPLINEIK);
504 remove_constraint(&pchan->constraints, con);
505 ED_object_constraint_update(ob);
506 constraints_set_active(&pchan->constraints, NULL);
507 WM_main_add_notifier(NC_OBJECT|ND_CONSTRAINT|NA_REMOVED, id);
510 BIK_clear_data(ob->pose);
515 static int rna_PoseChannel_proxy_editable(PointerRNA *ptr)
517 Object *ob = (Object*)ptr->id.data;
518 bArmature *arm = ob->data;
519 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
521 return (ob->proxy && pchan->bone && (pchan->bone->layer & arm->layer_protected))? 0: PROP_EDITABLE;
524 static int rna_PoseChannel_location_editable(PointerRNA *ptr, int index)
526 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
528 /* only if the axis in question is locked, not editable... */
529 if ((index == 0) && (pchan->protectflag & OB_LOCK_LOCX))
531 else if ((index == 1) && (pchan->protectflag & OB_LOCK_LOCY))
533 else if ((index == 2) && (pchan->protectflag & OB_LOCK_LOCZ))
536 return PROP_EDITABLE;
539 static int rna_PoseChannel_scale_editable(PointerRNA *ptr, int index)
541 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
543 /* only if the axis in question is locked, not editable... */
544 if ((index == 0) && (pchan->protectflag & OB_LOCK_SCALEX))
546 else if ((index == 1) && (pchan->protectflag & OB_LOCK_SCALEY))
548 else if ((index == 2) && (pchan->protectflag & OB_LOCK_SCALEZ))
551 return PROP_EDITABLE;
554 static int rna_PoseChannel_rotation_euler_editable(PointerRNA *ptr, int index)
556 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
558 /* only if the axis in question is locked, not editable... */
559 if ((index == 0) && (pchan->protectflag & OB_LOCK_ROTX))
561 else if ((index == 1) && (pchan->protectflag & OB_LOCK_ROTY))
563 else if ((index == 2) && (pchan->protectflag & OB_LOCK_ROTZ))
566 return PROP_EDITABLE;
569 static int rna_PoseChannel_rotation_4d_editable(PointerRNA *ptr, int index)
571 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
573 /* only consider locks if locking components individually... */
574 if (pchan->protectflag & OB_LOCK_ROT4D) {
575 /* only if the axis in question is locked, not editable... */
576 if ((index == 0) && (pchan->protectflag & OB_LOCK_ROTW))
578 else if ((index == 1) && (pchan->protectflag & OB_LOCK_ROTX))
580 else if ((index == 2) && (pchan->protectflag & OB_LOCK_ROTY))
582 else if ((index == 3) && (pchan->protectflag & OB_LOCK_ROTZ))
586 return PROP_EDITABLE;
589 /* not essential, but much faster then the default lookup function */
590 int rna_PoseBones_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
592 bPose *pose = (bPose*)ptr->data;
593 bPoseChannel *pchan = get_pose_channel(pose, key);
595 RNA_pointer_create(ptr->id.data, &RNA_PoseBone, pchan, r_ptr);
603 static void rna_PoseChannel_matrix_basis_get(PointerRNA *ptr, float *values)
605 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
606 pchan_to_mat4(pchan, (float (*)[4])values);
609 static void rna_PoseChannel_matrix_basis_set(PointerRNA *ptr, const float *values)
611 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
612 pchan_apply_mat4(pchan, (float (*)[4])values, FALSE); /* no compat for predictable result */
615 static void rna_PoseChannel_matrix_set(PointerRNA *ptr, const float *values)
617 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
618 Object *ob = (Object*)ptr->id.data;
621 armature_mat_pose_to_bone_ex(ob, pchan, (float (*)[4])values, tmat);
623 pchan_apply_mat4(pchan, tmat, FALSE); /* no compat for predictable result */
628 static void rna_def_bone_group(BlenderRNA *brna)
630 static EnumPropertyItem prop_colorSets_items[] = {
631 {0, "DEFAULT", 0, "Default Colors", ""},
632 {1, "THEME01", 0, "01 - Theme Color Set", ""},
633 {2, "THEME02", 0, "02 - Theme Color Set", ""},
634 {3, "THEME03", 0, "03 - Theme Color Set", ""},
635 {4, "THEME04", 0, "04 - Theme Color Set", ""},
636 {5, "THEME05", 0, "05 - Theme Color Set", ""},
637 {6, "THEME06", 0, "06 - Theme Color Set", ""},
638 {7, "THEME07", 0, "07 - Theme Color Set", ""},
639 {8, "THEME08", 0, "08 - Theme Color Set", ""},
640 {9, "THEME09", 0, "09 - Theme Color Set", ""},
641 {10, "THEME10", 0, "10 - Theme Color Set", ""},
642 {11, "THEME11", 0, "11 - Theme Color Set", ""},
643 {12, "THEME12", 0, "12 - Theme Color Set", ""},
644 {13, "THEME13", 0, "13 - Theme Color Set", ""},
645 {14, "THEME14", 0, "14 - Theme Color Set", ""},
646 {15, "THEME15", 0, "15 - Theme Color Set", ""},
647 {16, "THEME16", 0, "16 - Theme Color Set", ""},
648 {17, "THEME17", 0, "17 - Theme Color Set", ""},
649 {18, "THEME18", 0, "18 - Theme Color Set", ""},
650 {19, "THEME19", 0, "19 - Theme Color Set", ""},
651 {20, "THEME20", 0, "20 - Theme Color Set", ""},
652 {-1, "CUSTOM", 0, "Custom Color Set", ""},
653 {0, NULL, 0, NULL, NULL}};
659 srna = RNA_def_struct(brna, "BoneGroup", NULL);
660 RNA_def_struct_sdna(srna, "bActionGroup");
661 RNA_def_struct_ui_text(srna, "Bone Group", "Groups of Pose Channels (Bones)");
662 RNA_def_struct_ui_icon(srna, ICON_GROUP_BONE);
665 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
666 RNA_def_property_ui_text(prop, "Name", "");
667 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_BoneGroup_name_set");
668 RNA_def_struct_name_property(srna, prop);
670 /* TODO: add some runtime-collections stuff to access grouped bones */
672 /* color set + colors */
673 prop = RNA_def_property(srna, "color_set", PROP_ENUM, PROP_NONE);
674 RNA_def_property_enum_sdna(prop, NULL, "customCol");
675 RNA_def_property_enum_items(prop, prop_colorSets_items);
676 RNA_def_property_enum_funcs(prop, NULL, "rna_BoneGroup_color_set_set", NULL);
677 RNA_def_property_ui_text(prop, "Color Set", "Custom color set to use");
678 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
680 /* TODO: editing the colors for this should result in changes to the color type... */
681 prop = RNA_def_property(srna, "colors", PROP_POINTER, PROP_NONE);
682 RNA_def_property_flag(prop, PROP_NEVER_NULL);
683 RNA_def_property_struct_type(prop, "ThemeBoneColorSet");
684 /* NOTE: the DNA data is not really a pointer, but this code works :) */
685 RNA_def_property_pointer_sdna(prop, NULL, "cs");
686 RNA_def_property_ui_text(prop, "Colors", "Copy of the colors associated with the group's color set");
687 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
690 static EnumPropertyItem prop_iksolver_items[] = {
691 {IKSOLVER_LEGACY, "LEGACY", 0, "Legacy", "Original IK solver"},
692 {IKSOLVER_ITASC, "ITASC", 0, "iTaSC", "Multi constraint, stateful IK solver"},
693 {0, NULL, 0, NULL, NULL}};
695 static EnumPropertyItem prop_solver_items[] = {
696 {ITASC_SOLVER_SDLS, "SDLS", 0, "SDLS", "Selective Damped Least Square"},
697 {ITASC_SOLVER_DLS, "DLS", 0, "DLS", "Damped Least Square with Numerical Filtering"},
698 {0, NULL, 0, NULL, NULL}};
701 static void rna_def_pose_channel_constraints(BlenderRNA *brna, PropertyRNA *cprop)
709 RNA_def_property_srna(cprop, "PoseBoneConstraints");
710 srna = RNA_def_struct(brna, "PoseBoneConstraints", NULL);
711 RNA_def_struct_sdna(srna, "bPoseChannel");
712 RNA_def_struct_ui_text(srna, "PoseBone Constraints", "Collection of pose bone constraints");
714 /* Collection active property */
715 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
716 RNA_def_property_struct_type(prop, "Constraint");
717 RNA_def_property_pointer_funcs(prop, "rna_PoseChannel_active_constraint_get",
718 "rna_PoseChannel_active_constraint_set", NULL, NULL);
719 RNA_def_property_flag(prop, PROP_EDITABLE);
720 RNA_def_property_ui_text(prop, "Active Constraint", "Active PoseChannel constraint");
723 /* Constraint collection */
724 func = RNA_def_function(srna, "new", "rna_PoseChannel_constraints_new");
725 RNA_def_function_ui_description(func, "Add a constraint to this object");
727 parm = RNA_def_pointer(func, "constraint", "Constraint", "", "New constraint");
728 RNA_def_function_return(func, parm);
729 /* constraint to add */
730 parm = RNA_def_enum(func, "type", constraint_type_items, 1, "", "Constraint type to add");
731 RNA_def_property_flag(parm, PROP_REQUIRED);
733 func = RNA_def_function(srna, "remove", "rna_PoseChannel_constraints_remove");
734 RNA_def_function_ui_description(func, "Remove a constraint from this object");
735 RNA_def_function_flag(func, FUNC_USE_REPORTS|FUNC_USE_SELF_ID); /* ID needed for refresh */
736 /* constraint to remove */
737 parm = RNA_def_pointer(func, "constraint", "Constraint", "", "Removed constraint");
738 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
741 static void rna_def_pose_channel(BlenderRNA *brna)
743 static float default_quat[4] = {1,0,0,0}; /* default quaternion values */
744 static float default_axisAngle[4] = {0,0,1,0}; /* default axis-angle rotation values */
745 static float default_scale[3] = {1,1,1}; /* default scale values */
747 const int matrix_dimsize[] = {4, 4};
752 srna = RNA_def_struct(brna, "PoseBone", NULL);
753 RNA_def_struct_sdna(srna, "bPoseChannel");
754 RNA_def_struct_ui_text(srna, "Pose Bone", "Channel defining pose data for a bone in a Pose");
755 RNA_def_struct_path_func(srna, "rna_PoseBone_path");
756 RNA_def_struct_idprops_func(srna, "rna_PoseBone_idprops");
758 /* Bone Constraints */
759 prop = RNA_def_property(srna, "constraints", PROP_COLLECTION, PROP_NONE);
760 RNA_def_property_struct_type(prop, "Constraint");
761 RNA_def_property_ui_text(prop, "Constraints", "Constraints that act on this PoseChannel");
763 rna_def_pose_channel_constraints(brna, prop);
765 /* Name + Selection Status */
766 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
767 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_PoseChannel_name_set");
768 RNA_def_property_ui_text(prop, "Name", "");
769 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
770 RNA_def_struct_name_property(srna, prop);
772 /* Baked Bone Path cache data */
773 rna_def_motionpath_common(srna);
775 /* Relationships to other bones */
776 prop = RNA_def_property(srna, "bone", PROP_POINTER, PROP_NONE);
777 RNA_def_property_flag(prop, PROP_NEVER_NULL);
778 RNA_def_property_struct_type(prop, "Bone");
779 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
780 RNA_def_property_ui_text(prop, "Bone", "Bone associated with this PoseBone");
782 prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
783 RNA_def_property_struct_type(prop, "PoseBone");
784 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
785 RNA_def_property_ui_text(prop, "Parent", "Parent of this pose bone");
787 prop = RNA_def_property(srna, "child", PROP_POINTER, PROP_NONE);
788 RNA_def_property_struct_type(prop, "PoseBone");
789 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
790 RNA_def_property_ui_text(prop, "Child", "Child of this pose bone");
792 /* Transformation settings */
793 prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION);
794 RNA_def_property_float_sdna(prop, NULL, "loc");
795 RNA_def_property_editable_array_func(prop, "rna_PoseChannel_location_editable");
796 RNA_def_property_ui_text(prop, "Location", "");
797 /* XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too */
798 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
799 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
801 prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_XYZ);
802 RNA_def_property_float_sdna(prop, NULL, "size");
803 RNA_def_property_editable_array_func(prop, "rna_PoseChannel_scale_editable");
804 RNA_def_property_float_array_default(prop, default_scale);
805 RNA_def_property_ui_text(prop, "Scale", "");
806 /* XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too */
807 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
808 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
810 prop = RNA_def_property(srna, "rotation_quaternion", PROP_FLOAT, PROP_QUATERNION);
811 RNA_def_property_float_sdna(prop, NULL, "quat");
812 RNA_def_property_editable_array_func(prop, "rna_PoseChannel_rotation_4d_editable");
813 RNA_def_property_float_array_default(prop, default_quat);
814 RNA_def_property_ui_text(prop, "Quaternion Rotation", "Rotation in Quaternions");
815 /* XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too */
816 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
817 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
819 /* XXX: for axis-angle, it would have been nice to have 2 separate fields for UI purposes, but
820 * having a single one is better for Keyframing and other property-management situations...
822 prop = RNA_def_property(srna, "rotation_axis_angle", PROP_FLOAT, PROP_AXISANGLE);
823 RNA_def_property_array(prop, 4);
824 RNA_def_property_float_funcs(prop, "rna_PoseChannel_rotation_axis_angle_get",
825 "rna_PoseChannel_rotation_axis_angle_set", NULL);
826 RNA_def_property_editable_array_func(prop, "rna_PoseChannel_rotation_4d_editable");
827 RNA_def_property_float_array_default(prop, default_axisAngle);
828 RNA_def_property_ui_text(prop, "Axis-Angle Rotation", "Angle of Rotation for Axis-Angle rotation representation");
829 /* XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too */
830 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
831 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
833 prop = RNA_def_property(srna, "rotation_euler", PROP_FLOAT, PROP_EULER);
834 RNA_def_property_float_sdna(prop, NULL, "eul");
835 RNA_def_property_editable_array_func(prop, "rna_PoseChannel_rotation_euler_editable");
836 /* XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too */
837 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
838 RNA_def_property_ui_text(prop, "Euler Rotation", "Rotation in Eulers");
839 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
841 prop = RNA_def_property(srna, "rotation_mode", PROP_ENUM, PROP_NONE);
842 RNA_def_property_enum_sdna(prop, NULL, "rotmode");
843 RNA_def_property_enum_items(prop, posebone_rotmode_items); /* XXX move to using a single define of this someday */
844 RNA_def_property_enum_funcs(prop, NULL, "rna_PoseChannel_rotation_mode_set", NULL);
845 /* XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too */
846 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
847 RNA_def_property_ui_text(prop, "Rotation Mode", "");
848 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
850 /* transform matrices - should be read-only since these are set directly by AnimSys evaluation */
851 prop = RNA_def_property(srna, "matrix_channel", PROP_FLOAT, PROP_MATRIX);
852 RNA_def_property_float_sdna(prop, NULL, "chan_mat");
853 RNA_def_property_multi_array(prop, 2, matrix_dimsize);
854 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
855 RNA_def_property_ui_text(prop, "Channel Matrix", "4x4 matrix, before constraints");
857 /* writable because it touches loc/scale/rot directly */
858 prop = RNA_def_property(srna, "matrix_basis", PROP_FLOAT, PROP_MATRIX);
859 RNA_def_property_multi_array(prop, 2, matrix_dimsize);
860 RNA_def_property_ui_text(prop, "Basis Matrix",
861 "Alternative access to location/scale/rotation relative to the parent and own rest bone");
862 RNA_def_property_float_funcs(prop, "rna_PoseChannel_matrix_basis_get", "rna_PoseChannel_matrix_basis_set", NULL);
863 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
864 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
867 prop = RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX);
868 RNA_def_property_float_sdna(prop, NULL, "pose_mat");
869 RNA_def_property_multi_array(prop, 2, matrix_dimsize);
870 RNA_def_property_float_funcs(prop, NULL, "rna_PoseChannel_matrix_set", NULL);
871 RNA_def_property_ui_text(prop, "Pose Matrix",
872 "Final 4x4 matrix after constraints and drivers are applied (object space)");
873 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
875 /* Head/Tail Coordinates (in Pose Space) - Automatically calculated... */
876 prop = RNA_def_property(srna, "head", PROP_FLOAT, PROP_TRANSLATION);
877 RNA_def_property_float_sdna(prop, NULL, "pose_head");
878 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
879 RNA_def_property_ui_text(prop, "Pose Head Position", "Location of head of the channel's bone");
881 prop = RNA_def_property(srna, "tail", PROP_FLOAT, PROP_TRANSLATION);
882 RNA_def_property_float_sdna(prop, NULL, "pose_tail");
883 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
884 RNA_def_property_ui_text(prop, "Pose Tail Position", "Location of tail of the channel's bone");
887 prop = RNA_def_property(srna, "is_in_ik_chain", PROP_BOOLEAN, PROP_NONE);
888 RNA_def_property_boolean_funcs(prop, "rna_PoseChannel_has_ik_get", NULL);
889 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
890 RNA_def_property_ui_text(prop, "Has IK", "Is part of an IK chain");
891 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
893 prop = RNA_def_property(srna, "lock_ik_x", PROP_BOOLEAN, PROP_NONE);
894 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_NO_XDOF);
895 RNA_def_property_ui_text(prop, "IK X Lock", "Disallow movement around the X axis");
896 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
897 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
899 prop = RNA_def_property(srna, "lock_ik_y", PROP_BOOLEAN, PROP_NONE);
900 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_NO_YDOF);
901 RNA_def_property_ui_text(prop, "IK Y Lock", "Disallow movement around the Y axis");
902 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
903 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
905 prop = RNA_def_property(srna, "lock_ik_z", PROP_BOOLEAN, PROP_NONE);
906 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_NO_ZDOF);
907 RNA_def_property_ui_text(prop, "IK Z Lock", "Disallow movement around the Z axis");
908 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
909 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
911 prop = RNA_def_property(srna, "use_ik_limit_x", PROP_BOOLEAN, PROP_NONE);
912 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_XLIMIT);
913 RNA_def_property_ui_text(prop, "IK X Limit", "Limit movement around the X axis");
914 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
915 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
917 prop = RNA_def_property(srna, "use_ik_limit_y", PROP_BOOLEAN, PROP_NONE);
918 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_YLIMIT);
919 RNA_def_property_ui_text(prop, "IK Y Limit", "Limit movement around the Y axis");
920 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
921 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
923 prop = RNA_def_property(srna, "use_ik_limit_z", PROP_BOOLEAN, PROP_NONE);
924 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_ZLIMIT);
925 RNA_def_property_ui_text(prop, "IK Z Limit", "Limit movement around the Z axis");
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, "use_ik_rotation_control", PROP_BOOLEAN, PROP_NONE);
930 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_ROTCTL);
931 RNA_def_property_ui_text(prop, "IK rot control", "Apply channel rotation as IK constraint");
932 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
933 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
935 prop = RNA_def_property(srna, "use_ik_linear_control", PROP_BOOLEAN, PROP_NONE);
936 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_LINCTL);
937 RNA_def_property_ui_text(prop, "IK rot control", "Apply channel size as IK constraint if stretching is enabled");
938 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
939 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
941 prop = RNA_def_property(srna, "ik_min_x", PROP_FLOAT, PROP_ANGLE);
942 RNA_def_property_float_sdna(prop, NULL, "limitmin[0]");
943 RNA_def_property_range(prop, -M_PI, 0.0f);
944 RNA_def_property_ui_text(prop, "IK X Minimum", "Minimum angles for IK Limit");
945 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
946 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
948 prop = RNA_def_property(srna, "ik_max_x", PROP_FLOAT, PROP_ANGLE);
949 RNA_def_property_float_sdna(prop, NULL, "limitmax[0]");
950 RNA_def_property_range(prop, 0.0f, M_PI);
951 RNA_def_property_ui_text(prop, "IK X Maximum", "Maximum angles for IK Limit");
952 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
953 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
955 prop = RNA_def_property(srna, "ik_min_y", PROP_FLOAT, PROP_ANGLE);
956 RNA_def_property_float_sdna(prop, NULL, "limitmin[1]");
957 RNA_def_property_range(prop, -M_PI, 0.0f);
958 RNA_def_property_ui_text(prop, "IK Y Minimum", "Minimum angles for IK Limit");
959 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
960 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
962 prop = RNA_def_property(srna, "ik_max_y", PROP_FLOAT, PROP_ANGLE);
963 RNA_def_property_float_sdna(prop, NULL, "limitmax[1]");
964 RNA_def_property_range(prop, 0.0f, M_PI);
965 RNA_def_property_ui_text(prop, "IK Y Maximum", "Maximum angles for IK Limit");
966 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
967 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
969 prop = RNA_def_property(srna, "ik_min_z", PROP_FLOAT, PROP_ANGLE);
970 RNA_def_property_float_sdna(prop, NULL, "limitmin[2]");
971 RNA_def_property_range(prop, -M_PI, 0.0f);
972 RNA_def_property_ui_text(prop, "IK Z Minimum", "Minimum angles for IK Limit");
973 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
974 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
976 prop = RNA_def_property(srna, "ik_max_z", PROP_FLOAT, PROP_ANGLE);
977 RNA_def_property_float_sdna(prop, NULL, "limitmax[2]");
978 RNA_def_property_range(prop, 0.0f, M_PI);
979 RNA_def_property_ui_text(prop, "IK Z Maximum", "Maximum angles for IK Limit");
980 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
981 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
983 prop = RNA_def_property(srna, "ik_stiffness_x", PROP_FLOAT, PROP_NONE);
984 RNA_def_property_float_sdna(prop, NULL, "stiffness[0]");
985 RNA_def_property_range(prop, 0.0f, 0.99f);
986 RNA_def_property_ui_text(prop, "IK X Stiffness", "IK stiffness around the X axis");
987 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
988 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
990 prop = RNA_def_property(srna, "ik_stiffness_y", PROP_FLOAT, PROP_NONE);
991 RNA_def_property_float_sdna(prop, NULL, "stiffness[1]");
992 RNA_def_property_range(prop, 0.0f, 0.99f);
993 RNA_def_property_ui_text(prop, "IK Y Stiffness", "IK stiffness around the Y axis");
994 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
995 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
997 prop = RNA_def_property(srna, "ik_stiffness_z", PROP_FLOAT, PROP_NONE);
998 RNA_def_property_float_sdna(prop, NULL, "stiffness[2]");
999 RNA_def_property_range(prop, 0.0f, 0.99f);
1000 RNA_def_property_ui_text(prop, "IK Z Stiffness", "IK stiffness around the Z axis");
1001 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1002 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
1004 prop = RNA_def_property(srna, "ik_stretch", PROP_FLOAT, PROP_NONE);
1005 RNA_def_property_float_sdna(prop, NULL, "ikstretch");
1006 RNA_def_property_range(prop, 0.0f,1.0f);
1007 RNA_def_property_ui_text(prop, "IK Stretch", "Allow scaling of the bone for IK");
1008 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1009 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
1011 prop = RNA_def_property(srna, "ik_rotation_weight", PROP_FLOAT, PROP_NONE);
1012 RNA_def_property_float_sdna(prop, NULL, "ikrotweight");
1013 RNA_def_property_range(prop, 0.0f,1.0f);
1014 RNA_def_property_ui_text(prop, "IK Rot Weight", "Weight of rotation constraint for IK");
1015 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1016 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1018 prop = RNA_def_property(srna, "ik_linear_weight", PROP_FLOAT, PROP_NONE);
1019 RNA_def_property_float_sdna(prop, NULL, "iklinweight");
1020 RNA_def_property_range(prop, 0.0f,1.0f);
1021 RNA_def_property_ui_text(prop, "IK Lin Weight", "Weight of scale constraint for IK");
1022 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1023 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1025 /* custom bone shapes */
1026 prop = RNA_def_property(srna, "custom_shape", PROP_POINTER, PROP_NONE);
1027 RNA_def_property_pointer_sdna(prop, NULL, "custom");
1028 RNA_def_property_struct_type(prop, "Object");
1029 RNA_def_property_flag(prop, PROP_EDITABLE);
1030 RNA_def_property_pointer_funcs(prop, NULL, "rna_PoseChannel_bone_custom_set", NULL, NULL);
1031 RNA_def_property_ui_text(prop, "Custom Object", "Object that defines custom draw type for this bone");
1032 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1033 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1035 prop = RNA_def_property(srna, "custom_shape_transform", PROP_POINTER, PROP_NONE);
1036 RNA_def_property_pointer_sdna(prop, NULL, "custom_tx");
1037 RNA_def_property_struct_type(prop, "PoseBone");
1038 RNA_def_property_flag(prop, PROP_EDITABLE);
1039 RNA_def_property_ui_text(prop, "Custom Shape Transform",
1040 "Bone that defines the display transform of this custom shape");
1041 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1042 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1045 prop = RNA_def_property(srna, "bone_group_index", PROP_INT, PROP_NONE);
1046 RNA_def_property_int_sdna(prop, NULL, "agrp_index");
1047 RNA_def_property_flag(prop, PROP_EDITABLE);
1048 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
1049 RNA_def_property_int_funcs(prop, "rna_PoseChannel_bone_group_index_get", "rna_PoseChannel_bone_group_index_set",
1050 "rna_PoseChannel_bone_group_index_range");
1051 RNA_def_property_ui_text(prop, "Bone Group Index", "Bone Group this pose channel belongs to (0=no group)");
1052 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1053 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1055 prop = RNA_def_property(srna, "bone_group", PROP_POINTER, PROP_NONE);
1056 RNA_def_property_struct_type(prop, "BoneGroup");
1057 RNA_def_property_flag(prop, PROP_EDITABLE);
1058 RNA_def_property_pointer_funcs(prop, "rna_PoseChannel_bone_group_get",
1059 "rna_PoseChannel_bone_group_set", NULL, NULL);
1060 RNA_def_property_ui_text(prop, "Bone Group", "Bone Group this pose channel belongs to");
1061 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1062 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1064 /* transform locks */
1065 prop = RNA_def_property(srna, "lock_location", PROP_BOOLEAN, PROP_XYZ);
1066 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_LOCX);
1067 RNA_def_property_array(prop, 3);
1068 RNA_def_property_ui_text(prop, "Lock Location", "Lock editing of location in the interface");
1069 RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
1070 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1071 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1073 prop = RNA_def_property(srna, "lock_rotation", PROP_BOOLEAN, PROP_XYZ);
1074 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_ROTX);
1075 RNA_def_property_array(prop, 3);
1076 RNA_def_property_ui_text(prop, "Lock Rotation", "Lock editing of rotation in the interface");
1077 RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
1078 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1079 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1081 /* XXX this is sub-optimal - it really should be included above, but due to technical reasons
1082 * we can't do this! */
1083 prop = RNA_def_property(srna, "lock_rotation_w", PROP_BOOLEAN, PROP_NONE);
1084 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_ROTW);
1085 RNA_def_property_ui_text(prop, "Lock Rotation (4D Angle)",
1086 "Lock editing of 'angle' component of four-component rotations in the interface");
1087 RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
1088 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1089 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1091 /* XXX this needs a better name */
1092 prop = RNA_def_property(srna, "lock_rotations_4d", PROP_BOOLEAN, PROP_NONE);
1093 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_ROT4D);
1094 RNA_def_property_ui_text(prop, "Lock Rotations (4D)",
1095 "Lock editing of four component rotations by components (instead of as Eulers)");
1096 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1097 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1099 prop = RNA_def_property(srna, "lock_scale", PROP_BOOLEAN, PROP_XYZ);
1100 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_SCALEX);
1101 RNA_def_property_array(prop, 3);
1102 RNA_def_property_ui_text(prop, "Lock Scale", "Lock editing of scale in the interface");
1103 RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
1104 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1105 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1107 RNA_api_pose_channel(srna);
1110 static void rna_def_pose_itasc(BlenderRNA *brna)
1112 static const EnumPropertyItem prop_itasc_mode_items[] = {
1113 {0, "ANIMATION", 0, "Animation",
1114 "Stateless solver computing pose starting from current action and non-IK constraints"},
1115 {ITASC_SIMULATION, "SIMULATION", 0, "Simulation",
1116 "Statefull solver running in real-time context and ignoring actions "
1117 "and non-IK constraints"},
1118 {0, NULL, 0, NULL, NULL}};
1119 static const EnumPropertyItem prop_itasc_reiteration_items[] = {
1120 {0, "NEVER", 0, "Never", "The solver does not reiterate, not even on first frame (starts from rest pose)"},
1121 {ITASC_INITIAL_REITERATION, "INITIAL", 0, "Initial",
1122 "The solver reiterates (converges) on the first frame but not on "
1123 "subsequent frame"},
1124 {ITASC_INITIAL_REITERATION|ITASC_REITERATION, "ALWAYS", 0, "Always",
1125 "The solver reiterates (converges) on all frames"},
1126 {0, NULL, 0, NULL, NULL}};
1131 srna = RNA_def_struct(brna, "Itasc", "IKParam");
1132 RNA_def_struct_sdna(srna, "bItasc");
1133 RNA_def_struct_ui_text(srna, "bItasc", "Parameters for the iTaSC IK solver");
1135 prop = RNA_def_property(srna, "precision", PROP_FLOAT, PROP_NONE);
1136 RNA_def_property_float_sdna(prop, NULL, "precision");
1137 RNA_def_property_range(prop, 0.0f,0.1f);
1138 RNA_def_property_ui_text(prop, "Precision", "Precision of convergence in case of reiteration");
1139 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1141 prop = RNA_def_property(srna, "iterations", PROP_INT, PROP_NONE);
1142 RNA_def_property_int_sdna(prop, NULL, "numiter");
1143 RNA_def_property_range(prop, 1.f,1000.f);
1144 RNA_def_property_ui_text(prop, "Iterations",
1145 "Maximum number of iterations for convergence in case of reiteration");
1146 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1148 prop = RNA_def_property(srna, "step_count", PROP_INT, PROP_NONE);
1149 RNA_def_property_int_sdna(prop, NULL, "numstep");
1150 RNA_def_property_range(prop, 1.f, 50.f);
1151 RNA_def_property_ui_text(prop, "Num steps", "Divide the frame interval into this many steps");
1152 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1154 prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
1155 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
1156 RNA_def_property_enum_items(prop, prop_itasc_mode_items);
1157 RNA_def_property_ui_text(prop, "Mode", NULL);
1158 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update_rebuild");
1160 prop = RNA_def_property(srna, "reiteration_method", PROP_ENUM, PROP_NONE);
1161 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
1162 RNA_def_property_enum_items(prop, prop_itasc_reiteration_items);
1163 RNA_def_property_ui_text(prop, "Reiteration",
1164 "Defines if the solver is allowed to reiterate (converge until "
1165 "precision is met) on none, first or all frames");
1166 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1168 prop = RNA_def_property(srna, "use_auto_step", PROP_BOOLEAN, PROP_NONE);
1169 RNA_def_property_boolean_sdna(prop, NULL, "flag", ITASC_AUTO_STEP);
1170 RNA_def_property_ui_text(prop, "Auto step",
1171 "Automatically determine the optimal number of steps for best "
1172 "performance/accuracy trade off");
1173 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1175 prop = RNA_def_property(srna, "step_min", PROP_FLOAT, PROP_NONE);
1176 RNA_def_property_float_sdna(prop, NULL, "minstep");
1177 RNA_def_property_range(prop, 0.0f,0.1f);
1178 RNA_def_property_ui_text(prop, "Min step", "Lower bound for timestep in second in case of automatic substeps");
1179 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1181 prop = RNA_def_property(srna, "step_max", PROP_FLOAT, PROP_NONE);
1182 RNA_def_property_float_sdna(prop, NULL, "maxstep");
1183 RNA_def_property_range(prop, 0.0f,1.0f);
1184 RNA_def_property_ui_text(prop, "Max step", "Higher bound for timestep in second in case of automatic substeps");
1185 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1187 prop = RNA_def_property(srna, "feedback", PROP_FLOAT, PROP_NONE);
1188 RNA_def_property_float_sdna(prop, NULL, "feedback");
1189 RNA_def_property_range(prop, 0.0f,100.0f);
1190 RNA_def_property_ui_text(prop, "Feedback",
1191 "Feedback coefficient for error correction, average response time is 1/feedback "
1193 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1195 prop = RNA_def_property(srna, "velocity_max", PROP_FLOAT, PROP_NONE);
1196 RNA_def_property_float_sdna(prop, NULL, "maxvel");
1197 RNA_def_property_range(prop, 0.0f,100.0f);
1198 RNA_def_property_ui_text(prop, "Max Velocity", "Maximum joint velocity in rad/s (default=50)");
1199 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1201 prop = RNA_def_property(srna, "solver", PROP_ENUM, PROP_NONE);
1202 RNA_def_property_enum_sdna(prop, NULL, "solver");
1203 RNA_def_property_enum_items(prop, prop_solver_items);
1204 RNA_def_property_ui_text(prop, "Solver", "Solving method selection: automatic damping or manual damping");
1205 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update_rebuild");
1207 prop = RNA_def_property(srna, "damping_max", PROP_FLOAT, PROP_NONE);
1208 RNA_def_property_float_sdna(prop, NULL, "dampmax");
1209 RNA_def_property_range(prop, 0.0f,1.0f);
1210 RNA_def_property_ui_text(prop, "Damp",
1211 "Maximum damping coefficient when singular value is nearly 0 "
1212 "(higher values=more stability, less reactivity - default=0.5)");
1213 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1215 prop = RNA_def_property(srna, "damping_epsilon", PROP_FLOAT, PROP_NONE);
1216 RNA_def_property_float_sdna(prop, NULL, "dampeps");
1217 RNA_def_property_range(prop, 0.0f,1.0f);
1218 RNA_def_property_ui_text(prop, "Epsilon",
1219 "Singular value under which damping is progressively applied "
1220 "(higher values=more stability, less reactivity - default=0.1)");
1221 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1224 static void rna_def_pose_ikparam(BlenderRNA *brna)
1229 srna = RNA_def_struct(brna, "IKParam", NULL);
1230 RNA_def_struct_sdna(srna, "bIKParam");
1231 RNA_def_struct_ui_text(srna, "IKParam", "Base type for IK solver parameters");
1232 RNA_def_struct_refine_func(srna, "rna_IKParam_refine");
1234 prop = RNA_def_property(srna, "ik_solver", PROP_ENUM, PROP_NONE);
1235 RNA_def_property_enum_sdna(prop, NULL, "iksolver");
1236 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1237 RNA_def_property_enum_items(prop, prop_iksolver_items);
1238 RNA_def_property_ui_text(prop, "IK Solver",
1239 "IK solver for which these parameters are defined, 0 for Legacy, 1 for iTaSC");
1242 /* pose.bone_groups */
1243 static void rna_def_bone_groups(BlenderRNA *brna, PropertyRNA *cprop)
1248 /* FunctionRNA *func; */
1249 /* PropertyRNA *parm; */
1251 RNA_def_property_srna(cprop, "BoneGroups");
1252 srna = RNA_def_struct(brna, "BoneGroups", NULL);
1253 RNA_def_struct_sdna(srna, "bPose");
1254 RNA_def_struct_ui_text(srna, "Bone Groups", "Collection of bone groups");
1256 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
1257 RNA_def_property_struct_type(prop, "BoneGroup");
1258 RNA_def_property_flag(prop, PROP_EDITABLE);
1259 RNA_def_property_pointer_funcs(prop, "rna_Pose_active_bone_group_get",
1260 "rna_Pose_active_bone_group_set", NULL, NULL);
1261 RNA_def_property_ui_text(prop, "Active Bone Group", "Active bone group for this pose");
1262 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1264 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_NONE);
1265 RNA_def_property_int_sdna(prop, NULL, "active_group");
1266 RNA_def_property_int_funcs(prop, "rna_Pose_active_bone_group_index_get", "rna_Pose_active_bone_group_index_set",
1267 "rna_Pose_active_bone_group_index_range");
1268 RNA_def_property_ui_text(prop, "Active Bone Group Index", "Active index in bone groups array");
1269 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1272 static void rna_def_pose(BlenderRNA *brna)
1277 /* struct definition */
1278 srna = RNA_def_struct(brna, "Pose", NULL);
1279 RNA_def_struct_sdna(srna, "bPose");
1280 RNA_def_struct_ui_text(srna, "Pose", "A collection of pose channels, including settings for animating bones");
1283 prop = RNA_def_property(srna, "bones", PROP_COLLECTION, PROP_NONE);
1284 RNA_def_property_collection_sdna(prop, NULL, "chanbase", NULL);
1285 RNA_def_property_struct_type(prop, "PoseBone");
1286 RNA_def_property_ui_text(prop, "Pose Bones", "Individual pose bones for the armature");
1287 /* can be removed, only for fast lookup */
1288 RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, NULL, NULL, NULL, "rna_PoseBones_lookup_string", NULL);
1291 prop = RNA_def_property(srna, "bone_groups", PROP_COLLECTION, PROP_NONE);
1292 RNA_def_property_collection_sdna(prop, NULL, "agroups", NULL);
1293 RNA_def_property_struct_type(prop, "BoneGroup");
1294 RNA_def_property_ui_text(prop, "Bone Groups", "Groups of the bones");
1295 rna_def_bone_groups(brna, prop);
1298 prop = RNA_def_property(srna, "ik_solver", PROP_ENUM, PROP_NONE);
1299 RNA_def_property_enum_sdna(prop, NULL, "iksolver");
1300 RNA_def_property_enum_funcs(prop, NULL, "rna_Pose_ik_solver_set", NULL);
1301 RNA_def_property_enum_items(prop, prop_iksolver_items);
1302 RNA_def_property_ui_text(prop, "IK Solver",
1303 "Selection of IK solver for IK chain, current choice is 0 for Legacy, 1 for iTaSC");
1304 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_ik_solver_update");
1306 prop = RNA_def_property(srna, "ik_param", PROP_POINTER, PROP_NONE);
1307 RNA_def_property_struct_type(prop, "IKParam");
1308 RNA_def_property_pointer_funcs(prop, "rna_Pose_ikparam_get", NULL, "rna_Pose_ikparam_typef", NULL);
1309 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1310 RNA_def_property_ui_text(prop, "IK Param", "Parameters for IK solver");
1313 rna_def_animviz_common(srna);
1315 /* RNA_api_pose(srna); */
1318 void RNA_def_pose(BlenderRNA *brna)
1321 rna_def_pose_channel(brna);
1322 rna_def_pose_ikparam(brna);
1323 rna_def_pose_itasc(brna);
1324 rna_def_bone_group(brna);