diff options
Diffstat (limited to 'source/blender/makesrna/intern/rna_pose.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_pose.c | 471 |
1 files changed, 337 insertions, 134 deletions
diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c index 3a03e7a624d..03ced839ebe 100644 --- a/source/blender/makesrna/intern/rna_pose.c +++ b/source/blender/makesrna/intern/rna_pose.c @@ -23,6 +23,7 @@ */ #include <stdlib.h> +#include <string.h> #include "RNA_define.h" #include "RNA_types.h" @@ -39,8 +40,9 @@ #ifdef RNA_RUNTIME -#include <string.h> - +#include "BIK_api.h" +#include "BKE_action.h" +#include "BKE_armature.h" #include "BLI_arithb.h" #include "DNA_userdef_types.h" @@ -49,8 +51,11 @@ #include "BKE_depsgraph.h" #include "BKE_idprop.h" +#include "ED_object.h" #include "ED_armature.h" +#include "MEM_guardedalloc.h" + static void rna_Pose_update(bContext *C, PointerRNA *ptr) { // XXX when to use this? ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK); @@ -58,6 +63,15 @@ static void rna_Pose_update(bContext *C, PointerRNA *ptr) DAG_id_flush_update(ptr->id.data, OB_RECALC_DATA); } +static void rna_Pose_IK_update(bContext *C, PointerRNA *ptr) +{ + // XXX when to use this? ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK); + Object *ob= ptr->id.data; + + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + BIK_clear_data(ob->pose); +} + static char *rna_PoseChannel_path(PointerRNA *ptr) { return BLI_sprintfN("pose.pose_channels[\"%s\"]", ((bPoseChannel*)ptr->data)->name); @@ -98,7 +112,7 @@ static void rna_BoneGroup_color_set_set(PointerRNA *ptr, int value) } } -IDProperty *rna_PoseChannel_idproperties(PointerRNA *ptr, int create) +static IDProperty *rna_PoseChannel_idproperties(PointerRNA *ptr, int create) { bPoseChannel *pchan= ptr->data; @@ -110,106 +124,70 @@ IDProperty *rna_PoseChannel_idproperties(PointerRNA *ptr, int create) return pchan->prop; } +static void rna_Pose_ik_solver_set(struct PointerRNA *ptr, int value) +{ + bPose *pose= (bPose*)ptr->data; + + if (pose->iksolver != value) { + // the solver has changed, must clean any temporary structures + BIK_clear_data(pose); + if (pose->ikparam) { + MEM_freeN(pose->ikparam); + pose->ikparam = NULL; + } + pose->iksolver = value; + init_pose_ikparam(pose); + } +} + +static void rna_Pose_ik_solver_update(bContext *C, PointerRNA *ptr) +{ + Object *ob= ptr->id.data; + bPose *pose = ptr->data; + Scene *scene = CTX_data_scene(C); + + pose->flag |= POSE_RECALC; // checks & sorts pose channels + DAG_scene_sort(scene); + + update_pose_constraint_flags(pose); + + object_test_constraints(ob); + + DAG_id_flush_update(&ob->id, OB_RECALC_DATA|OB_RECALC_OB); +} + /* rotation - euler angles */ -static void rna_PoseChannel_euler_rotation_get(PointerRNA *ptr, float *value) +static void rna_PoseChannel_rotation_euler_get(PointerRNA *ptr, float *value) { bPoseChannel *pchan= ptr->data; - if(pchan->rotmode == PCHAN_ROT_AXISANGLE) /* default XYZ eulers */ + if(pchan->rotmode == ROT_MODE_AXISANGLE) /* default XYZ eulers */ AxisAngleToEulO(&pchan->quat[1], pchan->quat[0], value, EULER_ORDER_DEFAULT); - else if(pchan->rotmode == PCHAN_ROT_QUAT) /* default XYZ eulers */ + else if(pchan->rotmode == ROT_MODE_QUAT) /* default XYZ eulers */ QuatToEul(pchan->quat, value); else VECCOPY(value, pchan->eul); } /* rotation - euler angles */ -static void rna_PoseChannel_euler_rotation_set(PointerRNA *ptr, const float *value) +static void rna_PoseChannel_rotation_euler_set(PointerRNA *ptr, const float *value) { bPoseChannel *pchan= ptr->data; - if(pchan->rotmode == PCHAN_ROT_AXISANGLE) /* default XYZ eulers */ + if(pchan->rotmode == ROT_MODE_AXISANGLE) /* default XYZ eulers */ EulOToAxisAngle((float *)value, EULER_ORDER_DEFAULT, &pchan->quat[1], &pchan->quat[0]); - else if(pchan->rotmode == PCHAN_ROT_QUAT) /* default XYZ eulers */ + else if(pchan->rotmode == ROT_MODE_QUAT) /* default XYZ eulers */ EulToQuat((float*)value, pchan->quat); else VECCOPY(pchan->eul, value); } -/* rotation - axis angle only */ -static void rna_PoseChannel_rotation_axis_get(PointerRNA *ptr, float *value) -{ - bPoseChannel *pchan= ptr->data; - - if (pchan->rotmode == PCHAN_ROT_AXISANGLE) { - /* axis is stord in quat for now */ - VecCopyf(value, &pchan->quat[1]); - } -} - -/* rotation - axis angle only */ -static void rna_PoseChannel_rotation_axis_set(PointerRNA *ptr, const float *value) -{ - bPoseChannel *pchan= ptr->data; - - if (pchan->rotmode == PCHAN_ROT_AXISANGLE) { - /* axis is stored in quat for now */ - VecCopyf(&pchan->quat[1], (float *)value); - } -} - static void rna_PoseChannel_rotation_mode_set(PointerRNA *ptr, int value) { bPoseChannel *pchan= ptr->data; - /* check if any change - if so, need to convert data */ - // TODO: this needs to be generalised at some point to work for objects too... - if (value > 0) { /* to euler */ - if (pchan->rotmode == PCHAN_ROT_AXISANGLE) { - /* axis-angle to euler */ - AxisAngleToEulO(&pchan->quat[1], pchan->quat[0], pchan->eul, value); - } - else if (pchan->rotmode == PCHAN_ROT_QUAT) { - /* quat to euler */ - QuatToEulO(pchan->quat, pchan->eul, value); - } - /* else { no conversion needed } */ - } - else if (value == PCHAN_ROT_QUAT) { /* to quat */ - if (pchan->rotmode == PCHAN_ROT_AXISANGLE) { - /* axis angle to quat */ - float q[4]; - - /* copy to temp var first, since quats and axis-angle are stored in same place */ - QuatCopy(q, pchan->quat); - AxisAngleToQuat(q, &pchan->quat[1], pchan->quat[0]); - } - else if (pchan->rotmode > 0) { - /* euler to quat */ - EulOToQuat(pchan->eul, pchan->rotmode, pchan->quat); - } - /* else { no conversion needed } */ - } - else { /* to axis-angle */ - if (pchan->rotmode > 0) { - /* euler to axis angle */ - EulOToAxisAngle(pchan->eul, pchan->rotmode, &pchan->quat[1], &pchan->quat[0]); - } - else if (pchan->rotmode == PCHAN_ROT_QUAT) { - /* quat to axis angle */ - float q[4]; - - /* copy to temp var first, since quats and axis-angle are stored in same place */ - QuatCopy(q, pchan->quat); - QuatToAxisAngle(q, &pchan->quat[1], &pchan->quat[0]); - } - - /* when converting to axis-angle, we need a special exception for the case when there is no axis */ - if (IS_EQ(pchan->quat[1], pchan->quat[2]) && IS_EQ(pchan->quat[2], pchan->quat[3])) { - /* for now, rotate around y-axis then (so that it simply becomes the roll) */ - pchan->quat[2]= 1.0f; - } - } + /* use API Method for conversions... */ + BKE_rotMode_change_values(pchan->quat, pchan->eul, pchan->rotmode, (short)value); /* finally, set the new rotation type */ pchan->rotmode= value; @@ -236,6 +214,70 @@ static int rna_PoseChannel_has_ik_get(PointerRNA *ptr) return ED_pose_channel_in_IK_chain(ob, pchan); } +StructRNA *rna_IKParam_refine(PointerRNA *ptr) +{ + bIKParam *param = (bIKParam *)ptr->data; + + switch (param->iksolver) { + case IKSOLVER_ITASC: + return &RNA_Itasc; + default: + return &RNA_IKParam; + } +} + +PointerRNA rna_Pose_ikparam_get(struct PointerRNA *ptr) +{ + bPose *pose= (bPose*)ptr->data; + return rna_pointer_inherit_refine(ptr, &RNA_IKParam, pose->ikparam); +} + +static StructRNA *rna_Pose_ikparam_typef(PointerRNA *ptr) +{ + bPose *pose= (bPose*)ptr->data; + + switch (pose->iksolver) { + case IKSOLVER_ITASC: + return &RNA_Itasc; + default: + return &RNA_IKParam; + } +} + +static void rna_Itasc_update(bContext *C, PointerRNA *ptr) +{ + Object *ob = ptr->id.data; + bItasc *itasc = ptr->data; + + /* verify values */ + if (itasc->precision < 0.0001f) + itasc->precision = 0.0001f; + if (itasc->minstep < 0.001f) + itasc->minstep = 0.001f; + if (itasc->maxstep < itasc->minstep) + itasc->maxstep = itasc->minstep; + if (itasc->feedback < 0.01f) + itasc->feedback = 0.01f; + if (itasc->feedback > 100.f) + itasc->feedback = 100.f; + if (itasc->maxvel < 0.01f) + itasc->maxvel = 0.01f; + if (itasc->maxvel > 100.f) + itasc->maxvel = 100.f; + BIK_update_param(ob->pose); + + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); +} + +static void rna_Itasc_update_rebuild(bContext *C, PointerRNA *ptr) +{ + Object *ob= ptr->id.data; + bPose *pose = ob->pose; + + pose->flag |= POSE_RECALC; // checks & sorts pose channels + rna_Itasc_update(C, ptr); +} + static PointerRNA rna_PoseChannel_bone_group_get(PointerRNA *ptr) { Object *ob= (Object*)ptr->id.data; @@ -323,7 +365,8 @@ static void rna_Pose_active_bone_group_index_range(PointerRNA *ptr, int *min, in *max= MAX2(0, *max); } -void rna_pose_bgroup_name_index_get(PointerRNA *ptr, char *value, int index) +#if 0 +static void rna_pose_bgroup_name_index_get(PointerRNA *ptr, char *value, int index) { bPose *pose= (bPose*)ptr->data; bActionGroup *grp; @@ -334,7 +377,7 @@ void rna_pose_bgroup_name_index_get(PointerRNA *ptr, char *value, int index) else BLI_strncpy(value, "", sizeof(grp->name)); // XXX if invalid pointer, won't this crash? } -int rna_pose_bgroup_name_index_length(PointerRNA *ptr, int index) +static int rna_pose_bgroup_name_index_length(PointerRNA *ptr, int index) { bPose *pose= (bPose*)ptr->data; bActionGroup *grp; @@ -343,7 +386,7 @@ int rna_pose_bgroup_name_index_length(PointerRNA *ptr, int index) return (grp)? strlen(grp->name): 0; } -void rna_pose_bgroup_name_index_set(PointerRNA *ptr, const char *value, short *index) +static void rna_pose_bgroup_name_index_set(PointerRNA *ptr, const char *value, short *index) { bPose *pose= (bPose*)ptr->data; bActionGroup *grp; @@ -359,7 +402,7 @@ void rna_pose_bgroup_name_index_set(PointerRNA *ptr, const char *value, short *i *index= 0; } -void rna_pose_pgroup_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen) +static void rna_pose_pgroup_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen) { bPose *pose= (bPose*)ptr->data; bActionGroup *grp; @@ -373,6 +416,7 @@ void rna_pose_pgroup_name_set(PointerRNA *ptr, const char *value, char *result, BLI_strncpy(result, "", maxlen); } +#endif #else @@ -428,24 +472,36 @@ static void rna_def_bone_group(BlenderRNA *brna) RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); // TODO: editing the colors for this should result in changes to the color type... - prop= RNA_def_property(srna, "colors", PROP_POINTER, PROP_NEVER_NULL); + prop= RNA_def_property(srna, "colors", PROP_POINTER, PROP_NONE); + RNA_def_property_flag(prop, PROP_NEVER_NULL); RNA_def_property_struct_type(prop, "ThemeBoneColorSet"); RNA_def_property_pointer_sdna(prop, NULL, "cs"); /* NOTE: the DNA data is not really a pointer, but this code works :) */ RNA_def_property_ui_text(prop, "Colors", "Copy of the colors associated with the group's color set."); RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); } +static EnumPropertyItem prop_iksolver_items[] = { + {IKSOLVER_LEGACY, "LEGACY", 0, "Legacy", "Original IK solver."}, + {IKSOLVER_ITASC, "ITASC", 0, "iTaSC", "Multi constraint, stateful IK solver."}, + {0, NULL, 0, NULL, NULL}}; + +static EnumPropertyItem prop_solver_items[] = { + {ITASC_SOLVER_SDLS, "SDLS", 0, "SDLS", "Selective Damped Least Square"}, + {ITASC_SOLVER_DLS, "DLS", 0, "DLS", "Damped Least Square with Numerical Filtering"}, + {0, NULL, 0, NULL, NULL}}; + static void rna_def_pose_channel(BlenderRNA *brna) { + // XXX: this RNA enum define is currently duplicated for objects, since there is some text here which is not applicable static EnumPropertyItem prop_rotmode_items[] = { - {PCHAN_ROT_QUAT, "QUATERNION", 0, "Quaternion (WXYZ)", "No Gimbal Lock (default)"}, - {PCHAN_ROT_XYZ, "XYZ", 0, "XYZ Euler", "XYZ Rotation Order. Prone to Gimbal Lock"}, - {PCHAN_ROT_XZY, "XZY", 0, "XZY Euler", "XZY Rotation Order. Prone to Gimbal Lock"}, - {PCHAN_ROT_YXZ, "YXZ", 0, "YXZ Euler", "YXZ Rotation Order. Prone to Gimbal Lock"}, - {PCHAN_ROT_YZX, "YZX", 0, "YZX Euler", "YZX Rotation Order. Prone to Gimbal Lock"}, - {PCHAN_ROT_ZXY, "ZXY", 0, "ZXY Euler", "ZXY Rotation Order. Prone to Gimbal Lock"}, - {PCHAN_ROT_ZYX, "ZYX", 0, "ZYX Euler", "ZYX Rotation Order. Prone to Gimbal Lock"}, - {PCHAN_ROT_AXISANGLE, "AXIS_ANGLE", 0, "Axis Angle", "Axis Angle (W+XYZ). Defines a rotation around some axis defined by 3D-Vector."}, + {ROT_MODE_QUAT, "QUATERNION", 0, "Quaternion (WXYZ)", "No Gimbal Lock (default)"}, + {ROT_MODE_XYZ, "XYZ", 0, "XYZ Euler", "XYZ Rotation Order. Prone to Gimbal Lock"}, + {ROT_MODE_XZY, "XZY", 0, "XZY Euler", "XZY Rotation Order. Prone to Gimbal Lock"}, + {ROT_MODE_YXZ, "YXZ", 0, "YXZ Euler", "YXZ Rotation Order. Prone to Gimbal Lock"}, + {ROT_MODE_YZX, "YZX", 0, "YZX Euler", "YZX Rotation Order. Prone to Gimbal Lock"}, + {ROT_MODE_ZXY, "ZXY", 0, "ZXY Euler", "ZXY Rotation Order. Prone to Gimbal Lock"}, + {ROT_MODE_ZYX, "ZYX", 0, "ZYX Euler", "ZYX Rotation Order. Prone to Gimbal Lock"}, + {ROT_MODE_AXISANGLE, "AXIS_ANGLE", 0, "Axis Angle", "Axis Angle (W+XYZ). Defines a rotation around some axis defined by 3D-Vector."}, {0, NULL, 0, NULL, NULL}}; StructRNA *srna; @@ -467,7 +523,7 @@ static void rna_def_pose_channel(BlenderRNA *brna) RNA_def_property_string_funcs(prop, NULL, NULL, "rna_PoseChannel_name_set"); RNA_def_property_ui_text(prop, "Name", ""); RNA_def_struct_name_property(srna, prop); - + prop= RNA_def_property(srna, "selected", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "selectflag", BONE_SELECTED); RNA_def_property_ui_text(prop, "Selected", ""); @@ -477,16 +533,17 @@ static void rna_def_pose_channel(BlenderRNA *brna) RNA_def_property_int_sdna(prop, NULL, "pathsf"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Bone Paths Calculation Start Frame", "Starting frame of range of frames to use for Bone Path calculations."); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); prop= RNA_def_property(srna, "path_end_frame", PROP_INT, PROP_TIME); RNA_def_property_int_sdna(prop, NULL, "pathef"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Bone Paths Calculation End Frame", "End frame of range of frames to use for Bone Path calculations."); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); /* Relationships to other bones */ - prop= RNA_def_property(srna, "bone", PROP_POINTER, PROP_NEVER_NULL); + prop= RNA_def_property(srna, "bone", PROP_POINTER, PROP_NONE); + RNA_def_property_flag(prop, PROP_NEVER_NULL); RNA_def_property_struct_type(prop, "Bone"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Bone", "Bone associated with this Pose Channel."); @@ -512,52 +569,53 @@ static void rna_def_pose_channel(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Scale", ""); RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Pose_update"); - prop= RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_QUATERNION); + prop= RNA_def_property(srna, "rotation_quaternion", PROP_FLOAT, PROP_QUATERNION); RNA_def_property_float_sdna(prop, NULL, "quat"); - RNA_def_property_ui_text(prop, "Rotation", "Rotation in Quaternions."); - RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Pose_update"); - - prop= RNA_def_property(srna, "rotation_angle", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "quat[0]"); - RNA_def_property_ui_text(prop, "Rotation Angle", "Angle of Rotation for Axis-Angle rotation representation."); + RNA_def_property_ui_text(prop, "Quaternion Rotation", "Rotation in Quaternions."); RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Pose_update"); - prop= RNA_def_property(srna, "rotation_axis", PROP_FLOAT, PROP_XYZ); + /* XXX: for axis-angle, it would have been nice to have 2 separate fields for UI purposes, but + * having a single one is better for Keyframing and other property-management situations... + */ + prop= RNA_def_property(srna, "rotation_axis_angle", PROP_FLOAT, PROP_AXISANGLE); RNA_def_property_float_sdna(prop, NULL, "quat"); - RNA_def_property_float_funcs(prop, "rna_PoseChannel_rotation_axis_get", "rna_PoseChannel_rotation_axis_set", NULL); - RNA_def_property_array(prop, 3); - RNA_def_property_ui_text(prop, "Rotation Axis", "Axis for Axis-Angle rotation representation."); + // TODO: we may need some validation funcs + RNA_def_property_ui_text(prop, "Axis-Angle Rotation", "Angle of Rotation for Axis-Angle rotation representation."); RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Pose_update"); - prop= RNA_def_property(srna, "euler_rotation", PROP_FLOAT, PROP_EULER); + prop= RNA_def_property(srna, "rotation_euler", PROP_FLOAT, PROP_EULER); RNA_def_property_float_sdna(prop, NULL, "eul"); - RNA_def_property_float_funcs(prop, "rna_PoseChannel_euler_rotation_get", "rna_PoseChannel_euler_rotation_set", NULL); - RNA_def_property_ui_text(prop, "Rotation (Euler)", "Rotation in Eulers."); + RNA_def_property_float_funcs(prop, "rna_PoseChannel_rotation_euler_get", "rna_PoseChannel_rotation_euler_set", NULL); + RNA_def_property_ui_text(prop, "Euler Rotation", "Rotation in Eulers."); RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Pose_update"); prop= RNA_def_property(srna, "rotation_mode", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "rotmode"); - RNA_def_property_enum_items(prop, prop_rotmode_items); + RNA_def_property_enum_items(prop, prop_rotmode_items); // XXX move to using a single define of this someday RNA_def_property_enum_funcs(prop, NULL, "rna_PoseChannel_rotation_mode_set", NULL); RNA_def_property_ui_text(prop, "Rotation Mode", ""); RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); /* These three matrix properties await an implementation of the PROP_MATRIX subtype, which currently doesn't exist. */ -/* prop= RNA_def_property(srna, "channel_matrix", PROP_FLOAT, PROP_MATRIX); - RNA_def_property_struct_type(prop, "chan_mat"); + prop= RNA_def_property(srna, "channel_matrix", PROP_FLOAT, PROP_MATRIX); + RNA_def_property_float_sdna(prop, NULL, "chan_mat"); + RNA_def_property_array(prop, 16); RNA_def_property_clear_flag(prop, PROP_EDITABLE); - RNA_def_property_ui_text(prop, "Channel Matrix", "4x4 matrix, before constraints.");*/ + RNA_def_property_ui_text(prop, "Channel Matrix", "4x4 matrix, before constraints."); /* kaito says this should be not user-editable; I disagree; power users should be able to force this in python; he's the boss. */ -/* prop= RNA_def_property(srna, "pose_matrix", PROP_FLOAT, PROP_MATRIX); - RNA_def_property_struct_type(prop, "pose_mat"); + prop= RNA_def_property(srna, "pose_matrix", PROP_FLOAT, PROP_MATRIX); + RNA_def_property_float_sdna(prop, NULL, "pose_mat"); + RNA_def_property_array(prop, 16); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Pose Matrix", "Final 4x4 matrix for this channel."); + /* prop= RNA_def_property(srna, "constraint_inverse_matrix", PROP_FLOAT, PROP_MATRIX); RNA_def_property_struct_type(prop, "constinv"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); - RNA_def_property_ui_text(prop, "Constraint Inverse Matrix", "4x4 matrix, defines transform from final position to unconstrained position."); */ + RNA_def_property_ui_text(prop, "Constraint Inverse Matrix", "4x4 matrix, defines transform from final position to unconstrained position."); + */ /* Head/Tail Coordinates (in Pose Space) - Automatically calculated... */ prop= RNA_def_property(srna, "pose_head", PROP_FLOAT, PROP_TRANSLATION); @@ -573,96 +631,118 @@ static void rna_def_pose_channel(BlenderRNA *brna) RNA_def_property_boolean_funcs(prop, "rna_PoseChannel_has_ik_get", NULL); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Has IK", "Is part of an IK chain."); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); prop= RNA_def_property(srna, "ik_dof_x", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_negative_sdna(prop, NULL, "ikflag", BONE_IK_NO_XDOF); RNA_def_property_ui_text(prop, "IK X DoF", "Allow movement around the X axis."); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); prop= RNA_def_property(srna, "ik_dof_y", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_negative_sdna(prop, NULL, "ikflag", BONE_IK_NO_YDOF); RNA_def_property_ui_text(prop, "IK Y DoF", "Allow movement around the Y axis."); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE|ND_TRANSFORM, "rna_Pose_IK_update"); prop= RNA_def_property(srna, "ik_dof_z", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_negative_sdna(prop, NULL, "ikflag", BONE_IK_NO_ZDOF); RNA_def_property_ui_text(prop, "IK Z DoF", "Allow movement around the Z axis."); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); prop= RNA_def_property(srna, "ik_limit_x", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_XLIMIT); RNA_def_property_ui_text(prop, "IK X Limit", "Limit movement around the X axis."); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); prop= RNA_def_property(srna, "ik_limit_y", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_YLIMIT); RNA_def_property_ui_text(prop, "IK Y Limit", "Limit movement around the Y axis."); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); prop= RNA_def_property(srna, "ik_limit_z", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_ZLIMIT); RNA_def_property_ui_text(prop, "IK Z Limit", "Limit movement around the Z axis."); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); + + prop= RNA_def_property(srna, "ik_rot_control", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_ROTCTL); + RNA_def_property_ui_text(prop, "IK rot control", "Apply channel rotation as IK constraint"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); + + prop= RNA_def_property(srna, "ik_lin_control", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "ikflag", BONE_IK_LINCTL); + RNA_def_property_ui_text(prop, "IK rot control", "Apply channel size as IK constraint if stretching is enabled"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); prop= RNA_def_property(srna, "ik_min_x", PROP_FLOAT, PROP_ANGLE); RNA_def_property_float_sdna(prop, NULL, "limitmin[0]"); RNA_def_property_range(prop, -180.0f, 0.0f); RNA_def_property_ui_text(prop, "IK X Minimum", "Minimum angles for IK Limit"); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); prop= RNA_def_property(srna, "ik_max_x", PROP_FLOAT, PROP_ANGLE); RNA_def_property_float_sdna(prop, NULL, "limitmax[0]"); RNA_def_property_range(prop, 0.0f, 180.0f); RNA_def_property_ui_text(prop, "IK X Maximum", "Maximum angles for IK Limit"); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); prop= RNA_def_property(srna, "ik_min_y", PROP_FLOAT, PROP_ANGLE); RNA_def_property_float_sdna(prop, NULL, "limitmin[1]"); RNA_def_property_range(prop, -180.0f, 0.0f); RNA_def_property_ui_text(prop, "IK Y Minimum", "Minimum angles for IK Limit"); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); prop= RNA_def_property(srna, "ik_max_y", PROP_FLOAT, PROP_ANGLE); RNA_def_property_float_sdna(prop, NULL, "limitmax[1]"); RNA_def_property_range(prop, 0.0f, 180.0f); RNA_def_property_ui_text(prop, "IK Y Maximum", "Maximum angles for IK Limit"); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); prop= RNA_def_property(srna, "ik_min_z", PROP_FLOAT, PROP_ANGLE); RNA_def_property_float_sdna(prop, NULL, "limitmin[2]"); RNA_def_property_range(prop, -180.0f, 0.0f); RNA_def_property_ui_text(prop, "IK Z Minimum", "Minimum angles for IK Limit"); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); prop= RNA_def_property(srna, "ik_max_z", PROP_FLOAT, PROP_ANGLE); RNA_def_property_float_sdna(prop, NULL, "limitmax[2]"); RNA_def_property_range(prop, 0.0f, 180.0f); RNA_def_property_ui_text(prop, "IK Z Maximum", "Maximum angles for IK Limit"); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); prop= RNA_def_property(srna, "ik_stiffness_x", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "stiffness[0]"); RNA_def_property_range(prop, 0.0f, 0.99f); RNA_def_property_ui_text(prop, "IK X Stiffness", "IK stiffness around the X axis."); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); prop= RNA_def_property(srna, "ik_stiffness_y", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "stiffness[1]"); RNA_def_property_range(prop, 0.0f, 0.99f); RNA_def_property_ui_text(prop, "IK Y Stiffness", "IK stiffness around the Y axis."); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); prop= RNA_def_property(srna, "ik_stiffness_z", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "stiffness[2]"); RNA_def_property_range(prop, 0.0f, 0.99f); RNA_def_property_ui_text(prop, "IK Z Stiffness", "IK stiffness around the Z axis."); - RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); prop= RNA_def_property(srna, "ik_stretch", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "ikstretch"); RNA_def_property_range(prop, 0.0f,1.0f); RNA_def_property_ui_text(prop, "IK Stretch", "Allow scaling of the bone for IK."); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_IK_update"); + + prop= RNA_def_property(srna, "ik_rot_weight", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "ikrotweight"); + RNA_def_property_range(prop, 0.0f,1.0f); + RNA_def_property_ui_text(prop, "IK Rot Weight", "Weight of rotation constraint for IK."); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + + prop= RNA_def_property(srna, "ik_lin_weight", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "iklinweight"); + RNA_def_property_range(prop, 0.0f,1.0f); + RNA_def_property_ui_text(prop, "IK Lin Weight", "Weight of scale constraint for IK."); RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); /* custom bone shapes */ @@ -719,6 +799,113 @@ static void rna_def_pose_channel(BlenderRNA *brna) RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); } +static void rna_def_pose_itasc(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "Itasc", "IKParam"); + RNA_def_struct_sdna(srna, "bItasc"); + RNA_def_struct_ui_text(srna, "bItasc", "Parameters for the iTaSC IK solver."); + + prop= RNA_def_property(srna, "precision", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "precision"); + RNA_def_property_range(prop, 0.0f,0.1f); + RNA_def_property_ui_text(prop, "Precision", "Precision of convergence in case of reiteration."); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update"); + + prop= RNA_def_property(srna, "num_iter", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "numiter"); + RNA_def_property_range(prop, 1.f,1000.f); + RNA_def_property_ui_text(prop, "Iterations", "Maximum number of iterations for convergence in case of reiteration."); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update"); + + prop= RNA_def_property(srna, "num_step", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "numstep"); + RNA_def_property_range(prop, 1.f, 50.f); + RNA_def_property_ui_text(prop, "Num steps", "Divides the frame interval into this many steps."); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update"); + + prop= RNA_def_property(srna, "simulation", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", ITASC_SIMULATION); + RNA_def_property_ui_text(prop, "Simulation", "Simulation mode: solver is statefull, runs in real-time context and ignores actions and non-IK constraints (i.e. solver is in full charge of the IK chain)."); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update_rebuild"); + + prop= RNA_def_property(srna, "initial_reiteration", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", ITASC_INITIAL_REITERATION); + RNA_def_property_ui_text(prop, "Initial Reiteration", "Allow reiteration for initial frame."); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update"); + + prop= RNA_def_property(srna, "reiteration", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", ITASC_REITERATION); + RNA_def_property_ui_text(prop, "Reiteration", "Allow reiteration for all frames."); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update"); + + prop= RNA_def_property(srna, "auto_step", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", ITASC_AUTO_STEP); + RNA_def_property_ui_text(prop, "Auto step", "Automatically determine the optimal number of steps for best performance/accurary trade off."); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update"); + + prop= RNA_def_property(srna, "min_step", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "minstep"); + RNA_def_property_range(prop, 0.0f,0.1f); + RNA_def_property_ui_text(prop, "Min step", "Lower bound for timestep in second in case of automatic substeps."); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update"); + + prop= RNA_def_property(srna, "max_step", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "maxstep"); + RNA_def_property_range(prop, 0.0f,1.0f); + RNA_def_property_ui_text(prop, "Max step", "Higher bound for timestep in second in case of automatic substeps."); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update"); + + prop= RNA_def_property(srna, "feedback", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "feedback"); + RNA_def_property_range(prop, 0.0f,100.0f); + RNA_def_property_ui_text(prop, "Feedback", "Feedback coefficient for error correction. Average response time=1/feedback. Default=20."); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update"); + + prop= RNA_def_property(srna, "max_velocity", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "maxvel"); + RNA_def_property_range(prop, 0.0f,100.0f); + RNA_def_property_ui_text(prop, "Max Velocity", "Maximum joint velocity in rad/s. Default=50."); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update"); + + prop= RNA_def_property(srna, "solver", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "solver"); + RNA_def_property_enum_items(prop, prop_solver_items); + RNA_def_property_ui_text(prop, "Solver", "Solving method selection: Automatic damping or manual damping"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update_rebuild"); + + prop= RNA_def_property(srna, "dampmax", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "dampmax"); + RNA_def_property_range(prop, 0.0f,1.0f); + RNA_def_property_ui_text(prop, "Damp", "Maximum damping coefficient when singular value is nearly 0. Higher values=more stability, less reactivity. Default=0.5"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update"); + + prop= RNA_def_property(srna, "dampeps", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "dampeps"); + RNA_def_property_range(prop, 0.0f,1.0f); + RNA_def_property_ui_text(prop, "Epsilon", "Singular value under which damping is progressively applied. Higher values=more stability, less reactivity. Default=0.1"); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Itasc_update"); +} + +static void rna_def_pose_ikparam(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "IKParam", NULL); + RNA_def_struct_sdna(srna, "bIKParam"); + RNA_def_struct_ui_text(srna, "IKParam", "Base type for IK solver parameters."); + RNA_def_struct_refine_func(srna, "rna_IKParam_refine"); + + prop= RNA_def_property(srna, "ik_solver", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "iksolver"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_enum_items(prop, prop_iksolver_items); + RNA_def_property_ui_text(prop, "IK Solver", "IK solver for which these parameters are defined, 0 for Legacy, 1 for iTaSC."); +} + static void rna_def_pose(BlenderRNA *brna) { StructRNA *srna; @@ -753,13 +940,29 @@ static void rna_def_pose(BlenderRNA *brna) RNA_def_property_int_funcs(prop, "rna_Pose_active_bone_group_index_get", "rna_Pose_active_bone_group_index_set", "rna_Pose_active_bone_group_index_range"); RNA_def_property_ui_text(prop, "Active Bone Group Index", "Active index in bone groups array."); RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update"); + + prop= RNA_def_property(srna, "ik_solver", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "iksolver"); + RNA_def_property_enum_funcs(prop, NULL, "rna_Pose_ik_solver_set", NULL); + RNA_def_property_enum_items(prop, prop_iksolver_items); + RNA_def_property_ui_text(prop, "IK Solver", "Selection of IK solver for IK chain, current choice is 0 for Legacy, 1 for iTaSC."); + RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_ik_solver_update"); + + prop= RNA_def_property(srna, "ik_param", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "IKParam"); + RNA_def_property_pointer_funcs(prop, "rna_Pose_ikparam_get", NULL, "rna_Pose_ikparam_typef"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "IK Param", "Parameters for IK solver."); + + /* RNA_api_pose(srna); */ } void RNA_def_pose(BlenderRNA *brna) { rna_def_pose(brna); rna_def_pose_channel(brna); - + rna_def_pose_ikparam(brna); + rna_def_pose_itasc(brna); rna_def_bone_group(brna); } |