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 rgba_char_args_set(grp->cs.solid, 0xff, 0x00, 0x00, 255);
134 rgba_char_args_set(grp->cs.select, 0x81, 0xe6, 0x14, 255);
135 rgba_char_args_set(grp->cs.active, 0x18, 0xb6, 0xe0, 255);
141 void rna_BoneGroup_name_set(PointerRNA *ptr, const char *value)
143 Object *ob = ptr->id.data;
144 bActionGroup *agrp = ptr->data;
146 /* copy the new name into the name slot */
147 BLI_strncpy_utf8(agrp->name, value, sizeof(agrp->name));
149 BLI_uniquename(&ob->pose->agroups, agrp, "Group", '.', offsetof(bActionGroup, name), sizeof(agrp->name));
152 static IDProperty *rna_PoseBone_idprops(PointerRNA *ptr, int create)
154 bPoseChannel *pchan = ptr->data;
156 if (create && !pchan->prop) {
157 IDPropertyTemplate val = {0};
158 pchan->prop = IDP_New(IDP_GROUP, &val, "RNA_PoseBone group");
164 static void rna_Pose_ik_solver_set(struct PointerRNA *ptr, int value)
166 bPose *pose = (bPose*)ptr->data;
168 if (pose->iksolver != value) {
169 /* the solver has changed, must clean any temporary structures */
170 BIK_clear_data(pose);
172 MEM_freeN(pose->ikparam);
173 pose->ikparam = NULL;
175 pose->iksolver = value;
176 init_pose_ikparam(pose);
180 static void rna_Pose_ik_solver_update(Main *bmain, Scene *scene, PointerRNA *ptr)
182 Object *ob = ptr->id.data;
183 bPose *pose = ptr->data;
185 pose->flag |= POSE_RECALC; /* checks & sorts pose channels */
186 DAG_scene_sort(bmain, scene);
188 update_pose_constraint_flags(pose);
190 object_test_constraints(ob);
192 DAG_id_tag_update(&ob->id, OB_RECALC_DATA|OB_RECALC_OB);
195 /* rotation - axis-angle */
196 static void rna_PoseChannel_rotation_axis_angle_get(PointerRNA *ptr, float *value)
198 bPoseChannel *pchan = ptr->data;
200 /* for now, assume that rotation mode is axis-angle */
201 value[0] = pchan->rotAngle;
202 copy_v3_v3(&value[1], pchan->rotAxis);
205 /* rotation - axis-angle */
206 static void rna_PoseChannel_rotation_axis_angle_set(PointerRNA *ptr, const float *value)
208 bPoseChannel *pchan = ptr->data;
210 /* for now, assume that rotation mode is axis-angle */
211 pchan->rotAngle = value[0];
212 copy_v3_v3(pchan->rotAxis, (float *)&value[1]);
214 /* TODO: validate axis? */
217 static void rna_PoseChannel_rotation_mode_set(PointerRNA *ptr, int value)
219 bPoseChannel *pchan = ptr->data;
221 /* use API Method for conversions... */
222 BKE_rotMode_change_values(pchan->quat, pchan->eul, pchan->rotAxis, &pchan->rotAngle,
223 pchan->rotmode, (short)value);
225 /* finally, set the new rotation type */
226 pchan->rotmode = value;
229 static void rna_PoseChannel_name_set(PointerRNA *ptr, const char *value)
231 Object *ob = (Object*)ptr->id.data;
232 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
233 char oldname[sizeof(pchan->name)], newname[sizeof(pchan->name)];
235 /* need to be on the stack */
236 BLI_strncpy_utf8(newname, value, sizeof(pchan->name));
237 BLI_strncpy(oldname, pchan->name, sizeof(pchan->name));
239 ED_armature_bone_rename(ob->data, oldname, newname);
242 static int rna_PoseChannel_has_ik_get(PointerRNA *ptr)
244 Object *ob = (Object*)ptr->id.data;
245 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
247 return ED_pose_channel_in_IK_chain(ob, pchan);
250 StructRNA *rna_IKParam_refine(PointerRNA *ptr)
252 bIKParam *param = (bIKParam *)ptr->data;
254 switch (param->iksolver) {
262 PointerRNA rna_Pose_ikparam_get(struct PointerRNA *ptr)
264 bPose *pose = (bPose*)ptr->data;
265 return rna_pointer_inherit_refine(ptr, &RNA_IKParam, pose->ikparam);
268 static StructRNA *rna_Pose_ikparam_typef(PointerRNA *ptr)
270 bPose *pose = (bPose*)ptr->data;
272 switch (pose->iksolver) {
280 static void rna_Itasc_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
282 Object *ob = ptr->id.data;
283 bItasc *itasc = ptr->data;
286 if (itasc->precision < 0.0001f)
287 itasc->precision = 0.0001f;
288 if (itasc->minstep < 0.001f)
289 itasc->minstep = 0.001f;
290 if (itasc->maxstep < itasc->minstep)
291 itasc->maxstep = itasc->minstep;
292 if (itasc->feedback < 0.01f)
293 itasc->feedback = 0.01f;
294 if (itasc->feedback > 100.f)
295 itasc->feedback = 100.f;
296 if (itasc->maxvel < 0.01f)
297 itasc->maxvel = 0.01f;
298 if (itasc->maxvel > 100.f)
299 itasc->maxvel = 100.f;
300 BIK_update_param(ob->pose);
302 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
305 static void rna_Itasc_update_rebuild(Main *bmain, Scene *scene, PointerRNA *ptr)
307 Object *ob = ptr->id.data;
308 bPose *pose = ob->pose;
310 pose->flag |= POSE_RECALC; /* checks & sorts pose channels */
311 rna_Itasc_update(bmain, scene, ptr);
314 static void rna_PoseChannel_bone_custom_set(PointerRNA *ptr, PointerRNA value)
316 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
320 id_us_min(&pchan->custom->id);
321 pchan->custom = NULL;
324 pchan->custom = value.data;
326 id_us_plus(&pchan->custom->id);
329 static PointerRNA rna_PoseChannel_bone_group_get(PointerRNA *ptr)
331 Object *ob = (Object*)ptr->id.data;
332 bPose *pose = (ob) ? ob->pose : NULL;
333 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
337 grp = BLI_findlink(&pose->agroups, pchan->agrp_index-1);
341 return rna_pointer_inherit_refine(ptr, &RNA_BoneGroup, grp);
344 static void rna_PoseChannel_bone_group_set(PointerRNA *ptr, PointerRNA value)
346 Object *ob = (Object*)ptr->id.data;
347 bPose *pose = (ob) ? ob->pose : NULL;
348 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
351 pchan->agrp_index = BLI_findindex(&pose->agroups, value.data) + 1;
353 pchan->agrp_index = 0;
356 static int rna_PoseChannel_bone_group_index_get(PointerRNA *ptr)
358 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
359 return MAX2(pchan->agrp_index-1, 0);
362 static void rna_PoseChannel_bone_group_index_set(PointerRNA *ptr, int value)
364 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
365 pchan->agrp_index = value+1;
368 static void rna_PoseChannel_bone_group_index_range(PointerRNA *ptr, int *min, int *max)
370 Object *ob = (Object*)ptr->id.data;
371 bPose *pose = (ob) ? ob->pose : NULL;
376 *max = BLI_countlist(&pose->agroups)-1;
377 *max = MAX2(0, *max);
383 static PointerRNA rna_Pose_active_bone_group_get(PointerRNA *ptr)
385 bPose *pose = (bPose*)ptr->data;
386 return rna_pointer_inherit_refine(ptr, &RNA_BoneGroup, BLI_findlink(&pose->agroups, pose->active_group-1));
389 static void rna_Pose_active_bone_group_set(PointerRNA *ptr, PointerRNA value)
391 bPose *pose = (bPose*)ptr->data;
392 pose->active_group = BLI_findindex(&pose->agroups, value.data) + 1;
395 static int rna_Pose_active_bone_group_index_get(PointerRNA *ptr)
397 bPose *pose = (bPose*)ptr->data;
398 return MAX2(pose->active_group-1, 0);
401 static void rna_Pose_active_bone_group_index_set(PointerRNA *ptr, int value)
403 bPose *pose = (bPose*)ptr->data;
404 pose->active_group = value+1;
407 static void rna_Pose_active_bone_group_index_range(PointerRNA *ptr, int *min, int *max)
409 bPose *pose = (bPose*)ptr->data;
412 *max = BLI_countlist(&pose->agroups)-1;
413 *max = MAX2(0, *max);
417 static void rna_pose_bgroup_name_index_get(PointerRNA *ptr, char *value, int index)
419 bPose *pose = (bPose*)ptr->data;
422 grp = BLI_findlink(&pose->agroups, index-1);
424 if (grp) BLI_strncpy(value, grp->name, sizeof(grp->name));
425 else value[0] = '\0';
428 static int rna_pose_bgroup_name_index_length(PointerRNA *ptr, int index)
430 bPose *pose = (bPose*)ptr->data;
433 grp = BLI_findlink(&pose->agroups, index-1);
434 return (grp)? strlen(grp->name): 0;
437 static void rna_pose_bgroup_name_index_set(PointerRNA *ptr, const char *value, short *index)
439 bPose *pose = (bPose*)ptr->data;
443 for (a = 1, grp = pose->agroups.first; grp; grp = grp->next, a++) {
444 if (strcmp(grp->name, value) == 0) {
453 static void rna_pose_pgroup_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen)
455 bPose *pose = (bPose*)ptr->data;
458 for (grp = pose->agroups.first; grp; grp = grp->next) {
459 if (strcmp(grp->name, value) == 0) {
460 BLI_strncpy(result, value, maxlen);
469 static PointerRNA rna_PoseChannel_active_constraint_get(PointerRNA *ptr)
471 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
472 bConstraint *con = constraints_get_active(&pchan->constraints);
473 return rna_pointer_inherit_refine(ptr, &RNA_Constraint, con);
476 static void rna_PoseChannel_active_constraint_set(PointerRNA *ptr, PointerRNA value)
478 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
479 constraints_set_active(&pchan->constraints, (bConstraint *)value.data);
482 static bConstraint *rna_PoseChannel_constraints_new(bPoseChannel *pchan, int type)
484 /*WM_main_add_notifier(NC_OBJECT|ND_CONSTRAINT|NA_ADDED, object); */
485 /* TODO, pass object also */
486 /* TODO, new pose bones don't have updated draw flags */
487 return add_pose_constraint(NULL, pchan, NULL, type);
490 static void rna_PoseChannel_constraints_remove(ID *id, bPoseChannel *pchan, ReportList *reports, bConstraint *con)
492 if (BLI_findindex(&pchan->constraints, con) == -1) {
493 BKE_reportf(reports, RPT_ERROR, "Constraint '%s' not found in pose bone '%s'", con->name, pchan->name);
497 Object *ob = (Object *)id;
498 const short is_ik = ELEM(con->type, CONSTRAINT_TYPE_KINEMATIC, CONSTRAINT_TYPE_SPLINEIK);
500 remove_constraint(&pchan->constraints, con);
501 ED_object_constraint_update(ob);
502 constraints_set_active(&pchan->constraints, NULL);
503 WM_main_add_notifier(NC_OBJECT|ND_CONSTRAINT|NA_REMOVED, id);
506 BIK_clear_data(ob->pose);
511 static int rna_PoseChannel_proxy_editable(PointerRNA *ptr)
513 Object *ob = (Object*)ptr->id.data;
514 bArmature *arm = ob->data;
515 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
517 return (ob->proxy && pchan->bone && (pchan->bone->layer & arm->layer_protected))? 0: PROP_EDITABLE;
520 static int rna_PoseChannel_location_editable(PointerRNA *ptr, int index)
522 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
524 /* only if the axis in question is locked, not editable... */
525 if ((index == 0) && (pchan->protectflag & OB_LOCK_LOCX))
527 else if ((index == 1) && (pchan->protectflag & OB_LOCK_LOCY))
529 else if ((index == 2) && (pchan->protectflag & OB_LOCK_LOCZ))
532 return PROP_EDITABLE;
535 static int rna_PoseChannel_scale_editable(PointerRNA *ptr, int index)
537 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
539 /* only if the axis in question is locked, not editable... */
540 if ((index == 0) && (pchan->protectflag & OB_LOCK_SCALEX))
542 else if ((index == 1) && (pchan->protectflag & OB_LOCK_SCALEY))
544 else if ((index == 2) && (pchan->protectflag & OB_LOCK_SCALEZ))
547 return PROP_EDITABLE;
550 static int rna_PoseChannel_rotation_euler_editable(PointerRNA *ptr, int index)
552 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
554 /* only if the axis in question is locked, not editable... */
555 if ((index == 0) && (pchan->protectflag & OB_LOCK_ROTX))
557 else if ((index == 1) && (pchan->protectflag & OB_LOCK_ROTY))
559 else if ((index == 2) && (pchan->protectflag & OB_LOCK_ROTZ))
562 return PROP_EDITABLE;
565 static int rna_PoseChannel_rotation_4d_editable(PointerRNA *ptr, int index)
567 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
569 /* only consider locks if locking components individually... */
570 if (pchan->protectflag & OB_LOCK_ROT4D) {
571 /* only if the axis in question is locked, not editable... */
572 if ((index == 0) && (pchan->protectflag & OB_LOCK_ROTW))
574 else if ((index == 1) && (pchan->protectflag & OB_LOCK_ROTX))
576 else if ((index == 2) && (pchan->protectflag & OB_LOCK_ROTY))
578 else if ((index == 3) && (pchan->protectflag & OB_LOCK_ROTZ))
582 return PROP_EDITABLE;
585 /* not essential, but much faster then the default lookup function */
586 int rna_PoseBones_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
588 bPose *pose = (bPose*)ptr->data;
589 bPoseChannel *pchan = get_pose_channel(pose, key);
591 RNA_pointer_create(ptr->id.data, &RNA_PoseBone, pchan, r_ptr);
599 static void rna_PoseChannel_matrix_basis_get(PointerRNA *ptr, float *values)
601 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
602 pchan_to_mat4(pchan, (float (*)[4])values);
605 static void rna_PoseChannel_matrix_basis_set(PointerRNA *ptr, const float *values)
607 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
608 pchan_apply_mat4(pchan, (float (*)[4])values, FALSE); /* no compat for predictable result */
611 static void rna_PoseChannel_matrix_set(PointerRNA *ptr, const float *values)
613 bPoseChannel *pchan = (bPoseChannel*)ptr->data;
614 Object *ob = (Object*)ptr->id.data;
617 armature_mat_pose_to_bone_ex(ob, pchan, (float (*)[4])values, tmat);
619 pchan_apply_mat4(pchan, tmat, FALSE); /* no compat for predictable result */
624 static void rna_def_bone_group(BlenderRNA *brna)
626 static EnumPropertyItem prop_colorSets_items[] = {
627 {0, "DEFAULT", 0, "Default Colors", ""},
628 {1, "THEME01", 0, "01 - Theme Color Set", ""},
629 {2, "THEME02", 0, "02 - Theme Color Set", ""},
630 {3, "THEME03", 0, "03 - Theme Color Set", ""},
631 {4, "THEME04", 0, "04 - Theme Color Set", ""},
632 {5, "THEME05", 0, "05 - Theme Color Set", ""},
633 {6, "THEME06", 0, "06 - Theme Color Set", ""},
634 {7, "THEME07", 0, "07 - Theme Color Set", ""},
635 {8, "THEME08", 0, "08 - Theme Color Set", ""},
636 {9, "THEME09", 0, "09 - Theme Color Set", ""},
637 {10, "THEME10", 0, "10 - Theme Color Set", ""},
638 {11, "THEME11", 0, "11 - Theme Color Set", ""},
639 {12, "THEME12", 0, "12 - Theme Color Set", ""},
640 {13, "THEME13", 0, "13 - Theme Color Set", ""},
641 {14, "THEME14", 0, "14 - Theme Color Set", ""},
642 {15, "THEME15", 0, "15 - Theme Color Set", ""},
643 {16, "THEME16", 0, "16 - Theme Color Set", ""},
644 {17, "THEME17", 0, "17 - Theme Color Set", ""},
645 {18, "THEME18", 0, "18 - Theme Color Set", ""},
646 {19, "THEME19", 0, "19 - Theme Color Set", ""},
647 {20, "THEME20", 0, "20 - Theme Color Set", ""},
648 {-1, "CUSTOM", 0, "Custom Color Set", ""},
649 {0, NULL, 0, NULL, NULL}};
655 srna = RNA_def_struct(brna, "BoneGroup", NULL);
656 RNA_def_struct_sdna(srna, "bActionGroup");
657 RNA_def_struct_ui_text(srna, "Bone Group", "Groups of Pose Channels (Bones)");
658 RNA_def_struct_ui_icon(srna, ICON_GROUP_BONE);
661 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
662 RNA_def_property_ui_text(prop, "Name", "");
663 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_BoneGroup_name_set");
664 RNA_def_struct_name_property(srna, prop);
666 /* TODO: add some runtime-collections stuff to access grouped bones */
668 /* color set + colors */
669 prop = RNA_def_property(srna, "color_set", PROP_ENUM, PROP_NONE);
670 RNA_def_property_enum_sdna(prop, NULL, "customCol");
671 RNA_def_property_enum_items(prop, prop_colorSets_items);
672 RNA_def_property_enum_funcs(prop, NULL, "rna_BoneGroup_color_set_set", NULL);
673 RNA_def_property_ui_text(prop, "Color Set", "Custom color set to use");
674 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
676 /* TODO: editing the colors for this should result in changes to the color type... */
677 prop = RNA_def_property(srna, "colors", PROP_POINTER, PROP_NONE);
678 RNA_def_property_flag(prop, PROP_NEVER_NULL);
679 RNA_def_property_struct_type(prop, "ThemeBoneColorSet");
680 /* NOTE: the DNA data is not really a pointer, but this code works :) */
681 RNA_def_property_pointer_sdna(prop, NULL, "cs");
682 RNA_def_property_ui_text(prop, "Colors", "Copy of the colors associated with the group's color set");
683 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
686 static EnumPropertyItem prop_iksolver_items[] = {
687 {IKSOLVER_LEGACY, "LEGACY", 0, "Legacy", "Original IK solver"},
688 {IKSOLVER_ITASC, "ITASC", 0, "iTaSC", "Multi constraint, stateful IK solver"},
689 {0, NULL, 0, NULL, NULL}};
691 static EnumPropertyItem prop_solver_items[] = {
692 {ITASC_SOLVER_SDLS, "SDLS", 0, "SDLS", "Selective Damped Least Square"},
693 {ITASC_SOLVER_DLS, "DLS", 0, "DLS", "Damped Least Square with Numerical Filtering"},
694 {0, NULL, 0, NULL, NULL}};
697 static void rna_def_pose_channel_constraints(BlenderRNA *brna, PropertyRNA *cprop)
705 RNA_def_property_srna(cprop, "PoseBoneConstraints");
706 srna = RNA_def_struct(brna, "PoseBoneConstraints", NULL);
707 RNA_def_struct_sdna(srna, "bPoseChannel");
708 RNA_def_struct_ui_text(srna, "PoseBone Constraints", "Collection of pose bone constraints");
710 /* Collection active property */
711 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
712 RNA_def_property_struct_type(prop, "Constraint");
713 RNA_def_property_pointer_funcs(prop, "rna_PoseChannel_active_constraint_get",
714 "rna_PoseChannel_active_constraint_set", NULL, NULL);
715 RNA_def_property_flag(prop, PROP_EDITABLE);
716 RNA_def_property_ui_text(prop, "Active Constraint", "Active PoseChannel constraint");
719 /* Constraint collection */
720 func = RNA_def_function(srna, "new", "rna_PoseChannel_constraints_new");
721 RNA_def_function_ui_description(func, "Add a constraint to this object");
723 parm = RNA_def_pointer(func, "constraint", "Constraint", "", "New constraint");
724 RNA_def_function_return(func, parm);
725 /* constraint to add */
726 parm = RNA_def_enum(func, "type", constraint_type_items, 1, "", "Constraint type to add");
727 RNA_def_property_flag(parm, PROP_REQUIRED);
729 func = RNA_def_function(srna, "remove", "rna_PoseChannel_constraints_remove");
730 RNA_def_function_ui_description(func, "Remove a constraint from this object");
731 RNA_def_function_flag(func, FUNC_USE_REPORTS|FUNC_USE_SELF_ID); /* ID needed for refresh */
732 /* constraint to remove */
733 parm = RNA_def_pointer(func, "constraint", "Constraint", "", "Removed constraint");
734 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
737 static void rna_def_pose_channel(BlenderRNA *brna)
739 static float default_quat[4] = {1,0,0,0}; /* default quaternion values */
740 static float default_axisAngle[4] = {0,0,1,0}; /* default axis-angle rotation values */
741 static float default_scale[3] = {1,1,1}; /* default scale values */
743 const int matrix_dimsize[] = {4, 4};
748 srna = RNA_def_struct(brna, "PoseBone", NULL);
749 RNA_def_struct_sdna(srna, "bPoseChannel");
750 RNA_def_struct_ui_text(srna, "Pose Bone", "Channel defining pose data for a bone in a Pose");
751 RNA_def_struct_path_func(srna, "rna_PoseBone_path");
752 RNA_def_struct_idprops_func(srna, "rna_PoseBone_idprops");
754 /* Bone Constraints */
755 prop = RNA_def_property(srna, "constraints", PROP_COLLECTION, PROP_NONE);
756 RNA_def_property_struct_type(prop, "Constraint");
757 RNA_def_property_ui_text(prop, "Constraints", "Constraints that act on this PoseChannel");
759 rna_def_pose_channel_constraints(brna, prop);
761 /* Name + Selection Status */
762 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
763 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_PoseChannel_name_set");
764 RNA_def_property_ui_text(prop, "Name", "");
765 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
766 RNA_def_struct_name_property(srna, prop);
768 /* Baked Bone Path cache data */
769 rna_def_motionpath_common(srna);
771 /* Relationships to other bones */
772 prop = RNA_def_property(srna, "bone", PROP_POINTER, PROP_NONE);
773 RNA_def_property_flag(prop, PROP_NEVER_NULL);
774 RNA_def_property_struct_type(prop, "Bone");
775 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
776 RNA_def_property_ui_text(prop, "Bone", "Bone associated with this PoseBone");
778 prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
779 RNA_def_property_struct_type(prop, "PoseBone");
780 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
781 RNA_def_property_ui_text(prop, "Parent", "Parent of this pose bone");
783 prop = RNA_def_property(srna, "child", PROP_POINTER, PROP_NONE);
784 RNA_def_property_struct_type(prop, "PoseBone");
785 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
786 RNA_def_property_ui_text(prop, "Child", "Child of this pose bone");
788 /* Transformation settings */
789 prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION);
790 RNA_def_property_float_sdna(prop, NULL, "loc");
791 RNA_def_property_editable_array_func(prop, "rna_PoseChannel_location_editable");
792 RNA_def_property_ui_text(prop, "Location", "");
793 /* XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too */
794 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
795 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
797 prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_XYZ);
798 RNA_def_property_float_sdna(prop, NULL, "size");
799 RNA_def_property_editable_array_func(prop, "rna_PoseChannel_scale_editable");
800 RNA_def_property_float_array_default(prop, default_scale);
801 RNA_def_property_ui_text(prop, "Scale", "");
802 /* XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too */
803 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
804 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
806 prop = RNA_def_property(srna, "rotation_quaternion", PROP_FLOAT, PROP_QUATERNION);
807 RNA_def_property_float_sdna(prop, NULL, "quat");
808 RNA_def_property_editable_array_func(prop, "rna_PoseChannel_rotation_4d_editable");
809 RNA_def_property_float_array_default(prop, default_quat);
810 RNA_def_property_ui_text(prop, "Quaternion Rotation", "Rotation in Quaternions");
811 /* XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too */
812 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
813 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
815 /* XXX: for axis-angle, it would have been nice to have 2 separate fields for UI purposes, but
816 * having a single one is better for Keyframing and other property-management situations...
818 prop = RNA_def_property(srna, "rotation_axis_angle", PROP_FLOAT, PROP_AXISANGLE);
819 RNA_def_property_array(prop, 4);
820 RNA_def_property_float_funcs(prop, "rna_PoseChannel_rotation_axis_angle_get",
821 "rna_PoseChannel_rotation_axis_angle_set", NULL);
822 RNA_def_property_editable_array_func(prop, "rna_PoseChannel_rotation_4d_editable");
823 RNA_def_property_float_array_default(prop, default_axisAngle);
824 RNA_def_property_ui_text(prop, "Axis-Angle Rotation", "Angle of Rotation for Axis-Angle rotation representation");
825 /* XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too */
826 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
827 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
829 prop = RNA_def_property(srna, "rotation_euler", PROP_FLOAT, PROP_EULER);
830 RNA_def_property_float_sdna(prop, NULL, "eul");
831 RNA_def_property_editable_array_func(prop, "rna_PoseChannel_rotation_euler_editable");
832 /* XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too */
833 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
834 RNA_def_property_ui_text(prop, "Euler Rotation", "Rotation in Eulers");
835 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
837 prop = RNA_def_property(srna, "rotation_mode", PROP_ENUM, PROP_NONE);
838 RNA_def_property_enum_sdna(prop, NULL, "rotmode");
839 RNA_def_property_enum_items(prop, posebone_rotmode_items); /* XXX move to using a single define of this someday */
840 RNA_def_property_enum_funcs(prop, NULL, "rna_PoseChannel_rotation_mode_set", NULL);
841 /* XXX... disabled, since proxy-locked layers are currently used for ensuring proxy-syncing too */
842 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
843 RNA_def_property_ui_text(prop, "Rotation Mode", "");
844 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
846 /* transform matrices - should be read-only since these are set directly by AnimSys evaluation */
847 prop = RNA_def_property(srna, "matrix_channel", PROP_FLOAT, PROP_MATRIX);
848 RNA_def_property_float_sdna(prop, NULL, "chan_mat");
849 RNA_def_property_multi_array(prop, 2, matrix_dimsize);
850 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
851 RNA_def_property_ui_text(prop, "Channel Matrix", "4x4 matrix, before constraints");
853 /* writable because it touches loc/scale/rot directly */
854 prop = RNA_def_property(srna, "matrix_basis", PROP_FLOAT, PROP_MATRIX);
855 RNA_def_property_multi_array(prop, 2, matrix_dimsize);
856 RNA_def_property_ui_text(prop, "Basis Matrix",
857 "Alternative access to location/scale/rotation relative to the parent and own rest bone");
858 RNA_def_property_float_funcs(prop, "rna_PoseChannel_matrix_basis_get", "rna_PoseChannel_matrix_basis_set", NULL);
859 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
860 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
863 prop = RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX);
864 RNA_def_property_float_sdna(prop, NULL, "pose_mat");
865 RNA_def_property_multi_array(prop, 2, matrix_dimsize);
866 RNA_def_property_float_funcs(prop, NULL, "rna_PoseChannel_matrix_set", NULL);
867 RNA_def_property_ui_text(prop, "Pose Matrix",
868 "Final 4x4 matrix after constraints and drivers are applied (object space)");
869 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
871 /* Head/Tail Coordinates (in Pose Space) - Automatically calculated... */
872 prop = RNA_def_property(srna, "head", PROP_FLOAT, PROP_TRANSLATION);
873 RNA_def_property_float_sdna(prop, NULL, "pose_head");
874 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
875 RNA_def_property_ui_text(prop, "Pose Head Position", "Location of head of the channel's bone");
877 prop = RNA_def_property(srna, "tail", PROP_FLOAT, PROP_TRANSLATION);
878 RNA_def_property_float_sdna(prop, NULL, "pose_tail");
879 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
880 RNA_def_property_ui_text(prop, "Pose Tail Position", "Location of tail of the channel's bone");
883 prop = RNA_def_property(srna, "is_in_ik_chain", PROP_BOOLEAN, PROP_NONE);
884 RNA_def_property_boolean_funcs(prop, "rna_PoseChannel_has_ik_get", NULL);
885 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
886 RNA_def_property_ui_text(prop, "Has IK", "Is part of an IK chain");
887 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
889 prop = RNA_def_property(srna, "lock_ik_x", PROP_BOOLEAN, PROP_NONE);
890 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_NO_XDOF);
891 RNA_def_property_ui_text(prop, "IK X Lock", "Disallow movement around the X axis");
892 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
893 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
895 prop = RNA_def_property(srna, "lock_ik_y", PROP_BOOLEAN, PROP_NONE);
896 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_NO_YDOF);
897 RNA_def_property_ui_text(prop, "IK Y Lock", "Disallow movement around the Y axis");
898 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
899 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
901 prop = RNA_def_property(srna, "lock_ik_z", PROP_BOOLEAN, PROP_NONE);
902 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_NO_ZDOF);
903 RNA_def_property_ui_text(prop, "IK Z Lock", "Disallow movement around the Z axis");
904 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
905 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
907 prop = RNA_def_property(srna, "use_ik_limit_x", PROP_BOOLEAN, PROP_NONE);
908 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_XLIMIT);
909 RNA_def_property_ui_text(prop, "IK X Limit", "Limit movement around the X axis");
910 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
911 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
913 prop = RNA_def_property(srna, "use_ik_limit_y", PROP_BOOLEAN, PROP_NONE);
914 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_YLIMIT);
915 RNA_def_property_ui_text(prop, "IK Y Limit", "Limit movement around the Y axis");
916 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
917 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
919 prop = RNA_def_property(srna, "use_ik_limit_z", PROP_BOOLEAN, PROP_NONE);
920 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_ZLIMIT);
921 RNA_def_property_ui_text(prop, "IK Z Limit", "Limit movement around the Z axis");
922 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
923 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
925 prop = RNA_def_property(srna, "use_ik_rotation_control", PROP_BOOLEAN, PROP_NONE);
926 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_ROTCTL);
927 RNA_def_property_ui_text(prop, "IK rot control", "Apply channel rotation as IK constraint");
928 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
929 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
931 prop = RNA_def_property(srna, "use_ik_linear_control", PROP_BOOLEAN, PROP_NONE);
932 RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_LINCTL);
933 RNA_def_property_ui_text(prop, "IK rot control", "Apply channel size as IK constraint if stretching is enabled");
934 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
935 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
937 prop = RNA_def_property(srna, "ik_min_x", PROP_FLOAT, PROP_ANGLE);
938 RNA_def_property_float_sdna(prop, NULL, "limitmin[0]");
939 RNA_def_property_range(prop, -M_PI, 0.0f);
940 RNA_def_property_ui_text(prop, "IK X Minimum", "Minimum angles for IK Limit");
941 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
942 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
944 prop = RNA_def_property(srna, "ik_max_x", PROP_FLOAT, PROP_ANGLE);
945 RNA_def_property_float_sdna(prop, NULL, "limitmax[0]");
946 RNA_def_property_range(prop, 0.0f, M_PI);
947 RNA_def_property_ui_text(prop, "IK X Maximum", "Maximum angles for IK Limit");
948 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
949 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
951 prop = RNA_def_property(srna, "ik_min_y", PROP_FLOAT, PROP_ANGLE);
952 RNA_def_property_float_sdna(prop, NULL, "limitmin[1]");
953 RNA_def_property_range(prop, -M_PI, 0.0f);
954 RNA_def_property_ui_text(prop, "IK Y Minimum", "Minimum angles for IK Limit");
955 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
956 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
958 prop = RNA_def_property(srna, "ik_max_y", PROP_FLOAT, PROP_ANGLE);
959 RNA_def_property_float_sdna(prop, NULL, "limitmax[1]");
960 RNA_def_property_range(prop, 0.0f, M_PI);
961 RNA_def_property_ui_text(prop, "IK Y Maximum", "Maximum angles for IK Limit");
962 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
963 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
965 prop = RNA_def_property(srna, "ik_min_z", PROP_FLOAT, PROP_ANGLE);
966 RNA_def_property_float_sdna(prop, NULL, "limitmin[2]");
967 RNA_def_property_range(prop, -M_PI, 0.0f);
968 RNA_def_property_ui_text(prop, "IK Z Minimum", "Minimum angles for IK Limit");
969 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
970 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
972 prop = RNA_def_property(srna, "ik_max_z", PROP_FLOAT, PROP_ANGLE);
973 RNA_def_property_float_sdna(prop, NULL, "limitmax[2]");
974 RNA_def_property_range(prop, 0.0f, M_PI);
975 RNA_def_property_ui_text(prop, "IK Z Maximum", "Maximum angles for IK Limit");
976 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
977 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
979 prop = RNA_def_property(srna, "ik_stiffness_x", PROP_FLOAT, PROP_NONE);
980 RNA_def_property_float_sdna(prop, NULL, "stiffness[0]");
981 RNA_def_property_range(prop, 0.0f, 0.99f);
982 RNA_def_property_ui_text(prop, "IK X Stiffness", "IK stiffness around the X axis");
983 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
984 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
986 prop = RNA_def_property(srna, "ik_stiffness_y", PROP_FLOAT, PROP_NONE);
987 RNA_def_property_float_sdna(prop, NULL, "stiffness[1]");
988 RNA_def_property_range(prop, 0.0f, 0.99f);
989 RNA_def_property_ui_text(prop, "IK Y Stiffness", "IK stiffness around the Y axis");
990 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
991 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
993 prop = RNA_def_property(srna, "ik_stiffness_z", PROP_FLOAT, PROP_NONE);
994 RNA_def_property_float_sdna(prop, NULL, "stiffness[2]");
995 RNA_def_property_range(prop, 0.0f, 0.99f);
996 RNA_def_property_ui_text(prop, "IK Z Stiffness", "IK stiffness around the Z axis");
997 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
998 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
1000 prop = RNA_def_property(srna, "ik_stretch", PROP_FLOAT, PROP_NONE);
1001 RNA_def_property_float_sdna(prop, NULL, "ikstretch");
1002 RNA_def_property_range(prop, 0.0f,1.0f);
1003 RNA_def_property_ui_text(prop, "IK Stretch", "Allow scaling of the bone for IK");
1004 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1005 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update");
1007 prop = RNA_def_property(srna, "ik_rotation_weight", PROP_FLOAT, PROP_NONE);
1008 RNA_def_property_float_sdna(prop, NULL, "ikrotweight");
1009 RNA_def_property_range(prop, 0.0f,1.0f);
1010 RNA_def_property_ui_text(prop, "IK Rot Weight", "Weight of rotation constraint for IK");
1011 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1012 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1014 prop = RNA_def_property(srna, "ik_linear_weight", PROP_FLOAT, PROP_NONE);
1015 RNA_def_property_float_sdna(prop, NULL, "iklinweight");
1016 RNA_def_property_range(prop, 0.0f,1.0f);
1017 RNA_def_property_ui_text(prop, "IK Lin Weight", "Weight of scale constraint for IK");
1018 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1019 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1021 /* custom bone shapes */
1022 prop = RNA_def_property(srna, "custom_shape", PROP_POINTER, PROP_NONE);
1023 RNA_def_property_pointer_sdna(prop, NULL, "custom");
1024 RNA_def_property_struct_type(prop, "Object");
1025 RNA_def_property_flag(prop, PROP_EDITABLE);
1026 RNA_def_property_pointer_funcs(prop, NULL, "rna_PoseChannel_bone_custom_set", NULL, NULL);
1027 RNA_def_property_ui_text(prop, "Custom Object", "Object that defines custom draw type for this bone");
1028 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1029 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1031 prop = RNA_def_property(srna, "custom_shape_transform", PROP_POINTER, PROP_NONE);
1032 RNA_def_property_pointer_sdna(prop, NULL, "custom_tx");
1033 RNA_def_property_struct_type(prop, "PoseBone");
1034 RNA_def_property_flag(prop, PROP_EDITABLE);
1035 RNA_def_property_ui_text(prop, "Custom Shape Transform",
1036 "Bone that defines the display transform of this custom shape");
1037 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1038 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1041 prop = RNA_def_property(srna, "bone_group_index", PROP_INT, PROP_NONE);
1042 RNA_def_property_int_sdna(prop, NULL, "agrp_index");
1043 RNA_def_property_flag(prop, PROP_EDITABLE);
1044 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
1045 RNA_def_property_int_funcs(prop, "rna_PoseChannel_bone_group_index_get", "rna_PoseChannel_bone_group_index_set",
1046 "rna_PoseChannel_bone_group_index_range");
1047 RNA_def_property_ui_text(prop, "Bone Group Index", "Bone Group this pose channel belongs to (0=no group)");
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, "bone_group", PROP_POINTER, PROP_NONE);
1052 RNA_def_property_struct_type(prop, "BoneGroup");
1053 RNA_def_property_flag(prop, PROP_EDITABLE);
1054 RNA_def_property_pointer_funcs(prop, "rna_PoseChannel_bone_group_get",
1055 "rna_PoseChannel_bone_group_set", NULL, NULL);
1056 RNA_def_property_ui_text(prop, "Bone Group", "Bone Group this pose channel belongs to");
1057 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1058 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1060 /* transform locks */
1061 prop = RNA_def_property(srna, "lock_location", PROP_BOOLEAN, PROP_XYZ);
1062 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_LOCX);
1063 RNA_def_property_array(prop, 3);
1064 RNA_def_property_ui_text(prop, "Lock Location", "Lock editing of location in the interface");
1065 RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
1066 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1067 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1069 prop = RNA_def_property(srna, "lock_rotation", PROP_BOOLEAN, PROP_XYZ);
1070 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_ROTX);
1071 RNA_def_property_array(prop, 3);
1072 RNA_def_property_ui_text(prop, "Lock Rotation", "Lock editing of rotation in the interface");
1073 RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
1074 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1075 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1077 /* XXX this is sub-optimal - it really should be included above, but due to technical reasons
1078 * we can't do this! */
1079 prop = RNA_def_property(srna, "lock_rotation_w", PROP_BOOLEAN, PROP_NONE);
1080 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_ROTW);
1081 RNA_def_property_ui_text(prop, "Lock Rotation (4D Angle)",
1082 "Lock editing of 'angle' component of four-component rotations in the interface");
1083 RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
1084 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1085 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1087 /* XXX this needs a better name */
1088 prop = RNA_def_property(srna, "lock_rotations_4d", PROP_BOOLEAN, PROP_NONE);
1089 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_ROT4D);
1090 RNA_def_property_ui_text(prop, "Lock Rotations (4D)",
1091 "Lock editing of four component rotations by components (instead of as Eulers)");
1092 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1093 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1095 prop = RNA_def_property(srna, "lock_scale", PROP_BOOLEAN, PROP_XYZ);
1096 RNA_def_property_boolean_sdna(prop, NULL, "protectflag", OB_LOCK_SCALEX);
1097 RNA_def_property_array(prop, 3);
1098 RNA_def_property_ui_text(prop, "Lock Scale", "Lock editing of scale in the interface");
1099 RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
1100 RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
1101 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1103 RNA_api_pose_channel(srna);
1106 static void rna_def_pose_itasc(BlenderRNA *brna)
1108 static const EnumPropertyItem prop_itasc_mode_items[] = {
1109 {0, "ANIMATION", 0, "Animation",
1110 "Stateless solver computing pose starting from current action and non-IK constraints"},
1111 {ITASC_SIMULATION, "SIMULATION", 0, "Simulation",
1112 "Statefull solver running in real-time context and ignoring actions "
1113 "and non-IK constraints"},
1114 {0, NULL, 0, NULL, NULL}};
1115 static const EnumPropertyItem prop_itasc_reiteration_items[] = {
1116 {0, "NEVER", 0, "Never", "The solver does not reiterate, not even on first frame (starts from rest pose)"},
1117 {ITASC_INITIAL_REITERATION, "INITIAL", 0, "Initial",
1118 "The solver reiterates (converges) on the first frame but not on "
1119 "subsequent frame"},
1120 {ITASC_INITIAL_REITERATION|ITASC_REITERATION, "ALWAYS", 0, "Always",
1121 "The solver reiterates (converges) on all frames"},
1122 {0, NULL, 0, NULL, NULL}};
1127 srna = RNA_def_struct(brna, "Itasc", "IKParam");
1128 RNA_def_struct_sdna(srna, "bItasc");
1129 RNA_def_struct_ui_text(srna, "bItasc", "Parameters for the iTaSC IK solver");
1131 prop = RNA_def_property(srna, "precision", PROP_FLOAT, PROP_NONE);
1132 RNA_def_property_float_sdna(prop, NULL, "precision");
1133 RNA_def_property_range(prop, 0.0f,0.1f);
1134 RNA_def_property_ui_text(prop, "Precision", "Precision of convergence in case of reiteration");
1135 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1137 prop = RNA_def_property(srna, "iterations", PROP_INT, PROP_NONE);
1138 RNA_def_property_int_sdna(prop, NULL, "numiter");
1139 RNA_def_property_range(prop, 1.f,1000.f);
1140 RNA_def_property_ui_text(prop, "Iterations",
1141 "Maximum number of iterations for convergence in case of reiteration");
1142 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1144 prop = RNA_def_property(srna, "step_count", PROP_INT, PROP_NONE);
1145 RNA_def_property_int_sdna(prop, NULL, "numstep");
1146 RNA_def_property_range(prop, 1.f, 50.f);
1147 RNA_def_property_ui_text(prop, "Num steps", "Divide the frame interval into this many steps");
1148 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1150 prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
1151 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
1152 RNA_def_property_enum_items(prop, prop_itasc_mode_items);
1153 RNA_def_property_ui_text(prop, "Mode", NULL);
1154 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update_rebuild");
1156 prop = RNA_def_property(srna, "reiteration_method", PROP_ENUM, PROP_NONE);
1157 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
1158 RNA_def_property_enum_items(prop, prop_itasc_reiteration_items);
1159 RNA_def_property_ui_text(prop, "Reiteration",
1160 "Defines if the solver is allowed to reiterate (converge until "
1161 "precision is met) on none, first or all frames");
1162 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1164 prop = RNA_def_property(srna, "use_auto_step", PROP_BOOLEAN, PROP_NONE);
1165 RNA_def_property_boolean_sdna(prop, NULL, "flag", ITASC_AUTO_STEP);
1166 RNA_def_property_ui_text(prop, "Auto step",
1167 "Automatically determine the optimal number of steps for best "
1168 "performance/accuracy trade off");
1169 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1171 prop = RNA_def_property(srna, "step_min", PROP_FLOAT, PROP_NONE);
1172 RNA_def_property_float_sdna(prop, NULL, "minstep");
1173 RNA_def_property_range(prop, 0.0f,0.1f);
1174 RNA_def_property_ui_text(prop, "Min step", "Lower bound for timestep in second in case of automatic substeps");
1175 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1177 prop = RNA_def_property(srna, "step_max", PROP_FLOAT, PROP_NONE);
1178 RNA_def_property_float_sdna(prop, NULL, "maxstep");
1179 RNA_def_property_range(prop, 0.0f,1.0f);
1180 RNA_def_property_ui_text(prop, "Max step", "Higher bound for timestep in second in case of automatic substeps");
1181 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1183 prop = RNA_def_property(srna, "feedback", PROP_FLOAT, PROP_NONE);
1184 RNA_def_property_float_sdna(prop, NULL, "feedback");
1185 RNA_def_property_range(prop, 0.0f,100.0f);
1186 RNA_def_property_ui_text(prop, "Feedback",
1187 "Feedback coefficient for error correction, average response time is 1/feedback "
1189 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1191 prop = RNA_def_property(srna, "velocity_max", PROP_FLOAT, PROP_NONE);
1192 RNA_def_property_float_sdna(prop, NULL, "maxvel");
1193 RNA_def_property_range(prop, 0.0f,100.0f);
1194 RNA_def_property_ui_text(prop, "Max Velocity", "Maximum joint velocity in rad/s (default=50)");
1195 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1197 prop = RNA_def_property(srna, "solver", PROP_ENUM, PROP_NONE);
1198 RNA_def_property_enum_sdna(prop, NULL, "solver");
1199 RNA_def_property_enum_items(prop, prop_solver_items);
1200 RNA_def_property_ui_text(prop, "Solver", "Solving method selection: automatic damping or manual damping");
1201 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update_rebuild");
1203 prop = RNA_def_property(srna, "damping_max", PROP_FLOAT, PROP_NONE);
1204 RNA_def_property_float_sdna(prop, NULL, "dampmax");
1205 RNA_def_property_range(prop, 0.0f,1.0f);
1206 RNA_def_property_ui_text(prop, "Damp",
1207 "Maximum damping coefficient when singular value is nearly 0 "
1208 "(higher values=more stability, less reactivity - default=0.5)");
1209 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1211 prop = RNA_def_property(srna, "damping_epsilon", PROP_FLOAT, PROP_NONE);
1212 RNA_def_property_float_sdna(prop, NULL, "dampeps");
1213 RNA_def_property_range(prop, 0.0f,1.0f);
1214 RNA_def_property_ui_text(prop, "Epsilon",
1215 "Singular value under which damping is progressively applied "
1216 "(higher values=more stability, less reactivity - default=0.1)");
1217 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update");
1220 static void rna_def_pose_ikparam(BlenderRNA *brna)
1225 srna = RNA_def_struct(brna, "IKParam", NULL);
1226 RNA_def_struct_sdna(srna, "bIKParam");
1227 RNA_def_struct_ui_text(srna, "IKParam", "Base type for IK solver parameters");
1228 RNA_def_struct_refine_func(srna, "rna_IKParam_refine");
1230 prop = RNA_def_property(srna, "ik_solver", PROP_ENUM, PROP_NONE);
1231 RNA_def_property_enum_sdna(prop, NULL, "iksolver");
1232 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1233 RNA_def_property_enum_items(prop, prop_iksolver_items);
1234 RNA_def_property_ui_text(prop, "IK Solver",
1235 "IK solver for which these parameters are defined, 0 for Legacy, 1 for iTaSC");
1238 /* pose.bone_groups */
1239 static void rna_def_bone_groups(BlenderRNA *brna, PropertyRNA *cprop)
1244 /* FunctionRNA *func; */
1245 /* PropertyRNA *parm; */
1247 RNA_def_property_srna(cprop, "BoneGroups");
1248 srna = RNA_def_struct(brna, "BoneGroups", NULL);
1249 RNA_def_struct_sdna(srna, "bPose");
1250 RNA_def_struct_ui_text(srna, "Bone Groups", "Collection of bone groups");
1252 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
1253 RNA_def_property_struct_type(prop, "BoneGroup");
1254 RNA_def_property_flag(prop, PROP_EDITABLE);
1255 RNA_def_property_pointer_funcs(prop, "rna_Pose_active_bone_group_get",
1256 "rna_Pose_active_bone_group_set", NULL, NULL);
1257 RNA_def_property_ui_text(prop, "Active Bone Group", "Active bone group for this pose");
1258 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1260 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_NONE);
1261 RNA_def_property_int_sdna(prop, NULL, "active_group");
1262 RNA_def_property_int_funcs(prop, "rna_Pose_active_bone_group_index_get", "rna_Pose_active_bone_group_index_set",
1263 "rna_Pose_active_bone_group_index_range");
1264 RNA_def_property_ui_text(prop, "Active Bone Group Index", "Active index in bone groups array");
1265 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
1268 static void rna_def_pose(BlenderRNA *brna)
1273 /* struct definition */
1274 srna = RNA_def_struct(brna, "Pose", NULL);
1275 RNA_def_struct_sdna(srna, "bPose");
1276 RNA_def_struct_ui_text(srna, "Pose", "A collection of pose channels, including settings for animating bones");
1279 prop = RNA_def_property(srna, "bones", PROP_COLLECTION, PROP_NONE);
1280 RNA_def_property_collection_sdna(prop, NULL, "chanbase", NULL);
1281 RNA_def_property_struct_type(prop, "PoseBone");
1282 RNA_def_property_ui_text(prop, "Pose Bones", "Individual pose bones for the armature");
1283 /* can be removed, only for fast lookup */
1284 RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, NULL, NULL, NULL, "rna_PoseBones_lookup_string", NULL);
1287 prop = RNA_def_property(srna, "bone_groups", PROP_COLLECTION, PROP_NONE);
1288 RNA_def_property_collection_sdna(prop, NULL, "agroups", NULL);
1289 RNA_def_property_struct_type(prop, "BoneGroup");
1290 RNA_def_property_ui_text(prop, "Bone Groups", "Groups of the bones");
1291 rna_def_bone_groups(brna, prop);
1294 prop = RNA_def_property(srna, "ik_solver", PROP_ENUM, PROP_NONE);
1295 RNA_def_property_enum_sdna(prop, NULL, "iksolver");
1296 RNA_def_property_enum_funcs(prop, NULL, "rna_Pose_ik_solver_set", NULL);
1297 RNA_def_property_enum_items(prop, prop_iksolver_items);
1298 RNA_def_property_ui_text(prop, "IK Solver",
1299 "Selection of IK solver for IK chain, current choice is 0 for Legacy, 1 for iTaSC");
1300 RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_ik_solver_update");
1302 prop = RNA_def_property(srna, "ik_param", PROP_POINTER, PROP_NONE);
1303 RNA_def_property_struct_type(prop, "IKParam");
1304 RNA_def_property_pointer_funcs(prop, "rna_Pose_ikparam_get", NULL, "rna_Pose_ikparam_typef", NULL);
1305 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1306 RNA_def_property_ui_text(prop, "IK Param", "Parameters for IK solver");
1309 rna_def_animviz_common(srna);
1311 /* RNA_api_pose(srna); */
1314 void RNA_def_pose(BlenderRNA *brna)
1317 rna_def_pose_channel(brna);
1318 rna_def_pose_ikparam(brna);
1319 rna_def_pose_itasc(brna);
1320 rna_def_bone_group(brna);