@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
@@ -0,0 +1,189 @@
1
+ /**
2
+ * @internal
3
+ */
4
+ export function decodeMesh(decoderModule, data, attributes, onIndicesData, onAttributeData) {
5
+ let decoder = null;
6
+ let buffer = null;
7
+ let geometry = null;
8
+ try {
9
+ decoder = new decoderModule.Decoder();
10
+ buffer = new decoderModule.DecoderBuffer();
11
+ buffer.Init(data, data.byteLength);
12
+ let status;
13
+ const type = decoder.GetEncodedGeometryType(buffer);
14
+ switch (type) {
15
+ case decoderModule.TRIANGULAR_MESH: {
16
+ const mesh = new decoderModule.Mesh();
17
+ status = decoder.DecodeBufferToMesh(buffer, mesh);
18
+ if (!status.ok() || mesh.ptr === 0) {
19
+ throw new Error(status.error_msg());
20
+ }
21
+ const numFaces = mesh.num_faces();
22
+ const numIndices = numFaces * 3;
23
+ const byteLength = numIndices * 4;
24
+ const ptr = decoderModule._malloc(byteLength);
25
+ try {
26
+ decoder.GetTrianglesUInt32Array(mesh, byteLength, ptr);
27
+ const indices = new Uint32Array(numIndices);
28
+ indices.set(new Uint32Array(decoderModule.HEAPF32.buffer, ptr, numIndices));
29
+ onIndicesData(indices);
30
+ }
31
+ finally {
32
+ decoderModule._free(ptr);
33
+ }
34
+ geometry = mesh;
35
+ break;
36
+ }
37
+ case decoderModule.POINT_CLOUD: {
38
+ const pointCloud = new decoderModule.PointCloud();
39
+ status = decoder.DecodeBufferToPointCloud(buffer, pointCloud);
40
+ if (!status.ok() || !pointCloud.ptr) {
41
+ throw new Error(status.error_msg());
42
+ }
43
+ geometry = pointCloud;
44
+ break;
45
+ }
46
+ default: {
47
+ throw new Error(`Invalid geometry type ${type}`);
48
+ }
49
+ }
50
+ const numPoints = geometry.num_points();
51
+ const processAttribute = (decoder, geometry, kind, attribute) => {
52
+ const dataType = attribute.data_type();
53
+ const numComponents = attribute.num_components();
54
+ const normalized = attribute.normalized();
55
+ const byteStride = attribute.byte_stride();
56
+ const byteOffset = attribute.byte_offset();
57
+ const dataTypeInfo = {
58
+ [decoderModule.DT_FLOAT32]: { typedArrayConstructor: Float32Array, heap: decoderModule.HEAPF32 },
59
+ [decoderModule.DT_INT8]: { typedArrayConstructor: Int8Array, heap: decoderModule.HEAP8 },
60
+ [decoderModule.DT_INT16]: { typedArrayConstructor: Int16Array, heap: decoderModule.HEAP16 },
61
+ [decoderModule.DT_INT32]: { typedArrayConstructor: Int32Array, heap: decoderModule.HEAP32 },
62
+ [decoderModule.DT_UINT8]: { typedArrayConstructor: Uint8Array, heap: decoderModule.HEAPU8 },
63
+ [decoderModule.DT_UINT16]: { typedArrayConstructor: Uint16Array, heap: decoderModule.HEAPU16 },
64
+ [decoderModule.DT_UINT32]: { typedArrayConstructor: Uint32Array, heap: decoderModule.HEAPU32 },
65
+ };
66
+ const info = dataTypeInfo[dataType];
67
+ if (!info) {
68
+ throw new Error(`Invalid data type ${dataType}`);
69
+ }
70
+ const numValues = numPoints * numComponents;
71
+ const byteLength = numValues * info.typedArrayConstructor.BYTES_PER_ELEMENT;
72
+ const ptr = decoderModule._malloc(byteLength);
73
+ try {
74
+ decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, dataType, byteLength, ptr);
75
+ const data = new info.typedArrayConstructor(info.heap.buffer, ptr, numValues);
76
+ onAttributeData(kind, data.slice(), numComponents, byteOffset, byteStride, normalized);
77
+ }
78
+ finally {
79
+ decoderModule._free(ptr);
80
+ }
81
+ };
82
+ if (attributes) {
83
+ for (const kind in attributes) {
84
+ const id = attributes[kind];
85
+ const attribute = decoder.GetAttributeByUniqueId(geometry, id);
86
+ processAttribute(decoder, geometry, kind, attribute);
87
+ }
88
+ }
89
+ else {
90
+ const dracoAttributeTypes = {
91
+ position: decoderModule.POSITION,
92
+ normal: decoderModule.NORMAL,
93
+ color: decoderModule.COLOR,
94
+ uv: decoderModule.TEX_COORD,
95
+ };
96
+ for (const kind in dracoAttributeTypes) {
97
+ const id = decoder.GetAttributeId(geometry, dracoAttributeTypes[kind]);
98
+ if (id !== -1) {
99
+ const attribute = decoder.GetAttribute(geometry, id);
100
+ processAttribute(decoder, geometry, kind, attribute);
101
+ }
102
+ }
103
+ }
104
+ return numPoints;
105
+ }
106
+ finally {
107
+ if (geometry) {
108
+ decoderModule.destroy(geometry);
109
+ }
110
+ if (buffer) {
111
+ decoderModule.destroy(buffer);
112
+ }
113
+ if (decoder) {
114
+ decoderModule.destroy(decoder);
115
+ }
116
+ }
117
+ }
118
+ /**
119
+ * The worker function that gets converted to a blob url to pass into a worker.
120
+ * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.
121
+ */
122
+ export function workerFunction() {
123
+ let decoderPromise;
124
+ onmessage = (event) => {
125
+ const message = event.data;
126
+ switch (message.id) {
127
+ case "init": {
128
+ const decoder = message.decoder;
129
+ // if URL is provided then load the script. Otherwise expect the script to be loaded already
130
+ if (decoder.url) {
131
+ importScripts(decoder.url);
132
+ }
133
+ decoderPromise = DracoDecoderModule({ wasmBinary: decoder.wasmBinary });
134
+ postMessage({ id: "initDone" });
135
+ break;
136
+ }
137
+ case "decodeMesh": {
138
+ if (!decoderPromise) {
139
+ throw new Error("Draco decoder module is not available");
140
+ }
141
+ decoderPromise.then((decoder) => {
142
+ const numPoints = decodeMesh(decoder, message.dataView, message.attributes, (indices) => {
143
+ postMessage({ id: "indices", data: indices }, [indices.buffer]);
144
+ }, (kind, data, size, offset, stride, normalized) => {
145
+ postMessage({ id: "attribute", kind, data, size, byteOffset: offset, byteStride: stride, normalized }, [data.buffer]);
146
+ });
147
+ postMessage({ id: "decodeMeshDone", totalVertices: numPoints });
148
+ });
149
+ break;
150
+ }
151
+ }
152
+ };
153
+ }
154
+ /**
155
+ * Initializes a worker that was created for the draco agent pool
156
+ * @param worker The worker to initialize
157
+ * @param decoderWasmBinary The wasm binary to load into the worker
158
+ * @param moduleUrl The url to the draco decoder module (optional)
159
+ * @returns A promise that resolves when the worker is initialized
160
+ */
161
+ export function initializeWebWorker(worker, decoderWasmBinary, moduleUrl) {
162
+ return new Promise((resolve, reject) => {
163
+ const onError = (error) => {
164
+ worker.removeEventListener("error", onError);
165
+ worker.removeEventListener("message", onMessage);
166
+ reject(error);
167
+ };
168
+ const onMessage = (event) => {
169
+ if (event.data.id === "initDone") {
170
+ worker.removeEventListener("error", onError);
171
+ worker.removeEventListener("message", onMessage);
172
+ resolve(worker);
173
+ }
174
+ };
175
+ worker.addEventListener("error", onError);
176
+ worker.addEventListener("message", onMessage);
177
+ // clone the array buffer to make it transferable
178
+ const clone = decoderWasmBinary.slice(0);
179
+ worker.postMessage({
180
+ id: "init",
181
+ decoder: {
182
+ url: moduleUrl,
183
+ wasmBinary: clone,
184
+ },
185
+ }, [clone]);
186
+ // note: no transfer list as the ArrayBuffer is shared across main thread and pool workers
187
+ });
188
+ }
189
+ //# sourceMappingURL=dracoCompressionWorker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dracoCompressionWorker.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompressionWorker.ts"],"names":[],"mappings":"AAsCA;;GAEG;AACH,MAAM,UAAU,UAAU,CACtB,aAA4B,EAC5B,IAAe,EACf,UAAkD,EAClD,aAA2D,EAC3D,eAAiI;IAEjI,IAAI,OAAO,GAAsB,IAAI,CAAC;IACtC,IAAI,MAAM,GAA4B,IAAI,CAAC;IAC3C,IAAI,QAAQ,GAAgC,IAAI,CAAC;IAEjD,IAAI;QACA,OAAO,GAAG,IAAI,aAAa,CAAC,OAAO,EAAE,CAAC;QAEtC,MAAM,GAAG,IAAI,aAAa,CAAC,aAAa,EAAE,CAAC;QAC3C,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAEnC,IAAI,MAAc,CAAC;QACnB,MAAM,IAAI,GAAG,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;QACpD,QAAQ,IAAI,EAAE;YACV,KAAK,aAAa,CAAC,eAAe,CAAC,CAAC;gBAChC,MAAM,IAAI,GAAG,IAAI,aAAa,CAAC,IAAI,EAAE,CAAC;gBACtC,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAClD,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,IAAI,CAAC,GAAG,KAAK,CAAC,EAAE;oBAChC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;iBACvC;gBAED,MAA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CAAC,KAA4B,EAAE,EAAE;YAC/C,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,UAAU,EAAE;gBAC9B,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC7C,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;gBACjD,OAAO,CAAC,MAAM,CAAC,CAAC;aACnB;QACL,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC1C,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAE9C,iDAAiD;QACjD,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACzC,MAAM,CAAC,WAAW,CACd;YACI,EAAE,EAAE,MAAM;YACV,OAAO,EAAE;gBACL,GAAG,EAAE,SAAS;gBACd,UAAU,EAAE,KAAK;aACpB;SACJ,EACD,CAAC,KAAK,CAAC,CACV,CAAC;QACF,0FAA0F;IAC9F,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport type { DecoderModule, DecoderBuffer, Decoder, Mesh, PointCloud, Status } from \"draco3dgltf\";\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\nexport interface 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 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\nexport type Message = InitDoneMessage | DecodeMeshDoneMessage | IndicesMessage | AttributeMessage;\r\n// WorkerGlobalScope\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: Message, transfer?: any[]): void;\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function 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 * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.\r\n */\r\nexport function workerFunction(): void {\r\n 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 URL is provided then load the script. Otherwise expect the script to be loaded already\r\n if (decoder.url) {\r\n importScripts(decoder.url);\r\n }\r\n decoderPromise = DracoDecoderModule({ wasmBinary: decoder.wasmBinary });\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 * Initializes a worker that was created for the draco agent pool\r\n * @param worker The worker to initialize\r\n * @param decoderWasmBinary The wasm binary to load into the worker\r\n * @param moduleUrl The url to the draco decoder module (optional)\r\n * @returns A promise that resolves when the worker is initialized\r\n */\r\nexport function initializeWebWorker(worker: Worker, decoderWasmBinary: ArrayBuffer, moduleUrl?: string): Promise<Worker> {\r\n return new Promise<Worker>((resolve, reject) => {\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 // clone the array buffer to make it transferable\r\n const clone = decoderWasmBinary.slice(0);\r\n worker.postMessage(\r\n {\r\n id: \"init\",\r\n decoder: {\r\n url: moduleUrl,\r\n wasmBinary: clone,\r\n },\r\n },\r\n [clone]\r\n );\r\n // note: no transfer list as the ArrayBuffer is shared across main thread and pool workers\r\n });\r\n}\r\n"]}
@@ -53,7 +53,7 @@ export class TrailMesh extends Mesh {
53
53
  meshCenter = this._generator.getBoundingInfo().boundingBox.centerWorld;
54
54
  }
55
55
  else {
56
- meshCenter = this._generator.position;
56
+ meshCenter = this._generator.absolutePosition;
57
57
  }
58
58
  const alpha = (2 * Math.PI) / this._sectionPolygonPointsCount;
59
59
  for (let i = 0; i <= this._sectionPolygonPointsCount; i++) {
@@ -1 +1 @@
1
- {"version":3,"file":"trailMesh.js","sourceRoot":"","sources":["../../../../dev/core/src/Meshes/trailMesh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YA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AAE,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;IACpJ,CAAC;CACJ","sourcesContent":["import { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { VertexData } from \"../Meshes/mesh.vertexData\";\r\nimport type { TransformNode } from \"../Meshes/transformNode\";\r\n\r\nMesh._TrailMeshParser = (parsedMesh: any, scene: Scene) => {\r\n return TrailMesh.Parse(parsedMesh, scene);\r\n};\r\n\r\n/**\r\n * Class used to create a trail following a mesh\r\n */\r\nexport class TrailMesh extends Mesh {\r\n /**\r\n * The diameter of the trail, i.e. the width of the ribbon.\r\n */\r\n public diameter: number;\r\n\r\n private _generator: TransformNode;\r\n private _autoStart: boolean;\r\n private _running: boolean;\r\n private _length: number;\r\n private _sectionPolygonPointsCount: number = 4;\r\n private _sectionVectors: Array<Vector3>;\r\n private _sectionNormalVectors: Array<Vector3>;\r\n private _beforeRenderObserver: Nullable<Observer<Scene>>;\r\n\r\n /**\r\n * Creates a new TrailMesh.\r\n * @param name The value used by scene.getMeshByName() to do a lookup.\r\n * @param generator The mesh or transform node to generate a trail.\r\n * @param scene The scene to add this mesh to.\r\n * @param diameter Diameter of trailing mesh. Default is 1.\r\n * @param length Length of trailing mesh. Default is 60.\r\n * @param autoStart Automatically start trailing mesh. Default true.\r\n */\r\n constructor(name: string, generator: TransformNode, scene?: Scene, diameter: number = 1, length: number = 60, autoStart: boolean = true) {\r\n super(name, scene);\r\n\r\n this._running = false;\r\n this._autoStart = autoStart;\r\n this._generator = generator;\r\n this.diameter = diameter;\r\n this._length = length;\r\n this._sectionVectors = [];\r\n this._sectionNormalVectors = [];\r\n for (let i: number = 0; i <= this._sectionPolygonPointsCount; i++) {\r\n this._sectionVectors[i] = Vector3.Zero();\r\n this._sectionNormalVectors[i] = Vector3.Zero();\r\n }\r\n this._createMesh();\r\n }\r\n\r\n /**\r\n * \"TrailMesh\"\r\n * @returns \"TrailMesh\"\r\n */\r\n public getClassName(): string {\r\n return \"TrailMesh\";\r\n }\r\n\r\n private _createMesh(): void {\r\n const data: VertexData = new VertexData();\r\n const positions: Array<number> = [];\r\n const normals: Array<number> = [];\r\n const indices: Array<number> = [];\r\n const uvs: Array<number> = [];\r\n let meshCenter = Vector3.Zero();\r\n if (this._generator instanceof AbstractMesh && this._generator.hasBoundingInfo) {\r\n meshCenter = this._generator.getBoundingInfo().boundingBox.centerWorld;\r\n } else {\r\n meshCenter = this._generator.position;\r\n }\r\n const alpha: number = (2 * Math.PI) / this._sectionPolygonPointsCount;\r\n for (let i: number = 0; i <= this._sectionPolygonPointsCount; i++) {\r\n const angle = i !== this._sectionPolygonPointsCount ? i * alpha : 0;\r\n positions.push(meshCenter.x + Math.cos(angle) * this.diameter, meshCenter.y + Math.sin(angle) * this.diameter, meshCenter.z);\r\n uvs.push(i / this._sectionPolygonPointsCount, 0);\r\n }\r\n for (let i: number = 1; i <= this._length; i++) {\r\n for (let j: number = 0; j <= this._sectionPolygonPointsCount; j++) {\r\n const angle = j !== this._sectionPolygonPointsCount ? j * alpha : 0;\r\n positions.push(meshCenter.x + Math.cos(angle) * this.diameter, meshCenter.y + Math.sin(angle) * this.diameter, meshCenter.z);\r\n uvs.push(j / this._sectionPolygonPointsCount, i / this._length);\r\n }\r\n const l: number = positions.length / 3 - 2 * (this._sectionPolygonPointsCount + 1);\r\n for (let j: number = 0; j <= this._sectionPolygonPointsCount; j++) {\r\n indices.push(l + j, l + j + this._sectionPolygonPointsCount, l + j + this._sectionPolygonPointsCount + 1);\r\n indices.push(l + j, l + j + this._sectionPolygonPointsCount + 1, l + j + 1);\r\n }\r\n }\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n data.positions = positions;\r\n data.normals = normals;\r\n data.indices = indices;\r\n data.uvs = uvs;\r\n data.applyToMesh(this, true);\r\n if (this._autoStart) {\r\n this.start();\r\n }\r\n }\r\n\r\n /**\r\n * Start trailing mesh.\r\n */\r\n public start(): void {\r\n if (!this._running) {\r\n this._running = true;\r\n this._beforeRenderObserver = this.getScene().onBeforeRenderObservable.add(() => {\r\n this.update();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Stop trailing mesh.\r\n */\r\n public stop(): void {\r\n if (this._beforeRenderObserver && this._running) {\r\n this._running = false;\r\n this.getScene().onBeforeRenderObservable.remove(this._beforeRenderObserver);\r\n }\r\n }\r\n\r\n /**\r\n * Update trailing mesh geometry.\r\n */\r\n public update(): void {\r\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\r\n const normals = this.getVerticesData(VertexBuffer.NormalKind);\r\n const wm = this._generator.getWorldMatrix();\r\n if (positions && normals) {\r\n for (let i: number = 3 * (this._sectionPolygonPointsCount + 1); i < positions.length; i++) {\r\n positions[i - 3 * (this._sectionPolygonPointsCount + 1)] = positions[i] - (normals[i] / this._length) * this.diameter;\r\n }\r\n for (let i: number = 3 * (this._sectionPolygonPointsCount + 1); i < normals.length; i++) {\r\n normals[i - 3 * (this._sectionPolygonPointsCount + 1)] = normals[i];\r\n }\r\n const l: number = positions.length - 3 * (this._sectionPolygonPointsCount + 1);\r\n const alpha: number = (2 * Math.PI) / this._sectionPolygonPointsCount;\r\n for (let i: number = 0; i <= this._sectionPolygonPointsCount; i++) {\r\n const angle = i !== this._sectionPolygonPointsCount ? i * alpha : 0;\r\n this._sectionVectors[i].copyFromFloats(Math.cos(angle) * this.diameter, Math.sin(angle) * this.diameter, 0);\r\n this._sectionNormalVectors[i].copyFromFloats(Math.cos(angle), Math.sin(angle), 0);\r\n Vector3.TransformCoordinatesToRef(this._sectionVectors[i], wm, this._sectionVectors[i]);\r\n Vector3.TransformNormalToRef(this._sectionNormalVectors[i], wm, this._sectionNormalVectors[i]);\r\n }\r\n for (let i: number = 0; i <= this._sectionPolygonPointsCount; i++) {\r\n positions[l + 3 * i] = this._sectionVectors[i].x;\r\n positions[l + 3 * i + 1] = this._sectionVectors[i].y;\r\n positions[l + 3 * i + 2] = this._sectionVectors[i].z;\r\n normals[l + 3 * i] = this._sectionNormalVectors[i].x;\r\n normals[l + 3 * i + 1] = this._sectionNormalVectors[i].y;\r\n normals[l + 3 * i + 2] = this._sectionNormalVectors[i].z;\r\n }\r\n this.updateVerticesData(VertexBuffer.PositionKind, positions, true, false);\r\n this.updateVerticesData(VertexBuffer.NormalKind, normals, true, false);\r\n }\r\n }\r\n\r\n /**\r\n * Returns a new TrailMesh object.\r\n * @param name is a string, the name given to the new mesh\r\n * @param newGenerator use new generator object for cloned trail mesh\r\n * @returns a new mesh\r\n */\r\n public clone(name: string = \"\", newGenerator: TransformNode): TrailMesh {\r\n return new TrailMesh(name, newGenerator ?? this._generator, this.getScene(), this.diameter, this._length, this._autoStart);\r\n }\r\n\r\n /**\r\n * Serializes this trail mesh\r\n * @param serializationObject object to write serialization to\r\n */\r\n public serialize(serializationObject: any): void {\r\n super.serialize(serializationObject);\r\n\r\n serializationObject.generatorId = this._generator.id;\r\n }\r\n\r\n /**\r\n * Parses a serialized trail mesh\r\n * @param parsedMesh the serialized mesh\r\n * @param scene the scene to create the trail mesh in\r\n * @returns the created trail mesh\r\n */\r\n public static Parse(parsedMesh: any, scene: Scene): TrailMesh {\r\n const generator = scene.getLastMeshById(parsedMesh.generatorId) ?? scene.getLastTransformNodeById(parsedMesh.generatorId);\r\n\r\n if (!generator) {\r\n throw new Error(\"TrailMesh: generator not found with ID \" + parsedMesh.generatorId);\r\n }\r\n\r\n return new TrailMesh(parsedMesh.name, generator, scene, parsedMesh.diameter ?? parsedMesh._diameter, parsedMesh._length, parsedMesh._autoStart);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"trailMesh.js","sourceRoot":"","sources":["../../../../dev/core/src/Meshes/trailMesh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,Y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,EAAE,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;IACpJ,CAAC;CACJ","sourcesContent":["import { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { VertexData } from \"../Meshes/mesh.vertexData\";\r\nimport type { TransformNode } from \"../Meshes/transformNode\";\r\n\r\nMesh._TrailMeshParser = (parsedMesh: any, scene: Scene) => {\r\n return TrailMesh.Parse(parsedMesh, scene);\r\n};\r\n\r\n/**\r\n * Class used to create a trail following a mesh\r\n */\r\nexport class TrailMesh extends Mesh {\r\n /**\r\n * The diameter of the trail, i.e. the width of the ribbon.\r\n */\r\n public diameter: number;\r\n\r\n private _generator: TransformNode;\r\n private _autoStart: boolean;\r\n private _running: boolean;\r\n private _length: number;\r\n private _sectionPolygonPointsCount: number = 4;\r\n private _sectionVectors: Array<Vector3>;\r\n private _sectionNormalVectors: Array<Vector3>;\r\n private _beforeRenderObserver: Nullable<Observer<Scene>>;\r\n\r\n /**\r\n * Creates a new TrailMesh.\r\n * @param name The value used by scene.getMeshByName() to do a lookup.\r\n * @param generator The mesh or transform node to generate a trail.\r\n * @param scene The scene to add this mesh to.\r\n * @param diameter Diameter of trailing mesh. Default is 1.\r\n * @param length Length of trailing mesh. Default is 60.\r\n * @param autoStart Automatically start trailing mesh. Default true.\r\n */\r\n constructor(name: string, generator: TransformNode, scene?: Scene, diameter: number = 1, length: number = 60, autoStart: boolean = true) {\r\n super(name, scene);\r\n\r\n this._running = false;\r\n this._autoStart = autoStart;\r\n this._generator = generator;\r\n this.diameter = diameter;\r\n this._length = length;\r\n this._sectionVectors = [];\r\n this._sectionNormalVectors = [];\r\n for (let i: number = 0; i <= this._sectionPolygonPointsCount; i++) {\r\n this._sectionVectors[i] = Vector3.Zero();\r\n this._sectionNormalVectors[i] = Vector3.Zero();\r\n }\r\n this._createMesh();\r\n }\r\n\r\n /**\r\n * \"TrailMesh\"\r\n * @returns \"TrailMesh\"\r\n */\r\n public getClassName(): string {\r\n return \"TrailMesh\";\r\n }\r\n\r\n private _createMesh(): void {\r\n const data: VertexData = new VertexData();\r\n const positions: Array<number> = [];\r\n const normals: Array<number> = [];\r\n const indices: Array<number> = [];\r\n const uvs: Array<number> = [];\r\n let meshCenter = Vector3.Zero();\r\n if (this._generator instanceof AbstractMesh && this._generator.hasBoundingInfo) {\r\n meshCenter = this._generator.getBoundingInfo().boundingBox.centerWorld;\r\n } else {\r\n meshCenter = this._generator.absolutePosition;\r\n }\r\n const alpha: number = (2 * Math.PI) / this._sectionPolygonPointsCount;\r\n for (let i: number = 0; i <= this._sectionPolygonPointsCount; i++) {\r\n const angle = i !== this._sectionPolygonPointsCount ? i * alpha : 0;\r\n positions.push(meshCenter.x + Math.cos(angle) * this.diameter, meshCenter.y + Math.sin(angle) * this.diameter, meshCenter.z);\r\n uvs.push(i / this._sectionPolygonPointsCount, 0);\r\n }\r\n for (let i: number = 1; i <= this._length; i++) {\r\n for (let j: number = 0; j <= this._sectionPolygonPointsCount; j++) {\r\n const angle = j !== this._sectionPolygonPointsCount ? j * alpha : 0;\r\n positions.push(meshCenter.x + Math.cos(angle) * this.diameter, meshCenter.y + Math.sin(angle) * this.diameter, meshCenter.z);\r\n uvs.push(j / this._sectionPolygonPointsCount, i / this._length);\r\n }\r\n const l: number = positions.length / 3 - 2 * (this._sectionPolygonPointsCount + 1);\r\n for (let j: number = 0; j <= this._sectionPolygonPointsCount; j++) {\r\n indices.push(l + j, l + j + this._sectionPolygonPointsCount, l + j + this._sectionPolygonPointsCount + 1);\r\n indices.push(l + j, l + j + this._sectionPolygonPointsCount + 1, l + j + 1);\r\n }\r\n }\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n data.positions = positions;\r\n data.normals = normals;\r\n data.indices = indices;\r\n data.uvs = uvs;\r\n data.applyToMesh(this, true);\r\n if (this._autoStart) {\r\n this.start();\r\n }\r\n }\r\n\r\n /**\r\n * Start trailing mesh.\r\n */\r\n public start(): void {\r\n if (!this._running) {\r\n this._running = true;\r\n this._beforeRenderObserver = this.getScene().onBeforeRenderObservable.add(() => {\r\n this.update();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Stop trailing mesh.\r\n */\r\n public stop(): void {\r\n if (this._beforeRenderObserver && this._running) {\r\n this._running = false;\r\n this.getScene().onBeforeRenderObservable.remove(this._beforeRenderObserver);\r\n }\r\n }\r\n\r\n /**\r\n * Update trailing mesh geometry.\r\n */\r\n public update(): void {\r\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\r\n const normals = this.getVerticesData(VertexBuffer.NormalKind);\r\n const wm = this._generator.getWorldMatrix();\r\n if (positions && normals) {\r\n for (let i: number = 3 * (this._sectionPolygonPointsCount + 1); i < positions.length; i++) {\r\n positions[i - 3 * (this._sectionPolygonPointsCount + 1)] = positions[i] - (normals[i] / this._length) * this.diameter;\r\n }\r\n for (let i: number = 3 * (this._sectionPolygonPointsCount + 1); i < normals.length; i++) {\r\n normals[i - 3 * (this._sectionPolygonPointsCount + 1)] = normals[i];\r\n }\r\n const l: number = positions.length - 3 * (this._sectionPolygonPointsCount + 1);\r\n const alpha: number = (2 * Math.PI) / this._sectionPolygonPointsCount;\r\n for (let i: number = 0; i <= this._sectionPolygonPointsCount; i++) {\r\n const angle = i !== this._sectionPolygonPointsCount ? i * alpha : 0;\r\n this._sectionVectors[i].copyFromFloats(Math.cos(angle) * this.diameter, Math.sin(angle) * this.diameter, 0);\r\n this._sectionNormalVectors[i].copyFromFloats(Math.cos(angle), Math.sin(angle), 0);\r\n Vector3.TransformCoordinatesToRef(this._sectionVectors[i], wm, this._sectionVectors[i]);\r\n Vector3.TransformNormalToRef(this._sectionNormalVectors[i], wm, this._sectionNormalVectors[i]);\r\n }\r\n for (let i: number = 0; i <= this._sectionPolygonPointsCount; i++) {\r\n positions[l + 3 * i] = this._sectionVectors[i].x;\r\n positions[l + 3 * i + 1] = this._sectionVectors[i].y;\r\n positions[l + 3 * i + 2] = this._sectionVectors[i].z;\r\n normals[l + 3 * i] = this._sectionNormalVectors[i].x;\r\n normals[l + 3 * i + 1] = this._sectionNormalVectors[i].y;\r\n normals[l + 3 * i + 2] = this._sectionNormalVectors[i].z;\r\n }\r\n this.updateVerticesData(VertexBuffer.PositionKind, positions, true, false);\r\n this.updateVerticesData(VertexBuffer.NormalKind, normals, true, false);\r\n }\r\n }\r\n\r\n /**\r\n * Returns a new TrailMesh object.\r\n * @param name is a string, the name given to the new mesh\r\n * @param newGenerator use new generator object for cloned trail mesh\r\n * @returns a new mesh\r\n */\r\n public clone(name: string = \"\", newGenerator: TransformNode): TrailMesh {\r\n return new TrailMesh(name, newGenerator ?? this._generator, this.getScene(), this.diameter, this._length, this._autoStart);\r\n }\r\n\r\n /**\r\n * Serializes this trail mesh\r\n * @param serializationObject object to write serialization to\r\n */\r\n public serialize(serializationObject: any): void {\r\n super.serialize(serializationObject);\r\n\r\n serializationObject.generatorId = this._generator.id;\r\n }\r\n\r\n /**\r\n * Parses a serialized trail mesh\r\n * @param parsedMesh the serialized mesh\r\n * @param scene the scene to create the trail mesh in\r\n * @returns the created trail mesh\r\n */\r\n public static Parse(parsedMesh: any, scene: Scene): TrailMesh {\r\n const generator = scene.getLastMeshById(parsedMesh.generatorId) ?? scene.getLastTransformNodeById(parsedMesh.generatorId);\r\n\r\n if (!generator) {\r\n throw new Error(\"TrailMesh: generator not found with ID \" + parsedMesh.generatorId);\r\n }\r\n\r\n return new TrailMesh(parsedMesh.name, generator, scene, parsedMesh.diameter ?? parsedMesh._diameter, parsedMesh._length, parsedMesh._autoStart);\r\n }\r\n}\r\n"]}
package/Misc/basis.d.ts CHANGED
@@ -3,7 +3,7 @@ import type { Engine } from "../Engines/engine";
3
3
  /**
4
4
  * Info about the .basis files
5
5
  */
6
- declare class BasisFileInfo {
6
+ export declare class BasisFileInfo {
7
7
  /**
8
8
  * If the file has alpha
9
9
  */
@@ -95,6 +95,11 @@ export declare const BasisToolsOptions: {
95
95
  * @returns internal format corresponding to the Basis format
96
96
  */
97
97
  export declare const GetInternalFormatFromBasisFormat: (basisFormat: number, engine: Engine) => number;
98
+ /**
99
+ * Set the worker to use for transcoding
100
+ * @param worker The worker that will be used for transcoding
101
+ */
102
+ export declare const SetBasisTranscoderWorker: (worker: Worker) => void;
98
103
  /**
99
104
  * Transcodes a loaded image file to compressed pixel data
100
105
  * @param data image data to transcode
package/Misc/basis.js CHANGED
@@ -3,10 +3,11 @@ import { Texture } from "../Materials/Textures/texture.js";
3
3
  import { InternalTexture, InternalTextureSource } from "../Materials/Textures/internalTexture.js";
4
4
  import { Scalar } from "../Maths/math.scalar.js";
5
5
 
6
+ import { initializeWebWorker, workerFunction } from "./basisWorker.js";
6
7
  /**
7
8
  * Info about the .basis files
8
9
  */
9
- class BasisFileInfo {
10
+ export class BasisFileInfo {
10
11
  }
11
12
  /**
12
13
  * Result of transcoding a basis file
@@ -111,19 +112,9 @@ const _CreateWorkerAsync = () => {
111
112
  if (typeof URL !== "function") {
112
113
  return reject("Basis transcoder requires an environment with a URL constructor");
113
114
  }
114
- const workerBlobUrl = URL.createObjectURL(new Blob([`(${workerFunc})()`], { type: "application/javascript" }));
115
+ const workerBlobUrl = URL.createObjectURL(new Blob([`(${workerFunction})()`], { type: "application/javascript" }));
115
116
  _Worker = new Worker(workerBlobUrl);
116
- const initHandler = (msg) => {
117
- if (msg.data.action === "init") {
118
- _Worker.removeEventListener("message", initHandler);
119
- res(_Worker);
120
- }
121
- else if (msg.data.action === "error") {
122
- reject(msg.data.error || "error initializing worker");
123
- }
124
- };
125
- _Worker.addEventListener("message", initHandler);
126
- _Worker.postMessage({ action: "init", url: Tools.GetBabylonScriptURL(BasisToolsOptions.JSModuleURL), wasmBinary: wasmBinary });
117
+ initializeWebWorker(_Worker, wasmBinary, BasisToolsOptions.JSModuleURL).then(res, reject);
127
118
  })
128
119
  .catch(reject);
129
120
  }
@@ -131,6 +122,13 @@ const _CreateWorkerAsync = () => {
131
122
  }
132
123
  return _WorkerPromise;
133
124
  };
125
+ /**
126
+ * Set the worker to use for transcoding
127
+ * @param worker The worker that will be used for transcoding
128
+ */
129
+ export const SetBasisTranscoderWorker = (worker) => {
130
+ _Worker = worker;
131
+ };
134
132
  /**
135
133
  * Transcodes a loaded image file to compressed pixel data
136
134
  * @param data image data to transcode
@@ -270,224 +268,6 @@ export const BasisTools = {
270
268
  */
271
269
  LoadTextureFromTranscodeResult,
272
270
  };
273
- function workerFunc() {
274
- const _BASIS_FORMAT = {
275
- cTFETC1: 0,
276
- cTFETC2: 1,
277
- cTFBC1: 2,
278
- cTFBC3: 3,
279
- cTFBC4: 4,
280
- cTFBC5: 5,
281
- cTFBC7: 6,
282
- cTFPVRTC1_4_RGB: 8,
283
- cTFPVRTC1_4_RGBA: 9,
284
- cTFASTC_4x4: 10,
285
- cTFATC_RGB: 11,
286
- cTFATC_RGBA_INTERPOLATED_ALPHA: 12,
287
- cTFRGBA32: 13,
288
- cTFRGB565: 14,
289
- cTFBGR565: 15,
290
- cTFRGBA4444: 16,
291
- cTFFXT1_RGB: 17,
292
- cTFPVRTC2_4_RGB: 18,
293
- cTFPVRTC2_4_RGBA: 19,
294
- cTFETC2_EAC_R11: 20,
295
- cTFETC2_EAC_RG11: 21,
296
- };
297
- let transcoderModulePromise = null;
298
- onmessage = (event) => {
299
- if (event.data.action === "init") {
300
- // Load the transcoder if it hasn't been yet
301
- if (!transcoderModulePromise) {
302
- // make sure we loaded the script correctly
303
- try {
304
- importScripts(event.data.url);
305
- }
306
- catch (e) {
307
- postMessage({ action: "error", error: e });
308
- }
309
- transcoderModulePromise = BASIS({
310
- // Override wasm binary
311
- wasmBinary: event.data.wasmBinary,
312
- });
313
- }
314
- if (transcoderModulePromise !== null) {
315
- transcoderModulePromise.then((m) => {
316
- BASIS = m;
317
- m.initializeBasis();
318
- postMessage({ action: "init" });
319
- });
320
- }
321
- }
322
- else if (event.data.action === "transcode") {
323
- // Transcode the basis image and return the resulting pixels
324
- const config = event.data.config;
325
- const imgData = event.data.imageData;
326
- const loadedFile = new BASIS.BasisFile(imgData);
327
- const fileInfo = GetFileInfo(loadedFile);
328
- let format = event.data.ignoreSupportedFormats ? null : GetSupportedTranscodeFormat(event.data.config, fileInfo);
329
- let needsConversion = false;
330
- if (format === null) {
331
- needsConversion = true;
332
- format = fileInfo.hasAlpha ? _BASIS_FORMAT.cTFBC3 : _BASIS_FORMAT.cTFBC1;
333
- }
334
- // Begin transcode
335
- let success = true;
336
- if (!loadedFile.startTranscoding()) {
337
- success = false;
338
- }
339
- const buffers = [];
340
- for (let imageIndex = 0; imageIndex < fileInfo.images.length; imageIndex++) {
341
- if (!success) {
342
- break;
343
- }
344
- const image = fileInfo.images[imageIndex];
345
- if (config.loadSingleImage === undefined || config.loadSingleImage === imageIndex) {
346
- let mipCount = image.levels.length;
347
- if (config.loadMipmapLevels === false) {
348
- mipCount = 1;
349
- }
350
- for (let levelIndex = 0; levelIndex < mipCount; levelIndex++) {
351
- const levelInfo = image.levels[levelIndex];
352
- const pixels = TranscodeLevel(loadedFile, imageIndex, levelIndex, format, needsConversion);
353
- if (!pixels) {
354
- success = false;
355
- break;
356
- }
357
- levelInfo.transcodedPixels = pixels;
358
- buffers.push(levelInfo.transcodedPixels.buffer);
359
- }
360
- }
361
- }
362
- // Close file
363
- loadedFile.close();
364
- loadedFile.delete();
365
- if (needsConversion) {
366
- format = -1;
367
- }
368
- if (!success) {
369
- postMessage({ action: "transcode", success: success, id: event.data.id });
370
- }
371
- else {
372
- postMessage({ action: "transcode", success: success, id: event.data.id, fileInfo: fileInfo, format: format }, buffers);
373
- }
374
- }
375
- };
376
- /**
377
- * Detects the supported transcode format for the file
378
- * @param config transcode config
379
- * @param fileInfo info about the file
380
- * @returns the chosed format or null if none are supported
381
- */
382
- function GetSupportedTranscodeFormat(config, fileInfo) {
383
- let format = null;
384
- if (config.supportedCompressionFormats) {
385
- if (config.supportedCompressionFormats.astc) {
386
- format = _BASIS_FORMAT.cTFASTC_4x4;
387
- }
388
- else if (config.supportedCompressionFormats.bc7) {
389
- format = _BASIS_FORMAT.cTFBC7;
390
- }
391
- else if (config.supportedCompressionFormats.s3tc) {
392
- format = fileInfo.hasAlpha ? _BASIS_FORMAT.cTFBC3 : _BASIS_FORMAT.cTFBC1;
393
- }
394
- else if (config.supportedCompressionFormats.pvrtc) {
395
- format = fileInfo.hasAlpha ? _BASIS_FORMAT.cTFPVRTC1_4_RGBA : _BASIS_FORMAT.cTFPVRTC1_4_RGB;
396
- }
397
- else if (config.supportedCompressionFormats.etc2) {
398
- format = _BASIS_FORMAT.cTFETC2;
399
- }
400
- else if (config.supportedCompressionFormats.etc1) {
401
- format = _BASIS_FORMAT.cTFETC1;
402
- }
403
- else {
404
- format = _BASIS_FORMAT.cTFRGB565;
405
- }
406
- }
407
- return format;
408
- }
409
- /**
410
- * Retrieves information about the basis file eg. dimensions
411
- * @param basisFile the basis file to get the info from
412
- * @returns information about the basis file
413
- */
414
- function GetFileInfo(basisFile) {
415
- const hasAlpha = basisFile.getHasAlpha();
416
- const imageCount = basisFile.getNumImages();
417
- const images = [];
418
- for (let i = 0; i < imageCount; i++) {
419
- const imageInfo = {
420
- levels: [],
421
- };
422
- const levelCount = basisFile.getNumLevels(i);
423
- for (let level = 0; level < levelCount; level++) {
424
- const levelInfo = {
425
- width: basisFile.getImageWidth(i, level),
426
- height: basisFile.getImageHeight(i, level),
427
- };
428
- imageInfo.levels.push(levelInfo);
429
- }
430
- images.push(imageInfo);
431
- }
432
- const info = { hasAlpha, images };
433
- return info;
434
- }
435
- function TranscodeLevel(loadedFile, imageIndex, levelIndex, format, convertToRgb565) {
436
- const dstSize = loadedFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, format);
437
- let dst = new Uint8Array(dstSize);
438
- if (!loadedFile.transcodeImage(dst, imageIndex, levelIndex, format, 1, 0)) {
439
- return null;
440
- }
441
- // If no supported format is found, load as dxt and convert to rgb565
442
- if (convertToRgb565) {
443
- const alignedWidth = (loadedFile.getImageWidth(imageIndex, levelIndex) + 3) & ~3;
444
- const alignedHeight = (loadedFile.getImageHeight(imageIndex, levelIndex) + 3) & ~3;
445
- dst = ConvertDxtToRgb565(dst, 0, alignedWidth, alignedHeight);
446
- }
447
- return dst;
448
- }
449
- /**
450
- * From https://github.com/BinomialLLC/basis_universal/blob/master/webgl/texture/dxt-to-rgb565.js
451
- * An unoptimized version of dxtToRgb565. Also, the floating
452
- * point math used to compute the colors actually results in
453
- * slightly different colors compared to hardware DXT decoders.
454
- * @param src dxt src pixels
455
- * @param srcByteOffset offset for the start of src
456
- * @param width aligned width of the image
457
- * @param height aligned height of the image
458
- * @returns the converted pixels
459
- */
460
- function ConvertDxtToRgb565(src, srcByteOffset, width, height) {
461
- const c = new Uint16Array(4);
462
- const dst = new Uint16Array(width * height);
463
- const blockWidth = width / 4;
464
- const blockHeight = height / 4;
465
- for (let blockY = 0; blockY < blockHeight; blockY++) {
466
- for (let blockX = 0; blockX < blockWidth; blockX++) {
467
- const i = srcByteOffset + 8 * (blockY * blockWidth + blockX);
468
- c[0] = src[i] | (src[i + 1] << 8);
469
- c[1] = src[i + 2] | (src[i + 3] << 8);
470
- c[2] =
471
- ((2 * (c[0] & 0x1f) + 1 * (c[1] & 0x1f)) / 3) |
472
- (((2 * (c[0] & 0x7e0) + 1 * (c[1] & 0x7e0)) / 3) & 0x7e0) |
473
- (((2 * (c[0] & 0xf800) + 1 * (c[1] & 0xf800)) / 3) & 0xf800);
474
- c[3] =
475
- ((2 * (c[1] & 0x1f) + 1 * (c[0] & 0x1f)) / 3) |
476
- (((2 * (c[1] & 0x7e0) + 1 * (c[0] & 0x7e0)) / 3) & 0x7e0) |
477
- (((2 * (c[1] & 0xf800) + 1 * (c[0] & 0xf800)) / 3) & 0xf800);
478
- for (let row = 0; row < 4; row++) {
479
- const m = src[i + 4 + row];
480
- let dstI = (blockY * 4 + row) * width + blockX * 4;
481
- dst[dstI++] = c[m & 0x3];
482
- dst[dstI++] = c[(m >> 2) & 0x3];
483
- dst[dstI++] = c[(m >> 4) & 0x3];
484
- dst[dstI++] = c[(m >> 6) & 0x3];
485
- }
486
- }
487
- }
488
- return dst;
489
- }
490
- }
491
271
  Object.defineProperty(BasisTools, "JSModuleURL", {
492
272
  get: function () {
493
273
  return BasisToolsOptions.JSModuleURL;