Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/constraint.c
| Show All 28 Lines | |||||
| #include <stddef.h> | #include <stddef.h> | ||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #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" | ||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "DNA_action_types.h" | #include "DNA_action_types.h" | ||||
| #include "DNA_armature_types.h" | #include "DNA_armature_types.h" | ||||
| #include "DNA_cachefile_types.h" | #include "DNA_cachefile_types.h" | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| bConstraint *con) | bConstraint *con) | ||||
| { | { | ||||
| if (!con) { | if (!con) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| 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)); | /* We need the evaluated constraint (e.g. shrinkwrap needs to access evaluated constraint target | ||||
| * mesh). */ | |||||
| 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( | ||||
| depsgraph, scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT); | depsgraph, scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT); | ||||
sergey: For the consistency is better to pass `secene_eval` and `ob_eval`. | |||||
| /* 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->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); | ||||
| /* Copy transforms back. This will leave the object in a bad state | /* Copy transforms back. This will leave the object in a bad state | ||||
| * as ob->constinv will be wrong until next evaluation. */ | * as ob->constinv will be wrong until next evaluation. */ | ||||
| BKE_constraints_clear_evalob(cob); | BKE_constraints_clear_evalob(cob); | ||||
| Show All 25 Lines | |||||
| Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan, bConstraint *con) | Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan, bConstraint *con) | ||||
| { | { | ||||
| if (!con) { | if (!con) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| 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)); | /* We need the evaluated constraint (e.g. shrinkwrap needs to access evaluated constraint target | ||||
| * mesh). */ | |||||
| 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->pose_mat[3]); | ||||
| bConstraintOb *cob = BKE_constraints_make_evalob( | bConstraintOb *cob = BKE_constraints_make_evalob( | ||||
| depsgraph, scene, ob, pchan, CONSTRAINT_OBTYPE_BONE); | depsgraph, scene, ob, pchan, CONSTRAINT_OBTYPE_BONE); | ||||
sergeyUnsubmitted Not Done Inline ActionsSame as above. sergey: Same as above. | |||||
| /* 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->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); | ||||
| /* Free the copied constraint. */ | /* Free the copied constraint. */ | ||||
| BKE_constraint_free_data(new_con); | BKE_constraint_free_data(new_con); | ||||
| ▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines | |||||
For the consistency is better to pass secene_eval and ob_eval.