three-zoo 0.11.13 → 0.11.15

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
@@ -1,4 +1,4 @@
1
- import { Object3D, Vector3, Quaternion, Matrix4, InstancedMesh, HemisphereLight, RGBAFormat, DirectionalLight, Box3, Spherical, MeshPhysicalMaterial, Color, MeshBasicMaterial, MeshLambertMaterial, MeshPhongMaterial, MeshToonMaterial, PerspectiveCamera, MathUtils, Mesh, BufferAttribute, AnimationMixer } from 'three';
1
+ import { Object3D, Vector3, Quaternion, Matrix4, InstancedMesh, HemisphereLight, RGBAFormat, DirectionalLight, Box3, Spherical, PerspectiveCamera, MeshPhysicalMaterial, Color, MeshBasicMaterial, MeshLambertMaterial, MeshPhongMaterial, MeshToonMaterial, MathUtils, Mesh, BufferAttribute, AnimationMixer } from 'three';
2
2
 
3
3
  class InstancedMeshGroup extends Object3D {
4
4
  constructor(_private_instances) {
@@ -434,6 +434,8 @@ class SkyLight extends HemisphereLight {
434
434
  }
435
435
  }
436
436
 
437
+ /** Radians-per-degree conversion factor */
438
+ const DEG2RAD = Math.PI / 180;
437
439
  /** Number of color channels in RGBA format */
438
440
  const RGBA_CHANNEL_COUNT = 4;
439
441
  /** Number of color channels in RGB format */
@@ -545,6 +547,48 @@ class Sun extends DirectionalLight {
545
547
  camera.updateWorldMatrix(true, false);
546
548
  camera.updateProjectionMatrix();
547
549
  }
550
+ /**
551
+ * Configures shadow camera frustum to cover the visible volume of a scene camera.
552
+ * Supports both perspective (frustum) and orthographic (box) cameras.
553
+ *
554
+ * @param sceneCamera - PerspectiveCamera or OrthographicCamera whose visible volume defines the shadow region
555
+ */
556
+ configureShadowsForCamera(sceneCamera) {
557
+ const shadowCamera = this.shadow.camera;
558
+ this.target.updateWorldMatrix(true, false);
559
+ this.lookAt(this.target.getWorldPosition(this._private_tempVector3D0));
560
+ this.updateWorldMatrix(true, false);
561
+ sceneCamera.updateWorldMatrix(true, false);
562
+ if (sceneCamera instanceof PerspectiveCamera) {
563
+ this._private_computeFrustumPoints(sceneCamera);
564
+ }
565
+ else {
566
+ this._private_computeOrthographicPoints(sceneCamera);
567
+ }
568
+ const inverseMatrix = this.matrixWorld.clone().invert();
569
+ const points = [
570
+ this._private_tempVector3D0,
571
+ this._private_tempVector3D1,
572
+ this._private_tempVector3D2,
573
+ this._private_tempVector3D3,
574
+ this._private_tempVector3D4,
575
+ this._private_tempVector3D5,
576
+ this._private_tempVector3D6,
577
+ this._private_tempVector3D7,
578
+ ];
579
+ for (const point of points) {
580
+ point.applyMatrix4(inverseMatrix);
581
+ }
582
+ const newBox3 = this._private_tempBox3.setFromPoints(points);
583
+ shadowCamera.left = newBox3.min.x;
584
+ shadowCamera.bottom = newBox3.min.y;
585
+ shadowCamera.near = -newBox3.max.z;
586
+ shadowCamera.right = newBox3.max.x;
587
+ shadowCamera.top = newBox3.max.y;
588
+ shadowCamera.far = -newBox3.min.z;
589
+ shadowCamera.updateWorldMatrix(true, false);
590
+ shadowCamera.updateProjectionMatrix();
591
+ }
548
592
  /**
549
593
  * Sets sun direction, color and intensity based on brightest point in HDR environment map.
550
594
  *
@@ -625,6 +669,60 @@ class Sun extends DirectionalLight {
625
669
  }
626
670
  return { index: maxIndex, luminance: maxLuminance };
627
671
  }
672
+ /**
673
+ * Computes the 8 frustum corner points of a perspective camera in world space,
674
+ * storing them in the temporary Vector3 members.
675
+ *
676
+ * @param camera - The perspective camera to compute frustum points for
677
+ */
678
+ _private_computeFrustumPoints(camera) {
679
+ const fovRad = camera.fov * DEG2RAD;
680
+ const halfTanFov = Math.tan(fovRad / 2);
681
+ const nearHalfH = camera.near * halfTanFov;
682
+ const nearHalfW = nearHalfH * camera.aspect;
683
+ const farHalfH = camera.far * halfTanFov;
684
+ const farHalfW = farHalfH * camera.aspect;
685
+ this._private_tempVector3D0.set(-nearHalfW, -nearHalfH, -camera.near);
686
+ this._private_tempVector3D1.set(nearHalfW, -nearHalfH, -camera.near);
687
+ this._private_tempVector3D2.set(-nearHalfW, nearHalfH, -camera.near);
688
+ this._private_tempVector3D3.set(nearHalfW, nearHalfH, -camera.near);
689
+ this._private_tempVector3D4.set(-farHalfW, -farHalfH, -camera.far);
690
+ this._private_tempVector3D5.set(farHalfW, -farHalfH, -camera.far);
691
+ this._private_tempVector3D6.set(-farHalfW, farHalfH, -camera.far);
692
+ this._private_tempVector3D7.set(farHalfW, farHalfH, -camera.far);
693
+ this._private_tempVector3D0.applyMatrix4(camera.matrixWorld);
694
+ this._private_tempVector3D1.applyMatrix4(camera.matrixWorld);
695
+ this._private_tempVector3D2.applyMatrix4(camera.matrixWorld);
696
+ this._private_tempVector3D3.applyMatrix4(camera.matrixWorld);
697
+ this._private_tempVector3D4.applyMatrix4(camera.matrixWorld);
698
+ this._private_tempVector3D5.applyMatrix4(camera.matrixWorld);
699
+ this._private_tempVector3D6.applyMatrix4(camera.matrixWorld);
700
+ this._private_tempVector3D7.applyMatrix4(camera.matrixWorld);
701
+ }
702
+ /**
703
+ * Computes the 8 corner points of an orthographic camera's visible box in world space,
704
+ * storing them in the temporary Vector3 members.
705
+ *
706
+ * @param camera - The orthographic camera to compute box points for
707
+ */
708
+ _private_computeOrthographicPoints(camera) {
709
+ this._private_tempVector3D0.set(camera.left, camera.bottom, -camera.near);
710
+ this._private_tempVector3D1.set(camera.right, camera.bottom, -camera.near);
711
+ this._private_tempVector3D2.set(camera.left, camera.top, -camera.near);
712
+ this._private_tempVector3D3.set(camera.right, camera.top, -camera.near);
713
+ this._private_tempVector3D4.set(camera.left, camera.bottom, -camera.far);
714
+ this._private_tempVector3D5.set(camera.right, camera.bottom, -camera.far);
715
+ this._private_tempVector3D6.set(camera.left, camera.top, -camera.far);
716
+ this._private_tempVector3D7.set(camera.right, camera.top, -camera.far);
717
+ this._private_tempVector3D0.applyMatrix4(camera.matrixWorld);
718
+ this._private_tempVector3D1.applyMatrix4(camera.matrixWorld);
719
+ this._private_tempVector3D2.applyMatrix4(camera.matrixWorld);
720
+ this._private_tempVector3D3.applyMatrix4(camera.matrixWorld);
721
+ this._private_tempVector3D4.applyMatrix4(camera.matrixWorld);
722
+ this._private_tempVector3D5.applyMatrix4(camera.matrixWorld);
723
+ this._private_tempVector3D6.applyMatrix4(camera.matrixWorld);
724
+ this._private_tempVector3D7.applyMatrix4(camera.matrixWorld);
725
+ }
628
726
  }
629
727
 
630
728
  class BasicToPhysicalConverter {
@@ -2089,7 +2187,18 @@ class SceneTraversal {
2089
2187
 
2090
2188
  const TEMP_VECTOR = new Vector3();
2091
2189
  const TEMP_BOX3 = new Box3();
2190
+ /**
2191
+ * Static utilities for sorting scene objects.
2192
+ */
2092
2193
  class SceneSorter {
2194
+ /**
2195
+ * Sorts all meshes in the hierarchy by distance to a point,
2196
+ * assigning sequential `renderOrder` values starting from `baseRenderOrder`.
2197
+ *
2198
+ * @param object - Root object to start from
2199
+ * @param point - Reference point to measure distances against
2200
+ * @param baseRenderOrder - Starting render order value
2201
+ */
2093
2202
  static sortByDistanceToPoint(object, point, baseRenderOrder) {
2094
2203
  object.updateWorldMatrix(true, true);
2095
2204
  const meshes = [];