@babylonjs/core 6.21.0 → 6.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/Audio/soundTrack.js +1 -1
  2. package/Audio/soundTrack.js.map +1 -1
  3. package/Buffers/buffer.d.ts +2 -1
  4. package/Buffers/buffer.js +12 -5
  5. package/Buffers/buffer.js.map +1 -1
  6. package/Debug/rayHelper.d.ts +3 -3
  7. package/Debug/rayHelper.js +2 -2
  8. package/Debug/rayHelper.js.map +1 -1
  9. package/Engines/Native/nativeHelpers.d.ts +9 -0
  10. package/Engines/Native/nativeHelpers.js +296 -0
  11. package/Engines/Native/nativeHelpers.js.map +1 -0
  12. package/Engines/Native/nativeInterfaces.d.ts +90 -0
  13. package/Engines/Native/nativeInterfaces.js.map +1 -1
  14. package/Engines/engine.d.ts +3 -3
  15. package/Engines/nativeEngine.d.ts +1 -10
  16. package/Engines/nativeEngine.js +13 -207
  17. package/Engines/nativeEngine.js.map +1 -1
  18. package/Engines/thinEngine.js +4 -2
  19. package/Engines/thinEngine.js.map +1 -1
  20. package/Engines/webgpuEngine.js +2 -1
  21. package/Engines/webgpuEngine.js.map +1 -1
  22. package/FlowGraph/Blocks/Data/Logic/flowGraphLogicBlocks.d.ts +23 -0
  23. package/FlowGraph/Blocks/Data/Logic/flowGraphLogicBlocks.js +31 -0
  24. package/FlowGraph/Blocks/Data/Logic/flowGraphLogicBlocks.js.map +1 -0
  25. package/FlowGraph/Blocks/Data/Math/flowGraphNumberMathBlocks.d.ts +270 -0
  26. package/FlowGraph/Blocks/Data/Math/flowGraphNumberMathBlocks.js +347 -0
  27. package/FlowGraph/Blocks/Data/Math/flowGraphNumberMathBlocks.js.map +1 -0
  28. package/FlowGraph/Blocks/Data/Math/flowGraphVector2MathBlocks.d.ts +52 -0
  29. package/FlowGraph/Blocks/Data/Math/flowGraphVector2MathBlocks.js +71 -0
  30. package/FlowGraph/Blocks/Data/Math/flowGraphVector2MathBlocks.js.map +1 -0
  31. package/FlowGraph/Blocks/Data/Math/flowGraphVector3MathBlocks.d.ts +66 -0
  32. package/FlowGraph/Blocks/Data/Math/flowGraphVector3MathBlocks.js +86 -0
  33. package/FlowGraph/Blocks/Data/Math/flowGraphVector3MathBlocks.js.map +1 -0
  34. package/FlowGraph/Blocks/Data/Math/flowGraphVector4MathBlocks.d.ts +52 -0
  35. package/FlowGraph/Blocks/Data/Math/flowGraphVector4MathBlocks.js +71 -0
  36. package/FlowGraph/Blocks/Data/Math/flowGraphVector4MathBlocks.js.map +1 -0
  37. package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.d.ts +17 -0
  38. package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.js +19 -0
  39. package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.js.map +1 -0
  40. package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.d.ts +13 -0
  41. package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.js +16 -0
  42. package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.js.map +1 -0
  43. package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.d.ts +15 -0
  44. package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.js +17 -0
  45. package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.js.map +1 -0
  46. package/FlowGraph/Blocks/Data/index.d.ts +4 -1
  47. package/FlowGraph/Blocks/Data/index.js +4 -1
  48. package/FlowGraph/Blocks/Data/index.js.map +1 -1
  49. package/FlowGraph/Blocks/Event/flowGraphSceneTickEventBlock.d.ts +16 -0
  50. package/FlowGraph/Blocks/Event/flowGraphSceneTickEventBlock.js +29 -0
  51. package/FlowGraph/Blocks/Event/flowGraphSceneTickEventBlock.js.map +1 -0
  52. package/FlowGraph/Blocks/Event/index.d.ts +1 -0
  53. package/FlowGraph/Blocks/Event/index.js +1 -0
  54. package/FlowGraph/Blocks/Event/index.js.map +1 -1
  55. package/FlowGraph/flowGraphDataConnection.d.ts +2 -2
  56. package/FlowGraph/flowGraphDataConnection.js +3 -3
  57. package/FlowGraph/flowGraphDataConnection.js.map +1 -1
  58. package/Gizmos/axisDragGizmo.d.ts +1 -1
  59. package/Gizmos/axisDragGizmo.js.map +1 -1
  60. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js +1 -0
  61. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
  62. package/Materials/PBR/pbrBaseMaterial.d.ts +1 -0
  63. package/Materials/PBR/pbrBaseMaterial.js +7 -1
  64. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  65. package/Materials/standardMaterial.d.ts +1 -0
  66. package/Materials/standardMaterial.js +6 -0
  67. package/Materials/standardMaterial.js.map +1 -1
  68. package/Meshes/Compression/dracoCompression.d.ts +19 -8
  69. package/Meshes/Compression/dracoCompression.js +162 -119
  70. package/Meshes/Compression/dracoCompression.js.map +1 -1
  71. package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.d.ts +22 -2
  72. package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.js +62 -4
  73. package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.js.map +1 -1
  74. package/Meshes/Node/Blocks/debugBlock.d.ts +2 -1
  75. package/Meshes/Node/Blocks/debugBlock.js +8 -2
  76. package/Meshes/Node/Blocks/debugBlock.js.map +1 -1
  77. package/Meshes/Node/Blocks/randomBlock.d.ts +14 -3
  78. package/Meshes/Node/Blocks/randomBlock.js +40 -13
  79. package/Meshes/Node/Blocks/randomBlock.js.map +1 -1
  80. package/Meshes/Node/nodeGeometryBuildState.d.ts +2 -2
  81. package/Meshes/Node/nodeGeometryBuildState.js +5 -3
  82. package/Meshes/Node/nodeGeometryBuildState.js.map +1 -1
  83. package/Meshes/meshSimplification.d.ts +1 -1
  84. package/Meshes/meshSimplification.js.map +1 -1
  85. package/Meshes/subMesh.js +1 -1
  86. package/Meshes/subMesh.js.map +1 -1
  87. package/Physics/v2/IPhysicsEnginePlugin.d.ts +8 -0
  88. package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
  89. package/Shaders/ShadersInclude/bumpFragmentFunctions.js +14 -2
  90. package/Shaders/ShadersInclude/bumpFragmentFunctions.js.map +1 -1
  91. package/package.json +1 -1
  92. package/FlowGraph/Blocks/Data/flowGraphAddBlock.d.ts +0 -23
  93. package/FlowGraph/Blocks/Data/flowGraphAddBlock.js +0 -18
  94. package/FlowGraph/Blocks/Data/flowGraphAddBlock.js.map +0 -1
@@ -1,5 +1,6 @@
1
- import type { IDisposable } from "../../scene";
2
- import { VertexData } from "../../Meshes/mesh.vertexData";
1
+ import type { IDisposable, Scene } from "../../scene";
2
+ import { Geometry } from "../geometry";
3
+ import { VertexData } from "../mesh.vertexData";
3
4
  /**
4
5
  * Configuration for Draco compression
5
6
  */
@@ -50,9 +51,9 @@ export interface IDracoCompressionConfiguration {
50
51
  * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.
51
52
  * Use `DracoCompression.DecoderAvailable` to determine if the decoder configuration is available for the current context.
52
53
  *
53
- * To decode Draco compressed data, get the default DracoCompression object and call decodeMeshAsync:
54
+ * To decode Draco compressed data, get the default DracoCompression object and call decodeMeshToGeometryAsync:
54
55
  * ```javascript
55
- * var vertexData = await DracoCompression.Default.decodeMeshAsync(data);
56
+ * var geometry = await DracoCompression.Default.decodeMeshToGeometryAsync(data);
56
57
  * ```
57
58
  *
58
59
  * @see https://playground.babylonjs.com/#DMZIBD#0
@@ -95,16 +96,26 @@ export declare class DracoCompression implements IDisposable {
95
96
  * @returns a promise that resolves when ready
96
97
  */
97
98
  whenReadyAsync(): Promise<void>;
99
+ private _decodeMeshAsync;
98
100
  /**
99
- * Decode Draco compressed mesh data to vertex data.
101
+ * Decode Draco compressed mesh data to Babylon geometry.
102
+ * @param name The name to use when creating the geometry
103
+ * @param scene The scene to use when creating the geometry
104
+ * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data
105
+ * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids
106
+ * @returns A promise that resolves with the decoded geometry
107
+ */
108
+ decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: {
109
+ [kind: string]: number;
110
+ }): Promise<Geometry>;
111
+ /**
112
+ * Decode Draco compressed mesh data to Babylon vertex data.
100
113
  * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data
101
114
  * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids
102
- * @param dividers a list of optional dividers for normalization
103
115
  * @returns A promise that resolves with the decoded vertex data
116
+ * @deprecated Use {@link decodeMeshToGeometryAsync} for better performance in some cases
104
117
  */
105
118
  decodeMeshAsync(data: ArrayBuffer | ArrayBufferView, attributes?: {
106
119
  [kind: string]: number;
107
- }, dividers?: {
108
- [kind: string]: number;
109
120
  }): Promise<VertexData>;
110
121
  }
@@ -1,7 +1,9 @@
1
1
  /* eslint-disable @typescript-eslint/naming-convention */
2
2
  import { Tools } from "../../Misc/tools.js";
3
3
  import { AutoReleaseWorkerPool } from "../../Misc/workerPool.js";
4
- import { VertexData } from "../../Meshes/mesh.vertexData.js";
4
+ import { Geometry } from "../geometry.js";
5
+ import { VertexBuffer } from "../buffer.js";
6
+ import { VertexData } from "../mesh.vertexData.js";
5
7
  function createDecoderAsync(wasmBinary) {
6
8
  return new Promise((resolve) => {
7
9
  DracoDecoderModule({ wasmBinary: wasmBinary }).then((module) => {
@@ -9,73 +11,79 @@ function createDecoderAsync(wasmBinary) {
9
11
  });
10
12
  });
11
13
  }
12
- function decodeMesh(decoderModule, dataView, attributes, onIndicesData, onAttributeData, dividers) {
13
- const buffer = new decoderModule.DecoderBuffer();
14
- buffer.Init(dataView, dataView.byteLength);
15
- const decoder = new decoderModule.Decoder();
16
- let geometry;
17
- let status;
14
+ function decodeMesh(decoderModule, data, attributes, onIndicesData, onAttributeData) {
15
+ let decoder = null;
16
+ let buffer = null;
17
+ let geometry = null;
18
18
  try {
19
+ decoder = new decoderModule.Decoder();
20
+ buffer = new decoderModule.DecoderBuffer();
21
+ buffer.Init(data, data.byteLength);
22
+ let status;
19
23
  const type = decoder.GetEncodedGeometryType(buffer);
20
24
  switch (type) {
21
- case decoderModule.TRIANGULAR_MESH:
22
- geometry = new decoderModule.Mesh();
23
- status = decoder.DecodeBufferToMesh(buffer, geometry);
25
+ case decoderModule.TRIANGULAR_MESH: {
26
+ const mesh = new decoderModule.Mesh();
27
+ status = decoder.DecodeBufferToMesh(buffer, mesh);
28
+ if (!status.ok() || mesh.ptr === 0) {
29
+ throw new Error(status.error_msg());
30
+ }
31
+ const numFaces = mesh.num_faces();
32
+ const numIndices = numFaces * 3;
33
+ const byteLength = numIndices * 4;
34
+ const ptr = decoderModule._malloc(byteLength);
35
+ try {
36
+ decoder.GetTrianglesUInt32Array(mesh, byteLength, ptr);
37
+ const indices = new Uint32Array(numIndices);
38
+ indices.set(new Uint32Array(decoderModule.HEAPF32.buffer, ptr, numIndices));
39
+ onIndicesData(indices);
40
+ }
41
+ finally {
42
+ decoderModule._free(ptr);
43
+ }
44
+ geometry = mesh;
24
45
  break;
25
- case decoderModule.POINT_CLOUD:
26
- geometry = new decoderModule.PointCloud();
27
- status = decoder.DecodeBufferToPointCloud(buffer, geometry);
46
+ }
47
+ case decoderModule.POINT_CLOUD: {
48
+ const pointCloud = new decoderModule.PointCloud();
49
+ status = decoder.DecodeBufferToPointCloud(buffer, pointCloud);
50
+ if (!status.ok() || !pointCloud.ptr) {
51
+ throw new Error(status.error_msg());
52
+ }
53
+ geometry = pointCloud;
28
54
  break;
29
- default:
30
- throw new Error(`Invalid geometry type ${type}`);
31
- }
32
- if (!status.ok() || !geometry.ptr) {
33
- throw new Error(status.error_msg());
34
- }
35
- if (type === decoderModule.TRIANGULAR_MESH) {
36
- const numFaces = geometry.num_faces();
37
- const numIndices = numFaces * 3;
38
- const byteLength = numIndices * 4;
39
- const ptr = decoderModule._malloc(byteLength);
40
- try {
41
- decoder.GetTrianglesUInt32Array(geometry, byteLength, ptr);
42
- const indices = new Uint32Array(numIndices);
43
- indices.set(new Uint32Array(decoderModule.HEAPF32.buffer, ptr, numIndices));
44
- onIndicesData(indices);
45
55
  }
46
- finally {
47
- decoderModule._free(ptr);
56
+ default: {
57
+ throw new Error(`Invalid geometry type ${type}`);
48
58
  }
49
59
  }
50
- const processAttribute = (kind, attribute, divider = 1) => {
60
+ const numPoints = geometry.num_points();
61
+ const processAttribute = (decoder, geometry, kind, attribute) => {
62
+ const dataType = attribute.data_type();
51
63
  const numComponents = attribute.num_components();
52
- const numPoints = geometry.num_points();
64
+ const normalized = attribute.normalized();
65
+ const byteStride = attribute.byte_stride();
66
+ const byteOffset = attribute.byte_offset();
67
+ const dataTypeInfo = {
68
+ [decoderModule.DT_FLOAT32]: { typedArrayConstructor: Float32Array, heap: decoderModule.HEAPF32 },
69
+ [decoderModule.DT_INT8]: { typedArrayConstructor: Int8Array, heap: decoderModule.HEAP8 },
70
+ [decoderModule.DT_INT16]: { typedArrayConstructor: Int16Array, heap: decoderModule.HEAP16 },
71
+ [decoderModule.DT_INT32]: { typedArrayConstructor: Int32Array, heap: decoderModule.HEAP32 },
72
+ [decoderModule.DT_UINT8]: { typedArrayConstructor: Uint8Array, heap: decoderModule.HEAPU8 },
73
+ [decoderModule.DT_UINT16]: { typedArrayConstructor: Uint16Array, heap: decoderModule.HEAPU16 },
74
+ [decoderModule.DT_UINT32]: { typedArrayConstructor: Uint32Array, heap: decoderModule.HEAPU32 },
75
+ };
76
+ const info = dataTypeInfo[dataType];
77
+ if (!info) {
78
+ throw new Error(`Invalid data type ${dataType}`);
79
+ }
53
80
  const numValues = numPoints * numComponents;
54
- const byteLength = numValues * Float32Array.BYTES_PER_ELEMENT;
81
+ const byteLength = numValues * info.typedArrayConstructor.BYTES_PER_ELEMENT;
55
82
  const ptr = decoderModule._malloc(byteLength);
56
83
  try {
57
- decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, decoderModule.DT_FLOAT32, byteLength, ptr);
58
- const values = new Float32Array(decoderModule.HEAPF32.buffer, ptr, numValues);
59
- if (kind === "color" && numComponents === 3) {
60
- const babylonData = new Float32Array(numPoints * 4);
61
- for (let i = 0, j = 0; i < babylonData.length; i += 4, j += numComponents) {
62
- babylonData[i + 0] = values[j + 0];
63
- babylonData[i + 1] = values[j + 1];
64
- babylonData[i + 2] = values[j + 2];
65
- babylonData[i + 3] = 1;
66
- }
67
- onAttributeData(kind, babylonData);
68
- }
69
- else {
70
- const babylonData = new Float32Array(numValues);
71
- babylonData.set(new Float32Array(decoderModule.HEAPF32.buffer, ptr, numValues));
72
- if (divider !== 1) {
73
- for (let i = 0; i < babylonData.length; i++) {
74
- babylonData[i] = babylonData[i] / divider;
75
- }
76
- }
77
- onAttributeData(kind, babylonData);
78
- }
84
+ decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, dataType, byteLength, ptr);
85
+ const data = new info.typedArrayConstructor(info.heap.buffer, ptr, numValues);
86
+ onAttributeData(kind, data.slice(), byteOffset, byteStride, normalized);
79
87
  }
80
88
  finally {
81
89
  decoderModule._free(ptr);
@@ -85,32 +93,36 @@ function decodeMesh(decoderModule, dataView, attributes, onIndicesData, onAttrib
85
93
  for (const kind in attributes) {
86
94
  const id = attributes[kind];
87
95
  const attribute = decoder.GetAttributeByUniqueId(geometry, id);
88
- const divider = (dividers && dividers[kind]) || 1;
89
- processAttribute(kind, attribute, divider);
96
+ processAttribute(decoder, geometry, kind, attribute);
90
97
  }
91
98
  }
92
99
  else {
93
- const nativeAttributeTypes = {
94
- position: "POSITION",
95
- normal: "NORMAL",
96
- color: "COLOR",
97
- uv: "TEX_COORD",
100
+ const dracoAttributeTypes = {
101
+ position: decoderModule.POSITION,
102
+ normal: decoderModule.NORMAL,
103
+ color: decoderModule.COLOR,
104
+ uv: decoderModule.TEX_COORD,
98
105
  };
99
- for (const kind in nativeAttributeTypes) {
100
- const id = decoder.GetAttributeId(geometry, decoderModule[nativeAttributeTypes[kind]]);
106
+ for (const kind in dracoAttributeTypes) {
107
+ const id = decoder.GetAttributeId(geometry, dracoAttributeTypes[kind]);
101
108
  if (id !== -1) {
102
109
  const attribute = decoder.GetAttribute(geometry, id);
103
- processAttribute(kind, attribute);
110
+ processAttribute(decoder, geometry, kind, attribute);
104
111
  }
105
112
  }
106
113
  }
114
+ return numPoints;
107
115
  }
108
116
  finally {
109
117
  if (geometry) {
110
118
  decoderModule.destroy(geometry);
111
119
  }
112
- decoderModule.destroy(decoder);
113
- decoderModule.destroy(buffer);
120
+ if (buffer) {
121
+ decoderModule.destroy(buffer);
122
+ }
123
+ if (decoder) {
124
+ decoderModule.destroy(decoder);
125
+ }
114
126
  }
115
127
  }
116
128
  /**
@@ -119,15 +131,15 @@ function decodeMesh(decoderModule, dataView, attributes, onIndicesData, onAttrib
119
131
  function worker() {
120
132
  let decoderPromise;
121
133
  onmessage = (event) => {
122
- const data = event.data;
123
- switch (data.id) {
134
+ const message = event.data;
135
+ switch (message.id) {
124
136
  case "init": {
125
- const decoder = data.decoder;
137
+ const decoder = message.decoder;
126
138
  if (decoder.url) {
127
139
  importScripts(decoder.url);
128
140
  decoderPromise = DracoDecoderModule({ wasmBinary: decoder.wasmBinary });
129
141
  }
130
- postMessage("done");
142
+ postMessage({ id: "initDone" });
131
143
  break;
132
144
  }
133
145
  case "decodeMesh": {
@@ -135,12 +147,12 @@ function worker() {
135
147
  throw new Error("Draco decoder module is not available");
136
148
  }
137
149
  decoderPromise.then((decoder) => {
138
- decodeMesh(decoder, data.dataView, data.attributes, (indices) => {
139
- postMessage({ id: "indices", value: indices }, [indices.buffer]);
140
- }, (kind, data) => {
141
- postMessage({ id: kind, value: data }, [data.buffer]);
150
+ const numPoints = decodeMesh(decoder, message.dataView, message.attributes, (indices) => {
151
+ postMessage({ id: "indices", data: indices }, [indices.buffer]);
152
+ }, (kind, data, offset, stride, normalized) => {
153
+ postMessage({ id: "attribute", kind, data, offset, stride, normalized }, [data.buffer]);
142
154
  });
143
- postMessage("done");
155
+ postMessage({ id: "decodeMeshDone", totalVertices: numPoints });
144
156
  });
145
157
  break;
146
158
  }
@@ -175,9 +187,9 @@ function worker() {
175
187
  * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.
176
188
  * Use `DracoCompression.DecoderAvailable` to determine if the decoder configuration is available for the current context.
177
189
  *
178
- * To decode Draco compressed data, get the default DracoCompression object and call decodeMeshAsync:
190
+ * To decode Draco compressed data, get the default DracoCompression object and call decodeMeshToGeometryAsync:
179
191
  * ```javascript
180
- * var vertexData = await DracoCompression.Default.decodeMeshAsync(data);
192
+ * var geometry = await DracoCompression.Default.decodeMeshToGeometryAsync(data);
181
193
  * ```
182
194
  *
183
195
  * @see https://playground.babylonjs.com/#DMZIBD#0
@@ -233,8 +245,8 @@ export class DracoCompression {
233
245
  worker.removeEventListener("message", onMessage);
234
246
  reject(error);
235
247
  };
236
- const onMessage = (message) => {
237
- if (message.data === "done") {
248
+ const onMessage = (event) => {
249
+ if (event.data.id === "initDone") {
238
250
  worker.removeEventListener("error", onError);
239
251
  worker.removeEventListener("message", onMessage);
240
252
  resolve(worker);
@@ -289,52 +301,43 @@ export class DracoCompression {
289
301
  }
290
302
  return Promise.resolve();
291
303
  }
292
- /**
293
- * Decode Draco compressed mesh data to vertex data.
294
- * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data
295
- * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids
296
- * @param dividers a list of optional dividers for normalization
297
- * @returns A promise that resolves with the decoded vertex data
298
- */
299
- decodeMeshAsync(data, attributes, dividers) {
300
- const dataView = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
304
+ _decodeMeshAsync(engine, data, attributes) {
305
+ const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);
301
306
  if (this._workerPoolPromise) {
302
307
  return this._workerPoolPromise.then((workerPool) => {
303
308
  return new Promise((resolve, reject) => {
304
309
  workerPool.push((worker, onComplete) => {
305
- const vertexData = new VertexData();
310
+ let resultIndices = null;
311
+ const resultAttributes = [];
306
312
  const onError = (error) => {
307
313
  worker.removeEventListener("error", onError);
308
314
  worker.removeEventListener("message", onMessage);
309
315
  reject(error);
310
316
  onComplete();
311
317
  };
312
- const onMessage = (message) => {
313
- if (message.data === "done") {
314
- worker.removeEventListener("error", onError);
315
- worker.removeEventListener("message", onMessage);
316
- resolve(vertexData);
317
- onComplete();
318
- }
319
- else if (message.data.id === "indices") {
320
- vertexData.indices = message.data.value;
321
- }
322
- else {
323
- // check normalization
324
- const divider = dividers && dividers[message.data.id] ? dividers[message.data.id] : 1;
325
- if (divider !== 1) {
326
- // normalize
327
- for (let i = 0; i < message.data.value.length; i++) {
328
- message.data.value[i] = message.data.value[i] / divider;
329
- }
318
+ const onMessage = (event) => {
319
+ const message = event.data;
320
+ switch (message.id) {
321
+ case "decodeMeshDone": {
322
+ worker.removeEventListener("error", onError);
323
+ worker.removeEventListener("message", onMessage);
324
+ resolve({ indices: resultIndices, attributes: resultAttributes, totalVertices: message.totalVertices });
325
+ onComplete();
326
+ break;
327
+ }
328
+ case "indices": {
329
+ resultIndices = message.data;
330
+ break;
331
+ }
332
+ case "attribute": {
333
+ resultAttributes.push(new VertexBuffer(engine, message.data, message.kind, false, undefined, message.stride, undefined, message.offset, undefined, undefined, message.normalized, true));
334
+ break;
330
335
  }
331
- vertexData.set(message.data.value, message.data.id);
332
336
  }
333
337
  };
334
338
  worker.addEventListener("error", onError);
335
339
  worker.addEventListener("message", onMessage);
336
- const dataViewCopy = new Uint8Array(dataView.byteLength);
337
- dataViewCopy.set(new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength));
340
+ const dataViewCopy = dataView.slice();
338
341
  worker.postMessage({ id: "decodeMesh", dataView: dataViewCopy, attributes: attributes }, [dataViewCopy.buffer]);
339
342
  });
340
343
  });
@@ -342,17 +345,57 @@ export class DracoCompression {
342
345
  }
343
346
  if (this._decoderModulePromise) {
344
347
  return this._decoderModulePromise.then((decoder) => {
345
- const vertexData = new VertexData();
346
- decodeMesh(decoder.module, dataView, attributes, (indices) => {
347
- vertexData.indices = indices;
348
- }, (kind, data) => {
349
- vertexData.set(data, kind);
350
- }, dividers);
351
- return vertexData;
348
+ let resultIndices = null;
349
+ const resultAttributes = [];
350
+ const numPoints = decodeMesh(decoder.module, dataView, attributes, (indices) => {
351
+ resultIndices = indices;
352
+ }, (kind, data, offset, stride, normalized) => {
353
+ resultAttributes.push(new VertexBuffer(null, data, kind, false, undefined, stride, undefined, offset, undefined, undefined, normalized, true));
354
+ });
355
+ return { indices: resultIndices, attributes: resultAttributes, totalVertices: numPoints };
352
356
  });
353
357
  }
354
358
  throw new Error("Draco decoder module is not available");
355
359
  }
360
+ /**
361
+ * Decode Draco compressed mesh data to Babylon geometry.
362
+ * @param name The name to use when creating the geometry
363
+ * @param scene The scene to use when creating the geometry
364
+ * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data
365
+ * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids
366
+ * @returns A promise that resolves with the decoded geometry
367
+ */
368
+ decodeMeshToGeometryAsync(name, scene, data, attributes) {
369
+ return this._decodeMeshAsync(scene.getEngine(), data, attributes).then((meshData) => {
370
+ const geometry = new Geometry(name, scene);
371
+ if (meshData.indices) {
372
+ geometry.setIndices(meshData.indices);
373
+ }
374
+ for (const attribute of meshData.attributes) {
375
+ geometry.setVerticesBuffer(attribute);
376
+ }
377
+ return geometry;
378
+ });
379
+ }
380
+ /**
381
+ * Decode Draco compressed mesh data to Babylon vertex data.
382
+ * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data
383
+ * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids
384
+ * @returns A promise that resolves with the decoded vertex data
385
+ * @deprecated Use {@link decodeMeshToGeometryAsync} for better performance in some cases
386
+ */
387
+ decodeMeshAsync(data, attributes) {
388
+ return this._decodeMeshAsync(null, data, attributes).then((meshData) => {
389
+ const vertexData = new VertexData();
390
+ if (meshData.indices) {
391
+ vertexData.indices = meshData.indices;
392
+ }
393
+ for (const attribute of meshData.attributes) {
394
+ vertexData.set(attribute.getFloatData(meshData.totalVertices), attribute.getKind());
395
+ }
396
+ return vertexData;
397
+ });
398
+ }
356
399
  }
357
400
  /**
358
401
  * The configuration. Defaults to the following urls:
@@ -1 +1 @@
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,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAS1D,SAAS,kBAAkB,CAAC,UAAwB;IAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,kBAAkB,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAW,EAAE,EAAE;YAChE,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC;AAED,SAAS,UAAU,CACf,aAAkB,EAClB,QAAyB,EACzB,UAAkD,EAClD,aAA0C,EAC1C,eAA2D,EAC3D,QAAqC;IAErC,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,aAAa,EAAE,CAAC;IACjD,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IAE3C,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,OAAO,EAAE,CAAC;IAC5C,IAAI,QAAa,CAAC;IAClB,IAAI,MAAW,CAAC;IAEhB,IAAI;QACA,MAAM,IAAI,GAAG,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;QACpD,QAAQ,IAAI,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AAE;QACL,OAAO,EAAE,0DAA0D;QACnE,aAAa,EAAE,uDAAuD;QACtE,WAAW,EAAE,qDAAqD;KACrE;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 } from \"../../scene\";\r\nimport { VertexData } from \"../../Meshes/mesh.vertexData\";\r\n\r\ndeclare let DracoDecoderModule: any;\r\ndeclare let WebAssembly: any;\r\n\r\n// WorkerGlobalScope\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: any, transfer?: any[]): void;\r\n\r\nfunction createDecoderAsync(wasmBinary?: ArrayBuffer): Promise<any> {\r\n return new Promise((resolve) => {\r\n DracoDecoderModule({ wasmBinary: wasmBinary }).then((module: any) => {\r\n resolve({ module: module });\r\n });\r\n });\r\n}\r\n\r\nfunction decodeMesh(\r\n decoderModule: any,\r\n dataView: ArrayBufferView,\r\n attributes: { [kind: string]: number } | undefined,\r\n onIndicesData: (data: Uint32Array) => void,\r\n onAttributeData: (kind: string, data: Float32Array) => void,\r\n dividers?: { [kind: string]: number }\r\n): void {\r\n const buffer = new decoderModule.DecoderBuffer();\r\n buffer.Init(dataView, dataView.byteLength);\r\n\r\n const decoder = new decoderModule.Decoder();\r\n let geometry: any;\r\n let status: any;\r\n\r\n try {\r\n const type = decoder.GetEncodedGeometryType(buffer);\r\n switch (type) {\r\n case decoderModule.TRIANGULAR_MESH:\r\n geometry = new decoderModule.Mesh();\r\n status = decoder.DecodeBufferToMesh(buffer, geometry);\r\n break;\r\n case decoderModule.POINT_CLOUD:\r\n geometry = new decoderModule.PointCloud();\r\n status = decoder.DecodeBufferToPointCloud(buffer, geometry);\r\n break;\r\n default:\r\n throw new Error(`Invalid geometry type ${type}`);\r\n }\r\n\r\n if (!status.ok() || !geometry.ptr) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n if (type === decoderModule.TRIANGULAR_MESH) {\r\n const numFaces = geometry.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(geometry, 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\r\n const processAttribute = (kind: string, attribute: any, divider = 1) => {\r\n const numComponents = attribute.num_components();\r\n const numPoints = geometry.num_points();\r\n const numValues = numPoints * numComponents;\r\n const byteLength = numValues * Float32Array.BYTES_PER_ELEMENT;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, decoderModule.DT_FLOAT32, byteLength, ptr);\r\n const values = new Float32Array(decoderModule.HEAPF32.buffer, ptr, numValues);\r\n if (kind === \"color\" && numComponents === 3) {\r\n const babylonData = new Float32Array(numPoints * 4);\r\n for (let i = 0, j = 0; i < babylonData.length; i += 4, j += numComponents) {\r\n babylonData[i + 0] = values[j + 0];\r\n babylonData[i + 1] = values[j + 1];\r\n babylonData[i + 2] = values[j + 2];\r\n babylonData[i + 3] = 1;\r\n }\r\n onAttributeData(kind, babylonData);\r\n } else {\r\n const babylonData = new Float32Array(numValues);\r\n babylonData.set(new Float32Array(decoderModule.HEAPF32.buffer, ptr, numValues));\r\n if (divider !== 1) {\r\n for (let i = 0; i < babylonData.length; i++) {\r\n babylonData[i] = babylonData[i] / divider;\r\n }\r\n }\r\n onAttributeData(kind, babylonData);\r\n }\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 const divider = (dividers && dividers[kind]) || 1;\r\n processAttribute(kind, attribute, divider);\r\n }\r\n } else {\r\n const nativeAttributeTypes: { [kind: string]: string } = {\r\n position: \"POSITION\",\r\n normal: \"NORMAL\",\r\n color: \"COLOR\",\r\n uv: \"TEX_COORD\",\r\n };\r\n\r\n for (const kind in nativeAttributeTypes) {\r\n const id = decoder.GetAttributeId(geometry, decoderModule[nativeAttributeTypes[kind]]);\r\n if (id !== -1) {\r\n const attribute = decoder.GetAttribute(geometry, id);\r\n processAttribute(kind, attribute);\r\n }\r\n }\r\n }\r\n } finally {\r\n if (geometry) {\r\n decoderModule.destroy(geometry);\r\n }\r\n\r\n decoderModule.destroy(decoder);\r\n decoderModule.destroy(buffer);\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 data = event.data;\r\n switch (data.id) {\r\n case \"init\": {\r\n const decoder = data.decoder;\r\n if (decoder.url) {\r\n importScripts(decoder.url);\r\n decoderPromise = DracoDecoderModule({ wasmBinary: decoder.wasmBinary });\r\n }\r\n postMessage(\"done\");\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 decodeMesh(\r\n decoder,\r\n data.dataView,\r\n data.attributes,\r\n (indices) => {\r\n postMessage({ id: \"indices\", value: indices }, [indices.buffer]);\r\n },\r\n (kind, data) => {\r\n postMessage({ id: kind, value: data }, [data.buffer]);\r\n }\r\n );\r\n postMessage(\"done\");\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 decodeMeshAsync:\r\n * ```javascript\r\n * var vertexData = await DracoCompression.Default.decodeMeshAsync(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<any>;\r\n\r\n /**\r\n * The configuration. Defaults to the following urls:\r\n * - wasmUrl: \"https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js\"\r\n * - wasmBinaryUrl: \"https://preview.babylonjs.com/draco_decoder_gltf.wasm\"\r\n * - fallbackUrl: \"https://preview.babylonjs.com/draco_decoder_gltf.js\"\r\n */\r\n public static Configuration: IDracoCompressionConfiguration = {\r\n decoder: {\r\n wasmUrl: \"https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js\",\r\n wasmBinaryUrl: \"https://preview.babylonjs.com/draco_decoder_gltf.wasm\",\r\n fallbackUrl: \"https://preview.babylonjs.com/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 | string | undefined> } =\r\n decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: Tools.GetAbsoluteUrl(decoder.wasmUrl),\r\n wasmBinaryPromise: Tools.LoadFileAsync(Tools.GetAbsoluteUrl(decoder.wasmBinaryUrl)),\r\n }\r\n : {\r\n url: Tools.GetAbsoluteUrl(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 = (message: MessageEvent) => {\r\n if (message.data === \"done\") {\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.LoadScriptAsync(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 /**\r\n * Decode Draco compressed mesh data to 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 * @param dividers a list of optional dividers for normalization\r\n * @returns A promise that resolves with the decoded vertex data\r\n */\r\n public decodeMeshAsync(data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }, dividers?: { [kind: string]: number }): Promise<VertexData> {\r\n const dataView = data instanceof ArrayBuffer ? new Uint8Array(data) : data;\r\n\r\n if (this._workerPoolPromise) {\r\n return this._workerPoolPromise.then((workerPool) => {\r\n return new Promise<VertexData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n const vertexData = new VertexData();\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 = (message: MessageEvent) => {\r\n if (message.data === \"done\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(vertexData);\r\n onComplete();\r\n } else if (message.data.id === \"indices\") {\r\n vertexData.indices = message.data.value;\r\n } else {\r\n // check normalization\r\n const divider = dividers && dividers[message.data.id] ? dividers[message.data.id] : 1;\r\n if (divider !== 1) {\r\n // normalize\r\n for (let i = 0; i < message.data.value.length; i++) {\r\n message.data.value[i] = message.data.value[i] / divider;\r\n }\r\n }\r\n vertexData.set(message.data.value, message.data.id);\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n const dataViewCopy = new Uint8Array(dataView.byteLength);\r\n dataViewCopy.set(new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength));\r\n\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 const vertexData = new VertexData();\r\n decodeMesh(\r\n decoder.module,\r\n dataView,\r\n attributes,\r\n (indices) => {\r\n vertexData.indices = indices;\r\n },\r\n (kind, data) => {\r\n vertexData.set(data, kind);\r\n },\r\n dividers\r\n );\r\n return vertexData;\r\n });\r\n }\r\n\r\n throw new Error(\"Draco decoder module is not available\");\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;AA0ChD,SAAS,kBAAkB,CAAC,UAAwB;IAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,kBAAkB,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YAC3D,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC;AAED,SAAS,UAAU,CACf,aAA4B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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 type { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\nimport type { DecoderModule, DecoderBuffer, Decoder, Mesh, PointCloud, Status } from \"draco3dgltf\";\r\n\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\ninterface MeshData {\r\n indices?: Uint16Array | Uint32Array;\r\n attributes: Array<VertexBuffer>;\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 {\r\n id: \"attribute\";\r\n kind: string;\r\n data: ArrayBufferView;\r\n offset: number;\r\n stride: number;\r\n normalized: boolean;\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, 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(), 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, offset, stride, normalized) => {\r\n postMessage({ id: \"attribute\", kind, data, offset, 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://preview.babylonjs.com/draco_wasm_wrapper_gltf.js\"\r\n * - wasmBinaryUrl: \"https://preview.babylonjs.com/draco_decoder_gltf.wasm\"\r\n * - fallbackUrl: \"https://preview.babylonjs.com/draco_decoder_gltf.js\"\r\n */\r\n public static Configuration: IDracoCompressionConfiguration = {\r\n decoder: {\r\n wasmUrl: \"https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js\",\r\n wasmBinaryUrl: \"https://preview.babylonjs.com/draco_decoder_gltf.wasm\",\r\n fallbackUrl: \"https://preview.babylonjs.com/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 | string | undefined> } =\r\n decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: Tools.GetAbsoluteUrl(decoder.wasmUrl),\r\n wasmBinaryPromise: Tools.LoadFileAsync(Tools.GetAbsoluteUrl(decoder.wasmBinaryUrl)),\r\n }\r\n : {\r\n url: Tools.GetAbsoluteUrl(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.LoadScriptAsync(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(engine: Nullable<ThinEngine>, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<MeshData> {\r\n const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);\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<VertexBuffer> = [];\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 new VertexBuffer(\r\n engine,\r\n message.data,\r\n message.kind,\r\n false,\r\n undefined,\r\n message.stride,\r\n undefined,\r\n message.offset,\r\n undefined,\r\n undefined,\r\n message.normalized,\r\n true\r\n )\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<VertexBuffer> = [];\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, offset, stride, normalized) => {\r\n resultAttributes.push(new VertexBuffer(null, data, kind, false, undefined, stride, undefined, offset, undefined, undefined, normalized, true));\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(scene.getEngine(), 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(attribute);\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(null, 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 vertexData.set(attribute.getFloatData(meshData.totalVertices)!, attribute.getKind());\r\n }\r\n\r\n return vertexData;\r\n });\r\n }\r\n}\r\n"]}