CoolFace
Apppublic

CyberSys/fruit-fly-simulation

sourceHugging Faceapache-2.0updated 16d agoView on Hugging Face
0likes
wings.js20 linesDownload Raw Back to src
1// Joint-space envelope measured against the supplied thorax/abdomen meshes.2// Original hinges and meshes are preserved. Angles are in model joint axes.3export const WINGBEAT_HZ = 277;4const clamp = (x) => Math.max(0, Math.min(1, x));5export function wingPose(state, phaseOffset = 0) {6  const extension = clamp(state.wingOpen || 0);7  const amplitude = clamp((extension - 0.7) / 0.3);8  const phase = (state.time || 0) * Math.PI * 2 * WINGBEAT_HZ + phaseOffset;9  const pose = {};10  for (const side of ['l', 'r']) {11    const sign = side === 'l' ? 1 : -1,12      prefix = `c_thorax-${side}_wing-`;13    pose[prefix + 'pitch'] = ((30 - 20 * extension) * Math.PI) / 180;14    pose[prefix + 'roll'] = (-75 * extension * sign * Math.PI) / 180;15    pose[prefix + 'yaw'] =16      ((5 + 15 * extension + 35 * amplitude * Math.sin(phase)) * sign * Math.PI) / 180;17  }18  return pose;19}20