@adatechnology/game-characters-three 0.9.6 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1048,6 +1048,7 @@ var createPlayerAvatar = (THREE, options = {}) => {
1048
1048
  parent.add(mesh);
1049
1049
  return mesh;
1050
1050
  };
1051
+ const TRIGGER_CURL = 1.22;
1051
1052
  const hands = [];
1052
1053
  rig.arms.forEach((arm, index) => {
1053
1054
  const el = arm.el;
@@ -1080,6 +1081,7 @@ var createPlayerAvatar = (THREE, options = {}) => {
1080
1081
  eyeSocket.position.set(BUILDER_EYE[0] + eyeOffset[0], BUILDER_EYE[1] + eyeOffset[1], BUILDER_EYE[2] + eyeOffset[2]);
1081
1082
  rig.headG.children[0].add(eyeSocket);
1082
1083
  const headHider = createHeadHider([rig.headG, ...rig.neck ? [rig.neck] : []]);
1084
+ const armsHider = createHeadHider(rig.arms.map((arm) => arm.g));
1083
1085
  const eyeLocal = new THREE.Vector3();
1084
1086
  let bob = 0;
1085
1087
  let hipWithoutBob = null;
@@ -1427,7 +1429,10 @@ var createPlayerAvatar = (THREE, options = {}) => {
1427
1429
  root.updateWorldMatrix(true, false);
1428
1430
  return root.localToWorld(out.copy(eyeLocal));
1429
1431
  },
1430
- setView: (mode, camera) => headHider.setView(mode, camera),
1432
+ setView: (mode, camera, viewOptions) => {
1433
+ headHider.setView(mode, camera);
1434
+ armsHider.setView(viewOptions?.arms ? mode : "third", camera);
1435
+ },
1431
1436
  play(clip, playOptions = {}) {
1432
1437
  const found = typeof clip === "string" ? clips.get(clip) : clip;
1433
1438
  if (!found) throw new Error(`Unknown pose clip: ${String(clip)}`);
@@ -1444,6 +1449,13 @@ var createPlayerAvatar = (THREE, options = {}) => {
1444
1449
  if (run || fall > 0) return;
1445
1450
  root.updateMatrixWorld(true);
1446
1451
  armReach.apply(targets, view);
1452
+ for (const hand of hands) {
1453
+ const curl = hand.side < 0 ? targets?.fingers?.index : targets?.fingersL?.index;
1454
+ if (curl === void 0 || !hand.fingers[1]) continue;
1455
+ const k = TRIGGER_CURL * Math.min(1, Math.max(0, curl));
1456
+ hand.fingers[0].rotation.z = -hand.side * k * 0.9;
1457
+ hand.fingers[1].rotation.z = -hand.side * k * 1.1;
1458
+ }
1447
1459
  },
1448
1460
  on(_type, listener) {
1449
1461
  listeners.add(listener);
@@ -1533,7 +1545,7 @@ var toRoomAvatar = (avatar, options = {}) => {
1533
1545
  root: avatar.root,
1534
1546
  avatar,
1535
1547
  eye: (out) => avatar.eye(out),
1536
- setView: (mode, camera) => avatar.setView(mode, camera),
1548
+ setView: (mode, camera, options2) => avatar.setView(mode, camera, options2),
1537
1549
  update: (dt, state) => {
1538
1550
  stepGuard(dt, state);
1539
1551
  updateFeet(state);
@@ -1898,7 +1910,7 @@ function createFirstPersonArms(THREE, options = {}) {
1898
1910
  const channelPose = newPose(THREE);
1899
1911
  const mixed = newPose(THREE);
1900
1912
  const dropped = newPose(THREE);
1901
- let indexCurl;
1913
+ const indexCurl = { R: void 0, L: void 0 };
1902
1914
  const bone = createTwoBone(THREE);
1903
1915
  const shoulder = new THREE.Vector3();
1904
1916
  const wristAt = new THREE.Vector3();
@@ -1962,7 +1974,7 @@ function createFirstPersonArms(THREE, options = {}) {
1962
1974
  arm.anchor.quaternion.copy(pose.q);
1963
1975
  arm.anchor.scale.setScalar(scale);
1964
1976
  arm.hand.setGrip(pose.grip);
1965
- arm.hand.setIndex(arm.side === "R" ? indexCurl : void 0);
1977
+ arm.hand.setIndex(indexCurl[arm.side]);
1966
1978
  arm.joints.shoulder.copy(shoulder);
1967
1979
  arm.joints.elbow.copy(bone.joint);
1968
1980
  arm.joints.wrist.copy(bone.end);
@@ -2048,7 +2060,7 @@ function createFirstPersonArms(THREE, options = {}) {
2048
2060
  desired.p.add(bobOffset);
2049
2061
  }
2050
2062
  modeOf(mode, arm);
2051
- if (side === "R") indexCurl = mode === "target" ? targets?.fingers?.index : void 0;
2063
+ indexCurl[side] = mode === "target" ? side === "R" ? targets?.fingers?.index : targets?.fingersL?.index : void 0;
2052
2064
  arm.blend = blendSeconds <= 0 ? 1 : Math.min(1, arm.blend + dt / blendSeconds);
2053
2065
  if (arm.blend >= 1) copyPose(arm.shown, desired);
2054
2066
  else mixPose(THREE, arm.shown, arm.from, desired, ease(arm.blend));