three-zoo 0.9.4 → 0.10.0

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.
@@ -3,7 +3,7 @@ import { HemisphereLight } from "three";
3
3
  /**
4
4
  * Configuration options for HDR color extraction.
5
5
  */
6
- export interface SkyOptions {
6
+ export interface SkyLightOptions {
7
7
  /** Number of brightest pixels to average for sky color (default: 100) */
8
8
  skySampleCount?: number;
9
9
  /** Number of pixels to average for ground color (default: 100) */
@@ -16,7 +16,7 @@ export interface SkyOptions {
16
16
  /**
17
17
  * Hemisphere light with HDR environment map support for automatic sky/ground color extraction.
18
18
  */
19
- export declare class Sky extends HemisphereLight {
19
+ export declare class SkyLight extends HemisphereLight {
20
20
  /**
21
21
  * Sets sky and ground colors from an HDR texture.
22
22
  * Analyzes upper hemisphere for sky color and lower hemisphere for ground color.
@@ -24,7 +24,7 @@ export declare class Sky extends HemisphereLight {
24
24
  * @param texture - HDR texture to analyze (must have image data)
25
25
  * @param options - Configuration options for color extraction
26
26
  */
27
- setColorsFromHDRTexture(texture: Texture, options?: SkyOptions): void;
27
+ setColorsFromHDRTexture(texture: Texture, options?: SkyLightOptions): void;
28
28
  /**
29
29
  * Inserts pixel into sorted array, maintaining size limit.
30
30
  */
package/dist/Sun.d.ts CHANGED
@@ -53,6 +53,27 @@ export declare class Sun extends DirectionalLight {
53
53
  * @param box3 - 3D bounding box to cover with shadows
54
54
  */
55
55
  configureShadowsForBoundingBox(box3: Box3): void;
56
+ /**
57
+ * Sets sun direction, color and intensity based on brightest point in HDR environment map.
58
+ *
59
+ * @param texture - HDR texture to analyze (must have image data)
60
+ * @param distance - Distance to place sun from origin
61
+ * @param intensityScale - Multiplier for intensity derived from luminance (default: 1)
62
+ */
63
+ setFromHDRTexture(texture: Texture, intensityScale?: number, distance?: number): void;
64
+ /**
65
+ * Sets sun color based on brightest point in HDR environment map.
66
+ *
67
+ * @param texture - HDR texture to analyze (must have image data)
68
+ */
69
+ setColorFromHDRTexture(texture: Texture): void;
70
+ /**
71
+ * Sets sun intensity based on luminance of brightest point in HDR environment map.
72
+ *
73
+ * @param texture - HDR texture to analyze (must have image data)
74
+ * @param scale - Multiplier for intensity (default: 1)
75
+ */
76
+ setIntensityFromHDRTexture(texture: Texture, scale?: number): void;
56
77
  /**
57
78
  * Sets sun direction based on brightest point in HDR environment map.
58
79
  *
@@ -60,4 +81,11 @@ export declare class Sun extends DirectionalLight {
60
81
  * @param distance - Distance to place sun from origin
61
82
  */
62
83
  setDirectionFromHDRTexture(texture: Texture, distance?: number): void;
84
+ /**
85
+ * Finds the brightest pixel in an HDR texture.
86
+ *
87
+ * @param texture - HDR texture to analyze
88
+ * @returns Index and luminance of brightest pixel
89
+ */
90
+ private findBrightestPixel;
63
91
  }
package/dist/index.d.ts CHANGED
@@ -1,7 +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
+ export { SkyLight } from "./SkyLight";
5
5
  export { StandardToBasicConverter } from "./StandardToBasicConverter";
6
6
  export { StandardToLambertConverter } from "./StandardToLambertConverter";
7
7
  export { StandardToPhongConverter } from "./StandardToPhongConverter";
package/dist/index.js CHANGED
@@ -569,7 +569,7 @@ const GROUND_SAMPLE_THRESHOLD = 0.75;
569
569
  /**
570
570
  * Hemisphere light with HDR environment map support for automatic sky/ground color extraction.
571
571
  */
572
- class Sky extends HemisphereLight {
572
+ class SkyLight extends HemisphereLight {
573
573
  /**
574
574
  * Sets sky and ground colors from an HDR texture.
575
575
  * Analyzes upper hemisphere for sky color and lower hemisphere for ground color.
@@ -1587,6 +1587,42 @@ class Sun extends DirectionalLight {
1587
1587
  camera.updateWorldMatrix(true, false);
1588
1588
  camera.updateProjectionMatrix();
1589
1589
  }
1590
+ /**
1591
+ * Sets sun direction, color and intensity based on brightest point in HDR environment map.
1592
+ *
1593
+ * @param texture - HDR texture to analyze (must have image data)
1594
+ * @param distance - Distance to place sun from origin
1595
+ * @param intensityScale - Multiplier for intensity derived from luminance (default: 1)
1596
+ */
1597
+ setFromHDRTexture(texture, intensityScale = 1, distance = 1) {
1598
+ this.setColorFromHDRTexture(texture);
1599
+ this.setIntensityFromHDRTexture(texture, intensityScale);
1600
+ this.setDirectionFromHDRTexture(texture, distance);
1601
+ }
1602
+ /**
1603
+ * Sets sun color based on brightest point in HDR environment map.
1604
+ *
1605
+ * @param texture - HDR texture to analyze (must have image data)
1606
+ */
1607
+ setColorFromHDRTexture(texture) {
1608
+ const { index } = this._private_findBrightestPixel(texture);
1609
+ const data = texture.image.data;
1610
+ const r = data[index];
1611
+ const g = data[index + 1];
1612
+ const b = data[index + 2];
1613
+ const maxChannel = Math.max(r, g, b, 1);
1614
+ this.color.setRGB(r / maxChannel, g / maxChannel, b / maxChannel);
1615
+ }
1616
+ /**
1617
+ * Sets sun intensity based on luminance of brightest point in HDR environment map.
1618
+ *
1619
+ * @param texture - HDR texture to analyze (must have image data)
1620
+ * @param scale - Multiplier for intensity (default: 1)
1621
+ */
1622
+ setIntensityFromHDRTexture(texture, scale = 1) {
1623
+ const { luminance } = this._private_findBrightestPixel(texture);
1624
+ this.intensity = luminance * scale;
1625
+ }
1590
1626
  /**
1591
1627
  * Sets sun direction based on brightest point in HDR environment map.
1592
1628
  *
@@ -1594,12 +1630,30 @@ class Sun extends DirectionalLight {
1594
1630
  * @param distance - Distance to place sun from origin
1595
1631
  */
1596
1632
  setDirectionFromHDRTexture(texture, distance = 1) {
1597
- const data = texture.image.data;
1633
+ const { index } = this._private_findBrightestPixel(texture);
1598
1634
  const width = texture.image.width;
1599
1635
  const height = texture.image.height;
1636
+ const step = texture.format === RGBAFormat ? RGBA_CHANNEL_COUNT : RGB_CHANNEL_COUNT;
1637
+ // Convert to spherical coordinates
1638
+ const pixelIndex = index / step;
1639
+ const x = pixelIndex % width;
1640
+ const y = Math.floor(pixelIndex / width);
1641
+ const u = x / width;
1642
+ const v = y / height;
1643
+ const elevation = v * Math.PI;
1644
+ const azimuth = u * -Math.PI * 2 - Math.PI / 2;
1645
+ this.position.setFromSphericalCoords(distance, elevation, azimuth);
1646
+ }
1647
+ /**
1648
+ * Finds the brightest pixel in an HDR texture.
1649
+ *
1650
+ * @param texture - HDR texture to analyze
1651
+ * @returns Index and luminance of brightest pixel
1652
+ */
1653
+ _private_findBrightestPixel(texture) {
1654
+ const data = texture.image.data;
1600
1655
  let maxLuminance = 0;
1601
1656
  let maxIndex = 0;
1602
- // Find brightest pixel
1603
1657
  const step = texture.format === RGBAFormat ? RGBA_CHANNEL_COUNT : RGB_CHANNEL_COUNT;
1604
1658
  for (let i = 0; i < data.length; i += step) {
1605
1659
  const r = data[i];
@@ -1611,17 +1665,9 @@ class Sun extends DirectionalLight {
1611
1665
  maxIndex = i;
1612
1666
  }
1613
1667
  }
1614
- // Convert to spherical coordinates
1615
- const pixelIndex = maxIndex / step;
1616
- const x = pixelIndex % width;
1617
- const y = Math.floor(pixelIndex / width);
1618
- const u = x / width;
1619
- const v = y / height;
1620
- const elevation = v * Math.PI;
1621
- const azimuth = u * -Math.PI * 2 - Math.PI / 2;
1622
- this.position.setFromSphericalCoords(distance, elevation, azimuth);
1668
+ return { index: maxIndex, luminance: maxLuminance };
1623
1669
  }
1624
1670
  }
1625
1671
 
1626
- export { DualFovCamera, SceneTraversal, SkinnedMeshBaker, Sky, StandardToBasicConverter, StandardToLambertConverter, StandardToPhongConverter, StandardToPhysicalConverter, StandardToToonConverter, Sun };
1672
+ export { DualFovCamera, SceneTraversal, SkinnedMeshBaker, SkyLight, StandardToBasicConverter, StandardToLambertConverter, StandardToPhongConverter, StandardToPhysicalConverter, StandardToToonConverter, Sun };
1627
1673
  //# sourceMappingURL=index.js.map