I'm trying to recreate the CHOP Lag / Overshoot / Smooth in vex. Trying to add some features to a little sequential value generator i'm feeding to animated geos / cameras to automate animatino.
Script looks like that, but it's all a bit abrupt, the ease in and out function is not working as expected, I'd love to smooth things in and out with controls. Any pointers welcome.
Cheers.
int frame = @Frame;
// Timing Controls
int rot_interval = chi("rot_interval");
int pause_interval = chi("pause_interval");
float rot_rand = chf("rot_interval_randomness");
float pause_rand = chf("pause_interval_randomness");
float ease = chf("ease");
// Axis Controls
float x_step = chf("x_step");
float y_step = chf("y_step");
float z_step = chf("z_step");
float flip_prob_x = chf("flip_prob_x");
float flip_prob_y = chf("flip_prob_y");
float flip_prob_z = chf("flip_prob_z");
int auto_pingpong = chi("auto_pingpong");
int dir_manual_x = chi("dir_manual_x");
int dir_manual_y = chi("dir_manual_y");
int dir_manual_z = chi("dir_manual_z");
// Estimate rough phase
int estimated_total = rot_interval + pause_interval;
int rough_phase = frame / estimated_total;
// Random Phase durations
float rand_rot = fit01(random(rough_phase * 111.1), 1.0 - rot_rand, 1.0 + rot_rand);
float rand_pause = fit01(random(rough_phase * 222.2), 1.0 - pause_rand, 1.0 + pause_rand);
int actual_rot = max(1, int(rot_interval * rand_rot));
int actual_pause = max(0, int(pause_interval * rand_pause));
int total = actual_rot + actual_pause;
int phase = frame / total;
int local_frame = frame % total;
// Axis setup
vector step = set(x_step, y_step, z_step);
vector flip_probs = set(flip_prob_x, flip_prob_y, flip_prob_z);
vector rot = {0, 0, 0};
vector base = {0, 0, 0};
int dir_table = array(dir_manual_x, dir_manual_y, dir_manual_z);
// per-axis rotation accumulation with direction
for (int axis = 0; axis < 3; axis++) {
float acc = 0;
int dir = dir_table;
// Flip history
for (int i = 0; i < phase; i++) {
if (auto_pingpong == 1 && random((i + axis * 1000) * 999.9) < flip_probs) {
dir *= -1;
}
acc += dir * step;
}
base = acc;
// Flip this phase
if (auto_pingpong == 1 && random((phase + axis * 1000) * 999.9) < flip_probs) {
dir *= -1;
}
float target = acc + dir * step;
if (local_frame < actual_rot) {
float t = clamp(float(local_frame) / float(actual_rot), 0.0, 1.0);
float s = t * t * (3.0 - 2.0 * t);
float shape = lerp(t, s, ease);
rot = lerp(acc, target, shape);
} else {
rot = target;
}
}
@x_rot = rot.x;
@y_rot = rot.y;
@z_rot = rot.z;
Lag / Overshoot / Smooth in VEX
263 0 1-
- Adriano
- Member
- 411 posts
- Joined: June 2015
- Online
-
- Quick Links