three-zoo 0.9.2 → 0.9.4
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/Sky.d.ts +36 -0
- package/dist/Sun.d.ts +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +127 -2
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +1 -1
package/dist/Sky.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Texture } from "three";
|
|
2
|
+
import { HemisphereLight } from "three";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for HDR color extraction.
|
|
5
|
+
*/
|
|
6
|
+
export interface SkyOptions {
|
|
7
|
+
/** Number of brightest pixels to average for sky color (default: 100) */
|
|
8
|
+
skySampleCount?: number;
|
|
9
|
+
/** Number of pixels to average for ground color (default: 100) */
|
|
10
|
+
groundSampleCount?: number;
|
|
11
|
+
/** Apply gamma correction to extracted colors (default: true) */
|
|
12
|
+
applyGamma?: boolean;
|
|
13
|
+
/** Gamma value for correction (default: 2.2) */
|
|
14
|
+
gamma?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Hemisphere light with HDR environment map support for automatic sky/ground color extraction.
|
|
18
|
+
*/
|
|
19
|
+
export declare class Sky extends HemisphereLight {
|
|
20
|
+
/**
|
|
21
|
+
* Sets sky and ground colors from an HDR texture.
|
|
22
|
+
* Analyzes upper hemisphere for sky color and lower hemisphere for ground color.
|
|
23
|
+
*
|
|
24
|
+
* @param texture - HDR texture to analyze (must have image data)
|
|
25
|
+
* @param options - Configuration options for color extraction
|
|
26
|
+
*/
|
|
27
|
+
setColorsFromHDRTexture(texture: Texture, options?: SkyOptions): void;
|
|
28
|
+
/**
|
|
29
|
+
* Inserts pixel into sorted array, maintaining size limit.
|
|
30
|
+
*/
|
|
31
|
+
private insertSorted;
|
|
32
|
+
/**
|
|
33
|
+
* Calculates average color from pixel array.
|
|
34
|
+
*/
|
|
35
|
+
private averagePixels;
|
|
36
|
+
}
|
package/dist/Sun.d.ts
CHANGED
|
@@ -39,6 +39,14 @@ export declare class Sun extends DirectionalLight {
|
|
|
39
39
|
* @param value - New azimuth angle in radians (theta angle)
|
|
40
40
|
*/
|
|
41
41
|
set azimuth(value: number);
|
|
42
|
+
/**
|
|
43
|
+
* Sets spherical position of the sun.
|
|
44
|
+
*
|
|
45
|
+
* @param elevation - Elevation angle in radians (phi angle)
|
|
46
|
+
* @param azimuth - Azimuth angle in radians (theta angle)
|
|
47
|
+
* @param distance - Distance from origin in world units
|
|
48
|
+
*/
|
|
49
|
+
setPosition(elevation: number, azimuth: number, distance?: number): void;
|
|
42
50
|
/**
|
|
43
51
|
* Configures shadow camera frustum to cover bounding box.
|
|
44
52
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { DualFovCamera } from "./DualFovCamera";
|
|
2
2
|
export { SceneTraversal } from "./SceneTraversal";
|
|
3
3
|
export { SkinnedMeshBaker } from "./SkinnedMeshBaker";
|
|
4
|
+
export { Sky } from "./Sky";
|
|
4
5
|
export { StandardToBasicConverter } from "./StandardToBasicConverter";
|
|
5
6
|
export { StandardToLambertConverter } from "./StandardToLambertConverter";
|
|
6
7
|
export { StandardToPhongConverter } from "./StandardToPhongConverter";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PerspectiveCamera, MathUtils, Vector3, Mesh, BufferAttribute, AnimationMixer, MeshBasicMaterial, MeshLambertMaterial, MeshPhongMaterial, Color, MeshPhysicalMaterial, MeshToonMaterial, DirectionalLight, Box3, Spherical
|
|
1
|
+
import { PerspectiveCamera, MathUtils, Vector3, Mesh, BufferAttribute, AnimationMixer, HemisphereLight, RGBAFormat, MeshBasicMaterial, MeshLambertMaterial, MeshPhongMaterial, Color, MeshPhysicalMaterial, MeshToonMaterial, DirectionalLight, Box3, Spherical } from 'three';
|
|
2
2
|
|
|
3
3
|
/** Default horizontal field of view in degrees */
|
|
4
4
|
const DEFAULT_HORIZONTAL_FOV = 90;
|
|
@@ -552,6 +552,121 @@ class SkinnedMeshBaker {
|
|
|
552
552
|
}
|
|
553
553
|
}
|
|
554
554
|
|
|
555
|
+
/** Number of color channels in RGBA format */
|
|
556
|
+
const RGBA_CHANNEL_COUNT$1 = 4;
|
|
557
|
+
/** Number of color channels in RGB format */
|
|
558
|
+
const RGB_CHANNEL_COUNT$1 = 3;
|
|
559
|
+
/** Red channel weight for luminance calculation (ITU-R BT.709) */
|
|
560
|
+
const LUMINANCE_R$1 = 0.2126;
|
|
561
|
+
/** Green channel weight for luminance calculation (ITU-R BT.709) */
|
|
562
|
+
const LUMINANCE_G$1 = 0.7152;
|
|
563
|
+
/** Blue channel weight for luminance calculation (ITU-R BT.709) */
|
|
564
|
+
const LUMINANCE_B$1 = 0.0722;
|
|
565
|
+
/** Threshold for upper hemisphere sampling (0 = equator, 1 = top) */
|
|
566
|
+
const SKY_SAMPLE_THRESHOLD = 0.25;
|
|
567
|
+
/** Threshold for lower hemisphere sampling (0 = equator, 1 = bottom) */
|
|
568
|
+
const GROUND_SAMPLE_THRESHOLD = 0.75;
|
|
569
|
+
/**
|
|
570
|
+
* Hemisphere light with HDR environment map support for automatic sky/ground color extraction.
|
|
571
|
+
*/
|
|
572
|
+
class Sky extends HemisphereLight {
|
|
573
|
+
/**
|
|
574
|
+
* Sets sky and ground colors from an HDR texture.
|
|
575
|
+
* Analyzes upper hemisphere for sky color and lower hemisphere for ground color.
|
|
576
|
+
*
|
|
577
|
+
* @param texture - HDR texture to analyze (must have image data)
|
|
578
|
+
* @param options - Configuration options for color extraction
|
|
579
|
+
*/
|
|
580
|
+
setColorsFromHDRTexture(texture, options = {}) {
|
|
581
|
+
const { skySampleCount = 100, groundSampleCount = 100, applyGamma = true, gamma = 2.2, } = options;
|
|
582
|
+
const data = texture.image.data;
|
|
583
|
+
const width = texture.image.width;
|
|
584
|
+
const height = texture.image.height;
|
|
585
|
+
const step = texture.format === RGBAFormat ? RGBA_CHANNEL_COUNT$1 : RGB_CHANNEL_COUNT$1;
|
|
586
|
+
const skyPixels = [];
|
|
587
|
+
const groundPixels = [];
|
|
588
|
+
// Sample pixels from upper and lower hemispheres
|
|
589
|
+
for (let i = 0; i < data.length; i += step) {
|
|
590
|
+
const pixelIndex = i / step;
|
|
591
|
+
const y = Math.floor(pixelIndex / width);
|
|
592
|
+
const v = y / height;
|
|
593
|
+
const r = data[i];
|
|
594
|
+
const g = data[i + 1];
|
|
595
|
+
const b = data[i + 2];
|
|
596
|
+
const luminance = LUMINANCE_R$1 * r + LUMINANCE_G$1 * g + LUMINANCE_B$1 * b;
|
|
597
|
+
const pixel = { r, g, b, lum: luminance };
|
|
598
|
+
// Upper hemisphere (sky)
|
|
599
|
+
if (v < SKY_SAMPLE_THRESHOLD) {
|
|
600
|
+
this._private_insertSorted(skyPixels, pixel, skySampleCount, true);
|
|
601
|
+
}
|
|
602
|
+
// Lower hemisphere (ground)
|
|
603
|
+
else if (v > GROUND_SAMPLE_THRESHOLD) {
|
|
604
|
+
this._private_insertSorted(groundPixels, pixel, groundSampleCount, false);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
// Calculate average sky color from brightest samples
|
|
608
|
+
const skyColor = this._private_averagePixels(skyPixels);
|
|
609
|
+
// Calculate average ground color
|
|
610
|
+
const groundColor = this._private_averagePixels(groundPixels);
|
|
611
|
+
// Apply gamma correction if needed
|
|
612
|
+
if (applyGamma) {
|
|
613
|
+
const invGamma = 1 / gamma;
|
|
614
|
+
skyColor.r = Math.pow(skyColor.r, invGamma);
|
|
615
|
+
skyColor.g = Math.pow(skyColor.g, invGamma);
|
|
616
|
+
skyColor.b = Math.pow(skyColor.b, invGamma);
|
|
617
|
+
groundColor.r = Math.pow(groundColor.r, invGamma);
|
|
618
|
+
groundColor.g = Math.pow(groundColor.g, invGamma);
|
|
619
|
+
groundColor.b = Math.pow(groundColor.b, invGamma);
|
|
620
|
+
}
|
|
621
|
+
// Normalize HDR values to [0, 1] range
|
|
622
|
+
const maxSky = Math.max(skyColor.r, skyColor.g, skyColor.b, 1);
|
|
623
|
+
const maxGround = Math.max(groundColor.r, groundColor.g, groundColor.b, 1);
|
|
624
|
+
this.color.setRGB(skyColor.r / maxSky, skyColor.g / maxSky, skyColor.b / maxSky);
|
|
625
|
+
this.groundColor.setRGB(groundColor.r / maxGround, groundColor.g / maxGround, groundColor.b / maxGround);
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Inserts pixel into sorted array, maintaining size limit.
|
|
629
|
+
*/
|
|
630
|
+
_private_insertSorted(array, pixel, maxSize, sortDescending) {
|
|
631
|
+
if (array.length < maxSize) {
|
|
632
|
+
array.push(pixel);
|
|
633
|
+
array.sort((a, b) => (sortDescending ? b.lum - a.lum : a.lum - b.lum));
|
|
634
|
+
}
|
|
635
|
+
else {
|
|
636
|
+
const threshold = array[array.length - 1].lum;
|
|
637
|
+
const shouldInsert = sortDescending
|
|
638
|
+
? pixel.lum > threshold
|
|
639
|
+
: pixel.lum < threshold;
|
|
640
|
+
if (shouldInsert) {
|
|
641
|
+
array.pop();
|
|
642
|
+
array.push(pixel);
|
|
643
|
+
array.sort((a, b) => (sortDescending ? b.lum - a.lum : a.lum - b.lum));
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Calculates average color from pixel array.
|
|
649
|
+
*/
|
|
650
|
+
_private_averagePixels(pixels) {
|
|
651
|
+
if (pixels.length === 0) {
|
|
652
|
+
return { r: 0.5, g: 0.5, b: 0.5 };
|
|
653
|
+
}
|
|
654
|
+
let totalR = 0;
|
|
655
|
+
let totalG = 0;
|
|
656
|
+
let totalB = 0;
|
|
657
|
+
for (const pixel of pixels) {
|
|
658
|
+
totalR += pixel.r;
|
|
659
|
+
totalG += pixel.g;
|
|
660
|
+
totalB += pixel.b;
|
|
661
|
+
}
|
|
662
|
+
return {
|
|
663
|
+
r: totalR / pixels.length,
|
|
664
|
+
g: totalG / pixels.length,
|
|
665
|
+
b: totalB / pixels.length,
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
555
670
|
/** Factor for metalness brightness adjustment */
|
|
556
671
|
const METALNESS_BRIGHTNESS_FACTOR = 0.3;
|
|
557
672
|
/** Factor for emissive color contribution when combining with base color */
|
|
@@ -1428,6 +1543,16 @@ class Sun extends DirectionalLight {
|
|
|
1428
1543
|
this._private_tempSpherical.setFromVector3(this.position);
|
|
1429
1544
|
this.position.setFromSphericalCoords(this._private_tempSpherical.radius, this._private_tempSpherical.phi, value);
|
|
1430
1545
|
}
|
|
1546
|
+
/**
|
|
1547
|
+
* Sets spherical position of the sun.
|
|
1548
|
+
*
|
|
1549
|
+
* @param elevation - Elevation angle in radians (phi angle)
|
|
1550
|
+
* @param azimuth - Azimuth angle in radians (theta angle)
|
|
1551
|
+
* @param distance - Distance from origin in world units
|
|
1552
|
+
*/
|
|
1553
|
+
setPosition(elevation, azimuth, distance = 1) {
|
|
1554
|
+
this.position.setFromSphericalCoords(distance, elevation, azimuth);
|
|
1555
|
+
}
|
|
1431
1556
|
/**
|
|
1432
1557
|
* Configures shadow camera frustum to cover bounding box.
|
|
1433
1558
|
*
|
|
@@ -1498,5 +1623,5 @@ class Sun extends DirectionalLight {
|
|
|
1498
1623
|
}
|
|
1499
1624
|
}
|
|
1500
1625
|
|
|
1501
|
-
export { DualFovCamera, SceneTraversal, SkinnedMeshBaker, StandardToBasicConverter, StandardToLambertConverter, StandardToPhongConverter, StandardToPhysicalConverter, StandardToToonConverter, Sun };
|
|
1626
|
+
export { DualFovCamera, SceneTraversal, SkinnedMeshBaker, Sky, StandardToBasicConverter, StandardToLambertConverter, StandardToPhongConverter, StandardToPhysicalConverter, StandardToToonConverter, Sun };
|
|
1502
1627
|
//# sourceMappingURL=index.js.map
|