Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/constraint.c
| Show First 20 Lines • Show All 854 Lines • ▼ Show 20 Lines | static void childof_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets) | ||||
| bConstraintTarget *ct = targets->first; | bConstraintTarget *ct = targets->first; | ||||
| /* only evaluate if there is a target */ | /* only evaluate if there is a target */ | ||||
| if (!VALID_CONS_TARGET(ct)) { | if (!VALID_CONS_TARGET(ct)) { | ||||
| return; | return; | ||||
| } | } | ||||
| float parmat[4][4]; | float parmat[4][4]; | ||||
| /* Simple matrix parenting. */ | |||||
| /* simple matrix parenting */ | if ((data->flag & CHILDOF_ALL) == CHILDOF_ALL) { | ||||
| if (data->flag == CHILDOF_ALL) { | copy_m4_m4(parmat, ct->matrix); | ||||
| /* multiply target (parent matrix) by offset (parent inverse) to get | |||||
| * the effect of the parent that will be exerted on the owner | |||||
| */ | |||||
| mul_m4_m4m4(parmat, ct->matrix, data->invmat); | |||||
| /* now multiply the parent matrix by the owner matrix to get the | |||||
| * the effect of this constraint (i.e. owner is 'parented' to parent) | |||||
| */ | |||||
| mul_m4_m4m4(cob->matrix, parmat, cob->matrix); | |||||
| } | } | ||||
| /* Filter the parent matrix by channel. */ | |||||
| else { | else { | ||||
| float invmat[4][4], tempmat[4][4]; | |||||
| float loc[3], eul[3], size[3]; | float loc[3], eul[3], size[3]; | ||||
| float loco[3], eulo[3], sizo[3]; | |||||
| /* get offset (parent-inverse) matrix */ | |||||
| copy_m4_m4(invmat, data->invmat); | |||||
| /* extract components of both matrices */ | /* extract components of both matrices */ | ||||
| copy_v3_v3(loc, ct->matrix[3]); | copy_v3_v3(loc, ct->matrix[3]); | ||||
| mat4_to_eulO(eul, ct->rotOrder, ct->matrix); | mat4_to_eulO(eul, ct->rotOrder, ct->matrix); | ||||
| mat4_to_size(size, ct->matrix); | mat4_to_size(size, ct->matrix); | ||||
| copy_v3_v3(loco, invmat[3]); | |||||
| mat4_to_eulO(eulo, cob->rotOrder, invmat); | |||||
| mat4_to_size(sizo, invmat); | |||||
| /* disable channels not enabled */ | /* disable channels not enabled */ | ||||
| if (!(data->flag & CHILDOF_LOCX)) { | if (!(data->flag & CHILDOF_LOCX)) { | ||||
| loc[0] = loco[0] = 0.0f; | loc[0] = 0.0f; | ||||
| } | } | ||||
| if (!(data->flag & CHILDOF_LOCY)) { | if (!(data->flag & CHILDOF_LOCY)) { | ||||
| loc[1] = loco[1] = 0.0f; | loc[1] = 0.0f; | ||||
| } | } | ||||
| if (!(data->flag & CHILDOF_LOCZ)) { | if (!(data->flag & CHILDOF_LOCZ)) { | ||||
| loc[2] = loco[2] = 0.0f; | loc[2] = 0.0f; | ||||
| } | } | ||||
| if (!(data->flag & CHILDOF_ROTX)) { | if (!(data->flag & CHILDOF_ROTX)) { | ||||
| eul[0] = eulo[0] = 0.0f; | eul[0] = 0.0f; | ||||
| } | } | ||||
| if (!(data->flag & CHILDOF_ROTY)) { | if (!(data->flag & CHILDOF_ROTY)) { | ||||
| eul[1] = eulo[1] = 0.0f; | eul[1] = 0.0f; | ||||
| } | } | ||||
| if (!(data->flag & CHILDOF_ROTZ)) { | if (!(data->flag & CHILDOF_ROTZ)) { | ||||
| eul[2] = eulo[2] = 0.0f; | eul[2] = 0.0f; | ||||
| } | } | ||||
| if (!(data->flag & CHILDOF_SIZEX)) { | if (!(data->flag & CHILDOF_SIZEX)) { | ||||
| size[0] = sizo[0] = 1.0f; | size[0] = 1.0f; | ||||
| } | } | ||||
| if (!(data->flag & CHILDOF_SIZEY)) { | if (!(data->flag & CHILDOF_SIZEY)) { | ||||
| size[1] = sizo[1] = 1.0f; | size[1] = 1.0f; | ||||
| } | } | ||||
| if (!(data->flag & CHILDOF_SIZEZ)) { | if (!(data->flag & CHILDOF_SIZEZ)) { | ||||
| size[2] = sizo[2] = 1.0f; | size[2] = 1.0f; | ||||
| } | } | ||||
| /* make new target mat and offset mat */ | /* make new target mat and offset mat */ | ||||
| loc_eulO_size_to_mat4(ct->matrix, loc, eul, size, ct->rotOrder); | loc_eulO_size_to_mat4(parmat, loc, eul, size, ct->rotOrder); | ||||
| loc_eulO_size_to_mat4(invmat, loco, eulo, sizo, cob->rotOrder); | } | ||||
| /* multiply target (parent matrix) by offset (parent inverse) to get | /* Compute the inverse matrix if requested. */ | ||||
| * the effect of the parent that will be exerted on the owner | if (data->flag & CHILDOF_SET_INVERSE) { | ||||
| */ | invert_m4_m4(data->invmat, parmat); | ||||
| mul_m4_m4m4(parmat, ct->matrix, invmat); | |||||
| /* now multiply the parent matrix by the owner matrix to get the | data->flag &= ~CHILDOF_SET_INVERSE; | ||||
| * the effect of this constraint (i.e. owner is 'parented' to parent) | |||||
| */ | /* Write the computed matrix back to the master copy if in COW evaluation. */ | ||||
| copy_m4_m4(tempmat, cob->matrix); | bConstraint *orig_con = constraint_find_original_for_update(cob, con); | ||||
| mul_m4_m4m4(cob->matrix, parmat, tempmat); | |||||
| if (orig_con != NULL) { | |||||
| bChildOfConstraint *orig_data = orig_con->data; | |||||
| copy_m4_m4(orig_data->invmat, data->invmat); | |||||
| orig_data->flag &= ~CHILDOF_SET_INVERSE; | |||||
| } | |||||
| } | |||||
| /* without this, changes to scale and rotation can change location | /* Multiply together the target (parent) matrix, parent inverse, | ||||
| * and the owner transform matrixto get the effect of this constraint | |||||
sybren: The space that should be between "matrixto" sneakily made its way to become a double space… | |||||
| * (i.e. owner is 'parented' to parent). */ | |||||
| float orig_cob_matrix[4][4]; | |||||
| copy_m4_m4(orig_cob_matrix, cob->matrix); | |||||
| mul_m4_series(cob->matrix, parmat, data->invmat, orig_cob_matrix); | |||||
| /* Without this, changes to scale and rotation can change location | |||||
| * of a parentless bone or a disconnected bone. Even though its set | * of a parentless bone or a disconnected bone. Even though its set | ||||
| * to zero above. */ | * to zero above. */ | ||||
| if (!(data->flag & CHILDOF_LOCX)) { | if (!(data->flag & CHILDOF_LOCX)) { | ||||
| cob->matrix[3][0] = tempmat[3][0]; | cob->matrix[3][0] = orig_cob_matrix[3][0]; | ||||
| } | } | ||||
| if (!(data->flag & CHILDOF_LOCY)) { | if (!(data->flag & CHILDOF_LOCY)) { | ||||
| cob->matrix[3][1] = tempmat[3][1]; | cob->matrix[3][1] = orig_cob_matrix[3][1]; | ||||
| } | } | ||||
| if (!(data->flag & CHILDOF_LOCZ)) { | if (!(data->flag & CHILDOF_LOCZ)) { | ||||
| cob->matrix[3][2] = tempmat[3][2]; | cob->matrix[3][2] = orig_cob_matrix[3][2]; | ||||
| } | |||||
| } | } | ||||
| } | } | ||||
| /* XXX note, con->flag should be CONSTRAINT_SPACEONCE for bone-childof, patched in readfile.c */ | /* XXX note, con->flag should be CONSTRAINT_SPACEONCE for bone-childof, patched in readfile.c */ | ||||
| static bConstraintTypeInfo CTI_CHILDOF = { | static bConstraintTypeInfo CTI_CHILDOF = { | ||||
| CONSTRAINT_TYPE_CHILDOF, /* type */ | CONSTRAINT_TYPE_CHILDOF, /* type */ | ||||
| sizeof(bChildOfConstraint), /* size */ | sizeof(bChildOfConstraint), /* size */ | ||||
| "Child Of", /* name */ | "Child Of", /* name */ | ||||
| ▲ Show 20 Lines • Show All 3,928 Lines • ▼ Show 20 Lines | static void objectsolver_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets)) | ||||
| MovieTracking *tracking = &clip->tracking; | MovieTracking *tracking = &clip->tracking; | ||||
| MovieTrackingObject *object; | MovieTrackingObject *object; | ||||
| object = BKE_tracking_object_get_named(tracking, data->object); | object = BKE_tracking_object_get_named(tracking, data->object); | ||||
| if (!object) { | if (!object) { | ||||
| return; | return; | ||||
| } | } | ||||
| float mat[4][4], obmat[4][4], imat[4][4], cammat[4][4], camimat[4][4], parmat[4][4]; | float mat[4][4], obmat[4][4], imat[4][4], parmat[4][4]; | ||||
| float ctime = DEG_get_ctime(depsgraph); | float ctime = DEG_get_ctime(depsgraph); | ||||
| float framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, ctime); | float framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, ctime); | ||||
| BKE_object_where_is_calc_mat4(camob, cammat); | |||||
| BKE_tracking_camera_get_reconstructed_interpolate(tracking, object, framenr, mat); | BKE_tracking_camera_get_reconstructed_interpolate(tracking, object, framenr, mat); | ||||
| invert_m4_m4(camimat, cammat); | invert_m4_m4(imat, mat); | ||||
| mul_m4_m4m4(parmat, cammat, data->invmat); | mul_m4_m4m4(parmat, camob->obmat, imat); | ||||
| copy_m4_m4(cammat, camob->obmat); | |||||
| copy_m4_m4(obmat, cob->matrix); | copy_m4_m4(obmat, cob->matrix); | ||||
| invert_m4_m4(imat, mat); | /* Recalculate the inverse matrix if requested. */ | ||||
| if (data->flag & OBJECTSOLVER_SET_INVERSE) { | |||||
| invert_m4_m4(data->invmat, parmat); | |||||
| data->flag &= ~OBJECTSOLVER_SET_INVERSE; | |||||
| /* Write the computed matrix back to the master copy if in COW evaluation. */ | |||||
| bConstraint *orig_con = constraint_find_original_for_update(cob, con); | |||||
| if (orig_con != NULL) { | |||||
| bObjectSolverConstraint *orig_data = orig_con->data; | |||||
| copy_m4_m4(orig_data->invmat, data->invmat); | |||||
| orig_data->flag &= ~OBJECTSOLVER_SET_INVERSE; | |||||
| } | |||||
| } | |||||
| mul_m4_series(cob->matrix, cammat, imat, camimat, parmat, obmat); | mul_m4_series(cob->matrix, parmat, data->invmat, obmat); | ||||
| } | } | ||||
| static bConstraintTypeInfo CTI_OBJECTSOLVER = { | static bConstraintTypeInfo CTI_OBJECTSOLVER = { | ||||
| CONSTRAINT_TYPE_OBJECTSOLVER, /* type */ | CONSTRAINT_TYPE_OBJECTSOLVER, /* type */ | ||||
| sizeof(bObjectSolverConstraint), /* size */ | sizeof(bObjectSolverConstraint), /* size */ | ||||
| "Object Solver", /* name */ | "Object Solver", /* name */ | ||||
| "bObjectSolverConstraint", /* struct name */ | "bObjectSolverConstraint", /* struct name */ | ||||
| NULL, /* free data */ | NULL, /* free data */ | ||||
| ▲ Show 20 Lines • Show All 912 Lines • Show Last 20 Lines | |||||
The space that should be between "matrixto" sneakily made its way to become a double space between "i.e. owner".