angular-three-soba 4.1.1 → 4.2.1

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.
@@ -767,17 +767,26 @@ function objectScale(el, camera) {
767
767
  * @param el - The object to calculate z-index for
768
768
  * @param camera - The camera reference (must be Perspective or Orthographic)
769
769
  * @param zIndexRange - `[max, min]` range to map distance to
770
+ * @param logarithmicDepth - Computes the z-index logarithmicly to enable a wider camera range
770
771
  * @returns Calculated z-index, or `undefined` for unsupported camera types
771
772
  */
772
- function objectZIndex(el, camera, zIndexRange) {
773
+ function objectZIndex(el, camera, zIndexRange, logarithmicDepth = false) {
773
774
  if (is.three(camera, 'isPerspectiveCamera') ||
774
775
  is.three(camera, 'isOrthographicCamera')) {
775
776
  const objectPos = v1.setFromMatrixPosition(el.matrixWorld);
776
777
  const cameraPos = v2.setFromMatrixPosition(camera.matrixWorld);
777
778
  const dist = objectPos.distanceTo(cameraPos);
778
- const A = (zIndexRange[1] - zIndexRange[0]) / (camera.far - camera.near);
779
- const B = zIndexRange[1] - A * camera.far;
780
- return Math.round(A * dist + B);
779
+ if (logarithmicDepth) {
780
+ const safeNear = Math.max(camera.near, 1e-6);
781
+ const safeDist = Math.max(dist, 1e-6);
782
+ const depth = Math.log(safeDist / safeNear) / Math.log(camera.far / safeNear);
783
+ return Math.round(zIndexRange[0] + depth * (zIndexRange[1] - zIndexRange[0]));
784
+ }
785
+ else {
786
+ const A = (zIndexRange[1] - zIndexRange[0]) / (camera.far - camera.near);
787
+ const B = zIndexRange[1] - A * camera.far;
788
+ return Math.round(A * dist + B);
789
+ }
781
790
  }
782
791
  return undefined;
783
792
  }
@@ -987,7 +996,7 @@ class NgtsHTMLContent extends NgtHTML {
987
996
  let oldZoom = 0;
988
997
  let oldPosition = [0, 0];
989
998
  beforeRender(({ camera: rootCamera }) => {
990
- const [hostEl, transformOuterEl, transformInnerEl, group, occlusionMesh, occlusionGeometry, isRaycastOcclusion, { camera, size, viewport, raycaster, scene }, { calculatePosition, eps, zIndexRange, sprite, distanceFactor }, { transform, occlude, scale },] = [
999
+ const [hostEl, transformOuterEl, transformInnerEl, group, occlusionMesh, occlusionGeometry, isRaycastOcclusion, { camera, size, viewport, raycaster, scene }, { calculatePosition, eps, zIndexRange, logarithmicDepth, sprite, distanceFactor }, { transform, occlude, scale },] = [
991
1000
  this.host.nativeElement,
992
1001
  this.transformOuterRef()?.nativeElement,
993
1002
  this.transformInnerRef()?.nativeElement,
@@ -1058,7 +1067,7 @@ class NgtsHTMLContent extends NgtHTML {
1058
1067
  ? [zIndexRange[0], halfRange]
1059
1068
  : [halfRange - 1, 0]
1060
1069
  : zIndexRange;
1061
- renderer.setStyle(hostEl, 'z-index', `${objectZIndex(group, camera, zRange)}`);
1070
+ renderer.setStyle(hostEl, 'z-index', `${objectZIndex(group, camera, zRange, logarithmicDepth)}`);
1062
1071
  if (transform) {
1063
1072
  const [widthHalf, heightHalf] = [size.width / 2, size.height / 2];
1064
1073
  const fov = camera.projectionMatrix.elements[5] * heightHalf;