@adatechnology/game-characters-three 0.11.1 → 0.11.2

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.
@@ -11506,16 +11506,62 @@ ${accessoryHead}`).replace("{ vec3 _nn = objectNormal; bodyAnim(position, _nn);"
11506
11506
  };
11507
11507
  };
11508
11508
 
11509
- // src/player/head-hiding.ts
11509
+ // src/player/eye-clip.ts
11510
11510
  var isDrawable = (object2) => {
11511
11511
  const flagged = object2;
11512
11512
  return Boolean(flagged.isMesh || flagged.isSprite || flagged.isPoints);
11513
11513
  };
11514
+ var createEyeClip = (THREE, options) => {
11515
+ let isCutting = false;
11516
+ let viewCamera = null;
11517
+ const plane2 = new THREE.Plane();
11518
+ const planes = [plane2];
11519
+ const eyeAt = new THREE.Vector3();
11520
+ const front = new THREE.Vector3();
11521
+ const place = () => {
11522
+ options.eye.getWorldPosition(eyeAt);
11523
+ front.set(0, 0, 1).transformDirection(options.front.matrixWorld);
11524
+ plane2.setFromNormalAndCoplanarPoint(front, eyeAt.addScaledVector(front, -options.behind));
11525
+ };
11526
+ const drawables = [];
11527
+ for (const root of options.roots) root.traverse((object2) => isDrawable(object2) && drawables.push(object2));
11528
+ for (const drawable of drawables) {
11529
+ const previousBefore = drawable.onBeforeRender;
11530
+ const previousAfter = drawable.onAfterRender;
11531
+ let saved = [];
11532
+ drawable.onBeforeRender = (renderer, scene2, camera, geometry, material, group) => {
11533
+ previousBefore.call(drawable, renderer, scene2, camera, geometry, material, group);
11534
+ if (!isCutting || camera !== viewCamera) return;
11535
+ renderer.localClippingEnabled = true;
11536
+ place();
11537
+ const drawn = Array.isArray(drawable.material) ? drawable.material : [material];
11538
+ saved = drawn.map((entry) => ({ material: entry, planes: entry.clippingPlanes }));
11539
+ for (const entry of drawn) entry.clippingPlanes = planes;
11540
+ };
11541
+ drawable.onAfterRender = (renderer, scene2, camera, geometry, material, group) => {
11542
+ previousAfter.call(drawable, renderer, scene2, camera, geometry, material, group);
11543
+ for (const entry of saved) entry.material.clippingPlanes = entry.planes;
11544
+ saved = [];
11545
+ };
11546
+ }
11547
+ return {
11548
+ setView(mode, camera) {
11549
+ isCutting = mode === "first" && camera !== null;
11550
+ viewCamera = camera;
11551
+ }
11552
+ };
11553
+ };
11554
+
11555
+ // src/player/head-hiding.ts
11556
+ var isDrawable2 = (object2) => {
11557
+ const flagged = object2;
11558
+ return Boolean(flagged.isMesh || flagged.isSprite || flagged.isPoints);
11559
+ };
11514
11560
  var createHeadHider = (roots) => {
11515
11561
  let isHiding = false;
11516
11562
  let viewCamera = null;
11517
11563
  const drawables = [];
11518
- for (const root of roots) root.traverse((object2) => isDrawable(object2) && drawables.push(object2));
11564
+ for (const root of roots) root.traverse((object2) => isDrawable2(object2) && drawables.push(object2));
11519
11565
  for (const drawable of drawables) {
11520
11566
  const previousBefore = drawable.onBeforeRender;
11521
11567
  const previousAfter = drawable.onAfterRender;
@@ -11554,6 +11600,7 @@ ${accessoryHead}`).replace("{ vec3 _nn = objectNormal; bodyAnim(position, _nn);"
11554
11600
  var CLIP_CASCADE = 5;
11555
11601
  var FALL_SECONDS2 = 0.3;
11556
11602
  var BUILDER_EYE = [0, 1.815, 0.16];
11603
+ var EYE_CLIP_BEHIND = 0;
11557
11604
  var EYE_OFFSET = [0, -0.068, 0];
11558
11605
  var EYE_BOB = 0.5;
11559
11606
  var HIP_HEIGHT = 0.95;
@@ -11667,6 +11714,8 @@ ${accessoryHead}`).replace("{ vec3 _nn = objectNormal; bodyAnim(position, _nn);"
11667
11714
  rig.headG.children[0].add(eyeSocket);
11668
11715
  const headHider = createHeadHider([rig.headG, ...rig.neck ? [rig.neck] : []]);
11669
11716
  const armsHider = createHeadHider(rig.arms.map((arm) => arm.g));
11717
+ const hips = rig.fig.children.filter((child) => child.isMesh);
11718
+ const eyeClip = createEyeClip(THREE, { roots: [rig.upper, ...hips], eye: eyeSocket, front: rig.upper, behind: EYE_CLIP_BEHIND });
11670
11719
  const eyeLocal = new THREE.Vector3();
11671
11720
  let bob = 0;
11672
11721
  let hipWithoutBob = null;
@@ -12016,6 +12065,7 @@ ${accessoryHead}`).replace("{ vec3 _nn = objectNormal; bodyAnim(position, _nn);"
12016
12065
  },
12017
12066
  setView: (mode, camera, viewOptions) => {
12018
12067
  headHider.setView(mode, camera);
12068
+ eyeClip.setView(mode, camera);
12019
12069
  armsHider.setView(viewOptions?.arms ? mode : "third", camera);
12020
12070
  },
12021
12071
  play(clip, playOptions = {}) {