@babylonjs/core 6.44.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 (133) hide show
  1. package/Buffers/buffer.d.ts +22 -22
  2. package/Buffers/buffer.js +16 -15
  3. package/Buffers/buffer.js.map +1 -1
  4. package/Cameras/camera.d.ts +5 -5
  5. package/Cameras/camera.js +19 -19
  6. package/Cameras/camera.js.map +1 -1
  7. package/Engines/ICanvas.d.ts +2 -1
  8. package/Engines/ICanvas.js.map +1 -1
  9. package/Engines/constants.d.ts +96 -0
  10. package/Engines/constants.js +96 -0
  11. package/Engines/constants.js.map +1 -1
  12. package/Engines/thinEngine.js +2 -2
  13. package/Engines/thinEngine.js.map +1 -1
  14. package/Gizmos/gizmo.d.ts +14 -0
  15. package/Gizmos/gizmo.js +16 -0
  16. package/Gizmos/gizmo.js.map +1 -1
  17. package/Gizmos/gizmoManager.d.ts +12 -0
  18. package/Gizmos/gizmoManager.js +26 -0
  19. package/Gizmos/gizmoManager.js.map +1 -1
  20. package/Gizmos/positionGizmo.d.ts +16 -2
  21. package/Gizmos/positionGizmo.js +12 -2
  22. package/Gizmos/positionGizmo.js.map +1 -1
  23. package/Gizmos/rotationGizmo.d.ts +8 -0
  24. package/Gizmos/rotationGizmo.js +9 -0
  25. package/Gizmos/rotationGizmo.js.map +1 -1
  26. package/Gizmos/scaleGizmo.d.ts +15 -1
  27. package/Gizmos/scaleGizmo.js +11 -1
  28. package/Gizmos/scaleGizmo.js.map +1 -1
  29. package/Layers/effectLayer.js +4 -4
  30. package/Layers/effectLayer.js.map +1 -1
  31. package/Lights/Shadows/shadowGenerator.js +5 -5
  32. package/Lights/Shadows/shadowGenerator.js.map +1 -1
  33. package/Materials/Background/backgroundMaterial.js +16 -16
  34. package/Materials/Background/backgroundMaterial.js.map +1 -1
  35. package/Materials/GaussianSplatting/gaussianSplattingMaterial.js +8 -8
  36. package/Materials/GaussianSplatting/gaussianSplattingMaterial.js.map +1 -1
  37. package/Materials/Node/Blocks/Dual/fogBlock.js +2 -2
  38. package/Materials/Node/Blocks/Dual/fogBlock.js.map +1 -1
  39. package/Materials/Node/Blocks/Dual/lightBlock.js +6 -6
  40. package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
  41. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js +2 -2
  42. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
  43. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +7 -7
  44. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
  45. package/Materials/Node/Blocks/Vertex/bonesBlock.js +3 -3
  46. package/Materials/Node/Blocks/Vertex/bonesBlock.js.map +1 -1
  47. package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js +3 -3
  48. package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js.map +1 -1
  49. package/Materials/Node/nodeMaterial.js +3 -3
  50. package/Materials/Node/nodeMaterial.js.map +1 -1
  51. package/Materials/PBR/pbrAnisotropicConfiguration.js +3 -3
  52. package/Materials/PBR/pbrAnisotropicConfiguration.js.map +1 -1
  53. package/Materials/PBR/pbrBaseMaterial.js +41 -41
  54. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  55. package/Materials/PBR/pbrClearCoatConfiguration.js +10 -10
  56. package/Materials/PBR/pbrClearCoatConfiguration.js.map +1 -1
  57. package/Materials/PBR/pbrIridescenceConfiguration.js +6 -6
  58. package/Materials/PBR/pbrIridescenceConfiguration.js.map +1 -1
  59. package/Materials/PBR/pbrSheenConfiguration.js +6 -6
  60. package/Materials/PBR/pbrSheenConfiguration.js.map +1 -1
  61. package/Materials/PBR/pbrSubSurfaceConfiguration.js +7 -7
  62. package/Materials/PBR/pbrSubSurfaceConfiguration.js.map +1 -1
  63. package/Materials/Textures/Loaders/ktxTextureLoader.js +1 -1
  64. package/Materials/Textures/Loaders/ktxTextureLoader.js.map +1 -1
  65. package/Materials/Textures/dynamicTexture.js +1 -1
  66. package/Materials/Textures/dynamicTexture.js.map +1 -1
  67. package/Materials/Textures/texture.js +1 -1
  68. package/Materials/Textures/texture.js.map +1 -1
  69. package/Materials/index.d.ts +1 -0
  70. package/Materials/index.js +1 -0
  71. package/Materials/index.js.map +1 -1
  72. package/Materials/material.decalMapConfiguration.js +3 -3
  73. package/Materials/material.decalMapConfiguration.js.map +1 -1
  74. package/Materials/material.detailMapConfiguration.js +3 -3
  75. package/Materials/material.detailMapConfiguration.js.map +1 -1
  76. package/Materials/material.js +2 -2
  77. package/Materials/material.js.map +1 -1
  78. package/Materials/materialHelper.d.ts +1 -4
  79. package/Materials/materialHelper.functions.d.ts +275 -0
  80. package/Materials/materialHelper.functions.js +823 -0
  81. package/Materials/materialHelper.functions.js.map +1 -0
  82. package/Materials/materialHelper.js +64 -589
  83. package/Materials/materialHelper.js.map +1 -1
  84. package/Materials/materialPluginBase.d.ts +1 -1
  85. package/Materials/materialPluginBase.js +1 -1
  86. package/Materials/materialPluginBase.js.map +1 -1
  87. package/Materials/shaderMaterial.js +8 -8
  88. package/Materials/shaderMaterial.js.map +1 -1
  89. package/Materials/standardMaterial.js +33 -33
  90. package/Materials/standardMaterial.js.map +1 -1
  91. package/Meshes/Compression/dracoCompression.d.ts +23 -2
  92. package/Meshes/Compression/dracoCompression.js +76 -236
  93. package/Meshes/Compression/dracoCompression.js.map +1 -1
  94. package/Meshes/Compression/dracoCompressionWorker.d.ts +44 -0
  95. package/Meshes/Compression/dracoCompressionWorker.js +189 -0
  96. package/Meshes/Compression/dracoCompressionWorker.js.map +1 -0
  97. package/Meshes/trailMesh.js +1 -1
  98. package/Meshes/trailMesh.js.map +1 -1
  99. package/Misc/basis.d.ts +6 -1
  100. package/Misc/basis.js +11 -231
  101. package/Misc/basis.js.map +1 -1
  102. package/Misc/basisWorker.d.ts +13 -0
  103. package/Misc/basisWorker.js +249 -0
  104. package/Misc/basisWorker.js.map +1 -0
  105. package/Misc/khronosTextureContainer2.d.ts +25 -3
  106. package/Misc/khronosTextureContainer2.js +35 -106
  107. package/Misc/khronosTextureContainer2.js.map +1 -1
  108. package/Misc/khronosTextureContainer2Worker.d.ts +12 -0
  109. package/Misc/khronosTextureContainer2Worker.js +136 -0
  110. package/Misc/khronosTextureContainer2Worker.js.map +1 -0
  111. package/Navigation/Plugins/recastJSPlugin.d.ts +1 -1
  112. package/Navigation/Plugins/recastJSPlugin.js.map +1 -1
  113. package/Particles/gpuParticleSystem.js +3 -3
  114. package/Particles/gpuParticleSystem.js.map +1 -1
  115. package/Particles/particleSystem.js +7 -3
  116. package/Particles/particleSystem.js.map +1 -1
  117. package/Physics/v2/IPhysicsEnginePlugin.d.ts +8 -0
  118. package/Physics/v2/IPhysicsEnginePlugin.js +9 -0
  119. package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
  120. package/Physics/v2/Plugins/havokPlugin.d.ts +7 -1
  121. package/Physics/v2/Plugins/havokPlugin.js +19 -1
  122. package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
  123. package/PostProcesses/volumetricLightScatteringPostProcess.js +2 -2
  124. package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
  125. package/Rendering/depthRenderer.js +4 -4
  126. package/Rendering/depthRenderer.js.map +1 -1
  127. package/Rendering/geometryBufferRenderer.js +5 -5
  128. package/Rendering/geometryBufferRenderer.js.map +1 -1
  129. package/Rendering/outlineRenderer.js +4 -4
  130. package/Rendering/outlineRenderer.js.map +1 -1
  131. package/package.json +1 -1
  132. package/scene.d.ts +4 -4
  133. package/scene.js.map +1 -1
@@ -1,3 +1,4 @@
1
+ import { AutoReleaseWorkerPool } from "../../Misc/workerPool";
1
2
  import type { IDisposable, Scene } from "../../scene";
2
3
  import { Geometry } from "../geometry";
3
4
  import { VertexData } from "../mesh.vertexData";
@@ -23,6 +24,26 @@ export interface IDracoCompressionConfiguration {
23
24
  fallbackUrl?: string;
24
25
  };
25
26
  }
27
+ /**
28
+ * Options for Draco compression
29
+ */
30
+ export interface IDracoCompressionOptions {
31
+ /**
32
+ * The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.
33
+ */
34
+ numWorkers?: number;
35
+ /**
36
+ * Optional ArrayBuffer of the WebAssembly binary.
37
+ * If provided it will be used instead of loading the binary from wasmBinaryUrl.
38
+ */
39
+ wasmBinary?: ArrayBuffer;
40
+ /**
41
+ * Optional worker pool to use for async decoding.
42
+ * If provided, numWorkers will be ignored and the worker pool will be used instead.
43
+ * If provided the draco script will not be loaded from the DracoConfiguration.
44
+ */
45
+ workerPool?: AutoReleaseWorkerPool;
46
+ }
26
47
  /**
27
48
  * Draco compression (https://google.github.io/draco/)
28
49
  *
@@ -84,9 +105,9 @@ export declare class DracoCompression implements IDisposable {
84
105
  static get Default(): DracoCompression;
85
106
  /**
86
107
  * Constructor
87
- * @param numWorkers The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.
108
+ * @param numWorkers The number of workers for async operations Or an options object. Specify `0` to disable web workers and run synchronously in the current context.
88
109
  */
89
- constructor(numWorkers?: number);
110
+ constructor(numWorkers?: number | IDracoCompressionOptions);
90
111
  /**
91
112
  * Stop all async operations and release resources.
92
113
  */
@@ -5,161 +5,14 @@ import { Geometry } from "../geometry.js";
5
5
  import { VertexBuffer } from "../buffer.js";
6
6
  import { VertexData } from "../mesh.vertexData.js";
7
7
  import { Logger } from "../../Misc/logger.js";
8
+ import { decodeMesh, workerFunction, initializeWebWorker } from "./dracoCompressionWorker.js";
8
9
  function createDecoderAsync(wasmBinary) {
9
10
  return new Promise((resolve) => {
10
- DracoDecoderModule({ wasmBinary: wasmBinary }).then((module) => {
11
- resolve({ module: module });
11
+ DracoDecoderModule({ wasmBinary }).then((module) => {
12
+ resolve({ module });
12
13
  });
13
14
  });
14
15
  }
15
- function decodeMesh(decoderModule, data, attributes, onIndicesData, onAttributeData) {
16
- let decoder = null;
17
- let buffer = null;
18
- let geometry = null;
19
- try {
20
- decoder = new decoderModule.Decoder();
21
- buffer = new decoderModule.DecoderBuffer();
22
- buffer.Init(data, data.byteLength);
23
- let status;
24
- const type = decoder.GetEncodedGeometryType(buffer);
25
- switch (type) {
26
- case decoderModule.TRIANGULAR_MESH: {
27
- const mesh = new decoderModule.Mesh();
28
- status = decoder.DecodeBufferToMesh(buffer, mesh);
29
- if (!status.ok() || mesh.ptr === 0) {
30
- throw new Error(status.error_msg());
31
- }
32
- const numFaces = mesh.num_faces();
33
- const numIndices = numFaces * 3;
34
- const byteLength = numIndices * 4;
35
- const ptr = decoderModule._malloc(byteLength);
36
- try {
37
- decoder.GetTrianglesUInt32Array(mesh, byteLength, ptr);
38
- const indices = new Uint32Array(numIndices);
39
- indices.set(new Uint32Array(decoderModule.HEAPF32.buffer, ptr, numIndices));
40
- onIndicesData(indices);
41
- }
42
- finally {
43
- decoderModule._free(ptr);
44
- }
45
- geometry = mesh;
46
- break;
47
- }
48
- case decoderModule.POINT_CLOUD: {
49
- const pointCloud = new decoderModule.PointCloud();
50
- status = decoder.DecodeBufferToPointCloud(buffer, pointCloud);
51
- if (!status.ok() || !pointCloud.ptr) {
52
- throw new Error(status.error_msg());
53
- }
54
- geometry = pointCloud;
55
- break;
56
- }
57
- default: {
58
- throw new Error(`Invalid geometry type ${type}`);
59
- }
60
- }
61
- const numPoints = geometry.num_points();
62
- const processAttribute = (decoder, geometry, kind, attribute) => {
63
- const dataType = attribute.data_type();
64
- const numComponents = attribute.num_components();
65
- const normalized = attribute.normalized();
66
- const byteStride = attribute.byte_stride();
67
- const byteOffset = attribute.byte_offset();
68
- const dataTypeInfo = {
69
- [decoderModule.DT_FLOAT32]: { typedArrayConstructor: Float32Array, heap: decoderModule.HEAPF32 },
70
- [decoderModule.DT_INT8]: { typedArrayConstructor: Int8Array, heap: decoderModule.HEAP8 },
71
- [decoderModule.DT_INT16]: { typedArrayConstructor: Int16Array, heap: decoderModule.HEAP16 },
72
- [decoderModule.DT_INT32]: { typedArrayConstructor: Int32Array, heap: decoderModule.HEAP32 },
73
- [decoderModule.DT_UINT8]: { typedArrayConstructor: Uint8Array, heap: decoderModule.HEAPU8 },
74
- [decoderModule.DT_UINT16]: { typedArrayConstructor: Uint16Array, heap: decoderModule.HEAPU16 },
75
- [decoderModule.DT_UINT32]: { typedArrayConstructor: Uint32Array, heap: decoderModule.HEAPU32 },
76
- };
77
- const info = dataTypeInfo[dataType];
78
- if (!info) {
79
- throw new Error(`Invalid data type ${dataType}`);
80
- }
81
- const numValues = numPoints * numComponents;
82
- const byteLength = numValues * info.typedArrayConstructor.BYTES_PER_ELEMENT;
83
- const ptr = decoderModule._malloc(byteLength);
84
- try {
85
- decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, dataType, byteLength, ptr);
86
- const data = new info.typedArrayConstructor(info.heap.buffer, ptr, numValues);
87
- onAttributeData(kind, data.slice(), numComponents, byteOffset, byteStride, normalized);
88
- }
89
- finally {
90
- decoderModule._free(ptr);
91
- }
92
- };
93
- if (attributes) {
94
- for (const kind in attributes) {
95
- const id = attributes[kind];
96
- const attribute = decoder.GetAttributeByUniqueId(geometry, id);
97
- processAttribute(decoder, geometry, kind, attribute);
98
- }
99
- }
100
- else {
101
- const dracoAttributeTypes = {
102
- position: decoderModule.POSITION,
103
- normal: decoderModule.NORMAL,
104
- color: decoderModule.COLOR,
105
- uv: decoderModule.TEX_COORD,
106
- };
107
- for (const kind in dracoAttributeTypes) {
108
- const id = decoder.GetAttributeId(geometry, dracoAttributeTypes[kind]);
109
- if (id !== -1) {
110
- const attribute = decoder.GetAttribute(geometry, id);
111
- processAttribute(decoder, geometry, kind, attribute);
112
- }
113
- }
114
- }
115
- return numPoints;
116
- }
117
- finally {
118
- if (geometry) {
119
- decoderModule.destroy(geometry);
120
- }
121
- if (buffer) {
122
- decoderModule.destroy(buffer);
123
- }
124
- if (decoder) {
125
- decoderModule.destroy(decoder);
126
- }
127
- }
128
- }
129
- /**
130
- * The worker function that gets converted to a blob url to pass into a worker.
131
- */
132
- function worker() {
133
- let decoderPromise;
134
- onmessage = (event) => {
135
- const message = event.data;
136
- switch (message.id) {
137
- case "init": {
138
- const decoder = message.decoder;
139
- if (decoder.url) {
140
- importScripts(decoder.url);
141
- decoderPromise = DracoDecoderModule({ wasmBinary: decoder.wasmBinary });
142
- }
143
- postMessage({ id: "initDone" });
144
- break;
145
- }
146
- case "decodeMesh": {
147
- if (!decoderPromise) {
148
- throw new Error("Draco decoder module is not available");
149
- }
150
- decoderPromise.then((decoder) => {
151
- const numPoints = decodeMesh(decoder, message.dataView, message.attributes, (indices) => {
152
- postMessage({ id: "indices", data: indices }, [indices.buffer]);
153
- }, (kind, data, size, offset, stride, normalized) => {
154
- postMessage({ id: "attribute", kind, data, size, byteOffset: offset, byteStride: stride, normalized }, [data.buffer]);
155
- });
156
- postMessage({ id: "decodeMeshDone", totalVertices: numPoints });
157
- });
158
- break;
159
- }
160
- }
161
- };
162
- }
163
16
  /**
164
17
  * Draco compression (https://google.github.io/draco/)
165
18
  *
@@ -221,60 +74,49 @@ export class DracoCompression {
221
74
  }
222
75
  /**
223
76
  * Constructor
224
- * @param numWorkers The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.
77
+ * @param numWorkers The number of workers for async operations Or an options object. Specify `0` to disable web workers and run synchronously in the current context.
225
78
  */
226
79
  constructor(numWorkers = DracoCompression.DefaultNumWorkers) {
227
- const decoder = DracoCompression.Configuration.decoder;
228
- const decoderInfo = decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === "object"
229
- ? {
230
- url: Tools.GetBabylonScriptURL(decoder.wasmUrl, true),
231
- wasmBinaryPromise: Tools.LoadFileAsync(Tools.GetBabylonScriptURL(decoder.wasmBinaryUrl, true)),
232
- }
233
- : {
234
- url: Tools.GetBabylonScriptURL(decoder.fallbackUrl),
235
- wasmBinaryPromise: Promise.resolve(undefined),
236
- };
237
- if (numWorkers && typeof Worker === "function" && typeof URL === "function") {
238
- this._workerPoolPromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {
239
- const workerContent = `${decodeMesh}(${worker})()`;
240
- const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
241
- return new AutoReleaseWorkerPool(numWorkers, () => {
242
- return new Promise((resolve, reject) => {
243
- const worker = new Worker(workerBlobUrl);
244
- const onError = (error) => {
245
- worker.removeEventListener("error", onError);
246
- worker.removeEventListener("message", onMessage);
247
- reject(error);
248
- };
249
- const onMessage = (event) => {
250
- if (event.data.id === "initDone") {
251
- worker.removeEventListener("error", onError);
252
- worker.removeEventListener("message", onMessage);
253
- resolve(worker);
254
- }
255
- };
256
- worker.addEventListener("error", onError);
257
- worker.addEventListener("message", onMessage);
258
- worker.postMessage({
259
- id: "init",
260
- decoder: {
261
- url: decoderInfo.url,
262
- wasmBinary: decoderWasmBinary,
263
- },
264
- });
265
- });
266
- });
267
- });
80
+ // check if the decoder binary and worker pool was injected
81
+ // Note - it is expected that the developer checked if WebWorker, WebAssembly and the URL object are available
82
+ if (typeof numWorkers === "object" && numWorkers.workerPool) {
83
+ // set the promise accordingly
84
+ this._workerPoolPromise = Promise.resolve(numWorkers.workerPool);
268
85
  }
269
86
  else {
270
- this._decoderModulePromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {
271
- if (!decoderInfo.url) {
272
- throw new Error("Draco decoder module is not available");
87
+ // to avoid making big changes to the decider, if wasmBinary is provided use it in the wasmBinaryPromise
88
+ const wasmBinaryProvided = typeof numWorkers === "object" && numWorkers.wasmBinary;
89
+ // code maintained here for back-compat with no changes
90
+ const decoder = DracoCompression.Configuration.decoder;
91
+ const decoderInfo = decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === "object"
92
+ ? {
93
+ url: Tools.GetBabylonScriptURL(decoder.wasmUrl, true),
94
+ wasmBinaryPromise: wasmBinaryProvided ? Promise.resolve(wasmBinaryProvided) : Tools.LoadFileAsync(Tools.GetBabylonScriptURL(decoder.wasmBinaryUrl, true)),
273
95
  }
274
- return Tools.LoadBabylonScriptAsync(decoderInfo.url).then(() => {
275
- return createDecoderAsync(decoderWasmBinary);
96
+ : {
97
+ url: Tools.GetBabylonScriptURL(decoder.fallbackUrl),
98
+ wasmBinaryPromise: Promise.resolve(undefined),
99
+ };
100
+ const numberOfWorkers = typeof numWorkers === "number" ? numWorkers : numWorkers.numWorkers;
101
+ if (numberOfWorkers && typeof Worker === "function" && typeof URL === "function") {
102
+ this._workerPoolPromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {
103
+ const workerContent = `${decodeMesh}(${workerFunction})()`;
104
+ const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
105
+ return new AutoReleaseWorkerPool(numberOfWorkers, () => {
106
+ const worker = new Worker(workerBlobUrl);
107
+ return initializeWebWorker(worker, decoderWasmBinary, decoderInfo.url);
108
+ });
276
109
  });
277
- });
110
+ }
111
+ else {
112
+ this._decoderModulePromise = decoderInfo.wasmBinaryPromise.then(async (decoderWasmBinary) => {
113
+ if (!decoderInfo.url) {
114
+ throw new Error("Draco decoder module is not available");
115
+ }
116
+ await Tools.LoadBabylonScriptAsync(decoderInfo.url);
117
+ return await createDecoderAsync(decoderWasmBinary);
118
+ });
119
+ }
278
120
  }
279
121
  }
280
122
  /**
@@ -293,14 +135,15 @@ export class DracoCompression {
293
135
  * Returns a promise that resolves when ready. Call this manually to ensure draco compression is ready before use.
294
136
  * @returns a promise that resolves when ready
295
137
  */
296
- whenReadyAsync() {
138
+ async whenReadyAsync() {
297
139
  if (this._workerPoolPromise) {
298
- return this._workerPoolPromise.then(() => { });
140
+ await this._workerPoolPromise;
141
+ return;
299
142
  }
300
143
  if (this._decoderModulePromise) {
301
- return this._decoderModulePromise.then(() => { });
144
+ await this._decoderModulePromise;
145
+ return;
302
146
  }
303
- return Promise.resolve();
304
147
  }
305
148
  _decodeMeshAsync(data, attributes, gltfNormalizedOverride) {
306
149
  const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);
@@ -391,30 +234,28 @@ export class DracoCompression {
391
234
  * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids
392
235
  * @returns A promise that resolves with the decoded geometry
393
236
  */
394
- decodeMeshToGeometryAsync(name, scene, data, attributes) {
395
- return this._decodeMeshAsync(data, attributes).then((meshData) => {
396
- const geometry = new Geometry(name, scene);
397
- if (meshData.indices) {
398
- geometry.setIndices(meshData.indices);
399
- }
400
- for (const attribute of meshData.attributes) {
401
- geometry.setVerticesBuffer(new VertexBuffer(scene.getEngine(), attribute.data, attribute.kind, false, undefined, attribute.byteStride, undefined, attribute.byteOffset, attribute.size, undefined, attribute.normalized, true), meshData.totalVertices);
402
- }
403
- return geometry;
404
- });
237
+ async decodeMeshToGeometryAsync(name, scene, data, attributes) {
238
+ const meshData = await this._decodeMeshAsync(data, attributes);
239
+ const geometry = new Geometry(name, scene);
240
+ if (meshData.indices) {
241
+ geometry.setIndices(meshData.indices);
242
+ }
243
+ for (const attribute of meshData.attributes) {
244
+ geometry.setVerticesBuffer(new VertexBuffer(scene.getEngine(), attribute.data, attribute.kind, false, undefined, attribute.byteStride, undefined, attribute.byteOffset, attribute.size, undefined, attribute.normalized, true), meshData.totalVertices);
245
+ }
246
+ return geometry;
405
247
  }
406
248
  /** @internal */
407
- _decodeMeshToGeometryForGltfAsync(name, scene, data, attributes, gltfNormalizedOverride) {
408
- return this._decodeMeshAsync(data, attributes, gltfNormalizedOverride).then((meshData) => {
409
- const geometry = new Geometry(name, scene);
410
- if (meshData.indices) {
411
- geometry.setIndices(meshData.indices);
412
- }
413
- for (const attribute of meshData.attributes) {
414
- geometry.setVerticesBuffer(new VertexBuffer(scene.getEngine(), attribute.data, attribute.kind, false, undefined, attribute.byteStride, undefined, attribute.byteOffset, attribute.size, undefined, attribute.normalized, true), meshData.totalVertices);
415
- }
416
- return geometry;
417
- });
249
+ async _decodeMeshToGeometryForGltfAsync(name, scene, data, attributes, gltfNormalizedOverride) {
250
+ const meshData = await this._decodeMeshAsync(data, attributes, gltfNormalizedOverride);
251
+ const geometry = new Geometry(name, scene);
252
+ if (meshData.indices) {
253
+ geometry.setIndices(meshData.indices);
254
+ }
255
+ for (const attribute of meshData.attributes) {
256
+ geometry.setVerticesBuffer(new VertexBuffer(scene.getEngine(), attribute.data, attribute.kind, false, undefined, attribute.byteStride, undefined, attribute.byteOffset, attribute.size, undefined, attribute.normalized, true), meshData.totalVertices);
257
+ }
258
+ return geometry;
418
259
  }
419
260
  /**
420
261
  * Decode Draco compressed mesh data to Babylon vertex data.
@@ -423,18 +264,17 @@ export class DracoCompression {
423
264
  * @returns A promise that resolves with the decoded vertex data
424
265
  * @deprecated Use {@link decodeMeshToGeometryAsync} for better performance in some cases
425
266
  */
426
- decodeMeshAsync(data, attributes) {
427
- return this._decodeMeshAsync(data, attributes).then((meshData) => {
428
- const vertexData = new VertexData();
429
- if (meshData.indices) {
430
- vertexData.indices = meshData.indices;
431
- }
432
- for (const attribute of meshData.attributes) {
433
- const floatData = VertexBuffer.GetFloatData(attribute.data, attribute.size, VertexBuffer.GetDataType(attribute.data), attribute.byteOffset, attribute.byteStride, attribute.normalized, meshData.totalVertices);
434
- vertexData.set(floatData, attribute.kind);
435
- }
436
- return vertexData;
437
- });
267
+ async decodeMeshAsync(data, attributes) {
268
+ const meshData = await this._decodeMeshAsync(data, attributes);
269
+ const vertexData = new VertexData();
270
+ if (meshData.indices) {
271
+ vertexData.indices = meshData.indices;
272
+ }
273
+ for (const attribute of meshData.attributes) {
274
+ const floatData = VertexBuffer.GetFloatData(attribute.data, attribute.size, VertexBuffer.GetDataType(attribute.data), attribute.byteOffset, attribute.byteStride, attribute.normalized, meshData.totalVertices);
275
+ vertexData.set(floatData, attribute.kind);
276
+ }
277
+ return vertexData;
438
278
  }
439
279
  }
440
280
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"dracoCompression.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompression.ts"],"names":[],"mappings":"AAAA,yDAAyD;A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,CAAC;AAW3D,yBAAQ,GAA+B,IAAI,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { AutoReleaseWorkerPool } from \"../../Misc/workerPool\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IDisposable, Scene } from \"../../scene\";\r\nimport { Geometry } from \"../geometry\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\nimport type { DecoderModule, DecoderBuffer, Decoder, Mesh, PointCloud, Status } from \"draco3dgltf\";\r\nimport { Logger } from \"../../Misc/logger\";\r\n\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\ninterface AttributeData {\r\n kind: string;\r\n data: ArrayBufferView;\r\n size: number;\r\n byteOffset: number;\r\n byteStride: number;\r\n normalized: boolean;\r\n}\r\n\r\ninterface MeshData {\r\n indices?: Uint16Array | Uint32Array;\r\n attributes: Array<AttributeData>;\r\n totalVertices: number;\r\n}\r\n\r\ninterface InitDoneMessage {\r\n id: \"initDone\";\r\n}\r\n\r\ninterface DecodeMeshDoneMessage {\r\n id: \"decodeMeshDone\";\r\n totalVertices: number;\r\n}\r\n\r\ninterface IndicesMessage {\r\n id: \"indices\";\r\n data: Uint16Array | Uint32Array;\r\n}\r\n\r\ninterface AttributeMessage extends AttributeData {\r\n id: \"attribute\";\r\n}\r\n\r\ntype Message = InitDoneMessage | DecodeMeshDoneMessage | IndicesMessage | AttributeMessage;\r\n\r\n// WorkerGlobalScope\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: Message, transfer?: any[]): void;\r\n\r\nfunction createDecoderAsync(wasmBinary?: ArrayBuffer): Promise<{ module: DecoderModule }> {\r\n return new Promise((resolve) => {\r\n DracoDecoderModule({ wasmBinary: wasmBinary }).then((module) => {\r\n resolve({ module: module });\r\n });\r\n });\r\n}\r\n\r\nfunction decodeMesh(\r\n decoderModule: DecoderModule,\r\n data: Int8Array,\r\n attributes: { [kind: string]: number } | undefined,\r\n onIndicesData: (indices: Uint16Array | Uint32Array) => void,\r\n onAttributeData: (kind: string, data: ArrayBufferView, size: number, offset: number, stride: number, normalized: boolean) => void\r\n): number {\r\n let decoder: Nullable<Decoder> = null;\r\n let buffer: Nullable<DecoderBuffer> = null;\r\n let geometry: Nullable<Mesh | PointCloud> = null;\r\n\r\n try {\r\n decoder = new decoderModule.Decoder();\r\n\r\n buffer = new decoderModule.DecoderBuffer();\r\n buffer.Init(data, data.byteLength);\r\n\r\n let status: Status;\r\n const type = decoder.GetEncodedGeometryType(buffer);\r\n switch (type) {\r\n case decoderModule.TRIANGULAR_MESH: {\r\n const mesh = new decoderModule.Mesh();\r\n status = decoder.DecodeBufferToMesh(buffer, mesh);\r\n if (!status.ok() || mesh.ptr === 0) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n const numFaces = mesh.num_faces();\r\n const numIndices = numFaces * 3;\r\n const byteLength = numIndices * 4;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetTrianglesUInt32Array(mesh, byteLength, ptr);\r\n const indices = new Uint32Array(numIndices);\r\n indices.set(new Uint32Array(decoderModule.HEAPF32.buffer, ptr, numIndices));\r\n onIndicesData(indices);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n\r\n geometry = mesh;\r\n break;\r\n }\r\n case decoderModule.POINT_CLOUD: {\r\n const pointCloud = new decoderModule.PointCloud();\r\n status = decoder.DecodeBufferToPointCloud(buffer, pointCloud);\r\n if (!status.ok() || !pointCloud.ptr) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n geometry = pointCloud;\r\n break;\r\n }\r\n default: {\r\n throw new Error(`Invalid geometry type ${type}`);\r\n }\r\n }\r\n\r\n const numPoints = geometry.num_points();\r\n\r\n const processAttribute = (decoder: Decoder, geometry: Mesh | PointCloud, kind: string, attribute: any) => {\r\n const dataType = attribute.data_type();\r\n const numComponents = attribute.num_components();\r\n const normalized = attribute.normalized();\r\n const byteStride = attribute.byte_stride();\r\n const byteOffset = attribute.byte_offset();\r\n\r\n const dataTypeInfo = {\r\n [decoderModule.DT_FLOAT32]: { typedArrayConstructor: Float32Array, heap: decoderModule.HEAPF32 },\r\n [decoderModule.DT_INT8]: { typedArrayConstructor: Int8Array, heap: decoderModule.HEAP8 },\r\n [decoderModule.DT_INT16]: { typedArrayConstructor: Int16Array, heap: decoderModule.HEAP16 },\r\n [decoderModule.DT_INT32]: { typedArrayConstructor: Int32Array, heap: decoderModule.HEAP32 },\r\n [decoderModule.DT_UINT8]: { typedArrayConstructor: Uint8Array, heap: decoderModule.HEAPU8 },\r\n [decoderModule.DT_UINT16]: { typedArrayConstructor: Uint16Array, heap: decoderModule.HEAPU16 },\r\n [decoderModule.DT_UINT32]: { typedArrayConstructor: Uint32Array, heap: decoderModule.HEAPU32 },\r\n };\r\n\r\n const info = dataTypeInfo[dataType];\r\n if (!info) {\r\n throw new Error(`Invalid data type ${dataType}`);\r\n }\r\n\r\n const numValues = numPoints * numComponents;\r\n const byteLength = numValues * info.typedArrayConstructor.BYTES_PER_ELEMENT;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, dataType, byteLength, ptr);\r\n const data = new info.typedArrayConstructor(info.heap.buffer, ptr, numValues);\r\n onAttributeData(kind, data.slice(), numComponents, byteOffset, byteStride, normalized);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n };\r\n\r\n if (attributes) {\r\n for (const kind in attributes) {\r\n const id = attributes[kind];\r\n const attribute = decoder.GetAttributeByUniqueId(geometry, id);\r\n processAttribute(decoder, geometry, kind, attribute);\r\n }\r\n } else {\r\n const dracoAttributeTypes: { [kind: string]: number } = {\r\n position: decoderModule.POSITION,\r\n normal: decoderModule.NORMAL,\r\n color: decoderModule.COLOR,\r\n uv: decoderModule.TEX_COORD,\r\n };\r\n\r\n for (const kind in dracoAttributeTypes) {\r\n const id = decoder.GetAttributeId(geometry, dracoAttributeTypes[kind]);\r\n if (id !== -1) {\r\n const attribute = decoder.GetAttribute(geometry, id);\r\n processAttribute(decoder, geometry, kind, attribute);\r\n }\r\n }\r\n }\r\n\r\n return numPoints;\r\n } finally {\r\n if (geometry) {\r\n decoderModule.destroy(geometry);\r\n }\r\n\r\n if (buffer) {\r\n decoderModule.destroy(buffer);\r\n }\r\n\r\n if (decoder) {\r\n decoderModule.destroy(decoder);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * The worker function that gets converted to a blob url to pass into a worker.\r\n */\r\nfunction worker(): void {\r\n let decoderPromise: PromiseLike<any> | undefined;\r\n\r\n onmessage = (event) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"init\": {\r\n const decoder = message.decoder;\r\n if (decoder.url) {\r\n importScripts(decoder.url);\r\n decoderPromise = DracoDecoderModule({ wasmBinary: decoder.wasmBinary });\r\n }\r\n postMessage({ id: \"initDone\" });\r\n break;\r\n }\r\n case \"decodeMesh\": {\r\n if (!decoderPromise) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n decoderPromise.then((decoder) => {\r\n const numPoints = decodeMesh(\r\n decoder,\r\n message.dataView,\r\n message.attributes,\r\n (indices) => {\r\n postMessage({ id: \"indices\", data: indices }, [indices.buffer]);\r\n },\r\n (kind, data, size, offset, stride, normalized) => {\r\n postMessage({ id: \"attribute\", kind, data, size, byteOffset: offset, byteStride: stride, normalized }, [data.buffer]);\r\n }\r\n );\r\n postMessage({ id: \"decodeMeshDone\", totalVertices: numPoints });\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Configuration for Draco compression\r\n */\r\nexport interface IDracoCompressionConfiguration {\r\n /**\r\n * Configuration for the decoder.\r\n */\r\n decoder: {\r\n /**\r\n * The url to the WebAssembly module.\r\n */\r\n wasmUrl?: string;\r\n\r\n /**\r\n * The url to the WebAssembly binary.\r\n */\r\n wasmBinaryUrl?: string;\r\n\r\n /**\r\n * The url to the fallback JavaScript module.\r\n */\r\n fallbackUrl?: string;\r\n };\r\n}\r\n\r\n/**\r\n * Draco compression (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco module.\r\n *\r\n * **Encoder**\r\n *\r\n * The encoder is not currently implemented.\r\n *\r\n * **Decoder**\r\n *\r\n * By default, the configuration points to a copy of the Draco decoder files for glTF from the babylon.js preview cdn https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoCompression.Configuration = {\r\n * decoder: {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * }\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The decoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoCompression.DecoderAvailable` to determine if the decoder configuration is available for the current context.\r\n *\r\n * To decode Draco compressed data, get the default DracoCompression object and call decodeMeshToGeometryAsync:\r\n * ```javascript\r\n * var geometry = await DracoCompression.Default.decodeMeshToGeometryAsync(data);\r\n * ```\r\n *\r\n * @see https://playground.babylonjs.com/#DMZIBD#0\r\n */\r\nexport class DracoCompression implements IDisposable {\r\n private _workerPoolPromise?: Promise<AutoReleaseWorkerPool>;\r\n private _decoderModulePromise?: Promise<{ module: DecoderModule }>;\r\n\r\n /**\r\n * The configuration. Defaults to the following urls:\r\n * - wasmUrl: \"https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js\"\r\n * - wasmBinaryUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.wasm\"\r\n * - fallbackUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.js\"\r\n */\r\n public static Configuration: IDracoCompressionConfiguration = {\r\n decoder: {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_wasm_wrapper_gltf.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.js`,\r\n },\r\n };\r\n\r\n /**\r\n * Returns true if the decoder configuration is available.\r\n */\r\n public static get DecoderAvailable(): boolean {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n return !!((decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\") || decoder.fallbackUrl);\r\n }\r\n\r\n /**\r\n * Default number of workers to create when creating the draco compression object.\r\n */\r\n public static DefaultNumWorkers = DracoCompression.GetDefaultNumWorkers();\r\n\r\n private static GetDefaultNumWorkers(): number {\r\n if (typeof navigator !== \"object\" || !navigator.hardwareConcurrency) {\r\n return 1;\r\n }\r\n\r\n // Use 50% of the available logical processors but capped at 4.\r\n return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);\r\n }\r\n\r\n private static _Default: Nullable<DracoCompression> = null;\r\n\r\n /**\r\n * Default instance for the draco compression object.\r\n */\r\n public static get Default(): DracoCompression {\r\n if (!DracoCompression._Default) {\r\n DracoCompression._Default = new DracoCompression();\r\n }\r\n\r\n return DracoCompression._Default;\r\n }\r\n\r\n /**\r\n * Constructor\r\n * @param numWorkers The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n constructor(numWorkers = DracoCompression.DefaultNumWorkers) {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n\r\n const decoderInfo: { url: string | undefined; wasmBinaryPromise: Promise<ArrayBuffer | undefined> } =\r\n decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: Tools.GetBabylonScriptURL(decoder.wasmUrl, true),\r\n wasmBinaryPromise: Tools.LoadFileAsync(Tools.GetBabylonScriptURL(decoder.wasmBinaryUrl, true)),\r\n }\r\n : {\r\n url: Tools.GetBabylonScriptURL(decoder.fallbackUrl!),\r\n wasmBinaryPromise: Promise.resolve(undefined),\r\n };\r\n\r\n if (numWorkers && typeof Worker === \"function\" && typeof URL === \"function\") {\r\n this._workerPoolPromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {\r\n const workerContent = `${decodeMesh}(${worker})()`;\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n\r\n return new AutoReleaseWorkerPool(numWorkers, () => {\r\n return new Promise((resolve, reject) => {\r\n const worker = new Worker(workerBlobUrl);\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n };\r\n\r\n const onMessage = (event: MessageEvent<Message>) => {\r\n if (event.data.id === \"initDone\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(worker);\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n worker.postMessage({\r\n id: \"init\",\r\n decoder: {\r\n url: decoderInfo.url,\r\n wasmBinary: decoderWasmBinary,\r\n },\r\n });\r\n });\r\n });\r\n });\r\n } else {\r\n this._decoderModulePromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {\r\n if (!decoderInfo.url) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n\r\n return Tools.LoadBabylonScriptAsync(decoderInfo.url).then(() => {\r\n return createDecoderAsync(decoderWasmBinary as ArrayBuffer);\r\n });\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Stop all async operations and release resources.\r\n */\r\n public dispose(): void {\r\n if (this._workerPoolPromise) {\r\n this._workerPoolPromise.then((workerPool) => {\r\n workerPool.dispose();\r\n });\r\n }\r\n\r\n delete this._workerPoolPromise;\r\n delete this._decoderModulePromise;\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when ready. Call this manually to ensure draco compression is ready before use.\r\n * @returns a promise that resolves when ready\r\n */\r\n public whenReadyAsync(): Promise<void> {\r\n if (this._workerPoolPromise) {\r\n return this._workerPoolPromise.then(() => {});\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n return this._decoderModulePromise.then(() => {});\r\n }\r\n\r\n return Promise.resolve();\r\n }\r\n\r\n private _decodeMeshAsync(\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes?: { [kind: string]: number },\r\n gltfNormalizedOverride?: { [kind: string]: boolean }\r\n ): Promise<MeshData> {\r\n const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);\r\n\r\n const applyGltfNormalizedOverride = (kind: string, normalized: boolean): boolean => {\r\n if (gltfNormalizedOverride && gltfNormalizedOverride[kind] !== undefined) {\r\n if (normalized !== gltfNormalizedOverride[kind]) {\r\n Logger.Warn(\r\n `Normalized flag from Draco data (${normalized}) does not match normalized flag from glTF accessor (${gltfNormalizedOverride[kind]}). Using flag from glTF accessor.`\r\n );\r\n }\r\n\r\n return gltfNormalizedOverride[kind];\r\n } else {\r\n return normalized;\r\n }\r\n };\r\n\r\n if (this._workerPoolPromise) {\r\n return this._workerPoolPromise.then((workerPool) => {\r\n return new Promise<MeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (event: MessageEvent<Message>) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"decodeMeshDone\": {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve({ indices: resultIndices!, attributes: resultAttributes, totalVertices: message.totalVertices });\r\n onComplete();\r\n break;\r\n }\r\n case \"indices\": {\r\n resultIndices = message.data;\r\n break;\r\n }\r\n case \"attribute\": {\r\n resultAttributes.push({\r\n kind: message.kind,\r\n data: message.data,\r\n size: message.size,\r\n byteOffset: message.byteOffset,\r\n byteStride: message.byteStride,\r\n normalized: applyGltfNormalizedOverride(message.kind, message.normalized),\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n const dataViewCopy = dataView.slice();\r\n worker.postMessage({ id: \"decodeMesh\", dataView: dataViewCopy, attributes: attributes }, [dataViewCopy.buffer]);\r\n });\r\n });\r\n });\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n return this._decoderModulePromise.then((decoder) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const numPoints = decodeMesh(\r\n decoder.module,\r\n dataView,\r\n attributes,\r\n (indices) => {\r\n resultIndices = indices;\r\n },\r\n (kind, data, size, byteOffset, byteStride, normalized) => {\r\n resultAttributes.push({\r\n kind,\r\n data,\r\n size,\r\n byteOffset,\r\n byteStride,\r\n normalized,\r\n });\r\n }\r\n );\r\n\r\n return { indices: resultIndices!, attributes: resultAttributes, totalVertices: numPoints };\r\n });\r\n }\r\n\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon geometry.\r\n * @param name The name to use when creating the geometry\r\n * @param scene The scene to use when creating the geometry\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded geometry\r\n */\r\n public decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n return this._decodeMeshAsync(data, attributes).then((meshData) => {\r\n const geometry = new Geometry(name, scene);\r\n\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n\r\n return geometry;\r\n });\r\n }\r\n\r\n /** @internal */\r\n public _decodeMeshToGeometryForGltfAsync(\r\n name: string,\r\n scene: Scene,\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes: { [kind: string]: number },\r\n gltfNormalizedOverride: { [kind: string]: boolean }\r\n ): Promise<Geometry> {\r\n return this._decodeMeshAsync(data, attributes, gltfNormalizedOverride).then((meshData) => {\r\n const geometry = new Geometry(name, scene);\r\n\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n\r\n return geometry;\r\n });\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon vertex data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded vertex data\r\n * @deprecated Use {@link decodeMeshToGeometryAsync} for better performance in some cases\r\n */\r\n public decodeMeshAsync(data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<VertexData> {\r\n return this._decodeMeshAsync(data, attributes).then((meshData) => {\r\n const vertexData = new VertexData();\r\n\r\n if (meshData.indices) {\r\n vertexData.indices = meshData.indices;\r\n }\r\n\r\n for (const attribute of meshData.attributes) {\r\n const floatData = VertexBuffer.GetFloatData(\r\n attribute.data,\r\n attribute.size,\r\n VertexBuffer.GetDataType(attribute.data),\r\n attribute.byteOffset,\r\n attribute.byteStride,\r\n attribute.normalized,\r\n meshData.totalVertices\r\n );\r\n\r\n vertexData.set(floatData, attribute.kind);\r\n }\r\n\r\n return vertexData;\r\n });\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"dracoCompression.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompression.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAoC,cAAc,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAY7H,SAAS,kBAAkB,CAAC,UAAwB;IAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,kBAAkB,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YAC/C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC;AAgDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,OAAO,gBAAgB;IAkBzB;;OAEG;IACI,MAAM,KAAK,gBAAgB;QAC9B,MAAM,OAAO,GAAG,gBAAgB,CAAC,aAAa,CAAC,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ACzC;QACD,KAAK,MAAM,SAAS,IAAI,QAAQ,CAAC,UAAU,EAAE;YACzC,MAAM,SAAS,GAAG,YAAY,CAAC,YAAY,CACvC,SAAS,CAAC,IAAI,EACd,SAAS,CAAC,IAAI,EACd,YAAY,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,EACxC,SAAS,CAAC,UAAU,EACpB,SAAS,CAAC,UAAU,EACpB,SAAS,CAAC,UAAU,EACpB,QAAQ,CAAC,aAAa,CACzB,CAAC;YAEF,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;SAC7C;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;;AA7UD;;;;;GAKG;AACW,8BAAa,GAAmC;IAC1D,OAAO,EAAE;QACL,OAAO,EAAE,GAAG,KAAK,CAAC,cAAc,6BAA6B;QAC7D,aAAa,EAAE,GAAG,KAAK,CAAC,cAAc,0BAA0B;QAChE,WAAW,EAAE,GAAG,KAAK,CAAC,cAAc,wBAAwB;KAC/D;CACJ,CAAC;AAUF;;GAEG;AACW,kCAAiB,GAAG,gBAAgB,CAAC,oBAAoB,EAAE,CAAC;AAW3D,yBAAQ,GAA+B,IAAI,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { AutoReleaseWorkerPool } from \"../../Misc/workerPool\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IDisposable, Scene } from \"../../scene\";\r\nimport { Geometry } from \"../geometry\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { DecoderModule } from \"draco3dgltf\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { decodeMesh, type AttributeData, type Message, workerFunction, initializeWebWorker } from \"./dracoCompressionWorker\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\ninterface MeshData {\r\n indices?: Uint16Array | Uint32Array;\r\n attributes: Array<AttributeData>;\r\n totalVertices: number;\r\n}\r\n\r\nfunction createDecoderAsync(wasmBinary?: ArrayBuffer): Promise<{ module: DecoderModule }> {\r\n return new Promise((resolve) => {\r\n DracoDecoderModule({ wasmBinary }).then((module) => {\r\n resolve({ module });\r\n });\r\n });\r\n}\r\n\r\n/**\r\n * Configuration for Draco compression\r\n */\r\nexport interface IDracoCompressionConfiguration {\r\n /**\r\n * Configuration for the decoder.\r\n */\r\n decoder: {\r\n /**\r\n * The url to the WebAssembly module.\r\n */\r\n wasmUrl?: string;\r\n\r\n /**\r\n * The url to the WebAssembly binary.\r\n */\r\n wasmBinaryUrl?: string;\r\n\r\n /**\r\n * The url to the fallback JavaScript module.\r\n */\r\n fallbackUrl?: string;\r\n };\r\n}\r\n\r\n/**\r\n * Options for Draco compression\r\n */\r\nexport interface IDracoCompressionOptions {\r\n /**\r\n * The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n numWorkers?: number;\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary.\r\n * If provided it will be used instead of loading the binary from wasmBinaryUrl.\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n /**\r\n * Optional worker pool to use for async decoding.\r\n * If provided, numWorkers will be ignored and the worker pool will be used instead.\r\n * If provided the draco script will not be loaded from the DracoConfiguration.\r\n */\r\n workerPool?: AutoReleaseWorkerPool;\r\n}\r\n\r\n/**\r\n * Draco compression (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco module.\r\n *\r\n * **Encoder**\r\n *\r\n * The encoder is not currently implemented.\r\n *\r\n * **Decoder**\r\n *\r\n * By default, the configuration points to a copy of the Draco decoder files for glTF from the babylon.js preview cdn https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoCompression.Configuration = {\r\n * decoder: {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * }\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The decoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoCompression.DecoderAvailable` to determine if the decoder configuration is available for the current context.\r\n *\r\n * To decode Draco compressed data, get the default DracoCompression object and call decodeMeshToGeometryAsync:\r\n * ```javascript\r\n * var geometry = await DracoCompression.Default.decodeMeshToGeometryAsync(data);\r\n * ```\r\n *\r\n * @see https://playground.babylonjs.com/#DMZIBD#0\r\n */\r\nexport class DracoCompression implements IDisposable {\r\n private _workerPoolPromise?: Promise<AutoReleaseWorkerPool>;\r\n private _decoderModulePromise?: Promise<{ module: DecoderModule }>;\r\n\r\n /**\r\n * The configuration. Defaults to the following urls:\r\n * - wasmUrl: \"https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js\"\r\n * - wasmBinaryUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.wasm\"\r\n * - fallbackUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.js\"\r\n */\r\n public static Configuration: IDracoCompressionConfiguration = {\r\n decoder: {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_wasm_wrapper_gltf.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.js`,\r\n },\r\n };\r\n\r\n /**\r\n * Returns true if the decoder configuration is available.\r\n */\r\n public static get DecoderAvailable(): boolean {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n return !!((decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\") || decoder.fallbackUrl);\r\n }\r\n\r\n /**\r\n * Default number of workers to create when creating the draco compression object.\r\n */\r\n public static DefaultNumWorkers = DracoCompression.GetDefaultNumWorkers();\r\n\r\n private static GetDefaultNumWorkers(): number {\r\n if (typeof navigator !== \"object\" || !navigator.hardwareConcurrency) {\r\n return 1;\r\n }\r\n\r\n // Use 50% of the available logical processors but capped at 4.\r\n return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);\r\n }\r\n\r\n private static _Default: Nullable<DracoCompression> = null;\r\n\r\n /**\r\n * Default instance for the draco compression object.\r\n */\r\n public static get Default(): DracoCompression {\r\n if (!DracoCompression._Default) {\r\n DracoCompression._Default = new DracoCompression();\r\n }\r\n\r\n return DracoCompression._Default;\r\n }\r\n\r\n /**\r\n * Constructor\r\n * @param numWorkers The number of workers for async operations Or an options object. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n constructor(numWorkers: number | IDracoCompressionOptions = DracoCompression.DefaultNumWorkers) {\r\n // check if the decoder binary and worker pool was injected\r\n // Note - it is expected that the developer checked if WebWorker, WebAssembly and the URL object are available\r\n if (typeof numWorkers === \"object\" && numWorkers.workerPool) {\r\n // set the promise accordingly\r\n this._workerPoolPromise = Promise.resolve(numWorkers.workerPool);\r\n } else {\r\n // to avoid making big changes to the decider, if wasmBinary is provided use it in the wasmBinaryPromise\r\n const wasmBinaryProvided = typeof numWorkers === \"object\" && numWorkers.wasmBinary;\r\n\r\n // code maintained here for back-compat with no changes\r\n const decoder = DracoCompression.Configuration.decoder;\r\n\r\n const decoderInfo: { url: string | undefined; wasmBinaryPromise: Promise<ArrayBuffer | undefined> } =\r\n decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: Tools.GetBabylonScriptURL(decoder.wasmUrl, true),\r\n wasmBinaryPromise: wasmBinaryProvided ? Promise.resolve(wasmBinaryProvided) : Tools.LoadFileAsync(Tools.GetBabylonScriptURL(decoder.wasmBinaryUrl, true)),\r\n }\r\n : {\r\n url: Tools.GetBabylonScriptURL(decoder.fallbackUrl!),\r\n wasmBinaryPromise: Promise.resolve(undefined),\r\n };\r\n\r\n const numberOfWorkers = typeof numWorkers === \"number\" ? numWorkers : numWorkers.numWorkers;\r\n if (numberOfWorkers && typeof Worker === \"function\" && typeof URL === \"function\") {\r\n this._workerPoolPromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {\r\n const workerContent = `${decodeMesh}(${workerFunction})()`;\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n\r\n return new AutoReleaseWorkerPool(numberOfWorkers as number, () => {\r\n const worker = new Worker(workerBlobUrl);\r\n return initializeWebWorker(worker, decoderWasmBinary!, decoderInfo.url);\r\n });\r\n });\r\n } else {\r\n this._decoderModulePromise = decoderInfo.wasmBinaryPromise.then(async (decoderWasmBinary) => {\r\n if (!decoderInfo.url) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n\r\n await Tools.LoadBabylonScriptAsync(decoderInfo.url);\r\n return await createDecoderAsync(decoderWasmBinary as ArrayBuffer);\r\n });\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Stop all async operations and release resources.\r\n */\r\n public dispose(): void {\r\n if (this._workerPoolPromise) {\r\n this._workerPoolPromise.then((workerPool) => {\r\n workerPool.dispose();\r\n });\r\n }\r\n\r\n delete this._workerPoolPromise;\r\n delete this._decoderModulePromise;\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when ready. Call this manually to ensure draco compression is ready before use.\r\n * @returns a promise that resolves when ready\r\n */\r\n public async whenReadyAsync(): Promise<void> {\r\n if (this._workerPoolPromise) {\r\n await this._workerPoolPromise;\r\n return;\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n await this._decoderModulePromise;\r\n return;\r\n }\r\n }\r\n\r\n private _decodeMeshAsync(\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes?: { [kind: string]: number },\r\n gltfNormalizedOverride?: { [kind: string]: boolean }\r\n ): Promise<MeshData> {\r\n const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);\r\n\r\n const applyGltfNormalizedOverride = (kind: string, normalized: boolean): boolean => {\r\n if (gltfNormalizedOverride && gltfNormalizedOverride[kind] !== undefined) {\r\n if (normalized !== gltfNormalizedOverride[kind]) {\r\n Logger.Warn(\r\n `Normalized flag from Draco data (${normalized}) does not match normalized flag from glTF accessor (${gltfNormalizedOverride[kind]}). Using flag from glTF accessor.`\r\n );\r\n }\r\n\r\n return gltfNormalizedOverride[kind];\r\n } else {\r\n return normalized;\r\n }\r\n };\r\n\r\n if (this._workerPoolPromise) {\r\n return this._workerPoolPromise.then((workerPool) => {\r\n return new Promise<MeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (event: MessageEvent<Message>) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"decodeMeshDone\": {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve({ indices: resultIndices!, attributes: resultAttributes, totalVertices: message.totalVertices });\r\n onComplete();\r\n break;\r\n }\r\n case \"indices\": {\r\n resultIndices = message.data;\r\n break;\r\n }\r\n case \"attribute\": {\r\n resultAttributes.push({\r\n kind: message.kind,\r\n data: message.data,\r\n size: message.size,\r\n byteOffset: message.byteOffset,\r\n byteStride: message.byteStride,\r\n normalized: applyGltfNormalizedOverride(message.kind, message.normalized),\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n const dataViewCopy = dataView.slice();\r\n worker.postMessage({ id: \"decodeMesh\", dataView: dataViewCopy, attributes: attributes }, [dataViewCopy.buffer]);\r\n });\r\n });\r\n });\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n return this._decoderModulePromise.then((decoder) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const numPoints = decodeMesh(\r\n decoder.module,\r\n dataView,\r\n attributes,\r\n (indices) => {\r\n resultIndices = indices;\r\n },\r\n (kind, data, size, byteOffset, byteStride, normalized) => {\r\n resultAttributes.push({\r\n kind,\r\n data,\r\n size,\r\n byteOffset,\r\n byteStride,\r\n normalized,\r\n });\r\n }\r\n );\r\n\r\n return { indices: resultIndices!, attributes: resultAttributes, totalVertices: numPoints };\r\n });\r\n }\r\n\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon geometry.\r\n * @param name The name to use when creating the geometry\r\n * @param scene The scene to use when creating the geometry\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded geometry\r\n */\r\n public async decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n const meshData = await this._decodeMeshAsync(data, attributes);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /** @internal */\r\n public async _decodeMeshToGeometryForGltfAsync(\r\n name: string,\r\n scene: Scene,\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes: { [kind: string]: number },\r\n gltfNormalizedOverride: { [kind: string]: boolean }\r\n ): Promise<Geometry> {\r\n const meshData = await this._decodeMeshAsync(data, attributes, gltfNormalizedOverride);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon vertex data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded vertex data\r\n * @deprecated Use {@link decodeMeshToGeometryAsync} for better performance in some cases\r\n */\r\n public async decodeMeshAsync(data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<VertexData> {\r\n const meshData = await this._decodeMeshAsync(data, attributes);\r\n const vertexData = new VertexData();\r\n if (meshData.indices) {\r\n vertexData.indices = meshData.indices;\r\n }\r\n for (const attribute of meshData.attributes) {\r\n const floatData = VertexBuffer.GetFloatData(\r\n attribute.data,\r\n attribute.size,\r\n VertexBuffer.GetDataType(attribute.data),\r\n attribute.byteOffset,\r\n attribute.byteStride,\r\n attribute.normalized,\r\n meshData.totalVertices\r\n );\r\n\r\n vertexData.set(floatData, attribute.kind);\r\n }\r\n return vertexData;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,44 @@
1
+ import type { DecoderModule } from "draco3dgltf";
2
+ export interface AttributeData {
3
+ kind: string;
4
+ data: ArrayBufferView;
5
+ size: number;
6
+ byteOffset: number;
7
+ byteStride: number;
8
+ normalized: boolean;
9
+ }
10
+ interface InitDoneMessage {
11
+ id: "initDone";
12
+ }
13
+ interface DecodeMeshDoneMessage {
14
+ id: "decodeMeshDone";
15
+ totalVertices: number;
16
+ }
17
+ interface IndicesMessage {
18
+ id: "indices";
19
+ data: Uint16Array | Uint32Array;
20
+ }
21
+ interface AttributeMessage extends AttributeData {
22
+ id: "attribute";
23
+ }
24
+ export type Message = InitDoneMessage | DecodeMeshDoneMessage | IndicesMessage | AttributeMessage;
25
+ /**
26
+ * @internal
27
+ */
28
+ export declare function decodeMesh(decoderModule: DecoderModule, data: Int8Array, attributes: {
29
+ [kind: string]: number;
30
+ } | undefined, onIndicesData: (indices: Uint16Array | Uint32Array) => void, onAttributeData: (kind: string, data: ArrayBufferView, size: number, offset: number, stride: number, normalized: boolean) => void): number;
31
+ /**
32
+ * The worker function that gets converted to a blob url to pass into a worker.
33
+ * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.
34
+ */
35
+ export declare function workerFunction(): void;
36
+ /**
37
+ * Initializes a worker that was created for the draco agent pool
38
+ * @param worker The worker to initialize
39
+ * @param decoderWasmBinary The wasm binary to load into the worker
40
+ * @param moduleUrl The url to the draco decoder module (optional)
41
+ * @returns A promise that resolves when the worker is initialized
42
+ */
43
+ export declare function initializeWebWorker(worker: Worker, decoderWasmBinary: ArrayBuffer, moduleUrl?: string): Promise<Worker>;
44
+ export {};