import { V as w, a as t, b as F } from "../../../three-vrm.module--Wx-EJJ8.js";
import { M as s, V as H, a as k, E as S, Q as d } from "../../../three.module-g4QKgdLf.js";
import { clampByRadian as L } from "../three-helpers.js";
const T = 30, U = 1, R = s.degToRad(60), y = 0, m = s.degToRad(75), N = s.degToRad(15), B = s.degToRad(30), f = s.degToRad(-5), O = 0.5, V = 10, p = 0.2, G = 2, c = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), D = new H(), C = new d(), z = new d(), b = new d(), M = new k(), l = new S(0, 0, 0, w.EULER_ORDER), K = r(0, 0, m), i = r(0, 0, N), _ = r(0, B, 0), Q = r(
  0,
  0,
  f
), W = r(
  0,
  0,
  m - f
), v = r(0, 0, -m), a = r(
  0,
  0,
  -N
), P = r(0, -B, 0), Y = r(
  0,
  0,
  -f
), q = r(
  0,
  0,
  f - m
), X = /* @__PURE__ */ new Map([
  [t.LeftShoulder, new d()],
  [t.LeftUpperArm, K],
  [t.LeftIndexDistal, i],
  [t.LeftIndexIntermediate, i],
  [t.LeftIndexProximal, i],
  [t.LeftLittleDistal, i],
  [t.LeftLittleIntermediate, i],
  [t.LeftLittleProximal, i],
  [t.LeftMiddleDistal, i],
  [t.LeftMiddleIntermediate, i],
  [t.LeftMiddleProximal, i],
  [t.LeftRingDistal, i],
  [t.LeftRingIntermediate, i],
  [t.LeftRingProximal, i],
  [t.LeftThumbDistal, _],
  [t.LeftThumbMetacarpal, _],
  [t.LeftThumbProximal, i],
  [t.RightShoulder, new d()],
  [t.RightUpperArm, v],
  [t.RightIndexDistal, a],
  [t.RightIndexIntermediate, a],
  [t.RightIndexProximal, a],
  [t.RightLittleDistal, a],
  [t.RightLittleIntermediate, a],
  [t.RightLittleProximal, a],
  [t.RightMiddleDistal, a],
  [t.RightMiddleIntermediate, a],
  [t.RightMiddleProximal, a],
  [t.RightRingDistal, a],
  [t.RightRingIntermediate, a],
  [t.RightRingProximal, a],
  [t.RightThumbDistal, P],
  [t.RightThumbMetacarpal, P],
  [t.RightThumbProximal, a]
]), j = /* @__PURE__ */ new Map([
  [t.LeftShoulder, Q],
  [t.LeftUpperArm, W],
  [t.RightShoulder, Y],
  [t.RightUpperArm, q]
]);
function r(e, n, o) {
  return new d().setFromEuler(l.set(e, n, o));
}
function ot(e) {
  const { lookAt: n } = e;
  !n || c.has(e) || c.set(e, n);
}
function it(e) {
  const n = c.get(e);
  n && (n.target = void 0, c.delete(e), A.delete(e));
}
function at(e, n) {
  c.has(e) && (J(e, n), Z(e, n), $(e, n));
}
function J(e, n) {
  var h, g;
  const o = (h = e.firstPerson) == null ? void 0 : h.humanoid.getNormalizedBoneNode(
    t.Head
  );
  o && (D.set(0, 0, 1).applyMatrix4(M), D.z < 0 ? l.setFromRotationMatrix(M).set(
    L(-l.x, -R, R),
    L(
      Math.PI + l.y,
      -R,
      R
    ) + Math.PI,
    L(l.z, -R, R)
  ) : l.set(0, Math.PI, 0), o.quaternion.slerp(
    C.setFromEuler(l).multiply(
      b.setFromRotationMatrix(
        ((g = o.parent) == null ? void 0 : g.matrixWorld) || M.identity()
      )
    ),
    Math.min(
      s.damp(0, 1, U, n * T),
      1
    )
  ));
}
function Z(e, n) {
  if (!e.expressionManager)
    return;
  let o = x.get(e);
  o == null || o < -p ? o = s.randFloat(O, V) : o -= n, x.set(e, o), e.expressionManager.setValue(
    F.Blink,
    o > y ? 0 : s.pingpong(-o, p / 2) * 2 / p
  );
}
function $(e, n) {
  if (!e.humanoid)
    return;
  const o = (A.get(e) || 0) + n;
  A.set(e, o);
  for (const [h, g] of X) {
    const u = e.humanoid.getNormalizedBoneNode(h);
    let I = g;
    const E = j.get(h);
    E && (I = z.copy(g).slerp(E, s.pingpong(o, G))), u && u.setRotationFromQuaternion(
      b.setFromRotationMatrix(u.matrix).slerp(I, Math.min(n * T, 1))
    );
  }
}
export {
  ot as registerModel,
  it as unregisterModel,
  at as updateModel
};
