Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_constraint.c
| Show First 20 Lines • Show All 858 Lines • ▼ Show 20 Lines | void CONSTRAINT_OT_limitdistance_reset(wmOperatorType *ot) | ||||
| /* properties */ | /* properties */ | ||||
| edit_constraint_properties(ot); | edit_constraint_properties(ot); | ||||
| } | } | ||||
| /* ------------- Child-Of Constraint ------------------ */ | /* ------------- Child-Of Constraint ------------------ */ | ||||
| static void child_get_inverse_matrix_owner_bone( | static void child_get_inverse_matrix_owner_bone( | ||||
| const bContext *C, wmOperator *op, Scene *scene, Object *ob, float invmat[4][4]) | Depsgraph *depsgraph, wmOperator *op, Scene *scene, Object *ob, float invmat[4][4]) | ||||
| { | { | ||||
| /* For bone owner we want to do this in evaluated domain. | /* For bone owner we want to do this in evaluated domain. | ||||
| * BKE_pose_where_is / BKE_pose_where_is_bone relies on (re)evaluating parts of the scene | * BKE_pose_where_is / BKE_pose_where_is_bone relies on (re)evaluating parts of the scene | ||||
| * and copying new evaluated stuff back to original. | * and copying new evaluated stuff back to original. | ||||
| */ | */ | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | |||||
| Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | ||||
brecht: Make depsgraph a parameter of this function and get it at the start of… | |||||
| bConstraint *con_eval = edit_constraint_property_get(op, ob_eval, CONSTRAINT_TYPE_CHILDOF); | bConstraint *con_eval = edit_constraint_property_get(op, ob_eval, CONSTRAINT_TYPE_CHILDOF); | ||||
| /* nullify inverse matrix first */ | /* nullify inverse matrix first */ | ||||
| unit_m4(invmat); | unit_m4(invmat); | ||||
| bPoseChannel *pchan_eval = BKE_pose_channel_active(ob_eval); | bPoseChannel *pchan_eval = BKE_pose_channel_active(ob_eval); | ||||
| /* try to find a pose channel - assume that this is the constraint owner */ | /* try to find a pose channel - assume that this is the constraint owner */ | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | if (ob_eval && ob_eval->pose && pchan_eval) { | ||||
| /* 6. recalculate pose with new inv-mat applied */ | /* 6. recalculate pose with new inv-mat applied */ | ||||
| /* this one is unnecessary? (DEG seems to update correctly without) | /* this one is unnecessary? (DEG seems to update correctly without) | ||||
| + if we leave this in, we have to click "Set Inverse" twice to see updates... | + if we leave this in, we have to click "Set Inverse" twice to see updates... | ||||
| BKE_pose_where_is(depsgraph, scene, ob_eval); */ | BKE_pose_where_is(depsgraph, scene, ob_eval); */ | ||||
| } | } | ||||
| } | } | ||||
| static void child_get_inverse_matrix_owner_object( | static void child_get_inverse_matrix_owner_object( | ||||
| const bContext *C, Scene *scene, Object *ob, bConstraint *con, float invmat[4][4]) | Depsgraph *depsgraph, Scene *scene, Object *ob, bConstraint *con, float invmat[4][4]) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | |||||
Done Inline ActionsSame comment. brecht: Same comment. | |||||
| /* nullify inverse matrix first */ | /* nullify inverse matrix first */ | ||||
| unit_m4(invmat); | unit_m4(invmat); | ||||
| if (ob) { | if (ob) { | ||||
| Object workob; | Object workob; | ||||
| /* make sure we passed the correct constraint */ | /* make sure we passed the correct constraint */ | ||||
| BLI_assert(BLI_findindex(&ob->constraints, con) != -1); | BLI_assert(BLI_findindex(&ob->constraints, con) != -1); | ||||
| UNUSED_VARS_NDEBUG(con); | UNUSED_VARS_NDEBUG(con); | ||||
| /* use BKE_object_workob_calc_parent to find inverse - just like for normal parenting */ | /* use BKE_object_workob_calc_parent to find inverse - just like for normal parenting */ | ||||
| BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob); | BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob); | ||||
| invert_m4_m4(invmat, workob.obmat); | invert_m4_m4(invmat, workob.obmat); | ||||
| } | } | ||||
| } | } | ||||
| /* ChildOf Constraint - set inverse callback */ | /* ChildOf Constraint - set inverse callback */ | ||||
| static int childof_set_inverse_exec(bContext *C, wmOperator *op) | static int childof_set_inverse_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | |||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_CHILDOF); | bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_CHILDOF); | ||||
| bChildOfConstraint *data = (con) ? (bChildOfConstraint *)con->data : NULL; | bChildOfConstraint *data = (con) ? (bChildOfConstraint *)con->data : NULL; | ||||
| const int owner = RNA_enum_get(op->ptr, "owner"); | const int owner = RNA_enum_get(op->ptr, "owner"); | ||||
| /* despite 3 layers of checks, we may still not be able to find a constraint */ | /* despite 3 layers of checks, we may still not be able to find a constraint */ | ||||
| if (data == NULL) { | if (data == NULL) { | ||||
| printf("DEBUG: Child-Of Set Inverse - object = '%s'\n", (ob) ? ob->id.name + 2 : "<None>"); | printf("DEBUG: Child-Of Set Inverse - object = '%s'\n", (ob) ? ob->id.name + 2 : "<None>"); | ||||
| BKE_report(op->reports, RPT_ERROR, "Could not find constraint data for Child-Of Set Inverse"); | BKE_report(op->reports, RPT_ERROR, "Could not find constraint data for Child-Of Set Inverse"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| if (owner == EDIT_CONSTRAINT_OWNER_OBJECT) { | if (owner == EDIT_CONSTRAINT_OWNER_OBJECT) { | ||||
| child_get_inverse_matrix_owner_object(C, scene, ob, con, data->invmat); | child_get_inverse_matrix_owner_object(depsgraph, scene, ob, con, data->invmat); | ||||
| } | } | ||||
| else if (owner == EDIT_CONSTRAINT_OWNER_BONE) { | else if (owner == EDIT_CONSTRAINT_OWNER_BONE) { | ||||
| child_get_inverse_matrix_owner_bone(C, op, scene, ob, data->invmat); | child_get_inverse_matrix_owner_bone(depsgraph, op, scene, ob, data->invmat); | ||||
| } | } | ||||
| ED_object_constraint_update(bmain, ob); | ED_object_constraint_update(bmain, ob); | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT, ob); | WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT, ob); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 219 Lines • ▼ Show 20 Lines | RNA_def_int(ot->srna, | ||||
| MAXFRAME); | MAXFRAME); | ||||
| } | } | ||||
| /* ------------- Object Solver Constraint ------------------ */ | /* ------------- Object Solver Constraint ------------------ */ | ||||
| static int objectsolver_set_inverse_exec(bContext *C, wmOperator *op) | static int objectsolver_set_inverse_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | |||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_OBJECTSOLVER); | bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_OBJECTSOLVER); | ||||
| bObjectSolverConstraint *data = (con) ? (bObjectSolverConstraint *)con->data : NULL; | bObjectSolverConstraint *data = (con) ? (bObjectSolverConstraint *)con->data : NULL; | ||||
| const int owner = RNA_enum_get(op->ptr, "owner"); | const int owner = RNA_enum_get(op->ptr, "owner"); | ||||
| /* despite 3 layers of checks, we may still not be able to find a constraint */ | /* despite 3 layers of checks, we may still not be able to find a constraint */ | ||||
| if (data == NULL) { | if (data == NULL) { | ||||
| printf("DEBUG: Child-Of Set Inverse - object = '%s'\n", (ob) ? ob->id.name + 2 : "<None>"); | printf("DEBUG: Child-Of Set Inverse - object = '%s'\n", (ob) ? ob->id.name + 2 : "<None>"); | ||||
| BKE_report(op->reports, RPT_ERROR, "Could not find constraint data for Child-Of Set Inverse"); | BKE_report(op->reports, RPT_ERROR, "Could not find constraint data for Child-Of Set Inverse"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| if (owner == EDIT_CONSTRAINT_OWNER_OBJECT) { | if (owner == EDIT_CONSTRAINT_OWNER_OBJECT) { | ||||
| child_get_inverse_matrix_owner_object(C, scene, ob, con, data->invmat); | child_get_inverse_matrix_owner_object(depsgraph, scene, ob, con, data->invmat); | ||||
| } | } | ||||
| else if (owner == EDIT_CONSTRAINT_OWNER_BONE) { | else if (owner == EDIT_CONSTRAINT_OWNER_BONE) { | ||||
| child_get_inverse_matrix_owner_bone(C, op, scene, ob, data->invmat); | child_get_inverse_matrix_owner_bone(depsgraph, op, scene, ob, data->invmat); | ||||
| } | } | ||||
| ED_object_constraint_update(bmain, ob); | ED_object_constraint_update(bmain, ob); | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT, ob); | WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT, ob); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,059 Lines • Show Last 20 Lines | |||||
Make depsgraph a parameter of this function and get it at the start of childof_set_inverse_exec. Things are not obvious if this happens in deeper functions.