Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/constraint.c
| Context not available. | |||||
| #include "BLI_blenlib.h" | #include "BLI_blenlib.h" | ||||
| #include "BLI_kdopbvh.h" | #include "BLI_kdopbvh.h" | ||||
| #include "BLI_listbase.h" | |||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_string_utils.h" | #include "BLI_string_utils.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| Context not available. | |||||
| const float ctime = BKE_scene_frame_get(scene); | const float ctime = BKE_scene_frame_get(scene); | ||||
| bConstraint *new_con = BKE_constraint_duplicate_ex(con, 0, !ID_IS_LINKED(ob)); | /* Do this all in the evaluated domain (e.g. shrinkwrap needs to access evaluated constraint | ||||
| * target mesh). */ | |||||
| Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); | |||||
| Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | |||||
| bConstraint *con_eval = BKE_constraints_find_name(&ob_eval->constraints, con->name); | |||||
| bConstraint *new_con = BKE_constraint_duplicate_ex(con_eval, 0, !ID_IS_LINKED(ob)); | |||||
| ListBase single_con = {new_con, new_con}; | ListBase single_con = {new_con, new_con}; | ||||
| bConstraintOb *cob = BKE_constraints_make_evalob( | bConstraintOb *cob = BKE_constraints_make_evalob( | ||||
sergey: For the consistency is better to pass `secene_eval` and `ob_eval`. | |||||
| depsgraph, scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT); | depsgraph, scene_eval, ob_eval, NULL, CONSTRAINT_OBTYPE_OBJECT); | ||||
| /* Undo the effect of the current constraint stack evaluation. */ | /* Undo the effect of the current constraint stack evaluation. */ | ||||
| mul_m4_m4m4(cob->matrix, ob->constinv, cob->matrix); | mul_m4_m4m4(cob->matrix, ob_eval->constinv, cob->matrix); | ||||
| /* Evaluate single constraint. */ | /* Evaluate single constraint. */ | ||||
| BKE_constraints_solve(depsgraph, &single_con, cob, ctime); | BKE_constraints_solve(depsgraph, &single_con, cob, ctime); | ||||
| Context not available. | |||||
| BLI_freelinkN(&single_con, new_con); | BLI_freelinkN(&single_con, new_con); | ||||
| /* Apply transform from matrix. */ | /* Apply transform from matrix. */ | ||||
| BKE_object_apply_mat4(ob, ob->obmat, true, true); | BKE_object_apply_mat4(ob, ob_eval->obmat, true, true); | ||||
| return true; | return true; | ||||
| } | } | ||||
| Context not available. | |||||
| const float ctime = BKE_scene_frame_get(scene); | const float ctime = BKE_scene_frame_get(scene); | ||||
| bConstraint *new_con = BKE_constraint_duplicate_ex(con, 0, !ID_IS_LINKED(ob)); | /* Do this all in the evaluated domain (e.g. shrinkwrap needs to access evaluated constraint | ||||
| * target mesh). */ | |||||
| Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); | |||||
| Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | |||||
| bPoseChannel *pchan_eval = BKE_pose_channel_find_name(ob_eval->pose, pchan->name); | |||||
| bConstraint *con_eval = BKE_constraints_find_name(&pchan_eval->constraints, con->name); | |||||
| bConstraint *new_con = BKE_constraint_duplicate_ex(con_eval, 0, !ID_IS_LINKED(ob)); | |||||
| ListBase single_con; | ListBase single_con; | ||||
| single_con.first = new_con; | single_con.first = new_con; | ||||
| single_con.last = new_con; | single_con.last = new_con; | ||||
| float vec[3]; | float vec[3]; | ||||
| copy_v3_v3(vec, pchan->pose_mat[3]); | copy_v3_v3(vec, pchan_eval->pose_mat[3]); | ||||
Not Done Inline ActionsSame as above. sergey: Same as above. | |||||
| bConstraintOb *cob = BKE_constraints_make_evalob( | bConstraintOb *cob = BKE_constraints_make_evalob( | ||||
| depsgraph, scene, ob, pchan, CONSTRAINT_OBTYPE_BONE); | depsgraph, scene_eval, ob_eval, pchan_eval, CONSTRAINT_OBTYPE_BONE); | ||||
| /* Undo the effects of currently applied constraints. */ | /* Undo the effects of currently applied constraints. */ | ||||
| mul_m4_m4m4(cob->matrix, pchan->constinv, cob->matrix); | mul_m4_m4m4(cob->matrix, pchan_eval->constinv, cob->matrix); | ||||
| /* Evaluate single constraint. */ | /* Evaluate single constraint. */ | ||||
| BKE_constraints_solve(depsgraph, &single_con, cob, ctime); | BKE_constraints_solve(depsgraph, &single_con, cob, ctime); | ||||
| BKE_constraints_clear_evalob(cob); | BKE_constraints_clear_evalob(cob); | ||||
| Context not available. | |||||
| /* Prevent constraints breaking a chain. */ | /* Prevent constraints breaking a chain. */ | ||||
| if (pchan->bone->flag & BONE_CONNECTED) { | if (pchan->bone->flag & BONE_CONNECTED) { | ||||
| copy_v3_v3(pchan->pose_mat[3], vec); | copy_v3_v3(pchan_eval->pose_mat[3], vec); | ||||
| } | } | ||||
| /* Apply transform from matrix. */ | /* Apply transform from matrix. */ | ||||
| float mat[4][4]; | float mat[4][4]; | ||||
| BKE_armature_mat_pose_to_bone(pchan, pchan->pose_mat, mat); | BKE_armature_mat_pose_to_bone(pchan, pchan_eval->pose_mat, mat); | ||||
| BKE_pchan_apply_mat4(pchan, mat, true); | BKE_pchan_apply_mat4(pchan, mat, true); | ||||
| return true; | return true; | ||||
| Context not available. | |||||
For the consistency is better to pass secene_eval and ob_eval.