finger-loops.js

At 0ab6736Copy the commit ID

0ab6736History

Preview

Code1.2 KiB
export const floorY = -1.52;

const rest = [
  [12, 18, 9, -14],
  [0, 13, 19, 2],
  [1, 13, 16, 0],
  [4, 14, 18, -3],
  [8, 18, 20, -5],
];

// Each contact pose brings the padded fingertip to the plane.
const contact = [
  rest[0],
  [16, 20, 18, 2],
  [15, 17, 18, 0],
  [19, 18, 18, -3],
  [31, 25, 20, -5],
];

export const fingerLoops = {
  tap: { length: 1.37, hits: [[1, .29], [1, .84]] },
  drum: { length: 1.16, hits: [[4, .22], [3, .37], [2, .52], [1, .67]] },
};

function stroke(time) {
  const progress = Math.min(1, Math.max(0, time < 0 ? 1 + time / .13 : 1 - (time - .044) / .15));
  return progress * progress * (3 - 2 * progress);
}

export function fingerLoopPose({ length, hits }, progress) {
  const seconds = progress * length;
  const strengths = rest.map(() => 0);
  for (const [finger, beat] of hits) {
    strengths[finger] = Math.max(strengths[finger], stroke(seconds - beat));
  }

  return {
    x: -.26, y: floorY + .55, z: .18, tilt: 90, turn: 142, roll: -4,
    width: 1, height: 1, open: 1, floorView: 1,
    fingers: rest.map((digit, finger) =>
      digit.map((angle, joint) => angle + (contact[finger][joint] - angle) * strengths[finger])),
    cue: 0, spark: 0, sparkX: 0, sparkY: 0, rise: 0,
  };
}

Files