@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.
package/dist/index.js CHANGED
@@ -921,16 +921,62 @@ var createArmReach = (THREE, rig, hands) => {
921
921
  };
922
922
  };
923
923
 
924
- // src/player/head-hiding.ts
924
+ // src/player/eye-clip.ts
925
925
  var isDrawable = (object) => {
926
926
  const flagged = object;
927
927
  return Boolean(flagged.isMesh || flagged.isSprite || flagged.isPoints);
928
928
  };
929
+ var createEyeClip = (THREE, options) => {
930
+ let isCutting = false;
931
+ let viewCamera = null;
932
+ const plane = new THREE.Plane();
933
+ const planes = [plane];
934
+ const eyeAt = new THREE.Vector3();
935
+ const front = new THREE.Vector3();
936
+ const place = () => {
937
+ options.eye.getWorldPosition(eyeAt);
938
+ front.set(0, 0, 1).transformDirection(options.front.matrixWorld);
939
+ plane.setFromNormalAndCoplanarPoint(front, eyeAt.addScaledVector(front, -options.behind));
940
+ };
941
+ const drawables = [];
942
+ for (const root of options.roots) root.traverse((object) => isDrawable(object) && drawables.push(object));
943
+ for (const drawable of drawables) {
944
+ const previousBefore = drawable.onBeforeRender;
945
+ const previousAfter = drawable.onAfterRender;
946
+ let saved = [];
947
+ drawable.onBeforeRender = (renderer, scene, camera, geometry, material, group) => {
948
+ previousBefore.call(drawable, renderer, scene, camera, geometry, material, group);
949
+ if (!isCutting || camera !== viewCamera) return;
950
+ renderer.localClippingEnabled = true;
951
+ place();
952
+ const drawn = Array.isArray(drawable.material) ? drawable.material : [material];
953
+ saved = drawn.map((entry) => ({ material: entry, planes: entry.clippingPlanes }));
954
+ for (const entry of drawn) entry.clippingPlanes = planes;
955
+ };
956
+ drawable.onAfterRender = (renderer, scene, camera, geometry, material, group) => {
957
+ previousAfter.call(drawable, renderer, scene, camera, geometry, material, group);
958
+ for (const entry of saved) entry.material.clippingPlanes = entry.planes;
959
+ saved = [];
960
+ };
961
+ }
962
+ return {
963
+ setView(mode, camera) {
964
+ isCutting = mode === "first" && camera !== null;
965
+ viewCamera = camera;
966
+ }
967
+ };
968
+ };
969
+
970
+ // src/player/head-hiding.ts
971
+ var isDrawable2 = (object) => {
972
+ const flagged = object;
973
+ return Boolean(flagged.isMesh || flagged.isSprite || flagged.isPoints);
974
+ };
929
975
  var createHeadHider = (roots) => {
930
976
  let isHiding = false;
931
977
  let viewCamera = null;
932
978
  const drawables = [];
933
- for (const root of roots) root.traverse((object) => isDrawable(object) && drawables.push(object));
979
+ for (const root of roots) root.traverse((object) => isDrawable2(object) && drawables.push(object));
934
980
  for (const drawable of drawables) {
935
981
  const previousBefore = drawable.onBeforeRender;
936
982
  const previousAfter = drawable.onAfterRender;
@@ -969,6 +1015,7 @@ var CLIP_BLEND = 0.12;
969
1015
  var CLIP_CASCADE = 5;
970
1016
  var FALL_SECONDS = 0.3;
971
1017
  var BUILDER_EYE = [0, 1.815, 0.16];
1018
+ var EYE_CLIP_BEHIND = 0;
972
1019
  var EYE_OFFSET = [0, -0.068, 0];
973
1020
  var EYE_BOB = 0.5;
974
1021
  var HIP_HEIGHT = 0.95;
@@ -1082,6 +1129,8 @@ var createPlayerAvatar = (THREE, options = {}) => {
1082
1129
  rig.headG.children[0].add(eyeSocket);
1083
1130
  const headHider = createHeadHider([rig.headG, ...rig.neck ? [rig.neck] : []]);
1084
1131
  const armsHider = createHeadHider(rig.arms.map((arm) => arm.g));
1132
+ const hips = rig.fig.children.filter((child) => child.isMesh);
1133
+ const eyeClip = createEyeClip(THREE, { roots: [rig.upper, ...hips], eye: eyeSocket, front: rig.upper, behind: EYE_CLIP_BEHIND });
1085
1134
  const eyeLocal = new THREE.Vector3();
1086
1135
  let bob = 0;
1087
1136
  let hipWithoutBob = null;
@@ -1431,6 +1480,7 @@ var createPlayerAvatar = (THREE, options = {}) => {
1431
1480
  },
1432
1481
  setView: (mode, camera, viewOptions) => {
1433
1482
  headHider.setView(mode, camera);
1483
+ eyeClip.setView(mode, camera);
1434
1484
  armsHider.setView(viewOptions?.arms ? mode : "third", camera);
1435
1485
  },
1436
1486
  play(clip, playOptions = {}) {