Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/constraint.c
| Show First 20 Lines • Show All 1,457 Lines • ▼ Show 20 Lines | if (VALID_CONS_TARGET(ct) && (ct->tar->type == OB_CURVE)) { | ||||
| float curvetime; | float curvetime; | ||||
| unit_m4(ct->matrix); | unit_m4(ct->matrix); | ||||
| /* note: when creating constraints that follow path, the curve gets the CU_PATH set now, | /* note: when creating constraints that follow path, the curve gets the CU_PATH set now, | ||||
| * currently for paths to work it needs to go through the bevlist/displist system (ton) | * currently for paths to work it needs to go through the bevlist/displist system (ton) | ||||
| */ | */ | ||||
| if (ct->tar->runtime.curve_cache && ct->tar->runtime.curve_cache->path && | if (ct->tar->runtime.curve_cache && ct->tar->runtime.curve_cache->anim_path_accum_length) { | ||||
| ct->tar->runtime.curve_cache->path->data) { | |||||
| float quat[4]; | float quat[4]; | ||||
| if ((data->followflag & FOLLOWPATH_STATIC) == 0) { | if ((data->followflag & FOLLOWPATH_STATIC) == 0) { | ||||
| /* animated position along curve depending on time */ | /* animated position along curve depending on time */ | ||||
| Nurb *nu = cu->nurb.first; | |||||
| curvetime = cu->ctime - data->offset; | curvetime = cu->ctime - data->offset; | ||||
| /* ctime is now a proper var setting of Curve which gets set by Animato like any other var | /* ctime is now a proper var setting of Curve which gets set by Animato like any other var | ||||
| * that's animated, but this will only work if it actually is animated... | * that's animated, but this will only work if it actually is animated... | ||||
| * | * | ||||
| * we divide the curvetime calculated in the previous step by the length of the path, | * we divide the curvetime calculated in the previous step by the length of the path, | ||||
| * to get a time factor, which then gets clamped to lie within 0.0 - 1.0 range. */ | * to get a time factor, which then gets clamped to lie within 0.0 - 1.0 range. */ | ||||
| curvetime /= cu->pathlen; | curvetime /= cu->pathlen; | ||||
| if (nu && nu->flagu & CU_NURB_CYCLIC) { | |||||
| /* If the curve is cyclic, enable looping around if the time is | |||||
| * outside the bounds 0..1 */ | |||||
| if ((curvetime < 0.0f) || (curvetime > 1.0f)) { | |||||
| curvetime -= floorf(curvetime); | |||||
| } | |||||
| } | |||||
| else { | |||||
| /* The curve is not cyclic, so clamp to the begin/end points. */ | |||||
| CLAMP(curvetime, 0.0f, 1.0f); | |||||
| } | |||||
| } | } | ||||
| else { | else { | ||||
| /* fixed position along curve */ | /* fixed position along curve */ | ||||
| curvetime = data->offset_fac; | curvetime = data->offset_fac; | ||||
| } | } | ||||
| if (where_on_path(ct->tar, | if (BKE_where_on_path(ct->tar, | ||||
| curvetime, | curvetime, | ||||
| vec, | vec, | ||||
| dir, | dir, | ||||
| (data->followflag & FOLLOWPATH_FOLLOW) ? quat : NULL, | (data->followflag & FOLLOWPATH_FOLLOW) ? quat : NULL, | ||||
| &radius, | &radius, | ||||
| NULL)) { /* quat_pt is quat or NULL*/ | NULL)) { /* quat_pt is quat or NULL*/ | ||||
| float totmat[4][4]; | float totmat[4][4]; | ||||
| unit_m4(totmat); | unit_m4(totmat); | ||||
| if (data->followflag & FOLLOWPATH_FOLLOW) { | if (data->followflag & FOLLOWPATH_FOLLOW) { | ||||
| quat_apply_track(quat, data->trackflag, data->upflag); | quat_apply_track(quat, data->trackflag, data->upflag); | ||||
| quat_to_mat4(totmat, quat); | quat_to_mat4(totmat, quat); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 2,266 Lines • ▼ Show 20 Lines | if (VALID_CONS_TARGET(ct) && (ct->tar->type == OB_CURVE)) { | ||||
| copy_v3_v3(ownLoc, obmat[3]); | copy_v3_v3(ownLoc, obmat[3]); | ||||
| unit_m4(targetMatrix); | unit_m4(targetMatrix); | ||||
| INIT_MINMAX(curveMin, curveMax); | INIT_MINMAX(curveMin, curveMax); | ||||
| /* XXX - don't think this is good calling this here - campbell */ | /* XXX - don't think this is good calling this here - campbell */ | ||||
| BKE_object_minmax(ct->tar, curveMin, curveMax, true); | BKE_object_minmax(ct->tar, curveMin, curveMax, true); | ||||
| /* get targetmatrix */ | /* get targetmatrix */ | ||||
| if (data->tar->runtime.curve_cache && data->tar->runtime.curve_cache->path && | if (data->tar->runtime.curve_cache && data->tar->runtime.curve_cache->anim_path_accum_length) { | ||||
| data->tar->runtime.curve_cache->path->data) { | |||||
| float vec[4], dir[3], totmat[4][4]; | float vec[4], dir[3], totmat[4][4]; | ||||
| float curvetime; | float curvetime; | ||||
| short clamp_axis; | short clamp_axis; | ||||
| /* find best position on curve */ | /* find best position on curve */ | ||||
| /* 1. determine which axis to sample on? */ | /* 1. determine which axis to sample on? */ | ||||
| if (data->flag == CLAMPTO_AUTO) { | if (data->flag == CLAMPTO_AUTO) { | ||||
| float size[3]; | float size[3]; | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | if (data->tar->runtime.curve_cache && data->tar->runtime.curve_cache->anim_path_accum_length) { | ||||
| (curveMax[clamp_axis] - curveMin[clamp_axis]); | (curveMax[clamp_axis] - curveMin[clamp_axis]); | ||||
| } | } | ||||
| else { | else { | ||||
| curvetime = 0.0f; | curvetime = 0.0f; | ||||
| } | } | ||||
| } | } | ||||
| /* 3. position on curve */ | /* 3. position on curve */ | ||||
| if (where_on_path(ct->tar, curvetime, vec, dir, NULL, NULL, NULL)) { | if (BKE_where_on_path(ct->tar, curvetime, vec, dir, NULL, NULL, NULL)) { | ||||
| unit_m4(totmat); | unit_m4(totmat); | ||||
| copy_v3_v3(totmat[3], vec); | copy_v3_v3(totmat[3], vec); | ||||
| mul_m4_m4m4(targetMatrix, ct->tar->obmat, totmat); | mul_m4_m4m4(targetMatrix, ct->tar->obmat, totmat); | ||||
| } | } | ||||
| } | } | ||||
| /* obtain final object position */ | /* obtain final object position */ | ||||
| ▲ Show 20 Lines • Show All 2,561 Lines • Show Last 20 Lines | |||||