@babylonjs/core 6.43.0 → 6.45.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.
Files changed (214) hide show
  1. package/Animations/animatable.js +2 -2
  2. package/Animations/animatable.js.map +1 -1
  3. package/Animations/animationGroup.d.ts +4 -2
  4. package/Animations/animationGroup.js +22 -2
  5. package/Animations/animationGroup.js.map +1 -1
  6. package/Buffers/buffer.d.ts +22 -22
  7. package/Buffers/buffer.js +16 -15
  8. package/Buffers/buffer.js.map +1 -1
  9. package/Cameras/camera.d.ts +5 -5
  10. package/Cameras/camera.js +19 -19
  11. package/Cameras/camera.js.map +1 -1
  12. package/Culling/ray.d.ts +12 -1
  13. package/Culling/ray.js +20 -3
  14. package/Culling/ray.js.map +1 -1
  15. package/Debug/skeletonViewer.d.ts +2 -0
  16. package/Debug/skeletonViewer.js +111 -50
  17. package/Debug/skeletonViewer.js.map +1 -1
  18. package/Engines/ICanvas.d.ts +2 -1
  19. package/Engines/ICanvas.js.map +1 -1
  20. package/Engines/constants.d.ts +96 -0
  21. package/Engines/constants.js +96 -0
  22. package/Engines/constants.js.map +1 -1
  23. package/Engines/engine.d.ts +14 -3
  24. package/Engines/engine.js +11 -0
  25. package/Engines/engine.js.map +1 -1
  26. package/Engines/nullEngine.d.ts +2 -0
  27. package/Engines/nullEngine.js +3 -0
  28. package/Engines/nullEngine.js.map +1 -1
  29. package/Engines/thinEngine.d.ts +4 -1
  30. package/Engines/thinEngine.js +2 -2
  31. package/Engines/thinEngine.js.map +1 -1
  32. package/Gizmos/gizmo.d.ts +14 -0
  33. package/Gizmos/gizmo.js +16 -0
  34. package/Gizmos/gizmo.js.map +1 -1
  35. package/Gizmos/gizmoManager.d.ts +12 -0
  36. package/Gizmos/gizmoManager.js +26 -0
  37. package/Gizmos/gizmoManager.js.map +1 -1
  38. package/Gizmos/positionGizmo.d.ts +16 -2
  39. package/Gizmos/positionGizmo.js +12 -2
  40. package/Gizmos/positionGizmo.js.map +1 -1
  41. package/Gizmos/rotationGizmo.d.ts +8 -0
  42. package/Gizmos/rotationGizmo.js +9 -0
  43. package/Gizmos/rotationGizmo.js.map +1 -1
  44. package/Gizmos/scaleGizmo.d.ts +15 -1
  45. package/Gizmos/scaleGizmo.js +11 -1
  46. package/Gizmos/scaleGizmo.js.map +1 -1
  47. package/Inputs/scene.inputManager.js +2 -2
  48. package/Inputs/scene.inputManager.js.map +1 -1
  49. package/Layers/effectLayer.js +4 -4
  50. package/Layers/effectLayer.js.map +1 -1
  51. package/Lights/Shadows/shadowGenerator.js +5 -5
  52. package/Lights/Shadows/shadowGenerator.js.map +1 -1
  53. package/Materials/Background/backgroundMaterial.js +16 -16
  54. package/Materials/Background/backgroundMaterial.js.map +1 -1
  55. package/Materials/GaussianSplatting/gaussianSplattingMaterial.js +8 -8
  56. package/Materials/GaussianSplatting/gaussianSplattingMaterial.js.map +1 -1
  57. package/Materials/Node/Blocks/Dual/fogBlock.js +2 -2
  58. package/Materials/Node/Blocks/Dual/fogBlock.js.map +1 -1
  59. package/Materials/Node/Blocks/Dual/lightBlock.js +6 -6
  60. package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
  61. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js +2 -2
  62. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
  63. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +7 -7
  64. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
  65. package/Materials/Node/Blocks/Vertex/bonesBlock.js +3 -3
  66. package/Materials/Node/Blocks/Vertex/bonesBlock.js.map +1 -1
  67. package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js +3 -3
  68. package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js.map +1 -1
  69. package/Materials/Node/nodeMaterial.d.ts +50 -0
  70. package/Materials/Node/nodeMaterial.js +53 -3
  71. package/Materials/Node/nodeMaterial.js.map +1 -1
  72. package/Materials/PBR/pbrAnisotropicConfiguration.js +3 -3
  73. package/Materials/PBR/pbrAnisotropicConfiguration.js.map +1 -1
  74. package/Materials/PBR/pbrBaseMaterial.js +41 -41
  75. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  76. package/Materials/PBR/pbrClearCoatConfiguration.js +10 -10
  77. package/Materials/PBR/pbrClearCoatConfiguration.js.map +1 -1
  78. package/Materials/PBR/pbrIridescenceConfiguration.js +6 -6
  79. package/Materials/PBR/pbrIridescenceConfiguration.js.map +1 -1
  80. package/Materials/PBR/pbrSheenConfiguration.js +6 -6
  81. package/Materials/PBR/pbrSheenConfiguration.js.map +1 -1
  82. package/Materials/PBR/pbrSubSurfaceConfiguration.js +7 -7
  83. package/Materials/PBR/pbrSubSurfaceConfiguration.js.map +1 -1
  84. package/Materials/Textures/Loaders/ktxTextureLoader.js +1 -1
  85. package/Materials/Textures/Loaders/ktxTextureLoader.js.map +1 -1
  86. package/Materials/Textures/dynamicTexture.js +1 -1
  87. package/Materials/Textures/dynamicTexture.js.map +1 -1
  88. package/Materials/Textures/texture.js +1 -1
  89. package/Materials/Textures/texture.js.map +1 -1
  90. package/Materials/index.d.ts +1 -0
  91. package/Materials/index.js +1 -0
  92. package/Materials/index.js.map +1 -1
  93. package/Materials/material.decalMapConfiguration.js +3 -3
  94. package/Materials/material.decalMapConfiguration.js.map +1 -1
  95. package/Materials/material.detailMapConfiguration.js +3 -3
  96. package/Materials/material.detailMapConfiguration.js.map +1 -1
  97. package/Materials/material.js +2 -2
  98. package/Materials/material.js.map +1 -1
  99. package/Materials/materialHelper.d.ts +1 -4
  100. package/Materials/materialHelper.functions.d.ts +275 -0
  101. package/Materials/materialHelper.functions.js +823 -0
  102. package/Materials/materialHelper.functions.js.map +1 -0
  103. package/Materials/materialHelper.js +64 -589
  104. package/Materials/materialHelper.js.map +1 -1
  105. package/Materials/materialPluginBase.d.ts +1 -1
  106. package/Materials/materialPluginBase.js +1 -1
  107. package/Materials/materialPluginBase.js.map +1 -1
  108. package/Materials/shaderMaterial.js +8 -8
  109. package/Materials/shaderMaterial.js.map +1 -1
  110. package/Materials/standardMaterial.js +33 -33
  111. package/Materials/standardMaterial.js.map +1 -1
  112. package/Meshes/Compression/dracoCompression.d.ts +23 -2
  113. package/Meshes/Compression/dracoCompression.js +76 -236
  114. package/Meshes/Compression/dracoCompression.js.map +1 -1
  115. package/Meshes/Compression/dracoCompressionWorker.d.ts +44 -0
  116. package/Meshes/Compression/dracoCompressionWorker.js +189 -0
  117. package/Meshes/Compression/dracoCompressionWorker.js.map +1 -0
  118. package/Meshes/GreasedLine/greasedLineBaseMesh.d.ts +3 -1
  119. package/Meshes/GreasedLine/greasedLineBaseMesh.js +4 -2
  120. package/Meshes/GreasedLine/greasedLineBaseMesh.js.map +1 -1
  121. package/Meshes/Node/Blocks/geometryDistanceBlock.d.ts +30 -0
  122. package/Meshes/Node/Blocks/geometryDistanceBlock.js +63 -0
  123. package/Meshes/Node/Blocks/geometryDistanceBlock.js.map +1 -0
  124. package/Meshes/Node/Blocks/geometryDotBlock.d.ts +30 -0
  125. package/Meshes/Node/Blocks/geometryDotBlock.js +63 -0
  126. package/Meshes/Node/Blocks/geometryDotBlock.js.map +1 -0
  127. package/Meshes/Node/Blocks/geometryLengthBlock.d.ts +26 -0
  128. package/Meshes/Node/Blocks/geometryLengthBlock.js +52 -0
  129. package/Meshes/Node/Blocks/geometryLengthBlock.js.map +1 -0
  130. package/Meshes/Node/Blocks/geometryPosterizeBlock.d.ts +31 -0
  131. package/Meshes/Node/Blocks/geometryPosterizeBlock.js +63 -0
  132. package/Meshes/Node/Blocks/geometryPosterizeBlock.js.map +1 -0
  133. package/Meshes/Node/Blocks/geometryReplaceColorBlock.d.ts +38 -0
  134. package/Meshes/Node/Blocks/geometryReplaceColorBlock.js +88 -0
  135. package/Meshes/Node/Blocks/geometryReplaceColorBlock.js.map +1 -0
  136. package/Meshes/Node/Blocks/geometryRotate2dBlock.d.ts +30 -0
  137. package/Meshes/Node/Blocks/geometryRotate2dBlock.js +59 -0
  138. package/Meshes/Node/Blocks/geometryRotate2dBlock.js.map +1 -0
  139. package/Meshes/Node/index.d.ts +6 -0
  140. package/Meshes/Node/index.js +6 -0
  141. package/Meshes/Node/index.js.map +1 -1
  142. package/Meshes/trailMesh.js +1 -1
  143. package/Meshes/trailMesh.js.map +1 -1
  144. package/Misc/basis.d.ts +6 -1
  145. package/Misc/basis.js +11 -231
  146. package/Misc/basis.js.map +1 -1
  147. package/Misc/basisWorker.d.ts +13 -0
  148. package/Misc/basisWorker.js +249 -0
  149. package/Misc/basisWorker.js.map +1 -0
  150. package/Misc/khronosTextureContainer2.d.ts +25 -3
  151. package/Misc/khronosTextureContainer2.js +35 -106
  152. package/Misc/khronosTextureContainer2.js.map +1 -1
  153. package/Misc/khronosTextureContainer2Worker.d.ts +12 -0
  154. package/Misc/khronosTextureContainer2Worker.js +136 -0
  155. package/Misc/khronosTextureContainer2Worker.js.map +1 -0
  156. package/Navigation/Plugins/recastJSPlugin.d.ts +1 -1
  157. package/Navigation/Plugins/recastJSPlugin.js.map +1 -1
  158. package/Particles/gpuParticleSystem.js +3 -3
  159. package/Particles/gpuParticleSystem.js.map +1 -1
  160. package/Particles/particleSystem.js +7 -3
  161. package/Particles/particleSystem.js.map +1 -1
  162. package/Physics/v2/IPhysicsEnginePlugin.d.ts +8 -0
  163. package/Physics/v2/IPhysicsEnginePlugin.js +9 -0
  164. package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
  165. package/Physics/v2/Plugins/havokPlugin.d.ts +7 -1
  166. package/Physics/v2/Plugins/havokPlugin.js +19 -1
  167. package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
  168. package/PostProcesses/volumetricLightScatteringPostProcess.js +2 -2
  169. package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
  170. package/Rendering/depthRenderer.js +4 -4
  171. package/Rendering/depthRenderer.js.map +1 -1
  172. package/Rendering/geometryBufferRenderer.js +5 -5
  173. package/Rendering/geometryBufferRenderer.js.map +1 -1
  174. package/Rendering/outlineRenderer.js +4 -4
  175. package/Rendering/outlineRenderer.js.map +1 -1
  176. package/XR/features/Layers/WebXRCompositionLayer.d.ts +48 -0
  177. package/XR/features/Layers/WebXRCompositionLayer.js +94 -0
  178. package/XR/features/Layers/WebXRCompositionLayer.js.map +1 -0
  179. package/XR/features/Layers/WebXRProjectionLayer.d.ts +10 -0
  180. package/XR/features/Layers/WebXRProjectionLayer.js +51 -0
  181. package/XR/features/Layers/WebXRProjectionLayer.js.map +1 -0
  182. package/XR/features/WebXRControllerPointerSelection.js +4 -1
  183. package/XR/features/WebXRControllerPointerSelection.js.map +1 -1
  184. package/XR/features/WebXRControllerTeleportation.js +11 -10
  185. package/XR/features/WebXRControllerTeleportation.js.map +1 -1
  186. package/XR/features/WebXRHandTracking.d.ts +7 -1
  187. package/XR/features/WebXRHandTracking.js +28 -26
  188. package/XR/features/WebXRHandTracking.js.map +1 -1
  189. package/XR/features/WebXRLayers.d.ts +44 -26
  190. package/XR/features/WebXRLayers.js +204 -153
  191. package/XR/features/WebXRLayers.js.map +1 -1
  192. package/XR/features/WebXRNearInteraction.js +16 -1
  193. package/XR/features/WebXRNearInteraction.js.map +1 -1
  194. package/XR/webXRCamera.js +10 -0
  195. package/XR/webXRCamera.js.map +1 -1
  196. package/XR/webXRDefaultExperience.d.ts +9 -0
  197. package/XR/webXRDefaultExperience.js +8 -0
  198. package/XR/webXRDefaultExperience.js.map +1 -1
  199. package/XR/webXRExperienceHelper.js +1 -1
  200. package/XR/webXRExperienceHelper.js.map +1 -1
  201. package/XR/webXRFeaturesManager.js +8 -2
  202. package/XR/webXRFeaturesManager.js.map +1 -1
  203. package/XR/webXRLayerWrapper.d.ts +12 -3
  204. package/XR/webXRLayerWrapper.js +18 -2
  205. package/XR/webXRLayerWrapper.js.map +1 -1
  206. package/XR/webXRRenderTargetTextureProvider.js +0 -5
  207. package/XR/webXRRenderTargetTextureProvider.js.map +1 -1
  208. package/XR/webXRSessionManager.d.ts +9 -1
  209. package/XR/webXRSessionManager.js +24 -5
  210. package/XR/webXRSessionManager.js.map +1 -1
  211. package/package.json +1 -1
  212. package/scene.d.ts +13 -5
  213. package/scene.js +4 -4
  214. package/scene.js.map +1 -1
@@ -0,0 +1,249 @@
1
+ import { Tools } from "./tools.js";
2
+ /**
3
+ * The worker function that gets converted to a blob url to pass into a worker.
4
+ * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.
5
+ */
6
+ export function workerFunction() {
7
+ const _BASIS_FORMAT = {
8
+ cTFETC1: 0,
9
+ cTFETC2: 1,
10
+ cTFBC1: 2,
11
+ cTFBC3: 3,
12
+ cTFBC4: 4,
13
+ cTFBC5: 5,
14
+ cTFBC7: 6,
15
+ cTFPVRTC1_4_RGB: 8,
16
+ cTFPVRTC1_4_RGBA: 9,
17
+ cTFASTC_4x4: 10,
18
+ cTFATC_RGB: 11,
19
+ cTFATC_RGBA_INTERPOLATED_ALPHA: 12,
20
+ cTFRGBA32: 13,
21
+ cTFRGB565: 14,
22
+ cTFBGR565: 15,
23
+ cTFRGBA4444: 16,
24
+ cTFFXT1_RGB: 17,
25
+ cTFPVRTC2_4_RGB: 18,
26
+ cTFPVRTC2_4_RGBA: 19,
27
+ cTFETC2_EAC_R11: 20,
28
+ cTFETC2_EAC_RG11: 21,
29
+ };
30
+ let transcoderModulePromise = null;
31
+ onmessage = (event) => {
32
+ if (event.data.action === "init") {
33
+ // Load the transcoder if it hasn't been yet
34
+ if (event.data.url) {
35
+ // make sure we loaded the script correctly
36
+ try {
37
+ importScripts(event.data.url);
38
+ }
39
+ catch (e) {
40
+ postMessage({ action: "error", error: e });
41
+ }
42
+ }
43
+ if (!transcoderModulePromise) {
44
+ transcoderModulePromise = BASIS({
45
+ // Override wasm binary
46
+ wasmBinary: event.data.wasmBinary,
47
+ });
48
+ }
49
+ if (transcoderModulePromise !== null) {
50
+ transcoderModulePromise.then((m) => {
51
+ BASIS = m;
52
+ m.initializeBasis();
53
+ postMessage({ action: "init" });
54
+ });
55
+ }
56
+ }
57
+ else if (event.data.action === "transcode") {
58
+ // Transcode the basis image and return the resulting pixels
59
+ const config = event.data.config;
60
+ const imgData = event.data.imageData;
61
+ const loadedFile = new BASIS.BasisFile(imgData);
62
+ const fileInfo = GetFileInfo(loadedFile);
63
+ let format = event.data.ignoreSupportedFormats ? null : GetSupportedTranscodeFormat(event.data.config, fileInfo);
64
+ let needsConversion = false;
65
+ if (format === null) {
66
+ needsConversion = true;
67
+ format = fileInfo.hasAlpha ? _BASIS_FORMAT.cTFBC3 : _BASIS_FORMAT.cTFBC1;
68
+ }
69
+ // Begin transcode
70
+ let success = true;
71
+ if (!loadedFile.startTranscoding()) {
72
+ success = false;
73
+ }
74
+ const buffers = [];
75
+ for (let imageIndex = 0; imageIndex < fileInfo.images.length; imageIndex++) {
76
+ if (!success) {
77
+ break;
78
+ }
79
+ const image = fileInfo.images[imageIndex];
80
+ if (config.loadSingleImage === undefined || config.loadSingleImage === imageIndex) {
81
+ let mipCount = image.levels.length;
82
+ if (config.loadMipmapLevels === false) {
83
+ mipCount = 1;
84
+ }
85
+ for (let levelIndex = 0; levelIndex < mipCount; levelIndex++) {
86
+ const levelInfo = image.levels[levelIndex];
87
+ const pixels = TranscodeLevel(loadedFile, imageIndex, levelIndex, format, needsConversion);
88
+ if (!pixels) {
89
+ success = false;
90
+ break;
91
+ }
92
+ levelInfo.transcodedPixels = pixels;
93
+ buffers.push(levelInfo.transcodedPixels.buffer);
94
+ }
95
+ }
96
+ }
97
+ // Close file
98
+ loadedFile.close();
99
+ loadedFile.delete();
100
+ if (needsConversion) {
101
+ format = -1;
102
+ }
103
+ if (!success) {
104
+ postMessage({ action: "transcode", success: success, id: event.data.id });
105
+ }
106
+ else {
107
+ postMessage({ action: "transcode", success: success, id: event.data.id, fileInfo: fileInfo, format: format }, buffers);
108
+ }
109
+ }
110
+ };
111
+ /**
112
+ * Detects the supported transcode format for the file
113
+ * @param config transcode config
114
+ * @param fileInfo info about the file
115
+ * @returns the chosed format or null if none are supported
116
+ */
117
+ function GetSupportedTranscodeFormat(config, fileInfo) {
118
+ let format = null;
119
+ if (config.supportedCompressionFormats) {
120
+ if (config.supportedCompressionFormats.astc) {
121
+ format = _BASIS_FORMAT.cTFASTC_4x4;
122
+ }
123
+ else if (config.supportedCompressionFormats.bc7) {
124
+ format = _BASIS_FORMAT.cTFBC7;
125
+ }
126
+ else if (config.supportedCompressionFormats.s3tc) {
127
+ format = fileInfo.hasAlpha ? _BASIS_FORMAT.cTFBC3 : _BASIS_FORMAT.cTFBC1;
128
+ }
129
+ else if (config.supportedCompressionFormats.pvrtc) {
130
+ format = fileInfo.hasAlpha ? _BASIS_FORMAT.cTFPVRTC1_4_RGBA : _BASIS_FORMAT.cTFPVRTC1_4_RGB;
131
+ }
132
+ else if (config.supportedCompressionFormats.etc2) {
133
+ format = _BASIS_FORMAT.cTFETC2;
134
+ }
135
+ else if (config.supportedCompressionFormats.etc1) {
136
+ format = _BASIS_FORMAT.cTFETC1;
137
+ }
138
+ else {
139
+ format = _BASIS_FORMAT.cTFRGB565;
140
+ }
141
+ }
142
+ return format;
143
+ }
144
+ /**
145
+ * Retrieves information about the basis file eg. dimensions
146
+ * @param basisFile the basis file to get the info from
147
+ * @returns information about the basis file
148
+ */
149
+ function GetFileInfo(basisFile) {
150
+ const hasAlpha = basisFile.getHasAlpha();
151
+ const imageCount = basisFile.getNumImages();
152
+ const images = [];
153
+ for (let i = 0; i < imageCount; i++) {
154
+ const imageInfo = {
155
+ levels: [],
156
+ };
157
+ const levelCount = basisFile.getNumLevels(i);
158
+ for (let level = 0; level < levelCount; level++) {
159
+ const levelInfo = {
160
+ width: basisFile.getImageWidth(i, level),
161
+ height: basisFile.getImageHeight(i, level),
162
+ };
163
+ imageInfo.levels.push(levelInfo);
164
+ }
165
+ images.push(imageInfo);
166
+ }
167
+ const info = { hasAlpha, images };
168
+ return info;
169
+ }
170
+ function TranscodeLevel(loadedFile, imageIndex, levelIndex, format, convertToRgb565) {
171
+ const dstSize = loadedFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, format);
172
+ let dst = new Uint8Array(dstSize);
173
+ if (!loadedFile.transcodeImage(dst, imageIndex, levelIndex, format, 1, 0)) {
174
+ return null;
175
+ }
176
+ // If no supported format is found, load as dxt and convert to rgb565
177
+ if (convertToRgb565) {
178
+ const alignedWidth = (loadedFile.getImageWidth(imageIndex, levelIndex) + 3) & ~3;
179
+ const alignedHeight = (loadedFile.getImageHeight(imageIndex, levelIndex) + 3) & ~3;
180
+ dst = ConvertDxtToRgb565(dst, 0, alignedWidth, alignedHeight);
181
+ }
182
+ return dst;
183
+ }
184
+ /**
185
+ * From https://github.com/BinomialLLC/basis_universal/blob/master/webgl/texture/dxt-to-rgb565.js
186
+ * An unoptimized version of dxtToRgb565. Also, the floating
187
+ * point math used to compute the colors actually results in
188
+ * slightly different colors compared to hardware DXT decoders.
189
+ * @param src dxt src pixels
190
+ * @param srcByteOffset offset for the start of src
191
+ * @param width aligned width of the image
192
+ * @param height aligned height of the image
193
+ * @returns the converted pixels
194
+ */
195
+ function ConvertDxtToRgb565(src, srcByteOffset, width, height) {
196
+ const c = new Uint16Array(4);
197
+ const dst = new Uint16Array(width * height);
198
+ const blockWidth = width / 4;
199
+ const blockHeight = height / 4;
200
+ for (let blockY = 0; blockY < blockHeight; blockY++) {
201
+ for (let blockX = 0; blockX < blockWidth; blockX++) {
202
+ const i = srcByteOffset + 8 * (blockY * blockWidth + blockX);
203
+ c[0] = src[i] | (src[i + 1] << 8);
204
+ c[1] = src[i + 2] | (src[i + 3] << 8);
205
+ c[2] =
206
+ ((2 * (c[0] & 0x1f) + 1 * (c[1] & 0x1f)) / 3) |
207
+ (((2 * (c[0] & 0x7e0) + 1 * (c[1] & 0x7e0)) / 3) & 0x7e0) |
208
+ (((2 * (c[0] & 0xf800) + 1 * (c[1] & 0xf800)) / 3) & 0xf800);
209
+ c[3] =
210
+ ((2 * (c[1] & 0x1f) + 1 * (c[0] & 0x1f)) / 3) |
211
+ (((2 * (c[1] & 0x7e0) + 1 * (c[0] & 0x7e0)) / 3) & 0x7e0) |
212
+ (((2 * (c[1] & 0xf800) + 1 * (c[0] & 0xf800)) / 3) & 0xf800);
213
+ for (let row = 0; row < 4; row++) {
214
+ const m = src[i + 4 + row];
215
+ let dstI = (blockY * 4 + row) * width + blockX * 4;
216
+ dst[dstI++] = c[m & 0x3];
217
+ dst[dstI++] = c[(m >> 2) & 0x3];
218
+ dst[dstI++] = c[(m >> 4) & 0x3];
219
+ dst[dstI++] = c[(m >> 6) & 0x3];
220
+ }
221
+ }
222
+ }
223
+ return dst;
224
+ }
225
+ }
226
+ /**
227
+ * Initialize a web worker with the basis transcoder
228
+ * @param worker the worker to initialize
229
+ * @param wasmBinary the wasm binary to load into the worker
230
+ * @param moduleUrl the url to the basis transcoder module
231
+ * @returns a promise that resolves when the worker is initialized
232
+ */
233
+ export function initializeWebWorker(worker, wasmBinary, moduleUrl) {
234
+ return new Promise((res, reject) => {
235
+ const initHandler = (msg) => {
236
+ if (msg.data.action === "init") {
237
+ worker.removeEventListener("message", initHandler);
238
+ res(worker);
239
+ }
240
+ else if (msg.data.action === "error") {
241
+ reject(msg.data.error || "error initializing worker");
242
+ }
243
+ };
244
+ worker.addEventListener("message", initHandler);
245
+ // we can use transferable objects here because the worker will own the ArrayBuffer
246
+ worker.postMessage({ action: "init", url: moduleUrl ? Tools.GetBabylonScriptURL(moduleUrl) : undefined, wasmBinary }, [wasmBinary]);
247
+ });
248
+ }
249
+ //# sourceMappingURL=basisWorker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basisWorker.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/basisWorker.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAOhC;;;GAGG;AACH,MAAM,UAAU,cAAc;IAC1B,MAAM,aAAa,GAAG;QAClB,OAAO,EAAE,CAAC;QACV,OAAO,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AAE,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IACxI,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { Tools } from \"./tools\";\r\nimport type { BasisFileInfo, BasisTranscodeConfiguration } from \"./basis\";\r\n\r\n// WorkerGlobalScope\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: any, transfer?: any[]): void;\r\ndeclare let BASIS: any;\r\n/**\r\n * The worker function that gets converted to a blob url to pass into a worker.\r\n * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.\r\n */\r\nexport function workerFunction(): void {\r\n const _BASIS_FORMAT = {\r\n cTFETC1: 0,\r\n cTFETC2: 1,\r\n cTFBC1: 2,\r\n cTFBC3: 3,\r\n cTFBC4: 4,\r\n cTFBC5: 5,\r\n cTFBC7: 6,\r\n cTFPVRTC1_4_RGB: 8,\r\n cTFPVRTC1_4_RGBA: 9,\r\n cTFASTC_4x4: 10,\r\n cTFATC_RGB: 11,\r\n cTFATC_RGBA_INTERPOLATED_ALPHA: 12,\r\n cTFRGBA32: 13,\r\n cTFRGB565: 14,\r\n cTFBGR565: 15,\r\n cTFRGBA4444: 16,\r\n cTFFXT1_RGB: 17,\r\n cTFPVRTC2_4_RGB: 18,\r\n cTFPVRTC2_4_RGBA: 19,\r\n cTFETC2_EAC_R11: 20,\r\n cTFETC2_EAC_RG11: 21,\r\n };\r\n let transcoderModulePromise: Nullable<PromiseLike<any>> = null;\r\n onmessage = (event) => {\r\n if (event.data.action === \"init\") {\r\n // Load the transcoder if it hasn't been yet\r\n if (event.data.url) {\r\n // make sure we loaded the script correctly\r\n try {\r\n importScripts(event.data.url);\r\n } catch (e) {\r\n postMessage({ action: \"error\", error: e });\r\n }\r\n }\r\n if (!transcoderModulePromise) {\r\n transcoderModulePromise = BASIS({\r\n // Override wasm binary\r\n wasmBinary: event.data.wasmBinary,\r\n });\r\n }\r\n if (transcoderModulePromise !== null) {\r\n transcoderModulePromise.then((m) => {\r\n BASIS = m;\r\n m.initializeBasis();\r\n postMessage({ action: \"init\" });\r\n });\r\n }\r\n } else if (event.data.action === \"transcode\") {\r\n // Transcode the basis image and return the resulting pixels\r\n const config: BasisTranscodeConfiguration = event.data.config;\r\n const imgData = event.data.imageData;\r\n const loadedFile = new BASIS.BasisFile(imgData);\r\n const fileInfo = GetFileInfo(loadedFile);\r\n let format = event.data.ignoreSupportedFormats ? null : GetSupportedTranscodeFormat(event.data.config, fileInfo);\r\n\r\n let needsConversion = false;\r\n if (format === null) {\r\n needsConversion = true;\r\n format = fileInfo.hasAlpha ? _BASIS_FORMAT.cTFBC3 : _BASIS_FORMAT.cTFBC1;\r\n }\r\n\r\n // Begin transcode\r\n let success = true;\r\n if (!loadedFile.startTranscoding()) {\r\n success = false;\r\n }\r\n\r\n const buffers: Array<any> = [];\r\n for (let imageIndex = 0; imageIndex < fileInfo.images.length; imageIndex++) {\r\n if (!success) {\r\n break;\r\n }\r\n const image = fileInfo.images[imageIndex];\r\n if (config.loadSingleImage === undefined || config.loadSingleImage === imageIndex) {\r\n let mipCount = image.levels.length;\r\n if (config.loadMipmapLevels === false) {\r\n mipCount = 1;\r\n }\r\n for (let levelIndex = 0; levelIndex < mipCount; levelIndex++) {\r\n const levelInfo = image.levels[levelIndex];\r\n\r\n const pixels = TranscodeLevel(loadedFile, imageIndex, levelIndex, format!, needsConversion);\r\n if (!pixels) {\r\n success = false;\r\n break;\r\n }\r\n levelInfo.transcodedPixels = pixels;\r\n buffers.push(levelInfo.transcodedPixels.buffer);\r\n }\r\n }\r\n }\r\n // Close file\r\n loadedFile.close();\r\n loadedFile.delete();\r\n\r\n if (needsConversion) {\r\n format = -1;\r\n }\r\n if (!success) {\r\n postMessage({ action: \"transcode\", success: success, id: event.data.id });\r\n } else {\r\n postMessage({ action: \"transcode\", success: success, id: event.data.id, fileInfo: fileInfo, format: format }, buffers);\r\n }\r\n }\r\n };\r\n\r\n /**\r\n * Detects the supported transcode format for the file\r\n * @param config transcode config\r\n * @param fileInfo info about the file\r\n * @returns the chosed format or null if none are supported\r\n */\r\n function GetSupportedTranscodeFormat(config: BasisTranscodeConfiguration, fileInfo: BasisFileInfo): Nullable<number> {\r\n let format = null;\r\n if (config.supportedCompressionFormats) {\r\n if (config.supportedCompressionFormats.astc) {\r\n format = _BASIS_FORMAT.cTFASTC_4x4;\r\n } else if (config.supportedCompressionFormats.bc7) {\r\n format = _BASIS_FORMAT.cTFBC7;\r\n } else if (config.supportedCompressionFormats.s3tc) {\r\n format = fileInfo.hasAlpha ? _BASIS_FORMAT.cTFBC3 : _BASIS_FORMAT.cTFBC1;\r\n } else if (config.supportedCompressionFormats.pvrtc) {\r\n format = fileInfo.hasAlpha ? _BASIS_FORMAT.cTFPVRTC1_4_RGBA : _BASIS_FORMAT.cTFPVRTC1_4_RGB;\r\n } else if (config.supportedCompressionFormats.etc2) {\r\n format = _BASIS_FORMAT.cTFETC2;\r\n } else if (config.supportedCompressionFormats.etc1) {\r\n format = _BASIS_FORMAT.cTFETC1;\r\n } else {\r\n format = _BASIS_FORMAT.cTFRGB565;\r\n }\r\n }\r\n return format;\r\n }\r\n\r\n /**\r\n * Retrieves information about the basis file eg. dimensions\r\n * @param basisFile the basis file to get the info from\r\n * @returns information about the basis file\r\n */\r\n function GetFileInfo(basisFile: any): BasisFileInfo {\r\n const hasAlpha = basisFile.getHasAlpha();\r\n const imageCount = basisFile.getNumImages();\r\n const images = [];\r\n for (let i = 0; i < imageCount; i++) {\r\n const imageInfo = {\r\n levels: [] as Array<any>,\r\n };\r\n const levelCount = basisFile.getNumLevels(i);\r\n for (let level = 0; level < levelCount; level++) {\r\n const levelInfo = {\r\n width: basisFile.getImageWidth(i, level),\r\n height: basisFile.getImageHeight(i, level),\r\n };\r\n imageInfo.levels.push(levelInfo);\r\n }\r\n images.push(imageInfo);\r\n }\r\n const info = { hasAlpha, images };\r\n return info;\r\n }\r\n\r\n function TranscodeLevel(loadedFile: any, imageIndex: number, levelIndex: number, format: number, convertToRgb565: boolean): Nullable<Uint8Array | Uint16Array> {\r\n const dstSize = loadedFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, format);\r\n let dst: Uint8Array | Uint16Array = new Uint8Array(dstSize);\r\n if (!loadedFile.transcodeImage(dst, imageIndex, levelIndex, format, 1, 0)) {\r\n return null;\r\n }\r\n // If no supported format is found, load as dxt and convert to rgb565\r\n if (convertToRgb565) {\r\n const alignedWidth = (loadedFile.getImageWidth(imageIndex, levelIndex) + 3) & ~3;\r\n const alignedHeight = (loadedFile.getImageHeight(imageIndex, levelIndex) + 3) & ~3;\r\n dst = ConvertDxtToRgb565(dst, 0, alignedWidth, alignedHeight);\r\n }\r\n return dst;\r\n }\r\n\r\n /**\r\n * From https://github.com/BinomialLLC/basis_universal/blob/master/webgl/texture/dxt-to-rgb565.js\r\n * An unoptimized version of dxtToRgb565. Also, the floating\r\n * point math used to compute the colors actually results in\r\n * slightly different colors compared to hardware DXT decoders.\r\n * @param src dxt src pixels\r\n * @param srcByteOffset offset for the start of src\r\n * @param width aligned width of the image\r\n * @param height aligned height of the image\r\n * @returns the converted pixels\r\n */\r\n function ConvertDxtToRgb565(src: Uint8Array, srcByteOffset: number, width: number, height: number): Uint16Array {\r\n const c = new Uint16Array(4);\r\n const dst = new Uint16Array(width * height);\r\n\r\n const blockWidth = width / 4;\r\n const blockHeight = height / 4;\r\n for (let blockY = 0; blockY < blockHeight; blockY++) {\r\n for (let blockX = 0; blockX < blockWidth; blockX++) {\r\n const i = srcByteOffset + 8 * (blockY * blockWidth + blockX);\r\n c[0] = src[i] | (src[i + 1] << 8);\r\n c[1] = src[i + 2] | (src[i + 3] << 8);\r\n c[2] =\r\n ((2 * (c[0] & 0x1f) + 1 * (c[1] & 0x1f)) / 3) |\r\n (((2 * (c[0] & 0x7e0) + 1 * (c[1] & 0x7e0)) / 3) & 0x7e0) |\r\n (((2 * (c[0] & 0xf800) + 1 * (c[1] & 0xf800)) / 3) & 0xf800);\r\n c[3] =\r\n ((2 * (c[1] & 0x1f) + 1 * (c[0] & 0x1f)) / 3) |\r\n (((2 * (c[1] & 0x7e0) + 1 * (c[0] & 0x7e0)) / 3) & 0x7e0) |\r\n (((2 * (c[1] & 0xf800) + 1 * (c[0] & 0xf800)) / 3) & 0xf800);\r\n for (let row = 0; row < 4; row++) {\r\n const m = src[i + 4 + row];\r\n let dstI = (blockY * 4 + row) * width + blockX * 4;\r\n dst[dstI++] = c[m & 0x3];\r\n dst[dstI++] = c[(m >> 2) & 0x3];\r\n dst[dstI++] = c[(m >> 4) & 0x3];\r\n dst[dstI++] = c[(m >> 6) & 0x3];\r\n }\r\n }\r\n }\r\n return dst;\r\n }\r\n}\r\n\r\n/**\r\n * Initialize a web worker with the basis transcoder\r\n * @param worker the worker to initialize\r\n * @param wasmBinary the wasm binary to load into the worker\r\n * @param moduleUrl the url to the basis transcoder module\r\n * @returns a promise that resolves when the worker is initialized\r\n */\r\nexport function initializeWebWorker(worker: Worker, wasmBinary: ArrayBuffer, moduleUrl?: string) {\r\n return new Promise<Worker>((res, reject) => {\r\n const initHandler = (msg: any) => {\r\n if (msg.data.action === \"init\") {\r\n worker!.removeEventListener(\"message\", initHandler);\r\n res(worker!);\r\n } else if (msg.data.action === \"error\") {\r\n reject(msg.data.error || \"error initializing worker\");\r\n }\r\n };\r\n worker.addEventListener(\"message\", initHandler);\r\n // we can use transferable objects here because the worker will own the ArrayBuffer\r\n worker.postMessage({ action: \"init\", url: moduleUrl ? Tools.GetBabylonScriptURL(moduleUrl) : undefined, wasmBinary }, [wasmBinary]);\r\n });\r\n}\r\n"]}
@@ -1,7 +1,9 @@
1
1
  import type { InternalTexture } from "../Materials/Textures/internalTexture";
2
2
  import type { ThinEngine } from "../Engines/thinEngine";
3
+ import { AutoReleaseWorkerPool } from "./workerPool";
3
4
  import type { Nullable } from "../types";
4
5
  import type { IDecodedData, IKTX2DecoderOptions } from "../Materials/Textures/ktx2decoderTypes.js";
6
+ import type { AllowedKeys } from "./khronosTextureContainer2Worker";
5
7
  /**
6
8
  * Class that defines the default KTX2 decoder options.
7
9
  *
@@ -62,12 +64,32 @@ export declare class DefaultKTX2DecoderOptions {
62
64
  /** @internal */
63
65
  _getKTX2DecoderOptions(): IKTX2DecoderOptions;
64
66
  }
67
+ /**
68
+ * Options for the KTX2 decoder
69
+ */
70
+ export interface IKhronosTextureContainer2Options {
71
+ /**
72
+ * Number of workers to use for async operations. Specify `0` to disable web workers and run synchronously in the current context.
73
+ */
74
+ numWorkers?: number;
75
+ /**
76
+ * Worker pool to use for async operations. If set, `numWorkers` will be ignored.
77
+ */
78
+ workerPool?: AutoReleaseWorkerPool;
79
+ /**
80
+ * Optional container for the KTX2 decoder module and its dependencies. If set, the module will be used from this container and the URLs will be ignored.
81
+ */
82
+ binariesAndModulesContainer?: {
83
+ [key in AllowedKeys]?: ArrayBuffer | any;
84
+ };
85
+ }
65
86
  /**
66
87
  * Class for loading KTX2 files
67
88
  */
68
89
  export declare class KhronosTextureContainer2 {
69
90
  private static _WorkerPoolPromise?;
70
91
  private static _DecoderModulePromise?;
92
+ private static _KTX2DecoderModule?;
71
93
  /**
72
94
  * URLs to use when loading the KTX2 decoder module as well as its dependencies
73
95
  * If a url is null, the default url is used (pointing to https://preview.babylonjs.com)
@@ -112,13 +134,13 @@ export declare class KhronosTextureContainer2 {
112
134
  /**
113
135
  * Constructor
114
136
  * @param engine The engine to use
115
- * @param numWorkers The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.
137
+ * @param numWorkersOrOptions The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.
116
138
  */
117
- constructor(engine: ThinEngine, numWorkers?: number);
139
+ constructor(engine: ThinEngine, numWorkersOrOptions?: number | IKhronosTextureContainer2Options);
118
140
  /**
119
141
  * @internal
120
142
  */
121
- uploadAsync(data: ArrayBufferView, internalTexture: InternalTexture, options?: IKTX2DecoderOptions & IDecodedData): Promise<void>;
143
+ _uploadAsync(data: ArrayBufferView, internalTexture: InternalTexture, options?: IKTX2DecoderOptions & IDecodedData): Promise<void>;
122
144
  protected _createTexture(data: IDecodedData, internalTexture: InternalTexture, options?: IKTX2DecoderOptions & IDecodedData): void;
123
145
  /**
124
146
  * Checks if the given data starts with a KTX2 file identifier.
@@ -2,35 +2,7 @@
2
2
  import { AutoReleaseWorkerPool } from "./workerPool.js";
3
3
  import { Tools } from "./tools.js";
4
4
  import { EngineFormat, TranscodeTarget } from "../Materials/Textures/ktx2decoderTypes.js";
5
- function applyConfig(urls) {
6
- if (urls.wasmUASTCToASTC) {
7
- KTX2DECODER.LiteTranscoder_UASTC_ASTC.WasmModuleURL = urls.wasmUASTCToASTC;
8
- }
9
- if (urls.wasmUASTCToBC7) {
10
- KTX2DECODER.LiteTranscoder_UASTC_BC7.WasmModuleURL = urls.wasmUASTCToBC7;
11
- }
12
- if (urls.wasmUASTCToRGBA_UNORM) {
13
- KTX2DECODER.LiteTranscoder_UASTC_RGBA_UNORM.WasmModuleURL = urls.wasmUASTCToRGBA_UNORM;
14
- }
15
- if (urls.wasmUASTCToRGBA_SRGB) {
16
- KTX2DECODER.LiteTranscoder_UASTC_RGBA_SRGB.WasmModuleURL = urls.wasmUASTCToRGBA_SRGB;
17
- }
18
- if (urls.wasmUASTCToR8_UNORM) {
19
- KTX2DECODER.LiteTranscoder_UASTC_R8_UNORM.WasmModuleURL = urls.wasmUASTCToR8_UNORM;
20
- }
21
- if (urls.wasmUASTCToRG8_UNORM) {
22
- KTX2DECODER.LiteTranscoder_UASTC_RG8_UNORM.WasmModuleURL = urls.wasmUASTCToRG8_UNORM;
23
- }
24
- if (urls.jsMSCTranscoder) {
25
- KTX2DECODER.MSCTranscoder.JSModuleURL = urls.jsMSCTranscoder;
26
- }
27
- if (urls.wasmMSCTranscoder) {
28
- KTX2DECODER.MSCTranscoder.WasmModuleURL = urls.wasmMSCTranscoder;
29
- }
30
- if (urls.wasmZSTDDecoder) {
31
- KTX2DECODER.ZSTDDecoder.WasmModuleURL = urls.wasmZSTDDecoder;
32
- }
33
- }
5
+ import { applyConfig, initializeWebWorker, workerFunction } from "./khronosTextureContainer2Worker.js";
34
6
  /**
35
7
  * Class that defines the default KTX2 decoder options.
36
8
  *
@@ -193,58 +165,54 @@ export class KhronosTextureContainer2 {
193
165
  };
194
166
  if (numWorkers && typeof Worker === "function" && typeof URL !== "undefined") {
195
167
  KhronosTextureContainer2._WorkerPoolPromise = new Promise((resolve) => {
196
- const workerContent = `${applyConfig}(${workerFunc})()`;
168
+ const workerContent = `${applyConfig}(${workerFunction})()`;
197
169
  const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
198
- resolve(new AutoReleaseWorkerPool(numWorkers, () => new Promise((resolve, reject) => {
199
- const worker = new Worker(workerBlobUrl);
200
- const onError = (error) => {
201
- worker.removeEventListener("error", onError);
202
- worker.removeEventListener("message", onMessage);
203
- reject(error);
204
- };
205
- const onMessage = (message) => {
206
- if (message.data.action === "init") {
207
- worker.removeEventListener("error", onError);
208
- worker.removeEventListener("message", onMessage);
209
- resolve(worker);
210
- }
211
- };
212
- worker.addEventListener("error", onError);
213
- worker.addEventListener("message", onMessage);
214
- worker.postMessage({
215
- action: "init",
216
- urls: urls,
217
- });
218
- })));
219
- });
220
- }
221
- else if (typeof KTX2DECODER === "undefined") {
222
- KhronosTextureContainer2._DecoderModulePromise = Tools.LoadBabylonScriptAsync(urls.jsDecoderModule).then(() => {
223
- KTX2DECODER.MSCTranscoder.UseFromWorkerThread = false;
224
- KTX2DECODER.WASMMemoryManager.LoadBinariesFromCurrentThread = true;
225
- applyConfig(urls);
226
- return new KTX2DECODER.KTX2Decoder();
170
+ resolve(new AutoReleaseWorkerPool(numWorkers, () => initializeWebWorker(new Worker(workerBlobUrl), undefined, urls)));
227
171
  });
228
172
  }
229
173
  else {
230
- KTX2DECODER.MSCTranscoder.UseFromWorkerThread = false;
231
- KTX2DECODER.WASMMemoryManager.LoadBinariesFromCurrentThread = true;
232
- KhronosTextureContainer2._DecoderModulePromise = Promise.resolve(new KTX2DECODER.KTX2Decoder());
174
+ if (typeof KhronosTextureContainer2._KTX2DecoderModule === "undefined") {
175
+ KhronosTextureContainer2._DecoderModulePromise = Tools.LoadBabylonScriptAsync(urls.jsDecoderModule).then(() => {
176
+ KhronosTextureContainer2._KTX2DecoderModule = KTX2DECODER;
177
+ KhronosTextureContainer2._KTX2DecoderModule.MSCTranscoder.UseFromWorkerThread = false;
178
+ KhronosTextureContainer2._KTX2DecoderModule.WASMMemoryManager.LoadBinariesFromCurrentThread = true;
179
+ applyConfig(urls, KhronosTextureContainer2._KTX2DecoderModule);
180
+ return new KhronosTextureContainer2._KTX2DecoderModule.KTX2Decoder();
181
+ });
182
+ }
183
+ else {
184
+ KhronosTextureContainer2._KTX2DecoderModule.MSCTranscoder.UseFromWorkerThread = false;
185
+ KhronosTextureContainer2._KTX2DecoderModule.WASMMemoryManager.LoadBinariesFromCurrentThread = true;
186
+ KhronosTextureContainer2._DecoderModulePromise = Promise.resolve(new KhronosTextureContainer2._KTX2DecoderModule.KTX2Decoder());
187
+ }
233
188
  }
234
189
  }
235
190
  /**
236
191
  * Constructor
237
192
  * @param engine The engine to use
238
- * @param numWorkers The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.
193
+ * @param numWorkersOrOptions The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.
239
194
  */
240
- constructor(engine, numWorkers = KhronosTextureContainer2.DefaultNumWorkers) {
195
+ constructor(engine, numWorkersOrOptions = KhronosTextureContainer2.DefaultNumWorkers) {
241
196
  this._engine = engine;
242
- KhronosTextureContainer2._Initialize(numWorkers);
197
+ if (typeof numWorkersOrOptions === "object" && numWorkersOrOptions.workerPool) {
198
+ KhronosTextureContainer2._WorkerPoolPromise = Promise.resolve(numWorkersOrOptions.workerPool);
199
+ }
200
+ else {
201
+ // set the KTX2 decoder module
202
+ if (typeof numWorkersOrOptions === "object") {
203
+ KhronosTextureContainer2._KTX2DecoderModule = numWorkersOrOptions?.binariesAndModulesContainer?.jsDecoderModule;
204
+ }
205
+ else if (typeof KTX2DECODER !== "undefined") {
206
+ KhronosTextureContainer2._KTX2DecoderModule = KTX2DECODER;
207
+ }
208
+ const numberOfWorkers = typeof numWorkersOrOptions === "number" ? numWorkersOrOptions : numWorkersOrOptions.numWorkers ?? KhronosTextureContainer2.DefaultNumWorkers;
209
+ KhronosTextureContainer2._Initialize(numberOfWorkers);
210
+ }
243
211
  }
244
212
  /**
245
213
  * @internal
246
214
  */
247
- uploadAsync(data, internalTexture, options) {
215
+ _uploadAsync(data, internalTexture, options) {
248
216
  const caps = this._engine.getCaps();
249
217
  const compressedTexturesCaps = {
250
218
  astc: !!caps.astc,
@@ -296,7 +264,7 @@ export class KhronosTextureContainer2 {
296
264
  else if (KhronosTextureContainer2._DecoderModulePromise) {
297
265
  return KhronosTextureContainer2._DecoderModulePromise.then((decoder) => {
298
266
  if (KhronosTextureContainer2.DefaultDecoderOptions.isDirty) {
299
- KTX2DECODER.KTX2Decoder.DefaultDecoderOptions = KhronosTextureContainer2.DefaultDecoderOptions._getKTX2DecoderOptions();
267
+ KhronosTextureContainer2._KTX2DecoderModule.KTX2Decoder.DefaultDecoderOptions = KhronosTextureContainer2.DefaultDecoderOptions._getKTX2DecoderOptions();
300
268
  }
301
269
  return new Promise((resolve, reject) => {
302
270
  decoder
@@ -433,43 +401,4 @@ KhronosTextureContainer2.DefaultNumWorkers = KhronosTextureContainer2.GetDefault
433
401
  * The options defined in this way have priority over those passed when creating a KTX2 texture with new Texture(...).
434
402
  */
435
403
  KhronosTextureContainer2.DefaultDecoderOptions = new DefaultKTX2DecoderOptions();
436
- function workerFunc() {
437
- let ktx2Decoder;
438
- onmessage = (event) => {
439
- if (!event.data) {
440
- return;
441
- }
442
- switch (event.data.action) {
443
- case "init": {
444
- const urls = event.data.urls;
445
- importScripts(urls.jsDecoderModule);
446
- applyConfig(urls);
447
- ktx2Decoder = new KTX2DECODER.KTX2Decoder();
448
- postMessage({ action: "init" });
449
- break;
450
- }
451
- case "setDefaultDecoderOptions": {
452
- KTX2DECODER.KTX2Decoder.DefaultDecoderOptions = event.data.options;
453
- break;
454
- }
455
- case "decode":
456
- ktx2Decoder
457
- .decode(event.data.data, event.data.caps, event.data.options)
458
- .then((data) => {
459
- const buffers = [];
460
- for (let mip = 0; mip < data.mipmaps.length; ++mip) {
461
- const mipmap = data.mipmaps[mip];
462
- if (mipmap && mipmap.data) {
463
- buffers.push(mipmap.data.buffer);
464
- }
465
- }
466
- postMessage({ action: "decoded", success: true, decodedData: data }, buffers);
467
- })
468
- .catch((reason) => {
469
- postMessage({ action: "decoded", success: false, msg: reason });
470
- });
471
- break;
472
- }
473
- };
474
- }
475
404
  //# sourceMappingURL=khronosTextureContainer2.js.map