three-zoo 0.11.13 → 0.11.14
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.d.ts +0 -1
- package/dist/index.js +100 -27
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/lighting/Sun.d.ts +23 -2
- package/package.json +1 -1
- package/dist/miscellaneous/SceneSorter.d.ts +0 -5
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,5 @@ export { StandardToPhongConverter } from "./materialConverters/StandardToPhongCo
|
|
|
10
10
|
export { StandardToPhysicalConverter } from "./materialConverters/StandardToPhysicalConverter";
|
|
11
11
|
export { StandardToToonConverter } from "./materialConverters/StandardToToonConverter";
|
|
12
12
|
export { DualFovCamera } from "./miscellaneous/DualFovCamera";
|
|
13
|
-
export { SceneSorter } from "./miscellaneous/SceneSorter";
|
|
14
13
|
export { SceneTraversal } from "./miscellaneous/SceneTraversal";
|
|
15
14
|
export { SkinnedMeshBaker } from "./miscellaneous/SkinnedMeshBaker";
|
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,
|
|
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 {
|
|
@@ -2087,31 +2185,6 @@ class SceneTraversal {
|
|
|
2087
2185
|
}
|
|
2088
2186
|
}
|
|
2089
2187
|
|
|
2090
|
-
const TEMP_VECTOR = new Vector3();
|
|
2091
|
-
const TEMP_BOX3 = new Box3();
|
|
2092
|
-
class SceneSorter {
|
|
2093
|
-
static sortByDistanceToPoint(object, point, baseRenderOrder) {
|
|
2094
|
-
object.updateWorldMatrix(true, true);
|
|
2095
|
-
const meshes = [];
|
|
2096
|
-
SceneTraversal.enumerateObjectsByType(object, Mesh, (mesh) => meshes.push(mesh));
|
|
2097
|
-
if (meshes.length === 0) {
|
|
2098
|
-
return;
|
|
2099
|
-
}
|
|
2100
|
-
meshes.sort((a, b) => {
|
|
2101
|
-
const distanceA = TEMP_BOX3.setFromObject(a)
|
|
2102
|
-
.getCenter(TEMP_VECTOR)
|
|
2103
|
-
.distanceToSquared(point);
|
|
2104
|
-
const distanceB = TEMP_BOX3.setFromObject(b)
|
|
2105
|
-
.getCenter(TEMP_VECTOR)
|
|
2106
|
-
.distanceToSquared(point);
|
|
2107
|
-
return distanceA - distanceB;
|
|
2108
|
-
});
|
|
2109
|
-
for (let i = 0; i < meshes.length; i++) {
|
|
2110
|
-
meshes[i].renderOrder = baseRenderOrder + i;
|
|
2111
|
-
}
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
|
|
2115
2188
|
/** Number of components per vertex */
|
|
2116
2189
|
const COMPONENT_COUNT = 3;
|
|
2117
2190
|
/** Converts skinned meshes to static meshes. */
|
|
@@ -2162,5 +2235,5 @@ class SkinnedMeshBaker {
|
|
|
2162
2235
|
}
|
|
2163
2236
|
}
|
|
2164
2237
|
|
|
2165
|
-
export { BasicToPhysicalConverter, DualFovCamera, InstancedMeshGroup, InstancedMeshInstance, InstancedMeshPool,
|
|
2238
|
+
export { BasicToPhysicalConverter, DualFovCamera, InstancedMeshGroup, InstancedMeshInstance, InstancedMeshPool, SceneTraversal, SkinnedMeshBaker, SkyLight, StandardToBasicConverter, StandardToLambertConverter, StandardToPhongConverter, StandardToPhysicalConverter, StandardToToonConverter, Sun };
|
|
2166
2239
|
//# sourceMappingURL=index.js.map
|