@onerjs/core 8.55.9 → 8.56.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.
Files changed (187) hide show
  1. package/AudioV2/webAudio/webAudioEngine.d.ts +7 -0
  2. package/AudioV2/webAudio/webAudioEngine.js +6 -5
  3. package/AudioV2/webAudio/webAudioEngine.js.map +1 -1
  4. package/Culling/Helper/boundingInfoHelper.js +8 -4
  5. package/Culling/Helper/boundingInfoHelper.js.map +1 -1
  6. package/Engines/AbstractEngine/abstractEngine.textureLoaders.d.ts +5 -1
  7. package/Engines/AbstractEngine/abstractEngine.textureLoaders.js +7 -3
  8. package/Engines/AbstractEngine/abstractEngine.textureLoaders.js.map +1 -1
  9. package/Engines/AbstractEngine/abstractEngine.textureLoaders.pure.d.ts +6 -0
  10. package/Engines/AbstractEngine/abstractEngine.textureLoaders.pure.js +16 -0
  11. package/Engines/AbstractEngine/abstractEngine.textureLoaders.pure.js.map +1 -0
  12. package/Engines/AbstractEngine/pure.d.ts +1 -0
  13. package/Engines/AbstractEngine/pure.js +1 -0
  14. package/Engines/AbstractEngine/pure.js.map +1 -1
  15. package/Engines/IDrawContext.d.ts +2 -0
  16. package/Engines/IDrawContext.js.map +1 -1
  17. package/Engines/WebGPU/webgpuDrawContext.d.ts +8 -0
  18. package/Engines/WebGPU/webgpuDrawContext.js +15 -0
  19. package/Engines/WebGPU/webgpuDrawContext.js.map +1 -1
  20. package/Engines/abstractEngine.pure.js +2 -2
  21. package/Engines/abstractEngine.pure.js.map +1 -1
  22. package/Engines/engine.d.ts +11 -3
  23. package/Engines/webgpuEngine.d.ts +1 -0
  24. package/Engines/webgpuEngine.js +1 -0
  25. package/Engines/webgpuEngine.js.map +1 -1
  26. package/Engines/webgpuEngine.pure.d.ts +10 -0
  27. package/Engines/webgpuEngine.pure.js +15 -1
  28. package/Engines/webgpuEngine.pure.js.map +1 -1
  29. package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.pure.js +2 -5
  30. package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.pure.js.map +1 -1
  31. package/Materials/Node/Blocks/Fragment/imageProcessingBlock.pure.js +2 -0
  32. package/Materials/Node/Blocks/Fragment/imageProcessingBlock.pure.js.map +1 -1
  33. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.pure.js +1 -0
  34. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.pure.js.map +1 -1
  35. package/Materials/Node/Blocks/powBlock.pure.js +2 -1
  36. package/Materials/Node/Blocks/powBlock.pure.js.map +1 -1
  37. package/Materials/Node/Blocks/triPlanarBlock.pure.js +14 -12
  38. package/Materials/Node/Blocks/triPlanarBlock.pure.js.map +1 -1
  39. package/Materials/Node/nodeMaterial.pure.d.ts +1 -0
  40. package/Materials/Node/nodeMaterialBuildState.d.ts +3 -3
  41. package/Materials/PBR/openpbrMaterial.pure.d.ts +1 -0
  42. package/Materials/PBR/pbrBaseMaterial.pure.d.ts +1 -0
  43. package/Materials/Textures/index.d.ts +1 -0
  44. package/Materials/Textures/index.js +1 -0
  45. package/Materials/Textures/index.js.map +1 -1
  46. package/Materials/drawWrapper.js +3 -0
  47. package/Materials/drawWrapper.js.map +1 -1
  48. package/Materials/imageProcessingConfiguration.defines.d.ts +3 -0
  49. package/Materials/imageProcessingConfiguration.defines.js +2 -0
  50. package/Materials/imageProcessingConfiguration.defines.js.map +1 -1
  51. package/Materials/imageProcessingConfiguration.functions.js +3 -0
  52. package/Materials/imageProcessingConfiguration.functions.js.map +1 -1
  53. package/Materials/imageProcessingConfiguration.pure.d.ts +58 -0
  54. package/Materials/imageProcessingConfiguration.pure.js +123 -2
  55. package/Materials/imageProcessingConfiguration.pure.js.map +1 -1
  56. package/Materials/standardMaterial.pure.d.ts +1 -0
  57. package/Materials/uniformBuffer.d.ts +29 -0
  58. package/Materials/uniformBuffer.js +146 -0
  59. package/Materials/uniformBuffer.js.map +1 -1
  60. package/Maths/colorTemperature.functions.d.ts +29 -0
  61. package/Maths/colorTemperature.functions.js +196 -0
  62. package/Maths/colorTemperature.functions.js.map +1 -0
  63. package/Maths/index.d.ts +1 -0
  64. package/Maths/index.js +1 -0
  65. package/Maths/index.js.map +1 -1
  66. package/Maths/pure.d.ts +1 -0
  67. package/Maths/pure.js +1 -0
  68. package/Maths/pure.js.map +1 -1
  69. package/Misc/observable.pure.js +1 -3
  70. package/Misc/observable.pure.js.map +1 -1
  71. package/Misc/tools.pure.js +1 -1
  72. package/Misc/tools.pure.js.map +1 -1
  73. package/PostProcesses/imageProcessingPostProcess.d.ts +41 -1
  74. package/PostProcesses/imageProcessingPostProcess.js +41 -1
  75. package/PostProcesses/imageProcessingPostProcess.js.map +1 -1
  76. package/PostProcesses/thinImageProcessingPostProcess.d.ts +50 -0
  77. package/PostProcesses/thinImageProcessingPostProcess.js +65 -0
  78. package/PostProcesses/thinImageProcessingPostProcess.js.map +1 -1
  79. package/Rendering/IBLShadows/iblShadowsMaterialCompatibility.pure.d.ts +12 -0
  80. package/Rendering/IBLShadows/iblShadowsMaterialCompatibility.pure.js +22 -0
  81. package/Rendering/IBLShadows/iblShadowsMaterialCompatibility.pure.js.map +1 -0
  82. package/Rendering/IBLShadows/iblShadowsPluginMaterial.pure.d.ts +1 -0
  83. package/Rendering/IBLShadows/iblShadowsPluginMaterial.pure.js +39 -0
  84. package/Rendering/IBLShadows/iblShadowsPluginMaterial.pure.js.map +1 -1
  85. package/Rendering/IBLShadows/iblShadowsRenderPipeline.pure.js +2 -4
  86. package/Rendering/IBLShadows/iblShadowsRenderPipeline.pure.js.map +1 -1
  87. package/Rendering/IBLShadows/pure.d.ts +1 -0
  88. package/Rendering/IBLShadows/pure.js +1 -0
  89. package/Rendering/IBLShadows/pure.js.map +1 -1
  90. package/Rendering/fluidRenderer/fluidRenderingObject.d.ts +11 -0
  91. package/Rendering/fluidRenderer/fluidRenderingObject.js +36 -14
  92. package/Rendering/fluidRenderer/fluidRenderingObject.js.map +1 -1
  93. package/Rendering/fluidRenderer/fluidRenderingObjectCustomParticles.d.ts +5 -0
  94. package/Rendering/fluidRenderer/fluidRenderingObjectCustomParticles.js +16 -3
  95. package/Rendering/fluidRenderer/fluidRenderingObjectCustomParticles.js.map +1 -1
  96. package/Rendering/fluidRenderer/fluidRenderingObjectParticleSystem.d.ts +5 -0
  97. package/Rendering/fluidRenderer/fluidRenderingObjectParticleSystem.js +12 -0
  98. package/Rendering/fluidRenderer/fluidRenderingObjectParticleSystem.js.map +1 -1
  99. package/Rendering/iblCdfGenerator.js +10 -1
  100. package/Rendering/iblCdfGenerator.js.map +1 -1
  101. package/Shaders/ShadersInclude/hdrFilteringFunctions.js +1 -1
  102. package/Shaders/ShadersInclude/hdrFilteringFunctions.js.map +1 -1
  103. package/Shaders/ShadersInclude/helperFunctions.js +2 -2
  104. package/Shaders/ShadersInclude/helperFunctions.js.map +1 -1
  105. package/Shaders/ShadersInclude/imageProcessingDeclaration.js +3 -0
  106. package/Shaders/ShadersInclude/imageProcessingDeclaration.js.map +1 -1
  107. package/Shaders/ShadersInclude/imageProcessingFunctions.js +3 -0
  108. package/Shaders/ShadersInclude/imageProcessingFunctions.js.map +1 -1
  109. package/Shaders/ShadersInclude/openpbrDirectLighting.js +34 -4
  110. package/Shaders/ShadersInclude/openpbrDirectLighting.js.map +1 -1
  111. package/Shaders/ShadersInclude/openpbrIblFunctions.js +8 -2
  112. package/Shaders/ShadersInclude/openpbrIblFunctions.js.map +1 -1
  113. package/Shaders/ShadersInclude/pbrDirectLightingFunctions.js +5 -0
  114. package/Shaders/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
  115. package/Shaders/fluidRenderingParticleDepth.vertex.js +7 -1
  116. package/Shaders/fluidRenderingParticleDepth.vertex.js.map +1 -1
  117. package/Shaders/fluidRenderingParticleDiffuse.vertex.js +7 -1
  118. package/Shaders/fluidRenderingParticleDiffuse.vertex.js.map +1 -1
  119. package/Shaders/fluidRenderingParticleThickness.vertex.js +7 -1
  120. package/Shaders/fluidRenderingParticleThickness.vertex.js.map +1 -1
  121. package/ShadersWGSL/ShadersInclude/imageProcessingDeclaration.js +3 -0
  122. package/ShadersWGSL/ShadersInclude/imageProcessingDeclaration.js.map +1 -1
  123. package/ShadersWGSL/ShadersInclude/imageProcessingFunctions.js +3 -0
  124. package/ShadersWGSL/ShadersInclude/imageProcessingFunctions.js.map +1 -1
  125. package/ShadersWGSL/ShadersInclude/openpbrDirectLighting.js +35 -5
  126. package/ShadersWGSL/ShadersInclude/openpbrDirectLighting.js.map +1 -1
  127. package/ShadersWGSL/ShadersInclude/openpbrDirectLightingInit.js +1 -1
  128. package/ShadersWGSL/ShadersInclude/openpbrDirectLightingInit.js.map +1 -1
  129. package/ShadersWGSL/ShadersInclude/openpbrIblFunctions.js +8 -2
  130. package/ShadersWGSL/ShadersInclude/openpbrIblFunctions.js.map +1 -1
  131. package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js +5 -0
  132. package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
  133. package/ShadersWGSL/fluidRenderingParticleDepth.vertex.js +16 -4
  134. package/ShadersWGSL/fluidRenderingParticleDepth.vertex.js.map +1 -1
  135. package/ShadersWGSL/fluidRenderingParticleDiffuse.vertex.js +15 -3
  136. package/ShadersWGSL/fluidRenderingParticleDiffuse.vertex.js.map +1 -1
  137. package/ShadersWGSL/fluidRenderingParticleThickness.vertex.js +15 -3
  138. package/ShadersWGSL/fluidRenderingParticleThickness.vertex.js.map +1 -1
  139. package/XR/features/Layers/WebXRCompositionLayer.d.ts +52 -0
  140. package/XR/features/Layers/WebXRCompositionLayer.js +80 -0
  141. package/XR/features/Layers/WebXRCompositionLayer.js.map +1 -1
  142. package/XR/features/WebXRControllerPointerSelection.pure.js +2 -1
  143. package/XR/features/WebXRControllerPointerSelection.pure.js.map +1 -1
  144. package/XR/features/WebXRControllerTeleportation.pure.js +2 -1
  145. package/XR/features/WebXRControllerTeleportation.pure.js.map +1 -1
  146. package/XR/features/WebXRDepthSensing.pure.d.ts +21 -0
  147. package/XR/features/WebXRDepthSensing.pure.js +42 -0
  148. package/XR/features/WebXRDepthSensing.pure.js.map +1 -1
  149. package/XR/features/WebXRHandTracking.pure.js +2 -0
  150. package/XR/features/WebXRHandTracking.pure.js.map +1 -1
  151. package/XR/features/WebXRLayers.pure.d.ts +12 -0
  152. package/XR/features/WebXRLayers.pure.js +31 -1
  153. package/XR/features/WebXRLayers.pure.js.map +1 -1
  154. package/XR/features/WebXRTrackedSources.d.ts +5 -0
  155. package/XR/features/WebXRTrackedSources.js +8 -0
  156. package/XR/features/WebXRTrackedSources.js.map +1 -0
  157. package/XR/features/WebXRTrackedSources.pure.d.ts +70 -0
  158. package/XR/features/WebXRTrackedSources.pure.js +153 -0
  159. package/XR/features/WebXRTrackedSources.pure.js.map +1 -0
  160. package/XR/features/index.d.ts +1 -0
  161. package/XR/features/index.js +1 -0
  162. package/XR/features/index.js.map +1 -1
  163. package/XR/features/pure.d.ts +1 -0
  164. package/XR/features/pure.js +1 -0
  165. package/XR/features/pure.js.map +1 -1
  166. package/XR/motionController/webXRAbstractMotionController.d.ts +53 -1
  167. package/XR/motionController/webXRAbstractMotionController.js +61 -0
  168. package/XR/motionController/webXRAbstractMotionController.js.map +1 -1
  169. package/XR/webXRDefaultExperience.js +8 -4
  170. package/XR/webXRDefaultExperience.js.map +1 -1
  171. package/XR/webXRExperienceHelper.js +86 -44
  172. package/XR/webXRExperienceHelper.js.map +1 -1
  173. package/XR/webXRFeaturesManager.d.ts +9 -0
  174. package/XR/webXRFeaturesManager.js +4 -0
  175. package/XR/webXRFeaturesManager.js.map +1 -1
  176. package/XR/webXRGraphicsBinding.d.ts +29 -0
  177. package/XR/webXRGraphicsBinding.js +40 -0
  178. package/XR/webXRGraphicsBinding.js.map +1 -1
  179. package/XR/webXRInputSource.js +1 -1
  180. package/XR/webXRInputSource.js.map +1 -1
  181. package/XR/webXRLayerWrapper.d.ts +7 -5
  182. package/XR/webXRLayerWrapper.js +10 -7
  183. package/XR/webXRLayerWrapper.js.map +1 -1
  184. package/XR/webXRSessionManager.d.ts +45 -0
  185. package/XR/webXRSessionManager.js +174 -29
  186. package/XR/webXRSessionManager.js.map +1 -1
  187. package/package.json +1 -1
@@ -0,0 +1,196 @@
1
+ import { Clamp } from "./math.scalar.functions.js";
2
+ import { Matrix, Vector2, Vector3 } from "./math.vector.pure.js";
3
+ /**
4
+ * Tabulated Planckian locus in CIE 1960 UCS (u, v) space, with the local isotherm slope `t` used to offset
5
+ * a chromaticity along the tint axis. Source: Wyszecki & Stiles, "Color Science", 2nd ed., 1982, pp. 227-228.
6
+ * Each row is [mired, u, v, t].
7
+ */
8
+ const PlanckianLocusTable = [
9
+ [0, 0.18006, 0.26352, -0.24341],
10
+ [10, 0.18066, 0.26589, -0.25479],
11
+ [20, 0.18133, 0.26846, -0.26876],
12
+ [30, 0.18208, 0.27119, -0.28539],
13
+ [40, 0.18293, 0.27407, -0.3047],
14
+ [50, 0.18388, 0.27709, -0.32675],
15
+ [60, 0.18494, 0.28021, -0.35156],
16
+ [70, 0.18611, 0.28342, -0.37915],
17
+ [80, 0.1874, 0.28668, -0.40955],
18
+ [90, 0.1888, 0.28997, -0.44278],
19
+ [100, 0.19032, 0.29326, -0.47888],
20
+ [125, 0.19462, 0.30141, -0.58204],
21
+ [150, 0.19962, 0.30921, -0.70471],
22
+ [175, 0.20525, 0.31647, -0.84901],
23
+ [200, 0.21142, 0.32312, -1.0182],
24
+ [225, 0.21807, 0.32909, -1.2168],
25
+ [250, 0.22511, 0.33439, -1.4512],
26
+ [275, 0.23247, 0.33904, -1.7298],
27
+ [300, 0.2401, 0.34308, -2.0637],
28
+ [325, 0.24792, 0.34655, -2.4681],
29
+ [350, 0.25591, 0.34951, -2.9641],
30
+ [375, 0.264, 0.352, -3.5814],
31
+ [400, 0.27218, 0.35407, -4.3633],
32
+ [425, 0.28039, 0.35577, -5.3762],
33
+ [450, 0.28863, 0.35714, -6.7262],
34
+ [475, 0.29685, 0.35823, -8.5955],
35
+ [500, 0.30505, 0.35907, -11.324],
36
+ [525, 0.3132, 0.35968, -15.628],
37
+ [550, 0.32129, 0.36011, -23.325],
38
+ [575, 0.32931, 0.36038, -40.77],
39
+ [600, 0.33724, 0.36051, -116.45],
40
+ ];
41
+ /**
42
+ * The minimum correlated color temperature, in Kelvin, representable by {@link TemperatureTintToXyz} (there is no
43
+ * upper bound: increasingly high temperatures approach mired 0, already within the tabulated range).
44
+ */
45
+ export const MinTemperatureKelvin = 1e6 / PlanckianLocusTable[PlanckianLocusTable.length - 1][0];
46
+ /**
47
+ * The maximum magnitude of the tint offset accepted by {@link TemperatureTintToXyz}, in either direction.
48
+ */
49
+ export const MaxTintMagnitude = 150;
50
+ /**
51
+ * Converts a correlated color temperature and tint offset into the CIE XYZ (Y = 1) coordinates of the
52
+ * corresponding illuminant white point, using a tabulated approximation of the Planckian locus in CIE 1960 UCS
53
+ * (u, v) space.
54
+ * @param temperatureKelvin The correlated color temperature of the illuminant, in Kelvin
55
+ * @param tint An offset perpendicular to the Planckian locus (the green/magenta axis), in the range
56
+ * [-{@link MaxTintMagnitude}, {@link MaxTintMagnitude}]
57
+ * @returns The CIE XYZ (Y = 1) coordinates of the illuminant white point
58
+ */
59
+ export function TemperatureTintToXyz(temperatureKelvin, tint) {
60
+ // Clamp before taking the reciprocal: a non-positive or NaN Kelvin value has no valid reciprocal-mired
61
+ // representation, and taking 1e6 / temperatureKelvin first (before clamping the result) would map negative
62
+ // inputs to the *hottest* end of the table instead of the coldest/minimum one.
63
+ const safeTemperatureKelvin = Number.isNaN(temperatureKelvin) ? MinTemperatureKelvin : Math.max(temperatureKelvin, MinTemperatureKelvin);
64
+ const mired = Clamp(1e6 / safeTemperatureKelvin, PlanckianLocusTable[0][0], PlanckianLocusTable[PlanckianLocusTable.length - 1][0]);
65
+ // Binary search for the table row pair bracketing `mired` (the table is sorted ascending by mired).
66
+ let low = 0;
67
+ let high = PlanckianLocusTable.length - 1;
68
+ while (high - low > 1) {
69
+ const mid = (low + high) >> 1;
70
+ if (PlanckianLocusTable[mid][0] <= mired) {
71
+ low = mid;
72
+ }
73
+ else {
74
+ high = mid;
75
+ }
76
+ }
77
+ const index = low;
78
+ const [lowMired, lowU, lowV, lowT] = PlanckianLocusTable[index];
79
+ const [highMired, highU, highV, highT] = PlanckianLocusTable[index + 1];
80
+ const f = (mired - lowMired) / (highMired - lowMired);
81
+ const uv = Vector2.Lerp(new Vector2(lowU, lowV), new Vector2(highU, highV), f);
82
+ const isothermLow = Vector2.Normalize(new Vector2(1, lowT));
83
+ const isothermHigh = Vector2.Normalize(new Vector2(1, highT));
84
+ const isotherm = Vector2.Normalize(Vector2.Lerp(isothermLow, isothermHigh, f));
85
+ const clampedTint = Clamp(tint, -MaxTintMagnitude, MaxTintMagnitude);
86
+ uv.subtractInPlace(isotherm.scale(clampedTint / 3000));
87
+ // CIE 1960 (u, v) -> CIE xyY (Y = 1) -> CIE XYZ.
88
+ const denom = 2 * uv.x - 8 * uv.y + 4;
89
+ const x = (3 * uv.x) / denom;
90
+ const y = (2 * uv.y) / denom;
91
+ return new Vector3(x / y, 1, (1 - x - y) / y);
92
+ }
93
+ // `Matrix.FromArray` reads values column-major, so each 3x3 matrix below is written column-by-column, not row-by-row.
94
+ /**
95
+ * The Bradford cone-response matrix used for chromatic adaptation.
96
+ */
97
+ // prettier-ignore
98
+ const BradfordMatrix = Matrix.FromArray([
99
+ 0.8951, -0.7502, 0.0389, 0,
100
+ 0.2664, 1.7135, -0.0685, 0,
101
+ -0.1614, 0.0367, 1.0296, 0,
102
+ 0, 0, 0, 1,
103
+ ]);
104
+ const InverseBradfordMatrix = Matrix.Invert(BradfordMatrix);
105
+ /**
106
+ * Computes a per-channel Bradford adaptation ratio, clamped to avoid extreme temperature/tint combinations
107
+ * blowing up the resulting matrix when a cone-response component approaches zero.
108
+ * @param destComponent The destination white's cone-response component
109
+ * @param sourceComponent The source white's cone-response component
110
+ * @returns The ratio to use for this channel, clamped to [0.1, 10]
111
+ */
112
+ function ClampedAdaptationRatio(destComponent, sourceComponent) {
113
+ const ratio = sourceComponent > 0 ? destComponent / sourceComponent : 10;
114
+ return Clamp(ratio, 0.1, 10);
115
+ }
116
+ /**
117
+ * Computes the Bradford chromatic-adaptation matrix that maps CIE XYZ values from `sourceWhiteXYZ` to `destWhiteXYZ`.
118
+ * @param sourceWhiteXYZ The CIE XYZ (Y = 1) coordinates of the source reference white
119
+ * @param destWhiteXYZ The CIE XYZ (Y = 1) coordinates of the destination reference white
120
+ * @returns A matrix mapping source-referenced XYZ to destination-referenced XYZ
121
+ */
122
+ function BradfordAdapt(sourceWhiteXYZ, destWhiteXYZ) {
123
+ const sourceLMS = Vector3.TransformNormal(sourceWhiteXYZ, BradfordMatrix);
124
+ const destLMS = Vector3.TransformNormal(destWhiteXYZ, BradfordMatrix);
125
+ // prettier-ignore
126
+ const scale = Matrix.FromArray([
127
+ ClampedAdaptationRatio(destLMS.x, sourceLMS.x), 0, 0, 0,
128
+ 0, ClampedAdaptationRatio(destLMS.y, sourceLMS.y), 0, 0,
129
+ 0, 0, ClampedAdaptationRatio(destLMS.z, sourceLMS.z), 0,
130
+ 0, 0, 0, 1,
131
+ ]);
132
+ // adapt = InverseBradfordMatrix * scale * BradfordMatrix, written back-to-front since `A.multiply(B)` computes `B x A`.
133
+ const scaledByBradford = BradfordMatrix.multiply(scale);
134
+ return scaledByBradford.multiply(InverseBradfordMatrix);
135
+ }
136
+ /**
137
+ * The standard CIE Illuminant D65 white point, in CIE XYZ (Y = 1).
138
+ */
139
+ const StandardD65Xyz = new Vector3(0.95047, 1.0, 1.08883);
140
+ /**
141
+ * The standard sRGB / Rec.709 linear RGB to CIE XYZ matrix, calibrated to the externally-standardized CIE
142
+ * Illuminant D65 chromaticity - i.e. `StandardRgbToXyzD65 * (1, 1, 1) = StandardD65Xyz` exactly.
143
+ */
144
+ // prettier-ignore
145
+ const StandardRgbToXyzD65 = Matrix.FromArray([
146
+ 0.4124564, 0.2126729, 0.0193339, 0,
147
+ 0.3575761, 0.7151522, 0.119192, 0,
148
+ 0.1804375, 0.072175, 0.9503041, 0,
149
+ 0, 0, 0, 1,
150
+ ]);
151
+ /**
152
+ * The linear RGB to CIE XYZ matrix actually used by {@link GetWhiteBalanceMatrix}, recalibrated from
153
+ * {@link StandardRgbToXyzD65} via a single Bradford adaptation step so that neutral (1, 1, 1) maps exactly onto
154
+ * this module's own Planckian-locus approximation of 6500 K (see {@link TemperatureTintToXyz}) instead of the
155
+ * externally-standardized CIE D65 chromaticity. Those two are close but never exactly equal, by definition: D65
156
+ * is defined via the CIE daylight locus, a model fit to measured daylight spectra, which deliberately deviates
157
+ * from the Planckian locus (real daylight isn't quite blackbody radiation) - no table or precision fix can close
158
+ * that gap without distorting temperature/tint for every other illuminant.
159
+ *
160
+ * This is what lets `GetWhiteBalanceMatrix(6500, 0)` be exactly the identity matrix - the default "no adjustment"
161
+ * temperature/tint are a true no-op - without needing to special-case that one input: the reverse adaptation is
162
+ * applied once, here, to the matrix itself, rather than to every call's result.
163
+ */
164
+ const RgbToXyzD65 = StandardRgbToXyzD65.multiply(BradfordAdapt(StandardD65Xyz, TemperatureTintToXyz(6500, 0)));
165
+ /**
166
+ * The CIE XYZ to linear RGB matrix, the inverse of {@link RgbToXyzD65}.
167
+ */
168
+ const XyzToRgbD65 = Matrix.Invert(RgbToXyzD65);
169
+ /**
170
+ * The working color space's reference white, in CIE XYZ (Y = 1) - what neutral (1, 1, 1) linear RGB maps to
171
+ * through {@link RgbToXyzD65}. Since that matrix is itself calibrated to this module's own 6500 K point (see
172
+ * above), this is exactly `TemperatureTintToXyz(6500, 0)`. Deriving it as "whatever (1, 1, 1) maps to" (rather
173
+ * than calling `TemperatureTintToXyz` a second time) keeps the invariant self-documenting: a fully white-balanced
174
+ * neutral patch round-trips back to exactly (1, 1, 1) for any input illuminant, because the adaptation target is
175
+ * always tied directly to whatever the working color space itself already treats as neutral.
176
+ */
177
+ const ReferenceWhiteXyz = Vector3.TransformNormal(new Vector3(1, 1, 1), RgbToXyzD65);
178
+ /**
179
+ * Computes the linear RGB (sRGB / Rec.709 primaries) color-correction matrix that white-balances the given
180
+ * illuminant, by chromatically adapting its white point (see {@link TemperatureTintToXyz}) to the working
181
+ * color space's reference white using the Bradford transform.
182
+ * @param temperatureKelvin The correlated color temperature of the illuminant to neutralize, in Kelvin
183
+ * @param tint An offset perpendicular to the Planckian locus (the green/magenta axis), in the range [-150, 150]
184
+ * @returns A column-major 3x3 matrix (9 values), ready to be bound as a `mat3` shader uniform
185
+ */
186
+ export function GetWhiteBalanceMatrix(temperatureKelvin, tint) {
187
+ const targetWhiteXYZ = TemperatureTintToXyz(temperatureKelvin, tint);
188
+ const adapt = BradfordAdapt(targetWhiteXYZ, ReferenceWhiteXyz);
189
+ // finalMatrix = XyzToRgbD65 * adapt * RgbToXyzD65, written back-to-front (see BradfordAdapt).
190
+ const adaptedFromRgb = RgbToXyzD65.multiply(adapt);
191
+ const finalMatrix = adaptedFromRgb.multiply(XyzToRgbD65);
192
+ // `Matrix` stores its values column-major, matching the layout GLSL/WGSL `mat3` uniforms expect,
193
+ // so the upper-left 3x3 block can be extracted directly with no transpose.
194
+ return Matrix.GetAsMatrix3x3(finalMatrix);
195
+ }
196
+ //# sourceMappingURL=colorTemperature.functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colorTemperature.functions.js","sourceRoot":"","sources":["../../../../dev/core/src/Maths/colorTemperature.functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE9D;;;;GAIG;AACH,MAAM,mBAAmB,GAA6D;IAClF,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC;IAC/B,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC;IAChC,CAA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S,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;IAClC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;IACjC,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;IACjC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;CACb,CAAC,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,GAAG,mBAAmB,CAAC,QAAQ,CAAC,aAAa,CAAC,cAAc,EAAE,oBAAoB,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAE/G;;GAEG;AACH,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAE/C;;;;;;;GAOG;AACH,MAAM,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;AAErF;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,iBAAyB,EAAE,IAAY;IACzE,MAAM,cAAc,GAAG,oBAAoB,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;IACrE,MAAM,KAAK,GAAG,aAAa,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;IAE/D,8FAA8F;IAC9F,MAAM,cAAc,GAAG,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,WAAW,GAAG,cAAc,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAEzD,iGAAiG;IACjG,2EAA2E;IAC3E,OAAO,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["import { Clamp } from \"./math.scalar.functions\";\nimport { Matrix, Vector2, Vector3 } from \"./math.vector.pure\";\n\n/**\n * Tabulated Planckian locus in CIE 1960 UCS (u, v) space, with the local isotherm slope `t` used to offset\n * a chromaticity along the tint axis. Source: Wyszecki &amp; Stiles, \"Color Science\", 2nd ed., 1982, pp. 227-228.\n * Each row is [mired, u, v, t].\n */\nconst PlanckianLocusTable: ReadonlyArray<readonly [number, number, number, number]> = [\n [0, 0.18006, 0.26352, -0.24341],\n [10, 0.18066, 0.26589, -0.25479],\n [20, 0.18133, 0.26846, -0.26876],\n [30, 0.18208, 0.27119, -0.28539],\n [40, 0.18293, 0.27407, -0.3047],\n [50, 0.18388, 0.27709, -0.32675],\n [60, 0.18494, 0.28021, -0.35156],\n [70, 0.18611, 0.28342, -0.37915],\n [80, 0.1874, 0.28668, -0.40955],\n [90, 0.1888, 0.28997, -0.44278],\n [100, 0.19032, 0.29326, -0.47888],\n [125, 0.19462, 0.30141, -0.58204],\n [150, 0.19962, 0.30921, -0.70471],\n [175, 0.20525, 0.31647, -0.84901],\n [200, 0.21142, 0.32312, -1.0182],\n [225, 0.21807, 0.32909, -1.2168],\n [250, 0.22511, 0.33439, -1.4512],\n [275, 0.23247, 0.33904, -1.7298],\n [300, 0.2401, 0.34308, -2.0637],\n [325, 0.24792, 0.34655, -2.4681],\n [350, 0.25591, 0.34951, -2.9641],\n [375, 0.264, 0.352, -3.5814],\n [400, 0.27218, 0.35407, -4.3633],\n [425, 0.28039, 0.35577, -5.3762],\n [450, 0.28863, 0.35714, -6.7262],\n [475, 0.29685, 0.35823, -8.5955],\n [500, 0.30505, 0.35907, -11.324],\n [525, 0.3132, 0.35968, -15.628],\n [550, 0.32129, 0.36011, -23.325],\n [575, 0.32931, 0.36038, -40.77],\n [600, 0.33724, 0.36051, -116.45],\n];\n\n/**\n * The minimum correlated color temperature, in Kelvin, representable by {@link TemperatureTintToXyz} (there is no\n * upper bound: increasingly high temperatures approach mired 0, already within the tabulated range).\n */\nexport const MinTemperatureKelvin = 1e6 / PlanckianLocusTable[PlanckianLocusTable.length - 1][0];\n\n/**\n * The maximum magnitude of the tint offset accepted by {@link TemperatureTintToXyz}, in either direction.\n */\nexport const MaxTintMagnitude = 150;\n\n/**\n * Converts a correlated color temperature and tint offset into the CIE XYZ (Y = 1) coordinates of the\n * corresponding illuminant white point, using a tabulated approximation of the Planckian locus in CIE 1960 UCS\n * (u, v) space.\n * @param temperatureKelvin The correlated color temperature of the illuminant, in Kelvin\n * @param tint An offset perpendicular to the Planckian locus (the green/magenta axis), in the range\n * [-{@link MaxTintMagnitude}, {@link MaxTintMagnitude}]\n * @returns The CIE XYZ (Y = 1) coordinates of the illuminant white point\n */\nexport function TemperatureTintToXyz(temperatureKelvin: number, tint: number): Vector3 {\n // Clamp before taking the reciprocal: a non-positive or NaN Kelvin value has no valid reciprocal-mired\n // representation, and taking 1e6 / temperatureKelvin first (before clamping the result) would map negative\n // inputs to the *hottest* end of the table instead of the coldest/minimum one.\n const safeTemperatureKelvin = Number.isNaN(temperatureKelvin) ? MinTemperatureKelvin : Math.max(temperatureKelvin, MinTemperatureKelvin);\n const mired = Clamp(1e6 / safeTemperatureKelvin, PlanckianLocusTable[0][0], PlanckianLocusTable[PlanckianLocusTable.length - 1][0]);\n\n // Binary search for the table row pair bracketing `mired` (the table is sorted ascending by mired).\n let low = 0;\n let high = PlanckianLocusTable.length - 1;\n while (high - low > 1) {\n const mid = (low + high) >> 1;\n if (PlanckianLocusTable[mid][0] <= mired) {\n low = mid;\n } else {\n high = mid;\n }\n }\n const index = low;\n\n const [lowMired, lowU, lowV, lowT] = PlanckianLocusTable[index];\n const [highMired, highU, highV, highT] = PlanckianLocusTable[index + 1];\n const f = (mired - lowMired) / (highMired - lowMired);\n\n const uv = Vector2.Lerp(new Vector2(lowU, lowV), new Vector2(highU, highV), f);\n\n const isothermLow = Vector2.Normalize(new Vector2(1, lowT));\n const isothermHigh = Vector2.Normalize(new Vector2(1, highT));\n const isotherm = Vector2.Normalize(Vector2.Lerp(isothermLow, isothermHigh, f));\n\n const clampedTint = Clamp(tint, -MaxTintMagnitude, MaxTintMagnitude);\n uv.subtractInPlace(isotherm.scale(clampedTint / 3000));\n\n // CIE 1960 (u, v) -> CIE xyY (Y = 1) -> CIE XYZ.\n const denom = 2 * uv.x - 8 * uv.y + 4;\n const x = (3 * uv.x) / denom;\n const y = (2 * uv.y) / denom;\n\n return new Vector3(x / y, 1, (1 - x - y) / y);\n}\n\n// `Matrix.FromArray` reads values column-major, so each 3x3 matrix below is written column-by-column, not row-by-row.\n\n/**\n * The Bradford cone-response matrix used for chromatic adaptation.\n */\n// prettier-ignore\nconst BradfordMatrix = Matrix.FromArray([\n 0.8951, -0.7502, 0.0389, 0,\n 0.2664, 1.7135, -0.0685, 0,\n -0.1614, 0.0367, 1.0296, 0,\n 0, 0, 0, 1,\n]);\n\nconst InverseBradfordMatrix = Matrix.Invert(BradfordMatrix);\n\n/**\n * Computes a per-channel Bradford adaptation ratio, clamped to avoid extreme temperature/tint combinations\n * blowing up the resulting matrix when a cone-response component approaches zero.\n * @param destComponent The destination white's cone-response component\n * @param sourceComponent The source white's cone-response component\n * @returns The ratio to use for this channel, clamped to [0.1, 10]\n */\nfunction ClampedAdaptationRatio(destComponent: number, sourceComponent: number): number {\n const ratio = sourceComponent > 0 ? destComponent / sourceComponent : 10;\n return Clamp(ratio, 0.1, 10);\n}\n\n/**\n * Computes the Bradford chromatic-adaptation matrix that maps CIE XYZ values from `sourceWhiteXYZ` to `destWhiteXYZ`.\n * @param sourceWhiteXYZ The CIE XYZ (Y = 1) coordinates of the source reference white\n * @param destWhiteXYZ The CIE XYZ (Y = 1) coordinates of the destination reference white\n * @returns A matrix mapping source-referenced XYZ to destination-referenced XYZ\n */\nfunction BradfordAdapt(sourceWhiteXYZ: Vector3, destWhiteXYZ: Vector3): Matrix {\n const sourceLMS = Vector3.TransformNormal(sourceWhiteXYZ, BradfordMatrix);\n const destLMS = Vector3.TransformNormal(destWhiteXYZ, BradfordMatrix);\n\n // prettier-ignore\n const scale = Matrix.FromArray([\n ClampedAdaptationRatio(destLMS.x, sourceLMS.x), 0, 0, 0,\n 0, ClampedAdaptationRatio(destLMS.y, sourceLMS.y), 0, 0,\n 0, 0, ClampedAdaptationRatio(destLMS.z, sourceLMS.z), 0,\n 0, 0, 0, 1,\n ]);\n\n // adapt = InverseBradfordMatrix * scale * BradfordMatrix, written back-to-front since `A.multiply(B)` computes `B x A`.\n const scaledByBradford = BradfordMatrix.multiply(scale);\n return scaledByBradford.multiply(InverseBradfordMatrix);\n}\n\n/**\n * The standard CIE Illuminant D65 white point, in CIE XYZ (Y = 1).\n */\nconst StandardD65Xyz = new Vector3(0.95047, 1.0, 1.08883);\n\n/**\n * The standard sRGB / Rec.709 linear RGB to CIE XYZ matrix, calibrated to the externally-standardized CIE\n * Illuminant D65 chromaticity - i.e. `StandardRgbToXyzD65 * (1, 1, 1) = StandardD65Xyz` exactly.\n */\n// prettier-ignore\nconst StandardRgbToXyzD65 = Matrix.FromArray([\n 0.4124564, 0.2126729, 0.0193339, 0,\n 0.3575761, 0.7151522, 0.119192, 0,\n 0.1804375, 0.072175, 0.9503041, 0,\n 0, 0, 0, 1,\n]);\n\n/**\n * The linear RGB to CIE XYZ matrix actually used by {@link GetWhiteBalanceMatrix}, recalibrated from\n * {@link StandardRgbToXyzD65} via a single Bradford adaptation step so that neutral (1, 1, 1) maps exactly onto\n * this module's own Planckian-locus approximation of 6500 K (see {@link TemperatureTintToXyz}) instead of the\n * externally-standardized CIE D65 chromaticity. Those two are close but never exactly equal, by definition: D65\n * is defined via the CIE daylight locus, a model fit to measured daylight spectra, which deliberately deviates\n * from the Planckian locus (real daylight isn't quite blackbody radiation) - no table or precision fix can close\n * that gap without distorting temperature/tint for every other illuminant.\n *\n * This is what lets `GetWhiteBalanceMatrix(6500, 0)` be exactly the identity matrix - the default \"no adjustment\"\n * temperature/tint are a true no-op - without needing to special-case that one input: the reverse adaptation is\n * applied once, here, to the matrix itself, rather than to every call's result.\n */\nconst RgbToXyzD65 = StandardRgbToXyzD65.multiply(BradfordAdapt(StandardD65Xyz, TemperatureTintToXyz(6500, 0)));\n\n/**\n * The CIE XYZ to linear RGB matrix, the inverse of {@link RgbToXyzD65}.\n */\nconst XyzToRgbD65 = Matrix.Invert(RgbToXyzD65);\n\n/**\n * The working color space's reference white, in CIE XYZ (Y = 1) - what neutral (1, 1, 1) linear RGB maps to\n * through {@link RgbToXyzD65}. Since that matrix is itself calibrated to this module's own 6500 K point (see\n * above), this is exactly `TemperatureTintToXyz(6500, 0)`. Deriving it as \"whatever (1, 1, 1) maps to\" (rather\n * than calling `TemperatureTintToXyz` a second time) keeps the invariant self-documenting: a fully white-balanced\n * neutral patch round-trips back to exactly (1, 1, 1) for any input illuminant, because the adaptation target is\n * always tied directly to whatever the working color space itself already treats as neutral.\n */\nconst ReferenceWhiteXyz = Vector3.TransformNormal(new Vector3(1, 1, 1), RgbToXyzD65);\n\n/**\n * Computes the linear RGB (sRGB / Rec.709 primaries) color-correction matrix that white-balances the given\n * illuminant, by chromatically adapting its white point (see {@link TemperatureTintToXyz}) to the working\n * color space's reference white using the Bradford transform.\n * @param temperatureKelvin The correlated color temperature of the illuminant to neutralize, in Kelvin\n * @param tint An offset perpendicular to the Planckian locus (the green/magenta axis), in the range [-150, 150]\n * @returns A column-major 3x3 matrix (9 values), ready to be bound as a `mat3` shader uniform\n */\nexport function GetWhiteBalanceMatrix(temperatureKelvin: number, tint: number): Float32Array | Array<number> {\n const targetWhiteXYZ = TemperatureTintToXyz(temperatureKelvin, tint);\n const adapt = BradfordAdapt(targetWhiteXYZ, ReferenceWhiteXyz);\n\n // finalMatrix = XyzToRgbD65 * adapt * RgbToXyzD65, written back-to-front (see BradfordAdapt).\n const adaptedFromRgb = RgbToXyzD65.multiply(adapt);\n const finalMatrix = adaptedFromRgb.multiply(XyzToRgbD65);\n\n // `Matrix` stores its values column-major, matching the layout GLSL/WGSL `mat3` uniforms expect,\n // so the upper-left 3x3 block can be extracted directly with no transpose.\n return Matrix.GetAsMatrix3x3(finalMatrix);\n}\n"]}
package/Maths/index.d.ts CHANGED
@@ -18,3 +18,4 @@ export * from "./ThinMaths/index.js";
18
18
  export * from "./math.scalar.functions.js";
19
19
  export * from "./math.geospatial.js";
20
20
  export * from "./math.geospatial.functions.js";
21
+ export * from "./colorTemperature.functions.js";
package/Maths/index.js CHANGED
@@ -19,4 +19,5 @@ export * from "./ThinMaths/index.js";
19
19
  export * from "./math.scalar.functions.js";
20
20
  export * from "./math.geospatial.js";
21
21
  export * from "./math.geospatial.functions.js";
22
+ export * from "./colorTemperature.functions.js";
22
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/core/src/Maths/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-restricted-imports */\r\nexport * from \"./math.scalar\";\r\nexport * from \"./math.functions\";\r\nexport * from \"./math.polar\";\r\nexport * from \"./math.like\";\r\nexport * from \"./math.axis\";\r\nexport * from \"./math.constants\";\r\nexport * from \"./math.frustum\";\r\nexport * from \"./math.path\";\r\nexport * from \"./math.plane\";\r\nexport * from \"./math.size\";\r\nexport * from \"./math.vertexFormat\";\r\nexport * from \"./math.viewport\";\r\nexport * from \"./math\";\r\nexport * from \"./sphericalPolynomial\";\r\nexport * from \"./halton2DSequence\";\r\nexport * from \"./math.vector.functions\";\r\nexport * from \"./ThinMaths/index\";\r\nexport * from \"./math.scalar.functions\";\r\nexport * from \"./math.geospatial\";\r\nexport * from \"./math.geospatial.functions\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/core/src/Maths/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-restricted-imports */\r\nexport * from \"./math.scalar\";\r\nexport * from \"./math.functions\";\r\nexport * from \"./math.polar\";\r\nexport * from \"./math.like\";\r\nexport * from \"./math.axis\";\r\nexport * from \"./math.constants\";\r\nexport * from \"./math.frustum\";\r\nexport * from \"./math.path\";\r\nexport * from \"./math.plane\";\r\nexport * from \"./math.size\";\r\nexport * from \"./math.vertexFormat\";\r\nexport * from \"./math.viewport\";\r\nexport * from \"./math\";\r\nexport * from \"./sphericalPolynomial\";\r\nexport * from \"./halton2DSequence\";\r\nexport * from \"./math.vector.functions\";\r\nexport * from \"./ThinMaths/index\";\r\nexport * from \"./math.scalar.functions\";\r\nexport * from \"./math.geospatial\";\r\nexport * from \"./math.geospatial.functions\";\r\nexport * from \"./colorTemperature.functions\";\r\n"]}
package/Maths/pure.d.ts CHANGED
@@ -19,5 +19,6 @@ export * from "./ThinMaths/pure.js";
19
19
  export * from "./math.scalar.functions.js";
20
20
  export * from "./math.geospatial.js";
21
21
  export * from "./math.geospatial.functions.js";
22
+ export * from "./colorTemperature.functions.js";
22
23
  export * from "./math.color.pure.js";
23
24
  export * from "./math.vector.pure.js";
package/Maths/pure.js CHANGED
@@ -20,6 +20,7 @@ export * from "./ThinMaths/pure.js";
20
20
  export * from "./math.scalar.functions.js";
21
21
  export * from "./math.geospatial.js";
22
22
  export * from "./math.geospatial.functions.js";
23
+ export * from "./colorTemperature.functions.js";
23
24
  export * from "./math.color.pure.js";
24
25
  export * from "./math.vector.pure.js";
25
26
  //# sourceMappingURL=pure.js.map
package/Maths/pure.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pure.js","sourceRoot":"","sources":["../../../../dev/core/src/Maths/pure.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,6DAA6D;AAC7D,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC","sourcesContent":["/** Pure barrel — re-exports only side-effect-free modules */\n/* eslint-disable @typescript-eslint/no-restricted-imports */\nexport * from \"./math.scalar\";\nexport * from \"./math.functions\";\nexport * from \"./math.polar\";\nexport * from \"./math.like\";\nexport * from \"./math.axis\";\nexport * from \"./math.constants\";\nexport * from \"./math.frustum\";\nexport * from \"./math.path\";\nexport * from \"./math.plane\";\nexport * from \"./math.size\";\nexport * from \"./math.vertexFormat\";\nexport * from \"./math.viewport\";\nexport * from \"./math\";\nexport * from \"./sphericalPolynomial.pure\";\nexport * from \"./halton2DSequence\";\nexport * from \"./math.vector.functions\";\nexport * from \"./ThinMaths/pure\";\nexport * from \"./math.scalar.functions\";\nexport * from \"./math.geospatial\";\nexport * from \"./math.geospatial.functions\";\nexport * from \"./math.color.pure\";\nexport * from \"./math.vector.pure\";\n"]}
1
+ {"version":3,"file":"pure.js","sourceRoot":"","sources":["../../../../dev/core/src/Maths/pure.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,6DAA6D;AAC7D,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC","sourcesContent":["/** Pure barrel — re-exports only side-effect-free modules */\n/* eslint-disable @typescript-eslint/no-restricted-imports */\nexport * from \"./math.scalar\";\nexport * from \"./math.functions\";\nexport * from \"./math.polar\";\nexport * from \"./math.like\";\nexport * from \"./math.axis\";\nexport * from \"./math.constants\";\nexport * from \"./math.frustum\";\nexport * from \"./math.path\";\nexport * from \"./math.plane\";\nexport * from \"./math.size\";\nexport * from \"./math.vertexFormat\";\nexport * from \"./math.viewport\";\nexport * from \"./math\";\nexport * from \"./sphericalPolynomial.pure\";\nexport * from \"./halton2DSequence\";\nexport * from \"./math.vector.functions\";\nexport * from \"./ThinMaths/pure\";\nexport * from \"./math.scalar.functions\";\nexport * from \"./math.geospatial\";\nexport * from \"./math.geospatial.functions\";\nexport * from \"./colorTemperature.functions\";\nexport * from \"./math.color.pure\";\nexport * from \"./math.vector.pure\";\n"]}
@@ -157,9 +157,7 @@ export class Observable {
157
157
  }
158
158
  // If the observable was already triggered and the observable is set to notify if triggered, notify the new observer
159
159
  if (this._hasNotified && this.notifyIfTriggered) {
160
- if (this._lastNotifiedValue !== undefined) {
161
- this.notifyObserver(observer, this._lastNotifiedValue);
162
- }
160
+ this.notifyObserver(observer, this._lastNotifiedValue);
163
161
  }
164
162
  // attach the remove function to the observer
165
163
  const observableWeakRef = IsWeakRefSupported ? new WeakRef(this) : { deref: () => this };
@@ -1 +1 @@
1
- {"version":3,"file":"observable.pure.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/observable.pure.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAM7D,MAAM,kBAAkB,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,UAAU;IACnB;;;;;;OAMG;IACH,YAAY,IAAY,EAAE,iBAAiB,GAAG,KAAK,EAAE,MAAY,EAAE,aAAmB;QAClF,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,aAAa,CAAC,CA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AAC,IAAI,KAAK,IAAI,EAAE,CAAC;gBACvC,OAAO,IAAI,CAAC;YAChB,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ","sourcesContent":["/** This file must only contain pure code and pure imports */\r\n\r\nimport { type Nullable } from \"../types\";\r\n\r\ndeclare const WeakRef: any;\r\n\r\nconst IsWeakRefSupported = typeof WeakRef !== \"undefined\";\r\n\r\n/**\r\n * A class serves as a medium between the observable and its observers\r\n */\r\nexport class EventState {\r\n /**\r\n * Create a new EventState\r\n * @param mask defines the mask associated with this state\r\n * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n */\r\n constructor(mask: number, skipNextObservers = false, target?: any, currentTarget?: any) {\r\n this.initialize(mask, skipNextObservers, target, currentTarget);\r\n }\r\n\r\n /**\r\n * Initialize the current event state\r\n * @param mask defines the mask associated with this state\r\n * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n * @returns the current event state\r\n */\r\n public initialize(mask: number, skipNextObservers = false, target?: any, currentTarget?: any): EventState {\r\n this.mask = mask;\r\n this.skipNextObservers = skipNextObservers;\r\n this.target = target;\r\n this.currentTarget = currentTarget;\r\n return this;\r\n }\r\n\r\n /**\r\n * An Observer can set this property to true to prevent subsequent observers of being notified\r\n */\r\n public skipNextObservers: boolean;\r\n\r\n /**\r\n * Get the mask value that were used to trigger the event corresponding to this EventState object\r\n */\r\n public mask: number;\r\n\r\n /**\r\n * The object that originally notified the event\r\n */\r\n public target?: any;\r\n\r\n /**\r\n * The current object in the bubbling phase\r\n */\r\n public currentTarget?: any;\r\n\r\n /**\r\n * This will be populated with the return value of the last function that was executed.\r\n * If it is the first function in the callback chain it will be the event data.\r\n */\r\n public lastReturnValue?: any;\r\n\r\n /**\r\n * User defined information that will be sent to observers\r\n */\r\n public userInfo?: any;\r\n}\r\n\r\n/**\r\n * Represent an observer registered to a given IObservable object.\r\n */\r\nexport interface IObserver {\r\n /**\r\n * Remove the observer from its observable\r\n * @param defer if true, the removal will be deferred to avoid callback skipping (default: false)\r\n */\r\n remove(defer?: boolean): void;\r\n}\r\n\r\n/**\r\n * Represent an observer registered to a given Observable object.\r\n */\r\nexport class Observer<T> implements IObserver {\r\n /** @internal */\r\n public _willBeUnregistered = false;\r\n /**\r\n * Gets or sets a property defining that the observer as to be unregistered after the next notification\r\n */\r\n public unregisterOnNextCall = false;\r\n\r\n /**\r\n * this function can be used to remove the observer from the observable.\r\n * It will be set by the observable that the observer belongs to.\r\n * @internal\r\n */\r\n public _remove: Nullable<(defer?: boolean) => void> = null;\r\n\r\n /**\r\n * Creates a new observer\r\n * @param callback defines the callback to call when the observer is notified\r\n * @param mask defines the mask of the observer (used to filter notifications)\r\n * @param scope defines the current scope used to restore the JS context\r\n */\r\n constructor(\r\n /**\r\n * Defines the callback to call when the observer is notified\r\n */\r\n public callback: (eventData: T, eventState: EventState) => void,\r\n /**\r\n * Defines the mask of the observer (used to filter notifications)\r\n */\r\n public mask: number,\r\n /**\r\n * [null] Defines the current scope used to restore the JS context\r\n */\r\n public scope: any = null\r\n ) {}\r\n\r\n /**\r\n * Remove the observer from its observable\r\n * This can be used instead of using the observable's remove function.\r\n * @param defer if true, the removal will be deferred to avoid callback skipping (default: false)\r\n */\r\n public remove(defer = false) {\r\n if (this._remove) {\r\n this._remove(defer);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * An interface that defines the reader side of an Observable (receive notifications).\r\n */\r\nexport interface IReadonlyObservable<T = unknown> {\r\n /**\r\n * Create a new Observer with the specified callback\r\n * @param callback the callback that will be executed for that Observer\r\n * @param mask the mask used to filter observers\r\n * @param insertFirst if true the callback will be inserted at the first position, hence executed before the others ones. If false (default behavior) the callback will be inserted at the last position, executed after all the others already present.\r\n * @param scope optional scope for the callback to be called from\r\n * @param unregisterOnFirstCall defines if the observer as to be unregistered after the next notification\r\n * @returns the new observer created for the callback\r\n */\r\n add(callback: (eventData: T, eventState: EventState) => void, mask?: number, insertFirst?: boolean, scope?: unknown, unregisterOnFirstCall?: boolean): IObserver;\r\n\r\n /**\r\n * Create a new Observer with the specified callback and unregisters after the next notification\r\n * @param callback the callback that will be executed for that Observer\r\n * @returns the new observer created for the callback\r\n */\r\n addOnce(callback: (eventData: T, eventState: EventState) => void): IObserver;\r\n}\r\n\r\n/**\r\n * The Observable class is a simple implementation of the Observable pattern.\r\n *\r\n * There's one slight particularity though: a given Observable can notify its observer using a particular mask value, only the Observers registered with this mask value will be notified.\r\n * This enable a more fine grained execution without having to rely on multiple different Observable objects.\r\n * For instance you may have a given Observable that have four different types of notifications: Move (mask = 0x01), Stop (mask = 0x02), Turn Right (mask = 0X04), Turn Left (mask = 0X08).\r\n * A given observer can register itself with only Move and Stop (mask = 0x03), then it will only be notified when one of these two occurs and will never be for Turn Left/Right.\r\n */\r\nexport class Observable<T> implements IReadonlyObservable<T> {\r\n private _observers = new Array<Observer<T>>();\r\n private _numObserversMarkedAsDeleted = 0;\r\n private _hasNotified = false;\r\n private _lastNotifiedValue?: T;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _eventState: EventState;\r\n\r\n private _onObserverAdded: Nullable<(observer: Observer<T>) => void>;\r\n\r\n /**\r\n * Create an observable from a Promise.\r\n * @param promise a promise to observe for fulfillment.\r\n * @param onErrorObservable an observable to notify if a promise was rejected.\r\n * @returns the new Observable\r\n */\r\n public static FromPromise<T, E = Error>(promise: Promise<T>, onErrorObservable?: Observable<E>): Observable<T> {\r\n const observable = new Observable<T>();\r\n\r\n promise\r\n // eslint-disable-next-line github/no-then\r\n .then((ret: T) => {\r\n observable.notifyObservers(ret);\r\n })\r\n // eslint-disable-next-line github/no-then\r\n .catch((err) => {\r\n if (onErrorObservable) {\r\n onErrorObservable.notifyObservers(err as E);\r\n } else {\r\n throw err;\r\n }\r\n });\r\n\r\n return observable;\r\n }\r\n\r\n /**\r\n * Gets the list of observers\r\n * Note that observers that were recently deleted may still be present in the list because they are only really deleted on the next javascript tick!\r\n */\r\n public get observers(): Array<Observer<T>> {\r\n return this._observers;\r\n }\r\n\r\n /**\r\n * Creates a new observable\r\n * @param onObserverAdded defines a callback to call when a new observer is added\r\n * @param notifyIfTriggered If set to true the observable will notify when an observer was added if the observable was already triggered.\r\n */\r\n constructor(\r\n onObserverAdded?: (observer: Observer<T>) => void,\r\n /**\r\n * [false] If set to true the observable will notify when an observer was added if the observable was already triggered.\r\n * This is helpful to single-state observables like the scene onReady or the dispose observable.\r\n */\r\n public notifyIfTriggered = false\r\n ) {\r\n this._eventState = new EventState(0);\r\n\r\n if (onObserverAdded) {\r\n this._onObserverAdded = onObserverAdded;\r\n }\r\n }\r\n\r\n /**\r\n * Create a new Observer with the specified callback\r\n * @param callback the callback that will be executed for that Observer\r\n * @param mask the mask used to filter observers\r\n * @param insertFirst if true the callback will be inserted at the first position, hence executed before the others ones. If false (default behavior) the callback will be inserted at the last position, executed after all the others already present.\r\n * @param scope optional scope for the callback to be called from\r\n * @param unregisterOnFirstCall defines if the observer as to be unregistered after the next notification\r\n * @returns the new observer created for the callback\r\n */\r\n public add(callback?: null, mask?: number, insertFirst?: boolean, scope?: any, unregisterOnFirstCall?: boolean): null;\r\n public add(callback: (eventData: T, eventState: EventState) => void, mask?: number, insertFirst?: boolean, scope?: any, unregisterOnFirstCall?: boolean): Observer<T>;\r\n public add(\r\n callback?: ((eventData: T, eventState: EventState) => void) | null,\r\n mask?: number,\r\n insertFirst?: boolean,\r\n scope?: any,\r\n unregisterOnFirstCall?: boolean\r\n ): Nullable<Observer<T>>;\r\n public add(\r\n callback?: ((eventData: T, eventState: EventState) => void) | null,\r\n mask: number = -1,\r\n insertFirst = false,\r\n scope: any = null,\r\n unregisterOnFirstCall = false\r\n ): Nullable<Observer<T>> {\r\n if (!callback) {\r\n return null;\r\n }\r\n\r\n const observer = new Observer(callback, mask, scope);\r\n observer.unregisterOnNextCall = unregisterOnFirstCall;\r\n\r\n if (insertFirst) {\r\n this._observers.unshift(observer);\r\n } else {\r\n this._observers.push(observer);\r\n }\r\n\r\n if (this._onObserverAdded) {\r\n this._onObserverAdded(observer);\r\n }\r\n\r\n // If the observable was already triggered and the observable is set to notify if triggered, notify the new observer\r\n if (this._hasNotified && this.notifyIfTriggered) {\r\n if (this._lastNotifiedValue !== undefined) {\r\n this.notifyObserver(observer, this._lastNotifiedValue);\r\n }\r\n }\r\n\r\n // attach the remove function to the observer\r\n const observableWeakRef = IsWeakRefSupported ? new WeakRef(this) : { deref: () => this };\r\n observer._remove = (defer = false) => {\r\n const observable = observableWeakRef.deref();\r\n if (observable) {\r\n defer ? observable.remove(observer) : observable._remove(observer);\r\n }\r\n };\r\n\r\n return observer;\r\n }\r\n\r\n /**\r\n * Create a new Observer with the specified callback and unregisters after the next notification\r\n * @param callback the callback that will be executed for that Observer\r\n * @returns the new observer created for the callback\r\n */\r\n public addOnce(callback?: null): null;\r\n public addOnce(callback: (eventData: T, eventState: EventState) => void): Observer<T>;\r\n public addOnce(callback?: ((eventData: T, eventState: EventState) => void) | null): Nullable<Observer<T>>;\r\n public addOnce(callback?: ((eventData: T, eventState: EventState) => void) | null): Nullable<Observer<T>> {\r\n return this.add(callback, undefined, undefined, undefined, true);\r\n }\r\n\r\n /**\r\n * Remove an Observer from the Observable object\r\n * @param observer the instance of the Observer to remove\r\n * @returns false if it doesn't belong to this Observable\r\n */\r\n public remove(observer: Nullable<Observer<T>>): boolean {\r\n if (!observer) {\r\n return false;\r\n }\r\n\r\n observer._remove = null;\r\n const index = this._observers.indexOf(observer);\r\n\r\n if (index !== -1) {\r\n this._deferUnregister(observer);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Remove a callback from the Observable object\r\n * @param callback the callback to remove\r\n * @param scope optional scope. If used only the callbacks with this scope will be removed\r\n * @returns false if it doesn't belong to this Observable\r\n */\r\n public removeCallback(callback: (eventData: T, eventState: EventState) => void, scope?: any): boolean {\r\n for (let index = 0; index < this._observers.length; index++) {\r\n const observer = this._observers[index];\r\n if (observer._willBeUnregistered) {\r\n continue;\r\n }\r\n if (observer.callback === callback && (!scope || scope === observer.scope)) {\r\n this._deferUnregister(observer);\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _deferUnregister(observer: Observer<T>): void {\r\n if (observer._willBeUnregistered) {\r\n return;\r\n }\r\n this._numObserversMarkedAsDeleted++;\r\n observer.unregisterOnNextCall = false;\r\n observer._willBeUnregistered = true;\r\n setTimeout(() => {\r\n this._remove(observer);\r\n }, 0);\r\n }\r\n\r\n // This should only be called when not iterating over _observers to avoid callback skipping.\r\n // Removes an observer from the _observer Array.\r\n private _remove(observer: Nullable<Observer<T>>, updateCounter = true): boolean {\r\n if (!observer) {\r\n return false;\r\n }\r\n\r\n const index = this._observers.indexOf(observer);\r\n\r\n if (index !== -1) {\r\n if (updateCounter) {\r\n this._numObserversMarkedAsDeleted--;\r\n }\r\n this._observers.splice(index, 1);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Moves the observable to the top of the observer list making it get called first when notified\r\n * @param observer the observer to move\r\n */\r\n public makeObserverTopPriority(observer: Observer<T>) {\r\n this._remove(observer, false);\r\n this._observers.unshift(observer);\r\n }\r\n\r\n /**\r\n * Moves the observable to the bottom of the observer list making it get called last when notified\r\n * @param observer the observer to move\r\n */\r\n public makeObserverBottomPriority(observer: Observer<T>) {\r\n this._remove(observer, false);\r\n this._observers.push(observer);\r\n }\r\n\r\n /**\r\n * Notify all Observers by calling their respective callback with the given data\r\n * Will return true if all observers were executed, false if an observer set skipNextObservers to true, then prevent the subsequent ones to execute\r\n * @param eventData defines the data to send to all observers\r\n * @param mask defines the mask of the current notification (observers with incompatible mask (ie mask & observer.mask === 0) will not be notified)\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n * @param userInfo defines any user info to send to observers\r\n * @returns false if the complete observer chain was not processed (because one observer set the skipNextObservers to true)\r\n */\r\n public notifyObservers(eventData: T, mask: number = -1, target?: any, currentTarget?: any, userInfo?: any): boolean {\r\n // this prevents potential memory leaks - if an object is disposed but the observable doesn't get cleared.\r\n if (this.notifyIfTriggered) {\r\n this._hasNotified = true;\r\n this._lastNotifiedValue = eventData;\r\n }\r\n if (!this._observers.length) {\r\n return true;\r\n }\r\n\r\n const state = this._eventState;\r\n state.mask = mask;\r\n state.target = target;\r\n state.currentTarget = currentTarget;\r\n state.skipNextObservers = false;\r\n state.lastReturnValue = eventData;\r\n state.userInfo = userInfo;\r\n\r\n for (const obs of this._observers) {\r\n if (obs._willBeUnregistered) {\r\n continue;\r\n }\r\n\r\n if (obs.mask & mask) {\r\n if (obs.unregisterOnNextCall) {\r\n this._deferUnregister(obs);\r\n }\r\n\r\n if (obs.scope) {\r\n state.lastReturnValue = obs.callback.apply(obs.scope, [eventData, state]);\r\n } else {\r\n state.lastReturnValue = obs.callback(eventData, state);\r\n }\r\n }\r\n if (state.skipNextObservers) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Notify a specific observer\r\n * @param observer defines the observer to notify\r\n * @param eventData defines the data to be sent to each callback\r\n * @param mask is used to filter observers defaults to -1\r\n */\r\n public notifyObserver(observer: Observer<T>, eventData: T, mask: number = -1): void {\r\n // this prevents potential memory leaks - if an object is disposed but the observable doesn't get cleared.\r\n if (this.notifyIfTriggered) {\r\n this._hasNotified = true;\r\n this._lastNotifiedValue = eventData;\r\n }\r\n if (observer._willBeUnregistered) {\r\n return;\r\n }\r\n\r\n const state = this._eventState;\r\n state.mask = mask;\r\n state.skipNextObservers = false;\r\n\r\n if (observer.unregisterOnNextCall) {\r\n this._deferUnregister(observer);\r\n }\r\n\r\n observer.callback(eventData, state);\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the observable has at least one observer\r\n * @returns true is the Observable has at least one Observer registered\r\n */\r\n public hasObservers(): boolean {\r\n return this._observers.length - this._numObserversMarkedAsDeleted > 0;\r\n }\r\n\r\n /**\r\n * Clear the list of observers\r\n */\r\n public clear(): void {\r\n while (this._observers.length) {\r\n const o = this._observers.pop();\r\n if (o) {\r\n o._remove = null;\r\n }\r\n }\r\n this._onObserverAdded = null;\r\n this._numObserversMarkedAsDeleted = 0;\r\n this.cleanLastNotifiedState();\r\n }\r\n\r\n /**\r\n * Clean the last notified state - both the internal last value and the has-notified flag\r\n */\r\n public cleanLastNotifiedState(): void {\r\n this._hasNotified = false;\r\n this._lastNotifiedValue = undefined;\r\n }\r\n\r\n /**\r\n * Clone the current observable\r\n * @returns a new observable\r\n */\r\n public clone(): Observable<T> {\r\n const result = new Observable<T>();\r\n\r\n result._observers = this._observers.slice(0);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Does this observable handles observer registered with a given mask\r\n * @param mask defines the mask to be tested\r\n * @returns whether or not one observer registered with the given mask is handled\r\n **/\r\n public hasSpecificMask(mask: number = -1): boolean {\r\n for (const obs of this._observers) {\r\n if (obs.mask & mask || obs.mask === mask) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"observable.pure.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/observable.pure.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAM7D,MAAM,kBAAkB,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,UAAU;IACnB;;;;;;OAMG;IACH,YAAY,IAAY,EAAE,iBAAiB,GAAG,KAAK,EAAE,MAAY,EAAE,aAAmB;QAClF,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;;OAOG;IACI,UAAU,CAAC,IAAY,EAAE,iBAAiB,GAAG,KAAK,EAAE,MAAY,EAAE,aAAmB;QACxF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,I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C,CAAC;IACxC,CAAC;IAED;;;OAGG;IACI,YAAY;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC,4BAA4B,GAAG,CAAC,CAAC;IAC1E,CAAC;IAED;;OAEG;IACI,KAAK;QACR,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;YAC5B,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;YAChC,IAAI,CAAC,EAAE,CAAC;gBACJ,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC;YACrB,CAAC;QACL,CAAC;QACD,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC7B,IAAI,CAAC,4BAA4B,GAAG,CAAC,CAAC;QACtC,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAClC,CAAC;IAED;;OAEG;IACI,sBAAsB;QACzB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC1B,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;IACxC,CAAC;IAED;;;OAGG;IACI,KAAK;QACR,MAAM,MAAM,GAAG,IAAI,UAAU,EAAK,CAAC;QAEnC,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAE7C,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;;QAII;IACG,eAAe,CAAC,OAAe,CAAC,CAAC;QACpC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAChC,IAAI,GAAG,CAAC,IAAI,GAAG,IAAI,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;gBACvC,OAAO,IAAI,CAAC;YAChB,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ","sourcesContent":["/** This file must only contain pure code and pure imports */\r\n\r\nimport { type Nullable } from \"../types\";\r\n\r\ndeclare const WeakRef: any;\r\n\r\nconst IsWeakRefSupported = typeof WeakRef !== \"undefined\";\r\n\r\n/**\r\n * A class serves as a medium between the observable and its observers\r\n */\r\nexport class EventState {\r\n /**\r\n * Create a new EventState\r\n * @param mask defines the mask associated with this state\r\n * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n */\r\n constructor(mask: number, skipNextObservers = false, target?: any, currentTarget?: any) {\r\n this.initialize(mask, skipNextObservers, target, currentTarget);\r\n }\r\n\r\n /**\r\n * Initialize the current event state\r\n * @param mask defines the mask associated with this state\r\n * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n * @returns the current event state\r\n */\r\n public initialize(mask: number, skipNextObservers = false, target?: any, currentTarget?: any): EventState {\r\n this.mask = mask;\r\n this.skipNextObservers = skipNextObservers;\r\n this.target = target;\r\n this.currentTarget = currentTarget;\r\n return this;\r\n }\r\n\r\n /**\r\n * An Observer can set this property to true to prevent subsequent observers of being notified\r\n */\r\n public skipNextObservers: boolean;\r\n\r\n /**\r\n * Get the mask value that were used to trigger the event corresponding to this EventState object\r\n */\r\n public mask: number;\r\n\r\n /**\r\n * The object that originally notified the event\r\n */\r\n public target?: any;\r\n\r\n /**\r\n * The current object in the bubbling phase\r\n */\r\n public currentTarget?: any;\r\n\r\n /**\r\n * This will be populated with the return value of the last function that was executed.\r\n * If it is the first function in the callback chain it will be the event data.\r\n */\r\n public lastReturnValue?: any;\r\n\r\n /**\r\n * User defined information that will be sent to observers\r\n */\r\n public userInfo?: any;\r\n}\r\n\r\n/**\r\n * Represent an observer registered to a given IObservable object.\r\n */\r\nexport interface IObserver {\r\n /**\r\n * Remove the observer from its observable\r\n * @param defer if true, the removal will be deferred to avoid callback skipping (default: false)\r\n */\r\n remove(defer?: boolean): void;\r\n}\r\n\r\n/**\r\n * Represent an observer registered to a given Observable object.\r\n */\r\nexport class Observer<T> implements IObserver {\r\n /** @internal */\r\n public _willBeUnregistered = false;\r\n /**\r\n * Gets or sets a property defining that the observer as to be unregistered after the next notification\r\n */\r\n public unregisterOnNextCall = false;\r\n\r\n /**\r\n * this function can be used to remove the observer from the observable.\r\n * It will be set by the observable that the observer belongs to.\r\n * @internal\r\n */\r\n public _remove: Nullable<(defer?: boolean) => void> = null;\r\n\r\n /**\r\n * Creates a new observer\r\n * @param callback defines the callback to call when the observer is notified\r\n * @param mask defines the mask of the observer (used to filter notifications)\r\n * @param scope defines the current scope used to restore the JS context\r\n */\r\n constructor(\r\n /**\r\n * Defines the callback to call when the observer is notified\r\n */\r\n public callback: (eventData: T, eventState: EventState) => void,\r\n /**\r\n * Defines the mask of the observer (used to filter notifications)\r\n */\r\n public mask: number,\r\n /**\r\n * [null] Defines the current scope used to restore the JS context\r\n */\r\n public scope: any = null\r\n ) {}\r\n\r\n /**\r\n * Remove the observer from its observable\r\n * This can be used instead of using the observable's remove function.\r\n * @param defer if true, the removal will be deferred to avoid callback skipping (default: false)\r\n */\r\n public remove(defer = false) {\r\n if (this._remove) {\r\n this._remove(defer);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * An interface that defines the reader side of an Observable (receive notifications).\r\n */\r\nexport interface IReadonlyObservable<T = unknown> {\r\n /**\r\n * Create a new Observer with the specified callback\r\n * @param callback the callback that will be executed for that Observer\r\n * @param mask the mask used to filter observers\r\n * @param insertFirst if true the callback will be inserted at the first position, hence executed before the others ones. If false (default behavior) the callback will be inserted at the last position, executed after all the others already present.\r\n * @param scope optional scope for the callback to be called from\r\n * @param unregisterOnFirstCall defines if the observer as to be unregistered after the next notification\r\n * @returns the new observer created for the callback\r\n */\r\n add(callback: (eventData: T, eventState: EventState) => void, mask?: number, insertFirst?: boolean, scope?: unknown, unregisterOnFirstCall?: boolean): IObserver;\r\n\r\n /**\r\n * Create a new Observer with the specified callback and unregisters after the next notification\r\n * @param callback the callback that will be executed for that Observer\r\n * @returns the new observer created for the callback\r\n */\r\n addOnce(callback: (eventData: T, eventState: EventState) => void): IObserver;\r\n}\r\n\r\n/**\r\n * The Observable class is a simple implementation of the Observable pattern.\r\n *\r\n * There's one slight particularity though: a given Observable can notify its observer using a particular mask value, only the Observers registered with this mask value will be notified.\r\n * This enable a more fine grained execution without having to rely on multiple different Observable objects.\r\n * For instance you may have a given Observable that have four different types of notifications: Move (mask = 0x01), Stop (mask = 0x02), Turn Right (mask = 0X04), Turn Left (mask = 0X08).\r\n * A given observer can register itself with only Move and Stop (mask = 0x03), then it will only be notified when one of these two occurs and will never be for Turn Left/Right.\r\n */\r\nexport class Observable<T> implements IReadonlyObservable<T> {\r\n private _observers = new Array<Observer<T>>();\r\n private _numObserversMarkedAsDeleted = 0;\r\n private _hasNotified = false;\r\n private _lastNotifiedValue?: T;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _eventState: EventState;\r\n\r\n private _onObserverAdded: Nullable<(observer: Observer<T>) => void>;\r\n\r\n /**\r\n * Create an observable from a Promise.\r\n * @param promise a promise to observe for fulfillment.\r\n * @param onErrorObservable an observable to notify if a promise was rejected.\r\n * @returns the new Observable\r\n */\r\n public static FromPromise<T, E = Error>(promise: Promise<T>, onErrorObservable?: Observable<E>): Observable<T> {\r\n const observable = new Observable<T>();\r\n\r\n promise\r\n // eslint-disable-next-line github/no-then\r\n .then((ret: T) => {\r\n observable.notifyObservers(ret);\r\n })\r\n // eslint-disable-next-line github/no-then\r\n .catch((err) => {\r\n if (onErrorObservable) {\r\n onErrorObservable.notifyObservers(err as E);\r\n } else {\r\n throw err;\r\n }\r\n });\r\n\r\n return observable;\r\n }\r\n\r\n /**\r\n * Gets the list of observers\r\n * Note that observers that were recently deleted may still be present in the list because they are only really deleted on the next javascript tick!\r\n */\r\n public get observers(): Array<Observer<T>> {\r\n return this._observers;\r\n }\r\n\r\n /**\r\n * Creates a new observable\r\n * @param onObserverAdded defines a callback to call when a new observer is added\r\n * @param notifyIfTriggered If set to true the observable will notify when an observer was added if the observable was already triggered.\r\n */\r\n constructor(\r\n onObserverAdded?: (observer: Observer<T>) => void,\r\n /**\r\n * [false] If set to true the observable will notify when an observer was added if the observable was already triggered.\r\n * This is helpful to single-state observables like the scene onReady or the dispose observable.\r\n */\r\n public notifyIfTriggered = false\r\n ) {\r\n this._eventState = new EventState(0);\r\n\r\n if (onObserverAdded) {\r\n this._onObserverAdded = onObserverAdded;\r\n }\r\n }\r\n\r\n /**\r\n * Create a new Observer with the specified callback\r\n * @param callback the callback that will be executed for that Observer\r\n * @param mask the mask used to filter observers\r\n * @param insertFirst if true the callback will be inserted at the first position, hence executed before the others ones. If false (default behavior) the callback will be inserted at the last position, executed after all the others already present.\r\n * @param scope optional scope for the callback to be called from\r\n * @param unregisterOnFirstCall defines if the observer as to be unregistered after the next notification\r\n * @returns the new observer created for the callback\r\n */\r\n public add(callback?: null, mask?: number, insertFirst?: boolean, scope?: any, unregisterOnFirstCall?: boolean): null;\r\n public add(callback: (eventData: T, eventState: EventState) => void, mask?: number, insertFirst?: boolean, scope?: any, unregisterOnFirstCall?: boolean): Observer<T>;\r\n public add(\r\n callback?: ((eventData: T, eventState: EventState) => void) | null,\r\n mask?: number,\r\n insertFirst?: boolean,\r\n scope?: any,\r\n unregisterOnFirstCall?: boolean\r\n ): Nullable<Observer<T>>;\r\n public add(\r\n callback?: ((eventData: T, eventState: EventState) => void) | null,\r\n mask: number = -1,\r\n insertFirst = false,\r\n scope: any = null,\r\n unregisterOnFirstCall = false\r\n ): Nullable<Observer<T>> {\r\n if (!callback) {\r\n return null;\r\n }\r\n\r\n const observer = new Observer(callback, mask, scope);\r\n observer.unregisterOnNextCall = unregisterOnFirstCall;\r\n\r\n if (insertFirst) {\r\n this._observers.unshift(observer);\r\n } else {\r\n this._observers.push(observer);\r\n }\r\n\r\n if (this._onObserverAdded) {\r\n this._onObserverAdded(observer);\r\n }\r\n\r\n // If the observable was already triggered and the observable is set to notify if triggered, notify the new observer\r\n if (this._hasNotified && this.notifyIfTriggered) {\r\n this.notifyObserver(observer, this._lastNotifiedValue as T);\r\n }\r\n\r\n // attach the remove function to the observer\r\n const observableWeakRef = IsWeakRefSupported ? new WeakRef(this) : { deref: () => this };\r\n observer._remove = (defer = false) => {\r\n const observable = observableWeakRef.deref();\r\n if (observable) {\r\n defer ? observable.remove(observer) : observable._remove(observer);\r\n }\r\n };\r\n\r\n return observer;\r\n }\r\n\r\n /**\r\n * Create a new Observer with the specified callback and unregisters after the next notification\r\n * @param callback the callback that will be executed for that Observer\r\n * @returns the new observer created for the callback\r\n */\r\n public addOnce(callback?: null): null;\r\n public addOnce(callback: (eventData: T, eventState: EventState) => void): Observer<T>;\r\n public addOnce(callback?: ((eventData: T, eventState: EventState) => void) | null): Nullable<Observer<T>>;\r\n public addOnce(callback?: ((eventData: T, eventState: EventState) => void) | null): Nullable<Observer<T>> {\r\n return this.add(callback, undefined, undefined, undefined, true);\r\n }\r\n\r\n /**\r\n * Remove an Observer from the Observable object\r\n * @param observer the instance of the Observer to remove\r\n * @returns false if it doesn't belong to this Observable\r\n */\r\n public remove(observer: Nullable<Observer<T>>): boolean {\r\n if (!observer) {\r\n return false;\r\n }\r\n\r\n observer._remove = null;\r\n const index = this._observers.indexOf(observer);\r\n\r\n if (index !== -1) {\r\n this._deferUnregister(observer);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Remove a callback from the Observable object\r\n * @param callback the callback to remove\r\n * @param scope optional scope. If used only the callbacks with this scope will be removed\r\n * @returns false if it doesn't belong to this Observable\r\n */\r\n public removeCallback(callback: (eventData: T, eventState: EventState) => void, scope?: any): boolean {\r\n for (let index = 0; index < this._observers.length; index++) {\r\n const observer = this._observers[index];\r\n if (observer._willBeUnregistered) {\r\n continue;\r\n }\r\n if (observer.callback === callback && (!scope || scope === observer.scope)) {\r\n this._deferUnregister(observer);\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _deferUnregister(observer: Observer<T>): void {\r\n if (observer._willBeUnregistered) {\r\n return;\r\n }\r\n this._numObserversMarkedAsDeleted++;\r\n observer.unregisterOnNextCall = false;\r\n observer._willBeUnregistered = true;\r\n setTimeout(() => {\r\n this._remove(observer);\r\n }, 0);\r\n }\r\n\r\n // This should only be called when not iterating over _observers to avoid callback skipping.\r\n // Removes an observer from the _observer Array.\r\n private _remove(observer: Nullable<Observer<T>>, updateCounter = true): boolean {\r\n if (!observer) {\r\n return false;\r\n }\r\n\r\n const index = this._observers.indexOf(observer);\r\n\r\n if (index !== -1) {\r\n if (updateCounter) {\r\n this._numObserversMarkedAsDeleted--;\r\n }\r\n this._observers.splice(index, 1);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Moves the observable to the top of the observer list making it get called first when notified\r\n * @param observer the observer to move\r\n */\r\n public makeObserverTopPriority(observer: Observer<T>) {\r\n this._remove(observer, false);\r\n this._observers.unshift(observer);\r\n }\r\n\r\n /**\r\n * Moves the observable to the bottom of the observer list making it get called last when notified\r\n * @param observer the observer to move\r\n */\r\n public makeObserverBottomPriority(observer: Observer<T>) {\r\n this._remove(observer, false);\r\n this._observers.push(observer);\r\n }\r\n\r\n /**\r\n * Notify all Observers by calling their respective callback with the given data\r\n * Will return true if all observers were executed, false if an observer set skipNextObservers to true, then prevent the subsequent ones to execute\r\n * @param eventData defines the data to send to all observers\r\n * @param mask defines the mask of the current notification (observers with incompatible mask (ie mask & observer.mask === 0) will not be notified)\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n * @param userInfo defines any user info to send to observers\r\n * @returns false if the complete observer chain was not processed (because one observer set the skipNextObservers to true)\r\n */\r\n public notifyObservers(eventData: T, mask: number = -1, target?: any, currentTarget?: any, userInfo?: any): boolean {\r\n // this prevents potential memory leaks - if an object is disposed but the observable doesn't get cleared.\r\n if (this.notifyIfTriggered) {\r\n this._hasNotified = true;\r\n this._lastNotifiedValue = eventData;\r\n }\r\n if (!this._observers.length) {\r\n return true;\r\n }\r\n\r\n const state = this._eventState;\r\n state.mask = mask;\r\n state.target = target;\r\n state.currentTarget = currentTarget;\r\n state.skipNextObservers = false;\r\n state.lastReturnValue = eventData;\r\n state.userInfo = userInfo;\r\n\r\n for (const obs of this._observers) {\r\n if (obs._willBeUnregistered) {\r\n continue;\r\n }\r\n\r\n if (obs.mask & mask) {\r\n if (obs.unregisterOnNextCall) {\r\n this._deferUnregister(obs);\r\n }\r\n\r\n if (obs.scope) {\r\n state.lastReturnValue = obs.callback.apply(obs.scope, [eventData, state]);\r\n } else {\r\n state.lastReturnValue = obs.callback(eventData, state);\r\n }\r\n }\r\n if (state.skipNextObservers) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Notify a specific observer\r\n * @param observer defines the observer to notify\r\n * @param eventData defines the data to be sent to each callback\r\n * @param mask is used to filter observers defaults to -1\r\n */\r\n public notifyObserver(observer: Observer<T>, eventData: T, mask: number = -1): void {\r\n // this prevents potential memory leaks - if an object is disposed but the observable doesn't get cleared.\r\n if (this.notifyIfTriggered) {\r\n this._hasNotified = true;\r\n this._lastNotifiedValue = eventData;\r\n }\r\n if (observer._willBeUnregistered) {\r\n return;\r\n }\r\n\r\n const state = this._eventState;\r\n state.mask = mask;\r\n state.skipNextObservers = false;\r\n\r\n if (observer.unregisterOnNextCall) {\r\n this._deferUnregister(observer);\r\n }\r\n\r\n observer.callback(eventData, state);\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the observable has at least one observer\r\n * @returns true is the Observable has at least one Observer registered\r\n */\r\n public hasObservers(): boolean {\r\n return this._observers.length - this._numObserversMarkedAsDeleted > 0;\r\n }\r\n\r\n /**\r\n * Clear the list of observers\r\n */\r\n public clear(): void {\r\n while (this._observers.length) {\r\n const o = this._observers.pop();\r\n if (o) {\r\n o._remove = null;\r\n }\r\n }\r\n this._onObserverAdded = null;\r\n this._numObserversMarkedAsDeleted = 0;\r\n this.cleanLastNotifiedState();\r\n }\r\n\r\n /**\r\n * Clean the last notified state - both the internal last value and the has-notified flag\r\n */\r\n public cleanLastNotifiedState(): void {\r\n this._hasNotified = false;\r\n this._lastNotifiedValue = undefined;\r\n }\r\n\r\n /**\r\n * Clone the current observable\r\n * @returns a new observable\r\n */\r\n public clone(): Observable<T> {\r\n const result = new Observable<T>();\r\n\r\n result._observers = this._observers.slice(0);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Does this observable handles observer registered with a given mask\r\n * @param mask defines the mask to be tested\r\n * @returns whether or not one observer registered with the given mask is handled\r\n **/\r\n public hasSpecificMask(mask: number = -1): boolean {\r\n for (const obs of this._observers) {\r\n if (obs.mask & mask || obs.mask === mask) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n}\r\n"]}
@@ -1241,7 +1241,7 @@ Tools._DefaultCdnUrl = "https://cdn.babylonjs.com";
1241
1241
  * When set, unversioned CDN URLs will be rewritten to include this version prefix.
1242
1242
  * @internal
1243
1243
  */
1244
- Tools._CdnVersion = "9.22.2";
1244
+ Tools._CdnVersion = "9.25.0";
1245
1245
  /**
1246
1246
  * @internal
1247
1247
  */