@onerjs/core 8.41.4 → 8.41.6

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 (264) hide show
  1. package/Cameras/Inputs/geospatialCameraPointersInput.d.ts +16 -0
  2. package/Cameras/Inputs/geospatialCameraPointersInput.js +19 -3
  3. package/Cameras/Inputs/geospatialCameraPointersInput.js.map +1 -1
  4. package/Cameras/Limits/geospatialLimits.d.ts +0 -6
  5. package/Cameras/Limits/geospatialLimits.js +0 -6
  6. package/Cameras/Limits/geospatialLimits.js.map +1 -1
  7. package/Cameras/geospatialCamera.d.ts +5 -0
  8. package/Cameras/geospatialCamera.js +38 -10
  9. package/Cameras/geospatialCamera.js.map +1 -1
  10. package/Engines/abstractEngine.d.ts +2 -2
  11. package/Engines/abstractEngine.js +2 -2
  12. package/Engines/abstractEngine.js.map +1 -1
  13. package/Engines/webgpuEngine.d.ts +1 -4
  14. package/Engines/webgpuEngine.js +8 -6
  15. package/Engines/webgpuEngine.js.map +1 -1
  16. package/FrameGraph/frameGraphContext.js +1 -1
  17. package/FrameGraph/frameGraphContext.js.map +1 -1
  18. package/FrameGraph/frameGraphRenderContext.js +2 -2
  19. package/FrameGraph/frameGraphRenderContext.js.map +1 -1
  20. package/Lights/Shadows/cascadedShadowGenerator.js +1 -1
  21. package/Lights/Shadows/cascadedShadowGenerator.js.map +1 -1
  22. package/Lights/Shadows/shadowGenerator.js +1 -1
  23. package/Lights/Shadows/shadowGenerator.js.map +1 -1
  24. package/Lights/lightingVolume.js +1 -1
  25. package/Lights/lightingVolume.js.map +1 -1
  26. package/Materials/Textures/Procedurals/proceduralTexture.js +1 -1
  27. package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
  28. package/Maths/math.path.js +3 -3
  29. package/Maths/math.path.js.map +1 -1
  30. package/Meshes/Builders/capsuleBuilder.js +0 -3
  31. package/Meshes/Builders/capsuleBuilder.js.map +1 -1
  32. package/Meshes/Builders/cylinderBuilder.d.ts +1 -1
  33. package/Meshes/Builders/cylinderBuilder.js +1 -2
  34. package/Meshes/Builders/cylinderBuilder.js.map +1 -1
  35. package/Meshes/Builders/decalBuilder.js +2 -0
  36. package/Meshes/Builders/decalBuilder.js.map +1 -1
  37. package/Meshes/Builders/discBuilder.js +0 -1
  38. package/Meshes/Builders/discBuilder.js.map +1 -1
  39. package/Meshes/Builders/groundBuilder.d.ts +50 -54
  40. package/Meshes/Builders/groundBuilder.js +50 -54
  41. package/Meshes/Builders/groundBuilder.js.map +1 -1
  42. package/Meshes/Builders/tiledBoxBuilder.d.ts +0 -26
  43. package/Meshes/Builders/tiledBoxBuilder.js +0 -26
  44. package/Meshes/Builders/tiledBoxBuilder.js.map +1 -1
  45. package/Meshes/Builders/tiledPlaneBuilder.d.ts +0 -25
  46. package/Meshes/Builders/tiledPlaneBuilder.js +0 -25
  47. package/Meshes/Builders/tiledPlaneBuilder.js.map +1 -1
  48. package/Meshes/Builders/torusBuilder.d.ts +0 -13
  49. package/Meshes/Builders/torusBuilder.js +0 -13
  50. package/Meshes/Builders/torusBuilder.js.map +1 -1
  51. package/Meshes/Builders/torusKnotBuilder.d.ts +0 -19
  52. package/Meshes/Builders/torusKnotBuilder.js +0 -19
  53. package/Meshes/Builders/torusKnotBuilder.js.map +1 -1
  54. package/Meshes/Compression/dracoCompressionWorker.js.map +1 -1
  55. package/Meshes/Compression/dracoDecoder.js.map +1 -1
  56. package/Meshes/Compression/dracoDecoder.types.d.ts +11 -0
  57. package/Meshes/Compression/dracoDecoder.types.js.map +1 -1
  58. package/Meshes/Compression/dracoEncoder.js.map +1 -1
  59. package/Meshes/Compression/meshoptCompression.js +0 -2
  60. package/Meshes/Compression/meshoptCompression.js.map +1 -1
  61. package/Meshes/GreasedLine/greasedLineRibbonMesh.js +0 -8
  62. package/Meshes/GreasedLine/greasedLineRibbonMesh.js.map +1 -1
  63. package/Meshes/Node/Blocks/Instances/instantiateBaseBlock.d.ts +1 -0
  64. package/Meshes/Node/Blocks/Instances/instantiateBaseBlock.js +1 -0
  65. package/Meshes/Node/Blocks/Instances/instantiateBaseBlock.js.map +1 -1
  66. package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.d.ts +1 -0
  67. package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.js +1 -0
  68. package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.js.map +1 -1
  69. package/Meshes/Node/Blocks/Instances/instantiateOnVerticesBlock.d.ts +1 -0
  70. package/Meshes/Node/Blocks/Instances/instantiateOnVerticesBlock.js +1 -0
  71. package/Meshes/Node/Blocks/Instances/instantiateOnVerticesBlock.js.map +1 -1
  72. package/Meshes/Node/Blocks/Instances/instantiateOnVolumeBlock.d.ts +1 -0
  73. package/Meshes/Node/Blocks/Instances/instantiateOnVolumeBlock.js +1 -0
  74. package/Meshes/Node/Blocks/Instances/instantiateOnVolumeBlock.js.map +1 -1
  75. package/Meshes/Node/Blocks/Matrices/scalingBlock.d.ts +1 -0
  76. package/Meshes/Node/Blocks/Matrices/scalingBlock.js +1 -0
  77. package/Meshes/Node/Blocks/Matrices/scalingBlock.js.map +1 -1
  78. package/Meshes/Node/Blocks/Matrices/translationBlock.d.ts +1 -0
  79. package/Meshes/Node/Blocks/Matrices/translationBlock.js +1 -0
  80. package/Meshes/Node/Blocks/Matrices/translationBlock.js.map +1 -1
  81. package/Meshes/Node/Blocks/Set/aggregatorBlock.d.ts +1 -0
  82. package/Meshes/Node/Blocks/Set/aggregatorBlock.js +1 -0
  83. package/Meshes/Node/Blocks/Set/aggregatorBlock.js.map +1 -1
  84. package/Meshes/Node/Blocks/Set/latticeBlock.d.ts +1 -0
  85. package/Meshes/Node/Blocks/Set/latticeBlock.js +1 -0
  86. package/Meshes/Node/Blocks/Set/latticeBlock.js.map +1 -1
  87. package/Meshes/Node/Blocks/Set/setColorsBlock.d.ts +1 -0
  88. package/Meshes/Node/Blocks/Set/setColorsBlock.js +1 -0
  89. package/Meshes/Node/Blocks/Set/setColorsBlock.js.map +1 -1
  90. package/Meshes/Node/Blocks/Set/setMaterialIDBlock.d.ts +1 -0
  91. package/Meshes/Node/Blocks/Set/setMaterialIDBlock.js +1 -0
  92. package/Meshes/Node/Blocks/Set/setMaterialIDBlock.js.map +1 -1
  93. package/Meshes/Node/Blocks/Set/setNormalsBlock.d.ts +1 -0
  94. package/Meshes/Node/Blocks/Set/setNormalsBlock.js +1 -0
  95. package/Meshes/Node/Blocks/Set/setNormalsBlock.js.map +1 -1
  96. package/Meshes/Node/Blocks/Set/setPositionsBlock.d.ts +1 -0
  97. package/Meshes/Node/Blocks/Set/setPositionsBlock.js +1 -0
  98. package/Meshes/Node/Blocks/Set/setPositionsBlock.js.map +1 -1
  99. package/Meshes/Node/Blocks/Set/setTangentsBlock.d.ts +1 -0
  100. package/Meshes/Node/Blocks/Set/setTangentsBlock.js +1 -0
  101. package/Meshes/Node/Blocks/Set/setTangentsBlock.js.map +1 -1
  102. package/Meshes/Node/Blocks/Set/setUVsBlock.d.ts +1 -0
  103. package/Meshes/Node/Blocks/Set/setUVsBlock.js +1 -0
  104. package/Meshes/Node/Blocks/Set/setUVsBlock.js.map +1 -1
  105. package/Meshes/Node/Blocks/Sources/boxBlock.d.ts +2 -0
  106. package/Meshes/Node/Blocks/Sources/boxBlock.js +2 -0
  107. package/Meshes/Node/Blocks/Sources/boxBlock.js.map +1 -1
  108. package/Meshes/Node/Blocks/Sources/capsuleBlock.d.ts +2 -0
  109. package/Meshes/Node/Blocks/Sources/capsuleBlock.js +2 -0
  110. package/Meshes/Node/Blocks/Sources/capsuleBlock.js.map +1 -1
  111. package/Meshes/Node/Blocks/Sources/cylinderBlock.d.ts +2 -0
  112. package/Meshes/Node/Blocks/Sources/cylinderBlock.js +2 -0
  113. package/Meshes/Node/Blocks/Sources/cylinderBlock.js.map +1 -1
  114. package/Meshes/Node/Blocks/Sources/discBlock.d.ts +2 -0
  115. package/Meshes/Node/Blocks/Sources/discBlock.js +2 -0
  116. package/Meshes/Node/Blocks/Sources/discBlock.js.map +1 -1
  117. package/Meshes/Node/Blocks/Sources/gridBlock.d.ts +2 -0
  118. package/Meshes/Node/Blocks/Sources/gridBlock.js +2 -0
  119. package/Meshes/Node/Blocks/Sources/gridBlock.js.map +1 -1
  120. package/Meshes/Node/Blocks/Sources/icoSphereBlock.d.ts +2 -0
  121. package/Meshes/Node/Blocks/Sources/icoSphereBlock.js +2 -0
  122. package/Meshes/Node/Blocks/Sources/icoSphereBlock.js.map +1 -1
  123. package/Meshes/Node/Blocks/Sources/meshBlock.d.ts +1 -0
  124. package/Meshes/Node/Blocks/Sources/meshBlock.js +1 -0
  125. package/Meshes/Node/Blocks/Sources/meshBlock.js.map +1 -1
  126. package/Meshes/Node/Blocks/Sources/planeBlock.d.ts +2 -0
  127. package/Meshes/Node/Blocks/Sources/planeBlock.js +2 -0
  128. package/Meshes/Node/Blocks/Sources/planeBlock.js.map +1 -1
  129. package/Meshes/Node/Blocks/Sources/pointListBlock.d.ts +2 -1
  130. package/Meshes/Node/Blocks/Sources/pointListBlock.js +2 -1
  131. package/Meshes/Node/Blocks/Sources/pointListBlock.js.map +1 -1
  132. package/Meshes/Node/Blocks/Sources/sphereBlock.d.ts +2 -0
  133. package/Meshes/Node/Blocks/Sources/sphereBlock.js +2 -0
  134. package/Meshes/Node/Blocks/Sources/sphereBlock.js.map +1 -1
  135. package/Meshes/Node/Blocks/Sources/torusBlock.d.ts +2 -0
  136. package/Meshes/Node/Blocks/Sources/torusBlock.js +2 -0
  137. package/Meshes/Node/Blocks/Sources/torusBlock.js.map +1 -1
  138. package/Meshes/Node/Blocks/Teleport/teleportInBlock.d.ts +1 -0
  139. package/Meshes/Node/Blocks/Teleport/teleportInBlock.js +1 -0
  140. package/Meshes/Node/Blocks/Teleport/teleportInBlock.js.map +1 -1
  141. package/Meshes/Node/Blocks/Teleport/teleportOutBlock.d.ts +3 -0
  142. package/Meshes/Node/Blocks/Teleport/teleportOutBlock.js +3 -0
  143. package/Meshes/Node/Blocks/Teleport/teleportOutBlock.js.map +1 -1
  144. package/Meshes/Node/Blocks/Textures/geometryTextureBlock.d.ts +1 -0
  145. package/Meshes/Node/Blocks/Textures/geometryTextureBlock.js +1 -1
  146. package/Meshes/Node/Blocks/Textures/geometryTextureBlock.js.map +1 -1
  147. package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.d.ts +1 -0
  148. package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.js +1 -0
  149. package/Meshes/Node/Blocks/Textures/geometryTextureFetchBlock.js.map +1 -1
  150. package/Meshes/Node/Blocks/booleanGeometryBlock.d.ts +1 -0
  151. package/Meshes/Node/Blocks/booleanGeometryBlock.js +1 -1
  152. package/Meshes/Node/Blocks/booleanGeometryBlock.js.map +1 -1
  153. package/Meshes/Node/Blocks/cleanGeometryBlock.d.ts +1 -0
  154. package/Meshes/Node/Blocks/cleanGeometryBlock.js +1 -0
  155. package/Meshes/Node/Blocks/cleanGeometryBlock.js.map +1 -1
  156. package/Meshes/Node/Blocks/conditionBlock.d.ts +2 -0
  157. package/Meshes/Node/Blocks/conditionBlock.js +2 -0
  158. package/Meshes/Node/Blocks/conditionBlock.js.map +1 -1
  159. package/Meshes/Node/Blocks/geometryClampBlock.d.ts +1 -0
  160. package/Meshes/Node/Blocks/geometryClampBlock.js +1 -0
  161. package/Meshes/Node/Blocks/geometryClampBlock.js.map +1 -1
  162. package/Meshes/Node/Blocks/geometryCollectionBlock.d.ts +1 -0
  163. package/Meshes/Node/Blocks/geometryCollectionBlock.js +1 -0
  164. package/Meshes/Node/Blocks/geometryCollectionBlock.js.map +1 -1
  165. package/Meshes/Node/Blocks/geometryCurveBlock.d.ts +2 -0
  166. package/Meshes/Node/Blocks/geometryCurveBlock.js +2 -0
  167. package/Meshes/Node/Blocks/geometryCurveBlock.js.map +1 -1
  168. package/Meshes/Node/Blocks/geometryEaseBlock.d.ts +2 -0
  169. package/Meshes/Node/Blocks/geometryEaseBlock.js +2 -0
  170. package/Meshes/Node/Blocks/geometryEaseBlock.js.map +1 -1
  171. package/Meshes/Node/Blocks/geometryInputBlock.d.ts +3 -0
  172. package/Meshes/Node/Blocks/geometryInputBlock.js +3 -0
  173. package/Meshes/Node/Blocks/geometryInputBlock.js.map +1 -1
  174. package/Meshes/Node/Blocks/geometryOptimizeBlock.d.ts +1 -0
  175. package/Meshes/Node/Blocks/geometryOptimizeBlock.js +1 -0
  176. package/Meshes/Node/Blocks/geometryOptimizeBlock.js.map +1 -1
  177. package/Meshes/Node/Blocks/geometryTransformBlock.d.ts +1 -0
  178. package/Meshes/Node/Blocks/geometryTransformBlock.js +1 -0
  179. package/Meshes/Node/Blocks/geometryTransformBlock.js.map +1 -1
  180. package/Meshes/Node/Blocks/geometryTrigonometryBlock.d.ts +2 -0
  181. package/Meshes/Node/Blocks/geometryTrigonometryBlock.js +2 -0
  182. package/Meshes/Node/Blocks/geometryTrigonometryBlock.js.map +1 -1
  183. package/Meshes/Node/Blocks/mappingBlock.d.ts +1 -0
  184. package/Meshes/Node/Blocks/mappingBlock.js +1 -0
  185. package/Meshes/Node/Blocks/mappingBlock.js.map +1 -1
  186. package/Meshes/Node/Blocks/mathBlock.d.ts +1 -0
  187. package/Meshes/Node/Blocks/mathBlock.js +1 -0
  188. package/Meshes/Node/Blocks/mathBlock.js.map +1 -1
  189. package/Meshes/Node/Blocks/mergeGeometryBlock.d.ts +1 -0
  190. package/Meshes/Node/Blocks/mergeGeometryBlock.js +1 -0
  191. package/Meshes/Node/Blocks/mergeGeometryBlock.js.map +1 -1
  192. package/Meshes/Node/Blocks/randomBlock.d.ts +2 -0
  193. package/Meshes/Node/Blocks/randomBlock.js +2 -0
  194. package/Meshes/Node/Blocks/randomBlock.js.map +1 -1
  195. package/Meshes/Node/Blocks/subdivideBlock.d.ts +1 -0
  196. package/Meshes/Node/Blocks/subdivideBlock.js +1 -0
  197. package/Meshes/Node/Blocks/subdivideBlock.js.map +1 -1
  198. package/Meshes/Node/Interfaces/nodeGeometryTextureData.d.ts +3 -0
  199. package/Meshes/Node/Interfaces/nodeGeometryTextureData.js.map +1 -1
  200. package/Meshes/Node/nodeGeometry.js +0 -2
  201. package/Meshes/Node/nodeGeometry.js.map +1 -1
  202. package/Meshes/Node/nodeGeometryBlockConnectionPoint.js +0 -1
  203. package/Meshes/Node/nodeGeometryBlockConnectionPoint.js.map +1 -1
  204. package/Meshes/Node/nodeGeometryBuildState.js +0 -1
  205. package/Meshes/Node/nodeGeometryBuildState.js.map +1 -1
  206. package/Meshes/WebGL/webGLDataBuffer.d.ts +2 -0
  207. package/Meshes/WebGL/webGLDataBuffer.js +2 -0
  208. package/Meshes/WebGL/webGLDataBuffer.js.map +1 -1
  209. package/Meshes/WebGPU/webgpuDataBuffer.d.ts +4 -0
  210. package/Meshes/WebGPU/webgpuDataBuffer.js +4 -0
  211. package/Meshes/WebGPU/webgpuDataBuffer.js.map +1 -1
  212. package/Meshes/abstractMesh.d.ts +1 -0
  213. package/Meshes/abstractMesh.decalMap.d.ts +1 -0
  214. package/Meshes/abstractMesh.decalMap.js.map +1 -1
  215. package/Meshes/abstractMesh.js +1 -6
  216. package/Meshes/abstractMesh.js.map +1 -1
  217. package/Meshes/csg.js +0 -6
  218. package/Meshes/csg.js.map +1 -1
  219. package/Meshes/csg2.js +1 -2
  220. package/Meshes/csg2.js.map +1 -1
  221. package/Meshes/geodesicMesh.d.ts +26 -0
  222. package/Meshes/geodesicMesh.js +18 -3
  223. package/Meshes/geodesicMesh.js.map +1 -1
  224. package/Meshes/groundMesh.d.ts +1 -0
  225. package/Meshes/groundMesh.js +1 -0
  226. package/Meshes/groundMesh.js.map +1 -1
  227. package/Meshes/index.js +0 -2
  228. package/Meshes/index.js.map +1 -1
  229. package/Meshes/instancedMesh.d.ts +18 -3
  230. package/Meshes/instancedMesh.js +10 -3
  231. package/Meshes/instancedMesh.js.map +1 -1
  232. package/Meshes/mesh.d.ts +286 -204
  233. package/Meshes/mesh.js +251 -197
  234. package/Meshes/mesh.js.map +1 -1
  235. package/Meshes/mesh.vertexData.d.ts +15 -19
  236. package/Meshes/mesh.vertexData.js +15 -19
  237. package/Meshes/mesh.vertexData.js.map +1 -1
  238. package/Meshes/meshSimplification.d.ts +0 -1
  239. package/Meshes/meshSimplification.js +6 -1
  240. package/Meshes/meshSimplification.js.map +1 -1
  241. package/Meshes/meshSimplificationSceneComponent.d.ts +2 -0
  242. package/Meshes/meshSimplificationSceneComponent.js.map +1 -1
  243. package/Meshes/meshUVSpaceRenderer.d.ts +1 -0
  244. package/Meshes/meshUVSpaceRenderer.js.map +1 -1
  245. package/Meshes/polygonMesh.js +4 -0
  246. package/Meshes/polygonMesh.js.map +1 -1
  247. package/Meshes/subMesh.project.d.ts +1 -0
  248. package/Meshes/subMesh.project.js.map +1 -1
  249. package/Meshes/thinInstanceMesh.d.ts +5 -0
  250. package/Meshes/thinInstanceMesh.js.map +1 -1
  251. package/Meshes/transformNode.d.ts +1 -1
  252. package/Meshes/transformNode.js +1 -1
  253. package/Meshes/transformNode.js.map +1 -1
  254. package/Physics/v2/Plugins/havokPlugin.d.ts +75 -2
  255. package/Physics/v2/Plugins/havokPlugin.js +243 -52
  256. package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
  257. package/Probes/reflectionProbe.js +1 -1
  258. package/Probes/reflectionProbe.js.map +1 -1
  259. package/Rendering/depthRenderer.js +1 -1
  260. package/Rendering/depthRenderer.js.map +1 -1
  261. package/package.json +1 -1
  262. package/scene.d.ts +0 -3
  263. package/scene.js +18 -5
  264. package/scene.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"torusKnotBuilder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Builders/torusKnotBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,yBAAyB,EA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AC,eAAe,CAAC;IAEpE,MAAM,UAAU,GAAG,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAEtD,UAAU,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAErD,OAAO,SAAS,CAAC;AACrB,CAAC;AACD;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC5B,gEAAgE;IAChE,eAAe;CAClB,CAAC;AAEF,UAAU,CAAC,eAAe,GAAG,yBAAyB,CAAC;AAEvD,IAAI,CAAC,eAAe,GAAG,CACnB,IAAY,EACZ,MAAc,EACd,IAAY,EACZ,cAAsB,EACtB,eAAuB,EACvB,CAAS,EACT,CAAS,EACT,KAAa,EACb,SAAmB,EACnB,eAAwB,EACpB,EAAE;IACN,MAAM,OAAO,GAAG;QACZ,MAAM;QACN,IAAI;QACJ,cAAc;QACd,eAAe;QACf,CAAC;QACD,CAAC;QACD,eAAe;QACf,SAAS;KACZ,CAAC;IAEF,OAAO,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AACjD,CAAC,CAAC","sourcesContent":["import type { Vector4 } from \"../../Maths/math.vector\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { useOpenGLOrientationForUV } from \"../../Compat/compatibilityOptions\";\r\n\r\n// based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473\r\n/**\r\n * Creates the VertexData for a TorusKnot\r\n * @param options an object used to set the following optional parameters for the TorusKnot, required but can be empty\r\n * * radius the radius of the torus knot, optional, default 2\r\n * * tube the thickness of the tube, optional, default 0.5\r\n * * radialSegments the number of sides on each tube segments, optional, default 32\r\n * * tubularSegments the number of tubes to decompose the knot into, optional, default 32\r\n * * p the number of windings around the z axis, optional, default 2\r\n * * q the number of windings around the x axis, optional, default 3\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @param options.radius\r\n * @param options.tube\r\n * @param options.radialSegments\r\n * @param options.tubularSegments\r\n * @param options.p\r\n * @param options.q\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @returns the VertexData of the Torus Knot\r\n */\r\nexport function CreateTorusKnotVertexData(options: {\r\n radius?: number;\r\n tube?: number;\r\n radialSegments?: number;\r\n tubularSegments?: number;\r\n p?: number;\r\n q?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n}): VertexData {\r\n const indices: number[] = [];\r\n const positions: number[] = [];\r\n const normals: number[] = [];\r\n const uvs: number[] = [];\r\n\r\n const radius = options.radius || 2;\r\n const tube = options.tube || 0.5;\r\n const radialSegments = options.radialSegments || 32;\r\n const tubularSegments = options.tubularSegments || 32;\r\n const p = options.p || 2;\r\n const q = options.q || 3;\r\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n // Helper\r\n const getPos = (angle: number) => {\r\n const cu = Math.cos(angle);\r\n const su = Math.sin(angle);\r\n const quOverP = (q / p) * angle;\r\n const cs = Math.cos(quOverP);\r\n\r\n const tx = radius * (2 + cs) * 0.5 * cu;\r\n const ty = radius * (2 + cs) * su * 0.5;\r\n const tz = radius * Math.sin(quOverP) * 0.5;\r\n\r\n return new Vector3(tx, ty, tz);\r\n };\r\n\r\n // Vertices\r\n let i: number;\r\n let j: number;\r\n for (i = 0; i <= radialSegments; i++) {\r\n const modI = i % radialSegments;\r\n const u = (modI / radialSegments) * 2 * p * Math.PI;\r\n const p1 = getPos(u);\r\n const p2 = getPos(u + 0.01);\r\n const tang = p2.subtract(p1);\r\n let n = p2.add(p1);\r\n\r\n const bitan = Vector3.Cross(tang, n);\r\n n = Vector3.Cross(bitan, tang);\r\n\r\n bitan.normalize();\r\n n.normalize();\r\n\r\n for (j = 0; j < tubularSegments; j++) {\r\n const modJ = j % tubularSegments;\r\n const v = (modJ / tubularSegments) * 2 * Math.PI;\r\n const cx = -tube * Math.cos(v);\r\n const cy = tube * Math.sin(v);\r\n\r\n positions.push(p1.x + cx * n.x + cy * bitan.x);\r\n positions.push(p1.y + cx * n.y + cy * bitan.y);\r\n positions.push(p1.z + cx * n.z + cy * bitan.z);\r\n\r\n uvs.push(i / radialSegments);\r\n uvs.push(useOpenGLOrientationForUV ? 1.0 - j / tubularSegments : j / tubularSegments);\r\n }\r\n }\r\n\r\n for (i = 0; i < radialSegments; i++) {\r\n for (j = 0; j < tubularSegments; j++) {\r\n const jNext = (j + 1) % tubularSegments;\r\n const a = i * tubularSegments + j;\r\n const b = (i + 1) * tubularSegments + j;\r\n const c = (i + 1) * tubularSegments + jNext;\r\n const d = i * tubularSegments + jNext;\r\n\r\n indices.push(d);\r\n indices.push(b);\r\n indices.push(a);\r\n indices.push(d);\r\n indices.push(c);\r\n indices.push(b);\r\n }\r\n }\r\n\r\n // Normals\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n\r\n // Sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a torus knot mesh\r\n * * The parameter `radius` sets the global radius size (float) of the torus knot (default 2)\r\n * * The parameter `radialSegments` sets the number of sides on each tube segments (positive integer, default 32)\r\n * * The parameter `tubularSegments` sets the number of tubes to decompose the knot into (positive integer, default 32)\r\n * * The parameters `p` and `q` are the number of windings on each axis (positive integers, default 2 and 3)\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param options.radius\r\n * @param options.tube\r\n * @param options.radialSegments\r\n * @param options.tubularSegments\r\n * @param options.p\r\n * @param options.q\r\n * @param options.updatable\r\n * @param options.sideOrientation\r\n * @param options.frontUVs\r\n * @param options.backUVs\r\n * @param scene defines the hosting scene\r\n * @returns the torus knot mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#torus-knot\r\n */\r\nexport function CreateTorusKnot(\r\n name: string,\r\n options: {\r\n radius?: number;\r\n tube?: number;\r\n radialSegments?: number;\r\n tubularSegments?: number;\r\n p?: number;\r\n q?: number;\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n } = {},\r\n scene?: Scene\r\n): Mesh {\r\n const torusKnot = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n torusKnot._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = CreateTorusKnotVertexData(options);\r\n\r\n vertexData.applyToMesh(torusKnot, options.updatable);\r\n\r\n return torusKnot;\r\n}\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use CreateTorusKnot instead\r\n */\r\nexport const TorusKnotBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateTorusKnot,\r\n};\r\n\r\nVertexData.CreateTorusKnot = CreateTorusKnotVertexData;\r\n\r\nMesh.CreateTorusKnot = (\r\n name: string,\r\n radius: number,\r\n tube: number,\r\n radialSegments: number,\r\n tubularSegments: number,\r\n p: number,\r\n q: number,\r\n scene?: Scene,\r\n updatable?: boolean,\r\n sideOrientation?: number\r\n): Mesh => {\r\n const options = {\r\n radius,\r\n tube,\r\n radialSegments,\r\n tubularSegments,\r\n p,\r\n q,\r\n sideOrientation,\r\n updatable,\r\n };\r\n\r\n return CreateTorusKnot(name, options, scene);\r\n};\r\n"]}
1
+ {"version":3,"file":"torusKnotBuilder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Builders/torusKnotBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAE9E,kIAAkI;AAClI;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAUzC;IACG,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,SAAS,GAAa,EAAE,CAAC;IAC/B,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,GAAG,GAAa,EAAE,CAAC;IAEzB,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,GAAG,CAAC;IACjC,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC;IACpD,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC;IACtD,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;IACzB,MAAM,CAAC,GAAG,OA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IAEF,OAAO,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AACjD,CAAC,CAAC","sourcesContent":["import type { Vector4 } from \"../../Maths/math.vector\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { useOpenGLOrientationForUV } from \"../../Compat/compatibilityOptions\";\r\n\r\n// based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473\r\n/**\r\n * Creates the VertexData for a TorusKnot\r\n * @param options an object used to set the following optional parameters for the TorusKnot, required but can be empty\r\n * * radius the radius of the torus knot, optional, default 2\r\n * * tube the thickness of the tube, optional, default 0.5\r\n * * radialSegments the number of sides on each tube segments, optional, default 32\r\n * * tubularSegments the number of tubes to decompose the knot into, optional, default 32\r\n * * p the number of windings around the z axis, optional, default 2\r\n * * q the number of windings around the x axis, optional, default 3\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @returns the VertexData of the Torus Knot\r\n */\r\nexport function CreateTorusKnotVertexData(options: {\r\n radius?: number;\r\n tube?: number;\r\n radialSegments?: number;\r\n tubularSegments?: number;\r\n p?: number;\r\n q?: number;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n}): VertexData {\r\n const indices: number[] = [];\r\n const positions: number[] = [];\r\n const normals: number[] = [];\r\n const uvs: number[] = [];\r\n\r\n const radius = options.radius || 2;\r\n const tube = options.tube || 0.5;\r\n const radialSegments = options.radialSegments || 32;\r\n const tubularSegments = options.tubularSegments || 32;\r\n const p = options.p || 2;\r\n const q = options.q || 3;\r\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n // Helper\r\n const getPos = (angle: number) => {\r\n const cu = Math.cos(angle);\r\n const su = Math.sin(angle);\r\n const quOverP = (q / p) * angle;\r\n const cs = Math.cos(quOverP);\r\n\r\n const tx = radius * (2 + cs) * 0.5 * cu;\r\n const ty = radius * (2 + cs) * su * 0.5;\r\n const tz = radius * Math.sin(quOverP) * 0.5;\r\n\r\n return new Vector3(tx, ty, tz);\r\n };\r\n\r\n // Vertices\r\n let i: number;\r\n let j: number;\r\n for (i = 0; i <= radialSegments; i++) {\r\n const modI = i % radialSegments;\r\n const u = (modI / radialSegments) * 2 * p * Math.PI;\r\n const p1 = getPos(u);\r\n const p2 = getPos(u + 0.01);\r\n const tang = p2.subtract(p1);\r\n let n = p2.add(p1);\r\n\r\n const bitan = Vector3.Cross(tang, n);\r\n n = Vector3.Cross(bitan, tang);\r\n\r\n bitan.normalize();\r\n n.normalize();\r\n\r\n for (j = 0; j < tubularSegments; j++) {\r\n const modJ = j % tubularSegments;\r\n const v = (modJ / tubularSegments) * 2 * Math.PI;\r\n const cx = -tube * Math.cos(v);\r\n const cy = tube * Math.sin(v);\r\n\r\n positions.push(p1.x + cx * n.x + cy * bitan.x);\r\n positions.push(p1.y + cx * n.y + cy * bitan.y);\r\n positions.push(p1.z + cx * n.z + cy * bitan.z);\r\n\r\n uvs.push(i / radialSegments);\r\n uvs.push(useOpenGLOrientationForUV ? 1.0 - j / tubularSegments : j / tubularSegments);\r\n }\r\n }\r\n\r\n for (i = 0; i < radialSegments; i++) {\r\n for (j = 0; j < tubularSegments; j++) {\r\n const jNext = (j + 1) % tubularSegments;\r\n const a = i * tubularSegments + j;\r\n const b = (i + 1) * tubularSegments + j;\r\n const c = (i + 1) * tubularSegments + jNext;\r\n const d = i * tubularSegments + jNext;\r\n\r\n indices.push(d);\r\n indices.push(b);\r\n indices.push(a);\r\n indices.push(d);\r\n indices.push(c);\r\n indices.push(b);\r\n }\r\n }\r\n\r\n // Normals\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n\r\n // Sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a torus knot mesh\r\n * * The parameter `radius` sets the global radius size (float) of the torus knot (default 2)\r\n * * The parameter `radialSegments` sets the number of sides on each tube segments (positive integer, default 32)\r\n * * The parameter `tubularSegments` sets the number of tubes to decompose the knot into (positive integer, default 32)\r\n * * The parameters `p` and `q` are the number of windings on each axis (positive integers, default 2 and 3)\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @returns the torus knot mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#torus-knot\r\n */\r\nexport function CreateTorusKnot(\r\n name: string,\r\n options: {\r\n radius?: number;\r\n tube?: number;\r\n radialSegments?: number;\r\n tubularSegments?: number;\r\n p?: number;\r\n q?: number;\r\n updatable?: boolean;\r\n sideOrientation?: number;\r\n frontUVs?: Vector4;\r\n backUVs?: Vector4;\r\n } = {},\r\n scene?: Scene\r\n): Mesh {\r\n const torusKnot = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n torusKnot._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = CreateTorusKnotVertexData(options);\r\n\r\n vertexData.applyToMesh(torusKnot, options.updatable);\r\n\r\n return torusKnot;\r\n}\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use CreateTorusKnot instead\r\n */\r\nexport const TorusKnotBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreateTorusKnot,\r\n};\r\n\r\nVertexData.CreateTorusKnot = CreateTorusKnotVertexData;\r\n\r\nMesh.CreateTorusKnot = (\r\n name: string,\r\n radius: number,\r\n tube: number,\r\n radialSegments: number,\r\n tubularSegments: number,\r\n p: number,\r\n q: number,\r\n scene?: Scene,\r\n updatable?: boolean,\r\n sideOrientation?: number\r\n): Mesh => {\r\n const options = {\r\n radius,\r\n tube,\r\n radialSegments,\r\n tubularSegments,\r\n p,\r\n q,\r\n sideOrientation,\r\n updatable,\r\n };\r\n\r\n return CreateTorusKnot(name, options, scene);\r\n};\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"dracoCompressionWorker.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompressionWorker.ts"],"names":[],"mappings":"AAsBA;;GAEG;AACH,MAAM,UAAU,UAAU,CACtB,MAAe,CAAC,oBAAoB,EACpC,UAAsC,EACtC,OAA4C,EAC5C,OAA6B;IAE7B,MAAM,aAAa,GAAG,MAAuB,CAAC;IAC9C,IAAI,OAAO,GAAsB,IAAI,CAAC;IACtC,IAAI,WAAW,GAA0B,IAAI,CAAC;IAC9C,IAAI,IAAI,GAAmB,IAAI,CAAC;IAChC,IAAI,mBAAmB,GAA6B,IAAI,CAAC;IACzD,MAAM,YAAY,GAA2B,EAAE,CAAC,CAAC,kCAAkC;IAEnF,8DAA8D;IAC9D,MAAM,iBAAiB,GAAG,UAAU,CAAC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AAC,CAAC;YACjD,2EAA2E;YAC3E,MAAM,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC,CAAC;QAEF,MAAM,SAAS,GAAG,CAAC,KAAqC,EAAE,EAAE;YACxD,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,UAAU,EAAE,CAAC;gBAC/B,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;YACpB,CAAC;QACL,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC1C,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAE9C,2CAA2C;QAC3C,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,MAAM,CAAC,WAAW,CAAC;gBACf,EAAE,EAAE,MAAM;gBACV,GAAG,EAAE,SAAS;aACjB,CAAC,CAAC;QACP,CAAC;aAAM,CAAC;YACJ,iDAAiD;YACjD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAClC,MAAM,CAAC,WAAW,CACd;gBACI,EAAE,EAAE,MAAM;gBACV,GAAG,EAAE,SAAS;gBACd,UAAU,EAAE,KAAK;aACpB,EACD,CAAC,KAAK,CAAC,CACV,CAAC;QACN,CAAC;QACD,0FAA0F;IAC9F,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { Nullable, TypedArray, TypedArrayConstructor } from \"core/types\";\r\nimport type { EncoderMessage, IDracoAttributeData, IDracoEncodedMeshData, IDracoEncoderOptions } from \"./dracoEncoder.types\";\r\nimport type { DecoderMessage } from \"./dracoDecoder.types\";\r\nimport type { DecoderBuffer, Decoder, Mesh, PointCloud, Status, DecoderModule, EncoderModule, MeshBuilder, Encoder, DracoInt8Array } from \"draco3dgltf\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\nimport type { VertexDataTypedArray } from \"core/Buffers/bufferUtils\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoEncoderModule: (props: { wasmBinary?: ArrayBuffer }) => Promise<EncoderModule>;\r\n\r\ninterface IInitDoneMessage {\r\n id: \"initDone\";\r\n}\r\n\r\n// WorkerGlobalScope\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare function importScripts(...urls: string[]): void;\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare function postMessage(message: IInitDoneMessage | DecoderMessage | EncoderMessage, transfer?: ArrayBufferLike[]): void;\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function EncodeMesh(\r\n module: unknown /** EncoderModule */,\r\n attributes: Array<IDracoAttributeData>,\r\n indices: Nullable<Uint16Array | Uint32Array>,\r\n options: IDracoEncoderOptions\r\n): IDracoEncodedMeshData {\r\n const encoderModule = module as EncoderModule;\r\n let encoder: Nullable<Encoder> = null;\r\n let meshBuilder: Nullable<MeshBuilder> = null;\r\n let mesh: Nullable<Mesh> = null;\r\n let encodedNativeBuffer: Nullable<DracoInt8Array> = null;\r\n const attributeIDs: Record<string, number> = {}; // Babylon kind -> Draco unique id\r\n\r\n // Double-check that at least a position attribute is provided\r\n const positionAttribute = attributes.find((a) => a.dracoName === \"POSITION\");\r\n if (!positionAttribute) {\r\n throw new Error(\"Draco: Missing position attribute for encoding.\");\r\n }\r\n\r\n // If no indices are provided, assume mesh is unindexed. Let's generate them, since Draco meshes require them.\r\n // TODO: This may be the POINT_CLOUD case, but need to investigate. Should work for now-- just less efficient.\r\n if (!indices) {\r\n // Assume position attribute is the largest attribute.\r\n const positionVerticesCount = positionAttribute.data.length / positionAttribute.size;\r\n indices = new (positionVerticesCount > 65535 ? Uint32Array : Uint16Array)(positionVerticesCount);\r\n for (let i = 0; i < positionVerticesCount; i++) {\r\n indices[i] = i;\r\n }\r\n }\r\n\r\n try {\r\n encoder = new encoderModule.Encoder();\r\n meshBuilder = new encoderModule.MeshBuilder();\r\n mesh = new encoderModule.Mesh();\r\n\r\n // Add the faces\r\n meshBuilder.AddFacesToMesh(mesh, indices.length / 3, indices);\r\n\r\n const addAttributeMap = new Map<\r\n Function,\r\n (builder: MeshBuilder, mesh: Mesh, attr: any, count: number, size: number, data: Exclude<VertexDataTypedArray, Uint8ClampedArray>) => number\r\n >([\r\n [Float32Array, (mb, m, a, c, s, d) => mb.AddFloatAttribute(m, a, c, s, d)],\r\n [Uint32Array, (mb, m, a, c, s, d) => mb.AddUInt32Attribute(m, a, c, s, d)],\r\n [Uint16Array, (mb, m, a, c, s, d) => mb.AddUInt16Attribute(m, a, c, s, d)],\r\n [Uint8Array, (mb, m, a, c, s, d) => mb.AddUInt8Attribute(m, a, c, s, d)],\r\n [Int32Array, (mb, m, a, c, s, d) => mb.AddInt32Attribute(m, a, c, s, d)],\r\n [Int16Array, (mb, m, a, c, s, d) => mb.AddInt16Attribute(m, a, c, s, d)],\r\n [Int8Array, (mb, m, a, c, s, d) => mb.AddInt8Attribute(m, a, c, s, d)],\r\n ]);\r\n\r\n // Add the attributes\r\n for (const attribute of attributes) {\r\n if (attribute.data instanceof Uint8ClampedArray) {\r\n attribute.data = new Uint8Array(attribute.data); // Draco does not support Uint8ClampedArray\r\n }\r\n const addAttribute = addAttributeMap.get(attribute.data.constructor)!;\r\n const verticesCount = attribute.data.length / attribute.size;\r\n attributeIDs[attribute.kind] = addAttribute(meshBuilder, mesh, encoderModule[attribute.dracoName], verticesCount, attribute.size, attribute.data);\r\n if (options.quantizationBits && options.quantizationBits[attribute.dracoName]) {\r\n encoder.SetAttributeQuantization(encoderModule[attribute.dracoName], options.quantizationBits[attribute.dracoName]);\r\n }\r\n }\r\n\r\n // Set the options\r\n if (options.method) {\r\n encoder.SetEncodingMethod(encoderModule[options.method]);\r\n }\r\n if (options.encodeSpeed !== undefined && options.decodeSpeed !== undefined) {\r\n encoder.SetSpeedOptions(options.encodeSpeed, options.decodeSpeed);\r\n }\r\n\r\n // Encode to native buffer\r\n encodedNativeBuffer = new encoderModule.DracoInt8Array();\r\n const encodedLength = encoder.EncodeMeshToDracoBuffer(mesh, encodedNativeBuffer);\r\n if (encodedLength <= 0) {\r\n throw new Error(\"Draco: Failed to encode.\");\r\n }\r\n\r\n // Copy the native buffer data to worker heap\r\n const encodedData = new Int8Array(encodedLength);\r\n for (let i = 0; i < encodedLength; i++) {\r\n encodedData[i] = encodedNativeBuffer.GetValue(i);\r\n }\r\n\r\n return { data: encodedData, attributeIds: attributeIDs };\r\n } finally {\r\n if (mesh) {\r\n encoderModule.destroy(mesh);\r\n }\r\n if (meshBuilder) {\r\n encoderModule.destroy(meshBuilder);\r\n }\r\n if (encoder) {\r\n encoderModule.destroy(encoder);\r\n }\r\n if (encodedNativeBuffer) {\r\n encoderModule.destroy(encodedNativeBuffer);\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 EncoderWorkerFunction(): void {\r\n let encoderPromise: Promise<EncoderModule> | undefined;\r\n\r\n onmessage = (event) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"init\": {\r\n // if URL is provided then load the script. Otherwise expect the script to be loaded already\r\n if (message.url) {\r\n importScripts(message.url);\r\n }\r\n const initEncoderObject = message.wasmBinary ? { wasmBinary: message.wasmBinary } : {};\r\n encoderPromise = DracoEncoderModule(initEncoderObject);\r\n postMessage({ id: \"initDone\" });\r\n break;\r\n }\r\n case \"encodeMesh\": {\r\n if (!encoderPromise) {\r\n throw new Error(\"Draco: Encoder module is not available.\");\r\n }\r\n encoderPromise\r\n // eslint-disable-next-line github/no-then\r\n .then((encoder) => {\r\n const result = EncodeMesh(encoder, message.attributes, message.indices, message.options);\r\n postMessage({ id: \"encodeMeshSuccess\", encodedMeshData: result }, result ? [result.data.buffer] : undefined);\r\n })\r\n // eslint-disable-next-line github/no-then\r\n .catch((error) => {\r\n postMessage({ id: \"encodeMeshError\", errorMessage: error.message });\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function DecodeMesh(\r\n module: unknown /** DecoderModule */,\r\n data: Int8Array,\r\n attributeIDs: Record<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 const decoderModule = module as DecoderModule;\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(`Draco: Cannot decode 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 /** Attribute */) => {\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: Record<number, { typedArrayConstructor: TypedArrayConstructor; heap: TypedArray }> = {\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(`Draco: Cannot decode 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 (attributeIDs) {\r\n for (const kind in attributeIDs) {\r\n const id = attributeIDs[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: Record<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 DecoderWorkerFunction(): void {\r\n let decoderPromise: PromiseLike<DecoderModule> | undefined;\r\n\r\n onmessage = (event) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"init\": {\r\n // if URL is provided then load the script. Otherwise expect the script to be loaded already\r\n if (message.url) {\r\n importScripts(message.url);\r\n }\r\n const initDecoderObject = message.wasmBinary ? { wasmBinary: message.wasmBinary } : {};\r\n decoderPromise = DracoDecoderModule(initDecoderObject);\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 // eslint-disable-next-line github/no-then\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// For backwards compatibility\r\nexport { DecoderWorkerFunction as workerFunction };\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 wasmBinary 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\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport async function initializeWebWorker(worker: Worker, wasmBinary?: ArrayBuffer, moduleUrl?: string): Promise<Worker> {\r\n return await 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 // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\r\n reject(error);\r\n };\r\n\r\n const onMessage = (event: MessageEvent<IInitDoneMessage>) => {\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 // Load with either JS-only or WASM version\r\n if (!wasmBinary) {\r\n worker.postMessage({\r\n id: \"init\",\r\n url: moduleUrl,\r\n });\r\n } else {\r\n // clone the array buffer to make it transferable\r\n const clone = wasmBinary.slice(0);\r\n worker.postMessage(\r\n {\r\n id: \"init\",\r\n url: moduleUrl,\r\n wasmBinary: clone,\r\n },\r\n [clone]\r\n );\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"]}
1
+ {"version":3,"file":"dracoCompressionWorker.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompressionWorker.ts"],"names":[],"mappings":"AAoBA;;GAEG;AACH,MAAM,UAAU,UAAU,CACtB,MAAe,CAAC,oBAAoB,EACpC,UAAsC,EACtC,OAA4C,EAC5C,OAA6B;IAE7B,MAAM,aAAa,GAAG,MAAuB,CAAC;IAC9C,IAAI,OAAO,GAAsB,IAAI,CAAC;IACtC,IAAI,WAAW,GAA0B,IAAI,CAAC;IAC9C,IAAI,IAAI,GAAmB,IAAI,CAAC;IAChC,IAAI,mBAAmB,GAA6B,IAAI,CAAC;IACzD,MAAM,YAAY,GAA2B,EAAE,CAAC,CAAC,kCAAkC;IAEnF,8DAA8D;IAC9D,MAAM,iBAAiB,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,UAAU,CAAC,CAAC;IAC7E,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACvE,CAAC;IAED,8GAA8G;IAC9G,8GAA8G;IAC9G,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,sDAAsD;QACtD,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC;QACrF,OAAO,GAAG,IAAI,CAAC,qBAAqB,GAAG,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC;QACjG,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,qBAAqB,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7C,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACL,CAAC;IAED,IAAI,CAAC;QACD,OA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AAM,CAAC;YACJ,iDAAiD;YACjD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAClC,MAAM,CAAC,WAAW,CACd;gBACI,EAAE,EAAE,MAAM;gBACV,GAAG,EAAE,SAAS;gBACd,UAAU,EAAE,KAAK;aACpB,EACD,CAAC,KAAK,CAAC,CACV,CAAC;QACN,CAAC;QACD,0FAA0F;IAC9F,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { Nullable, TypedArray, TypedArrayConstructor } from \"core/types\";\r\nimport type { EncoderMessage, IDracoAttributeData, IDracoEncodedMeshData, IDracoEncoderOptions } from \"./dracoEncoder.types\";\r\nimport type { DecoderMessage } from \"./dracoDecoder.types\";\r\nimport type { DecoderBuffer, Decoder, Mesh, PointCloud, Status, DecoderModule, EncoderModule, MeshBuilder, Encoder, DracoInt8Array } from \"draco3dgltf\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\nimport type { VertexDataTypedArray } from \"core/Buffers/bufferUtils\";\r\n\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\ndeclare let DracoEncoderModule: (props: { wasmBinary?: ArrayBuffer }) => Promise<EncoderModule>;\r\n\r\ninterface IInitDoneMessage {\r\n id: \"initDone\";\r\n}\r\n\r\n// WorkerGlobalScope\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare function importScripts(...urls: string[]): void;\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare function postMessage(message: IInitDoneMessage | DecoderMessage | EncoderMessage, transfer?: ArrayBufferLike[]): void;\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function EncodeMesh(\r\n module: unknown /** EncoderModule */,\r\n attributes: Array<IDracoAttributeData>,\r\n indices: Nullable<Uint16Array | Uint32Array>,\r\n options: IDracoEncoderOptions\r\n): IDracoEncodedMeshData {\r\n const encoderModule = module as EncoderModule;\r\n let encoder: Nullable<Encoder> = null;\r\n let meshBuilder: Nullable<MeshBuilder> = null;\r\n let mesh: Nullable<Mesh> = null;\r\n let encodedNativeBuffer: Nullable<DracoInt8Array> = null;\r\n const attributeIDs: Record<string, number> = {}; // Babylon kind -> Draco unique id\r\n\r\n // Double-check that at least a position attribute is provided\r\n const positionAttribute = attributes.find((a) => a.dracoName === \"POSITION\");\r\n if (!positionAttribute) {\r\n throw new Error(\"Draco: Missing position attribute for encoding.\");\r\n }\r\n\r\n // If no indices are provided, assume mesh is unindexed. Let's generate them, since Draco meshes require them.\r\n // TODO: This may be the POINT_CLOUD case, but need to investigate. Should work for now-- just less efficient.\r\n if (!indices) {\r\n // Assume position attribute is the largest attribute.\r\n const positionVerticesCount = positionAttribute.data.length / positionAttribute.size;\r\n indices = new (positionVerticesCount > 65535 ? Uint32Array : Uint16Array)(positionVerticesCount);\r\n for (let i = 0; i < positionVerticesCount; i++) {\r\n indices[i] = i;\r\n }\r\n }\r\n\r\n try {\r\n encoder = new encoderModule.Encoder();\r\n meshBuilder = new encoderModule.MeshBuilder();\r\n mesh = new encoderModule.Mesh();\r\n\r\n // Add the faces\r\n meshBuilder.AddFacesToMesh(mesh, indices.length / 3, indices);\r\n\r\n const addAttributeMap = new Map<\r\n Function,\r\n (builder: MeshBuilder, mesh: Mesh, attr: any, count: number, size: number, data: Exclude<VertexDataTypedArray, Uint8ClampedArray>) => number\r\n >([\r\n [Float32Array, (mb, m, a, c, s, d) => mb.AddFloatAttribute(m, a, c, s, d)],\r\n [Uint32Array, (mb, m, a, c, s, d) => mb.AddUInt32Attribute(m, a, c, s, d)],\r\n [Uint16Array, (mb, m, a, c, s, d) => mb.AddUInt16Attribute(m, a, c, s, d)],\r\n [Uint8Array, (mb, m, a, c, s, d) => mb.AddUInt8Attribute(m, a, c, s, d)],\r\n [Int32Array, (mb, m, a, c, s, d) => mb.AddInt32Attribute(m, a, c, s, d)],\r\n [Int16Array, (mb, m, a, c, s, d) => mb.AddInt16Attribute(m, a, c, s, d)],\r\n [Int8Array, (mb, m, a, c, s, d) => mb.AddInt8Attribute(m, a, c, s, d)],\r\n ]);\r\n\r\n // Add the attributes\r\n for (const attribute of attributes) {\r\n if (attribute.data instanceof Uint8ClampedArray) {\r\n attribute.data = new Uint8Array(attribute.data); // Draco does not support Uint8ClampedArray\r\n }\r\n const addAttribute = addAttributeMap.get(attribute.data.constructor)!;\r\n const verticesCount = attribute.data.length / attribute.size;\r\n attributeIDs[attribute.kind] = addAttribute(meshBuilder, mesh, encoderModule[attribute.dracoName], verticesCount, attribute.size, attribute.data);\r\n if (options.quantizationBits && options.quantizationBits[attribute.dracoName]) {\r\n encoder.SetAttributeQuantization(encoderModule[attribute.dracoName], options.quantizationBits[attribute.dracoName]);\r\n }\r\n }\r\n\r\n // Set the options\r\n if (options.method) {\r\n encoder.SetEncodingMethod(encoderModule[options.method]);\r\n }\r\n if (options.encodeSpeed !== undefined && options.decodeSpeed !== undefined) {\r\n encoder.SetSpeedOptions(options.encodeSpeed, options.decodeSpeed);\r\n }\r\n\r\n // Encode to native buffer\r\n encodedNativeBuffer = new encoderModule.DracoInt8Array();\r\n const encodedLength = encoder.EncodeMeshToDracoBuffer(mesh, encodedNativeBuffer);\r\n if (encodedLength <= 0) {\r\n throw new Error(\"Draco: Failed to encode.\");\r\n }\r\n\r\n // Copy the native buffer data to worker heap\r\n const encodedData = new Int8Array(encodedLength);\r\n for (let i = 0; i < encodedLength; i++) {\r\n encodedData[i] = encodedNativeBuffer.GetValue(i);\r\n }\r\n\r\n return { data: encodedData, attributeIds: attributeIDs };\r\n } finally {\r\n if (mesh) {\r\n encoderModule.destroy(mesh);\r\n }\r\n if (meshBuilder) {\r\n encoderModule.destroy(meshBuilder);\r\n }\r\n if (encoder) {\r\n encoderModule.destroy(encoder);\r\n }\r\n if (encodedNativeBuffer) {\r\n encoderModule.destroy(encodedNativeBuffer);\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 EncoderWorkerFunction(): void {\r\n let encoderPromise: Promise<EncoderModule> | undefined;\r\n\r\n onmessage = (event) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"init\": {\r\n // if URL is provided then load the script. Otherwise expect the script to be loaded already\r\n if (message.url) {\r\n importScripts(message.url);\r\n }\r\n const initEncoderObject = message.wasmBinary ? { wasmBinary: message.wasmBinary } : {};\r\n encoderPromise = DracoEncoderModule(initEncoderObject);\r\n postMessage({ id: \"initDone\" });\r\n break;\r\n }\r\n case \"encodeMesh\": {\r\n if (!encoderPromise) {\r\n throw new Error(\"Draco: Encoder module is not available.\");\r\n }\r\n encoderPromise\r\n // eslint-disable-next-line github/no-then\r\n .then((encoder) => {\r\n const result = EncodeMesh(encoder, message.attributes, message.indices, message.options);\r\n postMessage({ id: \"encodeMeshSuccess\", encodedMeshData: result }, result ? [result.data.buffer] : undefined);\r\n })\r\n // eslint-disable-next-line github/no-then\r\n .catch((error) => {\r\n postMessage({ id: \"encodeMeshError\", errorMessage: error.message });\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function DecodeMesh(\r\n module: unknown /** DecoderModule */,\r\n data: Int8Array,\r\n attributeIDs: Record<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 const decoderModule = module as DecoderModule;\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(`Draco: Cannot decode 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 /** Attribute */) => {\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: Record<number, { typedArrayConstructor: TypedArrayConstructor; heap: TypedArray }> = {\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(`Draco: Cannot decode 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 (attributeIDs) {\r\n for (const kind in attributeIDs) {\r\n const id = attributeIDs[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: Record<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 DecoderWorkerFunction(): void {\r\n let decoderPromise: PromiseLike<DecoderModule> | undefined;\r\n\r\n onmessage = (event) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"init\": {\r\n // if URL is provided then load the script. Otherwise expect the script to be loaded already\r\n if (message.url) {\r\n importScripts(message.url);\r\n }\r\n const initDecoderObject = message.wasmBinary ? { wasmBinary: message.wasmBinary } : {};\r\n decoderPromise = DracoDecoderModule(initDecoderObject);\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 // eslint-disable-next-line github/no-then\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// For backwards compatibility\r\nexport { DecoderWorkerFunction as workerFunction };\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 wasmBinary 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\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport async function initializeWebWorker(worker: Worker, wasmBinary?: ArrayBuffer, moduleUrl?: string): Promise<Worker> {\r\n return await 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 // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\r\n reject(error);\r\n };\r\n\r\n const onMessage = (event: MessageEvent<IInitDoneMessage>) => {\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 // Load with either JS-only or WASM version\r\n if (!wasmBinary) {\r\n worker.postMessage({\r\n id: \"init\",\r\n url: moduleUrl,\r\n });\r\n } else {\r\n // clone the array buffer to make it transferable\r\n const clone = wasmBinary.slice(0);\r\n worker.postMessage(\r\n {\r\n id: \"init\",\r\n url: moduleUrl,\r\n wasmBinary: clone,\r\n },\r\n [clone]\r\n );\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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"dracoDecoder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,UAAU,EAAiC,MAAM,cAAc,CAAC;AACpG,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAI3C,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAM7E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU;IAcxC;;OAEG;IACI,MAAM,KAAK,gBAAgB;QAC9B,OAAO,yBAAyB,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC;IACxE,CAAC;IAGD;;OAEG;IACI,MAAM,KAAK,OAAO;QACrB,YAAY,CAAC,QAAQ,KAArB,YAAY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,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;;AA9PD;;;;;;GAMG;AACW,iCAAoB,GAA6B;IAC3D,OAAO,EAAE,GAAG,KAAK,CAAC,cAAc,6BAA6B;IAC7D,aAAa,EAAE,GAAG,KAAK,CAAC,cAAc,0BAA0B;IAChE,WAAW,EAAE,GAAG,KAAK,CAAC,cAAc,wBAAwB;CAC/D,CAAC;AASe,qBAAQ,GAA2B,IAAI,CAAC","sourcesContent":["import { DracoDecoderModule } from \"draco3dgltf\";\r\nimport { _IsConfigurationAvailable, DracoCodec, type IDracoCodecConfiguration } from \"./dracoCodec\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { Geometry } from \"../geometry\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { BoundingInfo } from \"../../Culling/boundingInfo\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { DecodeMesh, DecoderWorkerFunction } from \"./dracoCompressionWorker\";\r\nimport type { IAttributeData, MeshData, DecoderMessage } from \"./dracoDecoder.types\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\n/**\r\n * @experimental This class is an experimental version of `DracoCompression` and is subject to change.\r\n *\r\n * Draco Decoder (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco decoder module.\r\n *\r\n * By default, the configuration points to a copy of the Draco decoder files for glTF from the Babylon.js cdn https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoDecoder.DefaultConfiguration = {\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 * 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 `DracoDecoder.DefaultAvailable` to determine if the decoder configuration is available for the current context.\r\n *\r\n * To decode Draco compressed data, get the default DracoDecoder object and call decodeMeshToGeometryAsync:\r\n * ```javascript\r\n * var geometry = await DracoDecoder.Default.decodeMeshToGeometryAsync(data);\r\n * ```\r\n */\r\nexport class DracoDecoder extends DracoCodec {\r\n /**\r\n * Default configuration for the DracoDecoder. Defaults to the following:\r\n * - numWorkers: 50% of the available logical processors, capped to 4. If no logical processors are available, defaults to 1.\r\n * - wasmUrl: `\"https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js\"`\r\n * - wasmBinaryUrl: `\"https://cdn.babylonjs.com/draco_decoder_gltf.wasm\"`\r\n * - fallbackUrl: `\"https://cdn.babylonjs.com/draco_decoder_gltf.js\"`\r\n */\r\n public static DefaultConfiguration: IDracoCodecConfiguration = {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_wasm_wrapper_gltf.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.js`,\r\n };\r\n\r\n /**\r\n * Returns true if the decoder's `DefaultConfiguration` is available.\r\n */\r\n public static get DefaultAvailable(): boolean {\r\n return _IsConfigurationAvailable(DracoDecoder.DefaultConfiguration);\r\n }\r\n\r\n protected static _Default: Nullable<DracoDecoder> = null;\r\n /**\r\n * Default instance for the DracoDecoder.\r\n */\r\n public static get Default(): DracoDecoder {\r\n DracoDecoder._Default ??= new DracoDecoder();\r\n return DracoDecoder._Default;\r\n }\r\n\r\n /**\r\n * Reset the default DracoDecoder object to null and disposing the removed default instance.\r\n * Note that if the workerPool is a member of the static DefaultConfiguration object it is recommended not to run dispose,\r\n * unless the static worker pool is no longer needed.\r\n * @param skipDispose set to true to not dispose the removed default instance\r\n */\r\n public static ResetDefault(skipDispose?: boolean): void {\r\n if (DracoDecoder._Default) {\r\n if (!skipDispose) {\r\n DracoDecoder._Default.dispose();\r\n }\r\n DracoDecoder._Default = null;\r\n }\r\n }\r\n\r\n protected override _isModuleAvailable(): boolean {\r\n return typeof DracoDecoderModule !== \"undefined\";\r\n }\r\n\r\n protected override async _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: unknown /** DracoDecoderModule */): Promise<{ module: unknown /** DecoderModule */ }> {\r\n const module = await ((jsModule as DracoDecoderModule) || DracoDecoderModule)({ wasmBinary });\r\n return { module };\r\n }\r\n\r\n protected override _getWorkerContent(): string {\r\n return `${DecodeMesh}(${DecoderWorkerFunction})()`;\r\n }\r\n\r\n /**\r\n * Creates a new Draco decoder.\r\n * @param configuration Optional override of the configuration for the DracoDecoder. If not provided, defaults to {@link DracoDecoder.DefaultConfiguration}.\r\n */\r\n constructor(configuration: IDracoCodecConfiguration = DracoDecoder.DefaultConfiguration) {\r\n super(configuration);\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to mesh data.\r\n * @param data The ArrayBuffer or ArrayBufferView of the compressed Draco data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @param gltfNormalizedOverride A map of attributes from vertex buffer kinds to normalized flags to override the Draco normalization\r\n * @returns A promise that resolves with the decoded mesh data\r\n */\r\n // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n public decodeMeshToMeshDataAsync(\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes?: { [kind: string]: number },\r\n gltfNormalizedOverride?: { [kind: string]: boolean }\r\n ): Promise<MeshData> {\r\n const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);\r\n\r\n const applyGltfNormalizedOverride = (kind: string, normalized: boolean): boolean => {\r\n if (gltfNormalizedOverride && gltfNormalizedOverride[kind] !== undefined) {\r\n if (normalized !== gltfNormalizedOverride[kind]) {\r\n Logger.Warn(\r\n `Normalized flag from Draco data (${normalized}) does not match normalized flag from glTF accessor (${gltfNormalizedOverride[kind]}). Using flag from glTF accessor.`\r\n );\r\n }\r\n\r\n return gltfNormalizedOverride[kind];\r\n } else {\r\n return normalized;\r\n }\r\n };\r\n\r\n if (this._workerPoolPromise) {\r\n // eslint-disable-next-line github/no-then\r\n return this._workerPoolPromise.then(async (workerPool) => {\r\n return await new Promise<MeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<IAttributeData> = [];\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (event: MessageEvent<DecoderMessage>) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"indices\": {\r\n resultIndices = message.data;\r\n break;\r\n }\r\n case \"attribute\": {\r\n resultAttributes.push({\r\n kind: message.kind,\r\n data: message.data,\r\n size: message.size,\r\n byteOffset: message.byteOffset,\r\n byteStride: message.byteStride,\r\n normalized: applyGltfNormalizedOverride(message.kind, message.normalized),\r\n });\r\n break;\r\n }\r\n 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 }\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._modulePromise) {\r\n // eslint-disable-next-line github/no-then\r\n return this._modulePromise.then((decoder) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<IAttributeData> = [];\r\n\r\n const numPoints = DecodeMesh(\r\n decoder.module,\r\n dataView,\r\n attributes,\r\n (indices) => {\r\n resultIndices = indices;\r\n },\r\n (kind, data, size, byteOffset, byteStride, normalized) => {\r\n resultAttributes.push({\r\n kind,\r\n data,\r\n size,\r\n byteOffset,\r\n byteStride,\r\n normalized,\r\n });\r\n }\r\n );\r\n\r\n return { indices: resultIndices!, attributes: resultAttributes, totalVertices: numPoints };\r\n });\r\n }\r\n\r\n throw new Error(\"Draco: Decoder module is not available\");\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon geometry.\r\n * @param name The name to use when creating the geometry\r\n * @param scene The scene to use when creating the geometry\r\n * @param data The ArrayBuffer or ArrayBufferView of the Draco compressed data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded geometry\r\n */\r\n public async decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /** @internal */\r\n public async _decodeMeshToGeometryForGltfAsync(\r\n name: string,\r\n scene: Scene,\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes: { [kind: string]: number },\r\n gltfNormalizedOverride: { [kind: string]: boolean },\r\n boundingInfo: Nullable<BoundingInfo>\r\n ): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes, gltfNormalizedOverride);\r\n const geometry = new Geometry(name, scene);\r\n if (boundingInfo) {\r\n geometry._boundingInfo = boundingInfo;\r\n geometry.useBoundingInfoFromGeometry = true;\r\n }\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"dracoDecoder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,UAAU,EAAiC,MAAM,cAAc,CAAC;AACpG,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAI3C,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAK7E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU;IAcxC;;OAEG;IACI,MAAM,KAAK,gBAAgB;QAC9B,OAAO,yBAAyB,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC;IACxE,CAAC;IAGD;;OAEG;IACI,MAAM,KAAK,OAAO;QACrB,YAAY,CAAC,QAAQ,KAArB,YAAY,CAAC,QAAQ,GAAK,IAAI,YAAY,EAAE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CAAC;;AA9PD;;;;;;GAMG;AACW,iCAAoB,GAA6B;IAC3D,OAAO,EAAE,GAAG,KAAK,CAAC,cAAc,6BAA6B;IAC7D,aAAa,EAAE,GAAG,KAAK,CAAC,cAAc,0BAA0B;IAChE,WAAW,EAAE,GAAG,KAAK,CAAC,cAAc,wBAAwB;CAC/D,CAAC;AASe,qBAAQ,GAA2B,IAAI,CAAC","sourcesContent":["import { DracoDecoderModule } from \"draco3dgltf\";\r\nimport { _IsConfigurationAvailable, DracoCodec, type IDracoCodecConfiguration } from \"./dracoCodec\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { Geometry } from \"../geometry\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { BoundingInfo } from \"../../Culling/boundingInfo\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { DecodeMesh, DecoderWorkerFunction } from \"./dracoCompressionWorker\";\r\nimport type { IAttributeData, MeshData, DecoderMessage } from \"./dracoDecoder.types\";\r\n\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\n/**\r\n * @experimental This class is an experimental version of `DracoCompression` and is subject to change.\r\n *\r\n * Draco Decoder (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco decoder module.\r\n *\r\n * By default, the configuration points to a copy of the Draco decoder files for glTF from the Babylon.js cdn https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoDecoder.DefaultConfiguration = {\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 * 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 `DracoDecoder.DefaultAvailable` to determine if the decoder configuration is available for the current context.\r\n *\r\n * To decode Draco compressed data, get the default DracoDecoder object and call decodeMeshToGeometryAsync:\r\n * ```javascript\r\n * var geometry = await DracoDecoder.Default.decodeMeshToGeometryAsync(data);\r\n * ```\r\n */\r\nexport class DracoDecoder extends DracoCodec {\r\n /**\r\n * Default configuration for the DracoDecoder. Defaults to the following:\r\n * - numWorkers: 50% of the available logical processors, capped to 4. If no logical processors are available, defaults to 1.\r\n * - wasmUrl: `\"https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js\"`\r\n * - wasmBinaryUrl: `\"https://cdn.babylonjs.com/draco_decoder_gltf.wasm\"`\r\n * - fallbackUrl: `\"https://cdn.babylonjs.com/draco_decoder_gltf.js\"`\r\n */\r\n public static DefaultConfiguration: IDracoCodecConfiguration = {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_wasm_wrapper_gltf.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.js`,\r\n };\r\n\r\n /**\r\n * Returns true if the decoder's `DefaultConfiguration` is available.\r\n */\r\n public static get DefaultAvailable(): boolean {\r\n return _IsConfigurationAvailable(DracoDecoder.DefaultConfiguration);\r\n }\r\n\r\n protected static _Default: Nullable<DracoDecoder> = null;\r\n /**\r\n * Default instance for the DracoDecoder.\r\n */\r\n public static get Default(): DracoDecoder {\r\n DracoDecoder._Default ??= new DracoDecoder();\r\n return DracoDecoder._Default;\r\n }\r\n\r\n /**\r\n * Reset the default DracoDecoder object to null and disposing the removed default instance.\r\n * Note that if the workerPool is a member of the static DefaultConfiguration object it is recommended not to run dispose,\r\n * unless the static worker pool is no longer needed.\r\n * @param skipDispose set to true to not dispose the removed default instance\r\n */\r\n public static ResetDefault(skipDispose?: boolean): void {\r\n if (DracoDecoder._Default) {\r\n if (!skipDispose) {\r\n DracoDecoder._Default.dispose();\r\n }\r\n DracoDecoder._Default = null;\r\n }\r\n }\r\n\r\n protected override _isModuleAvailable(): boolean {\r\n return typeof DracoDecoderModule !== \"undefined\";\r\n }\r\n\r\n protected override async _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: unknown /** DracoDecoderModule */): Promise<{ module: unknown /** DecoderModule */ }> {\r\n const module = await ((jsModule as DracoDecoderModule) || DracoDecoderModule)({ wasmBinary });\r\n return { module };\r\n }\r\n\r\n protected override _getWorkerContent(): string {\r\n return `${DecodeMesh}(${DecoderWorkerFunction})()`;\r\n }\r\n\r\n /**\r\n * Creates a new Draco decoder.\r\n * @param configuration Optional override of the configuration for the DracoDecoder. If not provided, defaults to {@link DracoDecoder.DefaultConfiguration}.\r\n */\r\n constructor(configuration: IDracoCodecConfiguration = DracoDecoder.DefaultConfiguration) {\r\n super(configuration);\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to mesh data.\r\n * @param data The ArrayBuffer or ArrayBufferView of the compressed Draco data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @param gltfNormalizedOverride A map of attributes from vertex buffer kinds to normalized flags to override the Draco normalization\r\n * @returns A promise that resolves with the decoded mesh data\r\n */\r\n // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n public decodeMeshToMeshDataAsync(\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes?: { [kind: string]: number },\r\n gltfNormalizedOverride?: { [kind: string]: boolean }\r\n ): Promise<MeshData> {\r\n const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);\r\n\r\n const applyGltfNormalizedOverride = (kind: string, normalized: boolean): boolean => {\r\n if (gltfNormalizedOverride && gltfNormalizedOverride[kind] !== undefined) {\r\n if (normalized !== gltfNormalizedOverride[kind]) {\r\n Logger.Warn(\r\n `Normalized flag from Draco data (${normalized}) does not match normalized flag from glTF accessor (${gltfNormalizedOverride[kind]}). Using flag from glTF accessor.`\r\n );\r\n }\r\n\r\n return gltfNormalizedOverride[kind];\r\n } else {\r\n return normalized;\r\n }\r\n };\r\n\r\n if (this._workerPoolPromise) {\r\n // eslint-disable-next-line github/no-then\r\n return this._workerPoolPromise.then(async (workerPool) => {\r\n return await new Promise<MeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<IAttributeData> = [];\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (event: MessageEvent<DecoderMessage>) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"indices\": {\r\n resultIndices = message.data;\r\n break;\r\n }\r\n case \"attribute\": {\r\n resultAttributes.push({\r\n kind: message.kind,\r\n data: message.data,\r\n size: message.size,\r\n byteOffset: message.byteOffset,\r\n byteStride: message.byteStride,\r\n normalized: applyGltfNormalizedOverride(message.kind, message.normalized),\r\n });\r\n break;\r\n }\r\n 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 }\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._modulePromise) {\r\n // eslint-disable-next-line github/no-then\r\n return this._modulePromise.then((decoder) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<IAttributeData> = [];\r\n\r\n const numPoints = DecodeMesh(\r\n decoder.module,\r\n dataView,\r\n attributes,\r\n (indices) => {\r\n resultIndices = indices;\r\n },\r\n (kind, data, size, byteOffset, byteStride, normalized) => {\r\n resultAttributes.push({\r\n kind,\r\n data,\r\n size,\r\n byteOffset,\r\n byteStride,\r\n normalized,\r\n });\r\n }\r\n );\r\n\r\n return { indices: resultIndices!, attributes: resultAttributes, totalVertices: numPoints };\r\n });\r\n }\r\n\r\n throw new Error(\"Draco: Decoder module is not available\");\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon geometry.\r\n * @param name The name to use when creating the geometry\r\n * @param scene The scene to use when creating the geometry\r\n * @param data The ArrayBuffer or ArrayBufferView of the Draco compressed data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded geometry\r\n */\r\n public async decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /** @internal */\r\n public async _decodeMeshToGeometryForGltfAsync(\r\n name: string,\r\n scene: Scene,\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes: { [kind: string]: number },\r\n gltfNormalizedOverride: { [kind: string]: boolean },\r\n boundingInfo: Nullable<BoundingInfo>\r\n ): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes, gltfNormalizedOverride);\r\n const geometry = new Geometry(name, scene);\r\n if (boundingInfo) {\r\n geometry._boundingInfo = boundingInfo;\r\n geometry.useBoundingInfoFromGeometry = true;\r\n }\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n}\r\n"]}
@@ -19,31 +19,42 @@ export interface MeshData {
19
19
  * @internal
20
20
  */
21
21
  export interface IAttributeData {
22
+ /** @internal */
22
23
  kind: string;
24
+ /** @internal */
23
25
  data: ArrayBufferView;
26
+ /** @internal */
24
27
  size: number;
28
+ /** @internal */
25
29
  byteOffset: number;
30
+ /** @internal */
26
31
  byteStride: number;
32
+ /** @internal */
27
33
  normalized: boolean;
28
34
  }
29
35
  /**
30
36
  * @internal
31
37
  */
32
38
  export interface IDecodeMeshDoneMessage {
39
+ /** @internal */
33
40
  id: "decodeMeshDone";
41
+ /** @internal */
34
42
  totalVertices: number;
35
43
  }
36
44
  /**
37
45
  * @internal
38
46
  */
39
47
  export interface IIndicesMessage {
48
+ /** @internal */
40
49
  id: "indices";
50
+ /** @internal */
41
51
  data: Uint16Array | Uint32Array;
42
52
  }
43
53
  /**
44
54
  * @internal
45
55
  */
46
56
  export interface IAttributeMessage extends IAttributeData {
57
+ /** @internal */
47
58
  id: "attribute";
48
59
  }
49
60
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"dracoDecoder.types.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoDecoder.types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Decoded Draco mesh data.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface MeshData {\n /**\n * The indices of the mesh. Point clouds will not have indices.\n */\n indices?: Uint16Array | Uint32Array;\n /**\n * The attributes of the mesh.\n */\n attributes: Array<IAttributeData>;\n /**\n * The total number of vertices in the mesh.\n */\n totalVertices: number;\n}\n\n/**\n * @internal\n */\nexport interface IAttributeData {\n kind: string;\n data: ArrayBufferView;\n size: number;\n byteOffset: number;\n byteStride: number;\n normalized: boolean;\n}\n\n/**\n * @internal\n */\nexport interface IDecodeMeshDoneMessage {\n id: \"decodeMeshDone\";\n totalVertices: number;\n}\n\n/**\n * @internal\n */\nexport interface IIndicesMessage {\n id: \"indices\";\n data: Uint16Array | Uint32Array;\n}\n\n/**\n * @internal\n */\nexport interface IAttributeMessage extends IAttributeData {\n id: \"attribute\";\n}\n\n/**\n * @internal\n */\nexport type DecoderMessage = IDecodeMeshDoneMessage | IIndicesMessage | IAttributeMessage;\n"]}
1
+ {"version":3,"file":"dracoDecoder.types.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoDecoder.types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Decoded Draco mesh data.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface MeshData {\n /**\n * The indices of the mesh. Point clouds will not have indices.\n */\n indices?: Uint16Array | Uint32Array;\n /**\n * The attributes of the mesh.\n */\n attributes: Array<IAttributeData>;\n /**\n * The total number of vertices in the mesh.\n */\n totalVertices: number;\n}\n\n/**\n * @internal\n */\nexport interface IAttributeData {\n /** @internal */\n kind: string;\n /** @internal */\n data: ArrayBufferView;\n /** @internal */\n size: number;\n /** @internal */\n byteOffset: number;\n /** @internal */\n byteStride: number;\n /** @internal */\n normalized: boolean;\n}\n\n/**\n * @internal\n */\nexport interface IDecodeMeshDoneMessage {\n /** @internal */\n id: \"decodeMeshDone\";\n /** @internal */\n totalVertices: number;\n}\n\n/**\n * @internal\n */\nexport interface IIndicesMessage {\n /** @internal */\n id: \"indices\";\n /** @internal */\n data: Uint16Array | Uint32Array;\n}\n\n/**\n * @internal\n */\nexport interface IAttributeMessage extends IAttributeData {\n /** @internal */\n id: \"attribute\";\n}\n\n/**\n * @internal\n */\nexport type DecoderMessage = IDecodeMeshDoneMessage | IIndicesMessage | IAttributeMessage;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"dracoEncoder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoEncoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,UAAU,EAAiC,MAAM,cAAc,CAAC;AAEpG,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,qCAAiC;AAQ/E;;;GAGG;AACH,SAAS,qBAAqB,CAAC,IAAY;IACvC,IAAI,IAAI,KAAK,YAAY,CAAC,YAAY,EAAE,CAAC;QACrC,OAAO,UAAU,CAAC;IACtB,CAAC;SAAM,IAAI,IAAI,KAAK,YAAY,CAAC,UAAU,EAAE,CAAC;QAC1C,OAAO,QAAQ,CAAC;IACpB,CAAC;SAAM,IAAI,IAAI,KAAK,YAAY,CAAC,SAAS,EAAE,CAAC;QACzC,OAAO,OAAO,CAAC;IACnB,CAAC;SAAM,IAAI,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9C,OAAO,WAAW,CAAC;IACvB,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAED;;;;;GAKG;AACH,SAAS,sBAAsB,CAAC,KAAsB;IA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C,CAAC;QAC1E,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC9D,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,eAAe,CAAC,KAAsB,EAAE,OAA8B;QAC/E,MAAM,aAAa,GAAG,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC/C,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACvE,CAAC;QAED,kCAAkC;QAClC,IAAI,KAAK,YAAY,IAAI,IAAI,KAAK,CAAC,kBAAkB,IAAI,OAAO,EAAE,MAAM,KAAK,2BAA2B,EAAE,CAAC;YACvG,MAAM,CAAC,IAAI,CAAC,sGAAsG,CAAC,CAAC;YACpH,OAAO,CAAC,MAAM,GAAG,0BAA0B,CAAC;QAChD,CAAC;QAED,MAAM,OAAO,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC;QAC9C,MAAM,UAAU,GAAG,yBAAyB,CAAC,KAAK,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC;QAEjF,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACjE,CAAC;;AApJD;;;;;;GAMG;AACW,iCAAoB,GAA6B;IAC3D,OAAO,EAAE,GAAG,KAAK,CAAC,cAAc,gCAAgC;IAChE,aAAa,EAAE,GAAG,KAAK,CAAC,cAAc,qBAAqB;IAC3D,WAAW,EAAE,GAAG,KAAK,CAAC,cAAc,mBAAmB;CAC1D,CAAC;AASe,qBAAQ,GAA2B,IAAI,CAAC","sourcesContent":["import { _IsConfigurationAvailable, DracoCodec, type IDracoCodecConfiguration } from \"./dracoCodec\";\r\nimport type { EncoderMessage, IDracoAttributeData, IDracoEncodedMeshData, IDracoEncoderOptions, DracoAttributeName } from \"./dracoEncoder.types\";\r\nimport { EncodeMesh, EncoderWorkerFunction } from \"./dracoCompressionWorker\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Mesh } from \"../mesh\";\r\nimport type { Geometry } from \"../geometry\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { deepMerge } from \"../../Misc/deepMerger\";\r\nimport type { EncoderModule } from \"draco3d\";\r\nimport { AreIndices32Bits, GetTypedArrayData } from \"core/Buffers/bufferUtils\";\r\n\r\n// Missing type from types/draco3d. Do not use in public scope; UMD tests will fail because of EncoderModule.\r\ntype DracoEncoderModule = (props: { wasmBinary?: ArrayBuffer }) => Promise<EncoderModule>;\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoEncoderModule: DracoEncoderModule;\r\n\r\n/**\r\n * Map the Babylon.js attribute kind to the Draco attribute kind, defined by the `GeometryAttributeType` enum.\r\n * @internal\r\n */\r\nfunction GetDracoAttributeName(kind: string): DracoAttributeName {\r\n if (kind === VertexBuffer.PositionKind) {\r\n return \"POSITION\";\r\n } else if (kind === VertexBuffer.NormalKind) {\r\n return \"NORMAL\";\r\n } else if (kind === VertexBuffer.ColorKind) {\r\n return \"COLOR\";\r\n } else if (kind.startsWith(VertexBuffer.UVKind)) {\r\n return \"TEX_COORD\";\r\n }\r\n return \"GENERIC\";\r\n}\r\n\r\n/**\r\n * Get the indices for the geometry, if present. Eventually used as\r\n * `AddFacesToMesh(mesh: Mesh, numFaces: number, faces: Uint16Array | Uint32Array)`;\r\n * where `numFaces = indices.length / 3` and `faces = indices`.\r\n * @internal\r\n */\r\nfunction PrepareIndicesForDraco(input: Mesh | Geometry): Nullable<Uint32Array | Uint16Array> {\r\n let indices = input.getIndices(undefined, true);\r\n\r\n // Convert number[] and Int32Array types, if needed\r\n if (indices && !(indices instanceof Uint32Array) && !(indices instanceof Uint16Array)) {\r\n indices = (AreIndices32Bits(indices, indices.length) ? Uint32Array : Uint16Array).from(indices);\r\n }\r\n\r\n return indices;\r\n}\r\n\r\n/**\r\n * Get relevant information about the geometry's vertex attributes for Draco encoding. Eventually used for each attribute as\r\n * `AddFloatAttribute(mesh: Mesh, attribute: number, count: number, itemSize: number, array: TypedArray)`\r\n * where `attribute = EncoderModule[<dracoAttribute>]`, `itemSize = <size>`, `array = <data>`, and count is the number of position vertices.\r\n * @internal\r\n */\r\nfunction PrepareAttributesForDraco(input: Mesh | Geometry, excludedAttributes?: string[]): Array<IDracoAttributeData> {\r\n const attributes: Array<IDracoAttributeData> = [];\r\n\r\n for (const kind of input.getVerticesDataKinds()) {\r\n if (excludedAttributes?.includes(kind)) {\r\n if (kind === VertexBuffer.PositionKind) {\r\n throw new Error(\"Draco: Cannot exclude position attribute from encoding.\");\r\n }\r\n continue;\r\n }\r\n\r\n // Convert number[] to typed array, if needed.\r\n const vertexBuffer = input.getVertexBuffer(kind)!;\r\n const size = vertexBuffer.getSize();\r\n const data = GetTypedArrayData(vertexBuffer.getData()!, size, vertexBuffer.type, vertexBuffer.byteOffset, vertexBuffer.byteStride, input.getTotalVertices(), true);\r\n attributes.push({ kind: kind, dracoName: GetDracoAttributeName(kind), size: size, data: data });\r\n }\r\n\r\n return attributes;\r\n}\r\n\r\nconst DefaultEncoderOptions: IDracoEncoderOptions = {\r\n decodeSpeed: 5,\r\n encodeSpeed: 5,\r\n method: \"MESH_EDGEBREAKER_ENCODING\",\r\n quantizationBits: {\r\n POSITION: 14,\r\n NORMAL: 10,\r\n COLOR: 8,\r\n TEX_COORD: 12,\r\n GENERIC: 12,\r\n },\r\n};\r\n\r\n/**\r\n * @experimental This class is subject to change.\r\n *\r\n * Draco Encoder (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco encoder module.\r\n *\r\n * By default, the configuration points to a copy of the Draco encoder files from the Babylon.js cdn https://cdn.babylonjs.com/draco_encoder_wasm_wrapper.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoEncoder.DefaultConfiguration = {\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 * Draco has two versions, one for WebAssembly and one for JavaScript. The encoder 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 `DracoEncoder.DefaultAvailable` to determine if the encoder configuration is available for the current context.\r\n *\r\n * To encode Draco compressed data, get the default DracoEncoder object and call encodeMeshAsync:\r\n * ```javascript\r\n * var dracoData = await DracoEncoder.Default.encodeMeshAsync(mesh);\r\n * ```\r\n *\r\n * Currently, DracoEncoder only encodes to meshes. Encoding to point clouds is not yet supported.\r\n *\r\n * Only position, normal, color, and UV attributes are supported natively by the encoder. All other attributes are treated as generic. This means that,\r\n * when decoding these generic attributes later, additional information about their original Babylon types will be needed to interpret the data correctly.\r\n * You can use the return value of `encodeMeshAsync` to source this information, specifically the `attributes` field. E.g.,\r\n * ```javascript\r\n * var dracoData = await DracoEncoder.Default.encodeMeshAsync(mesh);\r\n * var meshData = await DracoDecoder.Default.decodeMeshToMeshDataAsync(dracoData.data, dracoData.attributes);\r\n * ```\r\n *\r\n * By default, DracoEncoder will encode all available attributes of the mesh. To exclude specific attributes, use the following code:\r\n * ```javascript\r\n * var options = { excludedAttributes: [VertexBuffer.MatricesIndicesKind, VertexBuffer.MatricesWeightsKind] };\r\n * var dracoData = await DracoDecoder.Default.encodeMeshAsync(mesh, options);\r\n * ```\r\n */\r\nexport class DracoEncoder extends DracoCodec {\r\n /**\r\n * Default configuration for the DracoEncoder. Defaults to the following:\r\n * - numWorkers: 50% of the available logical processors, capped to 4. If no logical processors are available, defaults to 1.\r\n * - wasmUrl: `\"https://cdn.babylonjs.com/draco_encoder_wasm_wrapper.js\"`\r\n * - wasmBinaryUrl: `\"https://cdn.babylonjs.com/draco_encoder.wasm\"`\r\n * - fallbackUrl: `\"https://cdn.babylonjs.com/draco_encoder.js\"`\r\n */\r\n public static DefaultConfiguration: IDracoCodecConfiguration = {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_encoder_wasm_wrapper.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_encoder.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_encoder.js`,\r\n };\r\n\r\n /**\r\n * Returns true if the encoder's `DefaultConfiguration` is available.\r\n */\r\n public static get DefaultAvailable(): boolean {\r\n return _IsConfigurationAvailable(DracoEncoder.DefaultConfiguration);\r\n }\r\n\r\n protected static _Default: Nullable<DracoEncoder> = null;\r\n /**\r\n * Default instance for the DracoEncoder.\r\n */\r\n public static get Default(): DracoEncoder {\r\n DracoEncoder._Default ??= new DracoEncoder();\r\n return DracoEncoder._Default;\r\n }\r\n\r\n /**\r\n * Reset the default DracoEncoder object to null and disposing the removed default instance.\r\n * Note that if the workerPool is a member of the static DefaultConfiguration object it is recommended not to run dispose,\r\n * unless the static worker pool is no longer needed.\r\n * @param skipDispose set to true to not dispose the removed default instance\r\n */\r\n public static ResetDefault(skipDispose?: boolean): void {\r\n if (DracoEncoder._Default) {\r\n if (!skipDispose) {\r\n DracoEncoder._Default.dispose();\r\n }\r\n DracoEncoder._Default = null;\r\n }\r\n }\r\n\r\n protected override _isModuleAvailable(): boolean {\r\n return typeof DracoEncoderModule !== \"undefined\";\r\n }\r\n\r\n protected override async _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: unknown /** DracoEncoderModule */): Promise<{ module: unknown /** EncoderModule */ }> {\r\n const module = await ((jsModule as DracoEncoderModule) || DracoEncoderModule)({ wasmBinary });\r\n return { module };\r\n }\r\n\r\n protected override _getWorkerContent(): string {\r\n return `${EncodeMesh}(${EncoderWorkerFunction})()`;\r\n }\r\n\r\n /**\r\n * Creates a new Draco encoder.\r\n * @param configuration Optional override of the configuration for the DracoEncoder. If not provided, defaults to {@link DracoEncoder.DefaultConfiguration}.\r\n */\r\n constructor(configuration: IDracoCodecConfiguration = DracoEncoder.DefaultConfiguration) {\r\n super(configuration);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public async _encodeAsync(\r\n attributes: Array<IDracoAttributeData>,\r\n indices: Nullable<Uint16Array | Uint32Array>,\r\n options?: IDracoEncoderOptions\r\n ): Promise<IDracoEncodedMeshData> {\r\n const mergedOptions = options ? deepMerge(DefaultEncoderOptions, options) : DefaultEncoderOptions;\r\n\r\n if (this._workerPoolPromise) {\r\n const workerPool = await this._workerPoolPromise;\r\n return await new Promise<IDracoEncodedMeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (message: MessageEvent<EncoderMessage>) => {\r\n if (message.data.id === \"encodeMeshSuccess\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(message.data.encodedMeshData);\r\n onComplete();\r\n } else if (message.data.id === \"encodeMeshError\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(new Error(message.data.errorMessage));\r\n onComplete();\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n // Build the transfer list. No need to copy, as the data was copied in previous steps.\r\n const transferList = [];\r\n for (const attribute of attributes) {\r\n transferList.push(attribute.data.buffer);\r\n }\r\n if (indices) {\r\n transferList.push(indices.buffer);\r\n }\r\n\r\n worker.postMessage({ id: \"encodeMesh\", attributes: attributes, indices: indices, options: mergedOptions }, transferList);\r\n });\r\n });\r\n }\r\n\r\n if (this._modulePromise) {\r\n const encoder = await this._modulePromise;\r\n return EncodeMesh(encoder.module, attributes, indices, mergedOptions);\r\n }\r\n\r\n throw new Error(\"Draco: Encoder module is not available\");\r\n }\r\n\r\n /**\r\n * Encodes a mesh or geometry into a Draco-encoded mesh data.\r\n * @param input the mesh or geometry to encode\r\n * @param options options for the encoding\r\n * @returns a promise that resolves to the newly-encoded data\r\n */\r\n public async encodeMeshAsync(input: Mesh | Geometry, options?: IDracoEncoderOptions): Promise<IDracoEncodedMeshData> {\r\n const verticesCount = input.getTotalVertices();\r\n if (verticesCount == 0) {\r\n throw new Error(\"Draco: Cannot encode geometry with no vertices.\");\r\n }\r\n\r\n // Prepare parameters for encoding\r\n if (input instanceof Mesh && input.morphTargetManager && options?.method === \"MESH_EDGEBREAKER_ENCODING\") {\r\n Logger.Warn(\"Draco: Cannot use EDGEBREAKER encoding method with morph targets. Falling back to SEQUENTIAL method.\");\r\n options.method = \"MESH_SEQUENTIAL_ENCODING\";\r\n }\r\n\r\n const indices = PrepareIndicesForDraco(input);\r\n const attributes = PrepareAttributesForDraco(input, options?.excludedAttributes);\r\n\r\n return await this._encodeAsync(attributes, indices, options);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"dracoEncoder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoEncoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,UAAU,EAAiC,MAAM,cAAc,CAAC;AAEpG,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,qCAAiC;AAO/E;;;GAGG;AACH,SAAS,qBAAqB,CAAC,IAAY;IACv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jE,CAAC;;AApJD;;;;;;GAMG;AACW,iCAAoB,GAA6B;IAC3D,OAAO,EAAE,GAAG,KAAK,CAAC,cAAc,gCAAgC;IAChE,aAAa,EAAE,GAAG,KAAK,CAAC,cAAc,qBAAqB;IAC3D,WAAW,EAAE,GAAG,KAAK,CAAC,cAAc,mBAAmB;CAC1D,CAAC;AASe,qBAAQ,GAA2B,IAAI,CAAC","sourcesContent":["import { _IsConfigurationAvailable, DracoCodec, type IDracoCodecConfiguration } from \"./dracoCodec\";\r\nimport type { EncoderMessage, IDracoAttributeData, IDracoEncodedMeshData, IDracoEncoderOptions, DracoAttributeName } from \"./dracoEncoder.types\";\r\nimport { EncodeMesh, EncoderWorkerFunction } from \"./dracoCompressionWorker\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Mesh } from \"../mesh\";\r\nimport type { Geometry } from \"../geometry\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { deepMerge } from \"../../Misc/deepMerger\";\r\nimport type { EncoderModule } from \"draco3d\";\r\nimport { AreIndices32Bits, GetTypedArrayData } from \"core/Buffers/bufferUtils\";\r\n\r\n// Missing type from types/draco3d. Do not use in public scope; UMD tests will fail because of EncoderModule.\r\ntype DracoEncoderModule = (props: { wasmBinary?: ArrayBuffer }) => Promise<EncoderModule>;\r\n\r\ndeclare let DracoEncoderModule: DracoEncoderModule;\r\n\r\n/**\r\n * Map the Babylon.js attribute kind to the Draco attribute kind, defined by the `GeometryAttributeType` enum.\r\n * @internal\r\n */\r\nfunction GetDracoAttributeName(kind: string): DracoAttributeName {\r\n if (kind === VertexBuffer.PositionKind) {\r\n return \"POSITION\";\r\n } else if (kind === VertexBuffer.NormalKind) {\r\n return \"NORMAL\";\r\n } else if (kind === VertexBuffer.ColorKind) {\r\n return \"COLOR\";\r\n } else if (kind.startsWith(VertexBuffer.UVKind)) {\r\n return \"TEX_COORD\";\r\n }\r\n return \"GENERIC\";\r\n}\r\n\r\n/**\r\n * Get the indices for the geometry, if present. Eventually used as\r\n * `AddFacesToMesh(mesh: Mesh, numFaces: number, faces: Uint16Array | Uint32Array)`;\r\n * where `numFaces = indices.length / 3` and `faces = indices`.\r\n * @internal\r\n */\r\nfunction PrepareIndicesForDraco(input: Mesh | Geometry): Nullable<Uint32Array | Uint16Array> {\r\n let indices = input.getIndices(undefined, true);\r\n\r\n // Convert number[] and Int32Array types, if needed\r\n if (indices && !(indices instanceof Uint32Array) && !(indices instanceof Uint16Array)) {\r\n indices = (AreIndices32Bits(indices, indices.length) ? Uint32Array : Uint16Array).from(indices);\r\n }\r\n\r\n return indices;\r\n}\r\n\r\n/**\r\n * Get relevant information about the geometry's vertex attributes for Draco encoding. Eventually used for each attribute as\r\n * `AddFloatAttribute(mesh: Mesh, attribute: number, count: number, itemSize: number, array: TypedArray)`\r\n * where `attribute = EncoderModule[<dracoAttribute>]`, `itemSize = <size>`, `array = <data>`, and count is the number of position vertices.\r\n * @internal\r\n */\r\nfunction PrepareAttributesForDraco(input: Mesh | Geometry, excludedAttributes?: string[]): Array<IDracoAttributeData> {\r\n const attributes: Array<IDracoAttributeData> = [];\r\n\r\n for (const kind of input.getVerticesDataKinds()) {\r\n if (excludedAttributes?.includes(kind)) {\r\n if (kind === VertexBuffer.PositionKind) {\r\n throw new Error(\"Draco: Cannot exclude position attribute from encoding.\");\r\n }\r\n continue;\r\n }\r\n\r\n // Convert number[] to typed array, if needed.\r\n const vertexBuffer = input.getVertexBuffer(kind)!;\r\n const size = vertexBuffer.getSize();\r\n const data = GetTypedArrayData(vertexBuffer.getData()!, size, vertexBuffer.type, vertexBuffer.byteOffset, vertexBuffer.byteStride, input.getTotalVertices(), true);\r\n attributes.push({ kind: kind, dracoName: GetDracoAttributeName(kind), size: size, data: data });\r\n }\r\n\r\n return attributes;\r\n}\r\n\r\nconst DefaultEncoderOptions: IDracoEncoderOptions = {\r\n decodeSpeed: 5,\r\n encodeSpeed: 5,\r\n method: \"MESH_EDGEBREAKER_ENCODING\",\r\n quantizationBits: {\r\n POSITION: 14,\r\n NORMAL: 10,\r\n COLOR: 8,\r\n TEX_COORD: 12,\r\n GENERIC: 12,\r\n },\r\n};\r\n\r\n/**\r\n * @experimental This class is subject to change.\r\n *\r\n * Draco Encoder (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco encoder module.\r\n *\r\n * By default, the configuration points to a copy of the Draco encoder files from the Babylon.js cdn https://cdn.babylonjs.com/draco_encoder_wasm_wrapper.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoEncoder.DefaultConfiguration = {\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 * Draco has two versions, one for WebAssembly and one for JavaScript. The encoder 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 `DracoEncoder.DefaultAvailable` to determine if the encoder configuration is available for the current context.\r\n *\r\n * To encode Draco compressed data, get the default DracoEncoder object and call encodeMeshAsync:\r\n * ```javascript\r\n * var dracoData = await DracoEncoder.Default.encodeMeshAsync(mesh);\r\n * ```\r\n *\r\n * Currently, DracoEncoder only encodes to meshes. Encoding to point clouds is not yet supported.\r\n *\r\n * Only position, normal, color, and UV attributes are supported natively by the encoder. All other attributes are treated as generic. This means that,\r\n * when decoding these generic attributes later, additional information about their original Babylon types will be needed to interpret the data correctly.\r\n * You can use the return value of `encodeMeshAsync` to source this information, specifically the `attributes` field. E.g.,\r\n * ```javascript\r\n * var dracoData = await DracoEncoder.Default.encodeMeshAsync(mesh);\r\n * var meshData = await DracoDecoder.Default.decodeMeshToMeshDataAsync(dracoData.data, dracoData.attributes);\r\n * ```\r\n *\r\n * By default, DracoEncoder will encode all available attributes of the mesh. To exclude specific attributes, use the following code:\r\n * ```javascript\r\n * var options = { excludedAttributes: [VertexBuffer.MatricesIndicesKind, VertexBuffer.MatricesWeightsKind] };\r\n * var dracoData = await DracoDecoder.Default.encodeMeshAsync(mesh, options);\r\n * ```\r\n */\r\nexport class DracoEncoder extends DracoCodec {\r\n /**\r\n * Default configuration for the DracoEncoder. Defaults to the following:\r\n * - numWorkers: 50% of the available logical processors, capped to 4. If no logical processors are available, defaults to 1.\r\n * - wasmUrl: `\"https://cdn.babylonjs.com/draco_encoder_wasm_wrapper.js\"`\r\n * - wasmBinaryUrl: `\"https://cdn.babylonjs.com/draco_encoder.wasm\"`\r\n * - fallbackUrl: `\"https://cdn.babylonjs.com/draco_encoder.js\"`\r\n */\r\n public static DefaultConfiguration: IDracoCodecConfiguration = {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_encoder_wasm_wrapper.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_encoder.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_encoder.js`,\r\n };\r\n\r\n /**\r\n * Returns true if the encoder's `DefaultConfiguration` is available.\r\n */\r\n public static get DefaultAvailable(): boolean {\r\n return _IsConfigurationAvailable(DracoEncoder.DefaultConfiguration);\r\n }\r\n\r\n protected static _Default: Nullable<DracoEncoder> = null;\r\n /**\r\n * Default instance for the DracoEncoder.\r\n */\r\n public static get Default(): DracoEncoder {\r\n DracoEncoder._Default ??= new DracoEncoder();\r\n return DracoEncoder._Default;\r\n }\r\n\r\n /**\r\n * Reset the default DracoEncoder object to null and disposing the removed default instance.\r\n * Note that if the workerPool is a member of the static DefaultConfiguration object it is recommended not to run dispose,\r\n * unless the static worker pool is no longer needed.\r\n * @param skipDispose set to true to not dispose the removed default instance\r\n */\r\n public static ResetDefault(skipDispose?: boolean): void {\r\n if (DracoEncoder._Default) {\r\n if (!skipDispose) {\r\n DracoEncoder._Default.dispose();\r\n }\r\n DracoEncoder._Default = null;\r\n }\r\n }\r\n\r\n protected override _isModuleAvailable(): boolean {\r\n return typeof DracoEncoderModule !== \"undefined\";\r\n }\r\n\r\n protected override async _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: unknown /** DracoEncoderModule */): Promise<{ module: unknown /** EncoderModule */ }> {\r\n const module = await ((jsModule as DracoEncoderModule) || DracoEncoderModule)({ wasmBinary });\r\n return { module };\r\n }\r\n\r\n protected override _getWorkerContent(): string {\r\n return `${EncodeMesh}(${EncoderWorkerFunction})()`;\r\n }\r\n\r\n /**\r\n * Creates a new Draco encoder.\r\n * @param configuration Optional override of the configuration for the DracoEncoder. If not provided, defaults to {@link DracoEncoder.DefaultConfiguration}.\r\n */\r\n constructor(configuration: IDracoCodecConfiguration = DracoEncoder.DefaultConfiguration) {\r\n super(configuration);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public async _encodeAsync(\r\n attributes: Array<IDracoAttributeData>,\r\n indices: Nullable<Uint16Array | Uint32Array>,\r\n options?: IDracoEncoderOptions\r\n ): Promise<IDracoEncodedMeshData> {\r\n const mergedOptions = options ? deepMerge(DefaultEncoderOptions, options) : DefaultEncoderOptions;\r\n\r\n if (this._workerPoolPromise) {\r\n const workerPool = await this._workerPoolPromise;\r\n return await new Promise<IDracoEncodedMeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (message: MessageEvent<EncoderMessage>) => {\r\n if (message.data.id === \"encodeMeshSuccess\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(message.data.encodedMeshData);\r\n onComplete();\r\n } else if (message.data.id === \"encodeMeshError\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(new Error(message.data.errorMessage));\r\n onComplete();\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n // Build the transfer list. No need to copy, as the data was copied in previous steps.\r\n const transferList = [];\r\n for (const attribute of attributes) {\r\n transferList.push(attribute.data.buffer);\r\n }\r\n if (indices) {\r\n transferList.push(indices.buffer);\r\n }\r\n\r\n worker.postMessage({ id: \"encodeMesh\", attributes: attributes, indices: indices, options: mergedOptions }, transferList);\r\n });\r\n });\r\n }\r\n\r\n if (this._modulePromise) {\r\n const encoder = await this._modulePromise;\r\n return EncodeMesh(encoder.module, attributes, indices, mergedOptions);\r\n }\r\n\r\n throw new Error(\"Draco: Encoder module is not available\");\r\n }\r\n\r\n /**\r\n * Encodes a mesh or geometry into a Draco-encoded mesh data.\r\n * @param input the mesh or geometry to encode\r\n * @param options options for the encoding\r\n * @returns a promise that resolves to the newly-encoded data\r\n */\r\n public async encodeMeshAsync(input: Mesh | Geometry, options?: IDracoEncoderOptions): Promise<IDracoEncodedMeshData> {\r\n const verticesCount = input.getTotalVertices();\r\n if (verticesCount == 0) {\r\n throw new Error(\"Draco: Cannot encode geometry with no vertices.\");\r\n }\r\n\r\n // Prepare parameters for encoding\r\n if (input instanceof Mesh && input.morphTargetManager && options?.method === \"MESH_EDGEBREAKER_ENCODING\") {\r\n Logger.Warn(\"Draco: Cannot use EDGEBREAKER encoding method with morph targets. Falling back to SEQUENTIAL method.\");\r\n options.method = \"MESH_SEQUENTIAL_ENCODING\";\r\n }\r\n\r\n const indices = PrepareIndicesForDraco(input);\r\n const attributes = PrepareAttributesForDraco(input, options?.excludedAttributes);\r\n\r\n return await this._encodeAsync(attributes, indices, options);\r\n }\r\n}\r\n"]}
@@ -1,7 +1,5 @@
1
1
  import { Tools } from "../../Misc/tools.js";
2
- // eslint-disable-next-line @typescript-eslint/naming-convention
3
2
  let NumberOfWorkers = 0;
4
- // eslint-disable-next-line @typescript-eslint/naming-convention
5
3
  let WorkerTimeout = null;
6
4
  /**
7
5
  * Meshopt compression (https://github.com/zeux/meshoptimizer)
@@ -1 +1 @@
1
- {"version":3,"file":"meshoptCompression.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/meshoptCompression.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAOzC,gEAAgE;AAChE,IAAI,eAAe,GAAG,CAAC,CAAC;AACxB,gEAAgE;AAChE,IAAI,aAAa,GAA4C,IAAI,CAAC;AAiBlE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,kBAAkB;IAmB3B;;OAEG;IACI,MAAM,KAAK,OAAO;QACrB,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,CAAC;YAC/B,kBAAkB,CAAC,QAAQ,GAAG,IAAI,kBAAkB,EAAE,CAAC;QAC3D,CAAC;QAED,OAAO,kBAAkB,CAAC,QAAQ,CAAC;IACvC,CAAC;IAED;;OAEG;IACH;QACI,MAAM,OAAO,GAAG,kBAAkB,CAAC,aAAa,CAAC,OAAO,CAAC;QAEzD,0CAA0C;QAC1C,IAAI,CAAC,qBAAqB,GAAG,KAAK,CAAC,sBAAsB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;YAC7E,4DAA4D;YAC5D,OAAO,cAAc,CAAC,KAAK,CAAC;QAChC,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACI,OAAO;QACV,OAAO,IAAI,CAAC,qBAAqB,CAAC;IACtC,CAAC;IAED;;;;;;;;;OASG;IACI,KAAK,CAAC,qBAAqB,CAAC,MAAkB,EAAE,KAAa,EAAE,MAAc,EAAE,IAA4C,EAAE,MAAe;QAC/I,MAAM,IAAI,CAAC,qBAAsB,CAAC;QAClC,IAAI,eAAe,KAAK,CAAC,EAAE,CAAC;YACxB,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC7B,eAAe,GAAG,CAAC,CAAC;QACxB,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAC/F,oGAAoG;QACpG,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;YACzB,YAAY,CAAC,aAAa,CAAC,CAAC;QAChC,CAAC;QACD,aAAa,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC7B,eAAe,GAAG,CAAC,CAAC;YACpB,aAAa,GAAG,IAAI,CAAC;QACzB,CAAC,EAAE,IAAI,CAAC,CAAC;QACT,OAAO,MAAM,CAAC;IAClB,CAAC;;AA1ED;;;;;;;GAOG;AACW,gCAAa,GAAqC;IAC5D,OAAO,EAAE;QACL,GAAG,EAAE,GAAG,KAAK,CAAC,cAAc,qBAAqB;KACpD;CACJ,CAAC;AAEa,2BAAQ,GAAiC,IAAI,CAAC","sourcesContent":["import { Tools } from \"../../Misc/tools\";\r\nimport type { IDisposable } from \"../../scene\";\r\nimport type { Nullable } from \"../../types\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let MeshoptDecoder: any;\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nlet NumberOfWorkers = 0;\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nlet WorkerTimeout: Nullable<ReturnType<typeof setTimeout>> = null;\r\n\r\n/**\r\n * Configuration for meshoptimizer compression\r\n */\r\nexport interface IMeshoptCompressionConfiguration {\r\n /**\r\n * Configuration for the decoder.\r\n */\r\n decoder: {\r\n /**\r\n * The url to the meshopt decoder library.\r\n */\r\n url: string;\r\n };\r\n}\r\n\r\n/**\r\n * Meshopt compression (https://github.com/zeux/meshoptimizer)\r\n *\r\n * This class wraps the meshopt library from https://github.com/zeux/meshoptimizer/tree/master/js.\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 meshopt files on the Babylon.js preview CDN (e.g. https://preview.babylonjs.com/meshopt_decoder.js).\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * MeshoptCompression.Configuration = {\r\n * decoder: {\r\n * url: \"<url to the meshopt decoder library>\"\r\n * }\r\n * };\r\n * ```\r\n */\r\nexport class MeshoptCompression implements IDisposable {\r\n private _decoderModulePromise?: Promise<any>;\r\n\r\n /**\r\n * The configuration. Defaults to the following:\r\n * ```javascript\r\n * decoder: {\r\n * url: \"https://cdn.babylonjs.com/meshopt_decoder.js\"\r\n * }\r\n * ```\r\n */\r\n public static Configuration: IMeshoptCompressionConfiguration = {\r\n decoder: {\r\n url: `${Tools._DefaultCdnUrl}/meshopt_decoder.js`,\r\n },\r\n };\r\n\r\n private static _Default: Nullable<MeshoptCompression> = null;\r\n\r\n /**\r\n * Default instance for the meshoptimizer object.\r\n */\r\n public static get Default(): MeshoptCompression {\r\n if (!MeshoptCompression._Default) {\r\n MeshoptCompression._Default = new MeshoptCompression();\r\n }\r\n\r\n return MeshoptCompression._Default;\r\n }\r\n\r\n /**\r\n * Constructor\r\n */\r\n constructor() {\r\n const decoder = MeshoptCompression.Configuration.decoder;\r\n\r\n // eslint-disable-next-line github/no-then\r\n this._decoderModulePromise = Tools.LoadBabylonScriptAsync(decoder.url).then(() => {\r\n // Wait for WebAssembly compilation before resolving promise\r\n return MeshoptDecoder.ready;\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 delete this._decoderModulePromise;\r\n }\r\n\r\n /**\r\n * Decode meshopt data.\r\n * @see https://github.com/zeux/meshoptimizer/tree/master/js#decoder\r\n * @param source The input data.\r\n * @param count The number of elements.\r\n * @param stride The stride in bytes.\r\n * @param mode The compression mode.\r\n * @param filter The compression filter.\r\n * @returns a Promise<Uint8Array> that resolves to the decoded data\r\n */\r\n public async decodeGltfBufferAsync(source: Uint8Array, count: number, stride: number, mode: \"ATTRIBUTES\" | \"TRIANGLES\" | \"INDICES\", filter?: string): Promise<Uint8Array> {\r\n await this._decoderModulePromise!;\r\n if (NumberOfWorkers === 0) {\r\n MeshoptDecoder.useWorkers(1);\r\n NumberOfWorkers = 1;\r\n }\r\n const result = await MeshoptDecoder.decodeGltfBufferAsync(count, stride, source, mode, filter);\r\n // a simple debounce to avoid switching back and forth between workers and no workers while decoding\r\n if (WorkerTimeout !== null) {\r\n clearTimeout(WorkerTimeout);\r\n }\r\n WorkerTimeout = setTimeout(() => {\r\n MeshoptDecoder.useWorkers(0);\r\n NumberOfWorkers = 0;\r\n WorkerTimeout = null;\r\n }, 1000);\r\n return result;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"meshoptCompression.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/meshoptCompression.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAMzC,IAAI,eAAe,GAAG,CAAC,CAAC;AACxB,IAAI,aAAa,GAA4C,IAAI,CAAC;AAiBlE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,kBAAkB;IAmB3B;;OAEG;IACI,MAAM,KAAK,OAAO;QACrB,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,CAAC;YAC/B,kBAAkB,CAAC,QAAQ,GAAG,IAAI,kBAAkB,EAAE,CAAC;QAC3D,CAAC;QAED,OAAO,kBAAkB,CAAC,QAAQ,CAAC;IACvC,CAAC;IAED;;OAEG;IACH;QACI,MAAM,OAAO,GAAG,kBAAkB,CAAC,aAAa,CAAC,OAAO,CAAC;QAEzD,0CAA0C;QAC1C,IAAI,CAAC,qBAAqB,GAAG,KAAK,CAAC,sBAAsB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;YAC7E,4DAA4D;YAC5D,OAAO,cAAc,CAAC,KAAK,CAAC;QAChC,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACI,OAAO;QACV,OAAO,IAAI,CAAC,qBAAqB,CAAC;IACtC,CAAC;IAED;;;;;;;;;OASG;IACI,KAAK,CAAC,qBAAqB,CAAC,MAAkB,EAAE,KAAa,EAAE,MAAc,EAAE,IAA4C,EAAE,MAAe;QAC/I,MAAM,IAAI,CAAC,qBAAsB,CAAC;QAClC,IAAI,eAAe,KAAK,CAAC,EAAE,CAAC;YACxB,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC7B,eAAe,GAAG,CAAC,CAAC;QACxB,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAC/F,oGAAoG;QACpG,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;YACzB,YAAY,CAAC,aAAa,CAAC,CAAC;QAChC,CAAC;QACD,aAAa,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC7B,eAAe,GAAG,CAAC,CAAC;YACpB,aAAa,GAAG,IAAI,CAAC;QACzB,CAAC,EAAE,IAAI,CAAC,CAAC;QACT,OAAO,MAAM,CAAC;IAClB,CAAC;;AA1ED;;;;;;;GAOG;AACW,gCAAa,GAAqC;IAC5D,OAAO,EAAE;QACL,GAAG,EAAE,GAAG,KAAK,CAAC,cAAc,qBAAqB;KACpD;CACJ,CAAC;AAEa,2BAAQ,GAAiC,IAAI,CAAC","sourcesContent":["import { Tools } from \"../../Misc/tools\";\r\nimport type { IDisposable } from \"../../scene\";\r\nimport type { Nullable } from \"../../types\";\r\n\r\ndeclare let MeshoptDecoder: any;\r\n\r\nlet NumberOfWorkers = 0;\r\nlet WorkerTimeout: Nullable<ReturnType<typeof setTimeout>> = null;\r\n\r\n/**\r\n * Configuration for meshoptimizer compression\r\n */\r\nexport interface IMeshoptCompressionConfiguration {\r\n /**\r\n * Configuration for the decoder.\r\n */\r\n decoder: {\r\n /**\r\n * The url to the meshopt decoder library.\r\n */\r\n url: string;\r\n };\r\n}\r\n\r\n/**\r\n * Meshopt compression (https://github.com/zeux/meshoptimizer)\r\n *\r\n * This class wraps the meshopt library from https://github.com/zeux/meshoptimizer/tree/master/js.\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 meshopt files on the Babylon.js preview CDN (e.g. https://preview.babylonjs.com/meshopt_decoder.js).\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * MeshoptCompression.Configuration = {\r\n * decoder: {\r\n * url: \"<url to the meshopt decoder library>\"\r\n * }\r\n * };\r\n * ```\r\n */\r\nexport class MeshoptCompression implements IDisposable {\r\n private _decoderModulePromise?: Promise<any>;\r\n\r\n /**\r\n * The configuration. Defaults to the following:\r\n * ```javascript\r\n * decoder: {\r\n * url: \"https://cdn.babylonjs.com/meshopt_decoder.js\"\r\n * }\r\n * ```\r\n */\r\n public static Configuration: IMeshoptCompressionConfiguration = {\r\n decoder: {\r\n url: `${Tools._DefaultCdnUrl}/meshopt_decoder.js`,\r\n },\r\n };\r\n\r\n private static _Default: Nullable<MeshoptCompression> = null;\r\n\r\n /**\r\n * Default instance for the meshoptimizer object.\r\n */\r\n public static get Default(): MeshoptCompression {\r\n if (!MeshoptCompression._Default) {\r\n MeshoptCompression._Default = new MeshoptCompression();\r\n }\r\n\r\n return MeshoptCompression._Default;\r\n }\r\n\r\n /**\r\n * Constructor\r\n */\r\n constructor() {\r\n const decoder = MeshoptCompression.Configuration.decoder;\r\n\r\n // eslint-disable-next-line github/no-then\r\n this._decoderModulePromise = Tools.LoadBabylonScriptAsync(decoder.url).then(() => {\r\n // Wait for WebAssembly compilation before resolving promise\r\n return MeshoptDecoder.ready;\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 delete this._decoderModulePromise;\r\n }\r\n\r\n /**\r\n * Decode meshopt data.\r\n * @see https://github.com/zeux/meshoptimizer/tree/master/js#decoder\r\n * @param source The input data.\r\n * @param count The number of elements.\r\n * @param stride The stride in bytes.\r\n * @param mode The compression mode.\r\n * @param filter The compression filter.\r\n * @returns a Promise<Uint8Array> that resolves to the decoded data\r\n */\r\n public async decodeGltfBufferAsync(source: Uint8Array, count: number, stride: number, mode: \"ATTRIBUTES\" | \"TRIANGLES\" | \"INDICES\", filter?: string): Promise<Uint8Array> {\r\n await this._decoderModulePromise!;\r\n if (NumberOfWorkers === 0) {\r\n MeshoptDecoder.useWorkers(1);\r\n NumberOfWorkers = 1;\r\n }\r\n const result = await MeshoptDecoder.decodeGltfBufferAsync(count, stride, source, mode, filter);\r\n // a simple debounce to avoid switching back and forth between workers and no workers while decoding\r\n if (WorkerTimeout !== null) {\r\n clearTimeout(WorkerTimeout);\r\n }\r\n WorkerTimeout = setTimeout(() => {\r\n MeshoptDecoder.useWorkers(0);\r\n NumberOfWorkers = 0;\r\n WorkerTimeout = null;\r\n }, 1000);\r\n return result;\r\n }\r\n}\r\n"]}
@@ -23,7 +23,6 @@ export class GreasedLineRibbonMesh extends GreasedLineBaseMesh {
23
23
  super(name, scene, _options);
24
24
  this.name = name;
25
25
  if (!_options.ribbonOptions) {
26
- // eslint-disable-next-line no-throw-literal
27
26
  throw "'GreasedLineMeshOptions.ribbonOptions' is not set.";
28
27
  }
29
28
  this._paths = [];
@@ -44,7 +43,6 @@ export class GreasedLineRibbonMesh extends GreasedLineBaseMesh {
44
43
  */
45
44
  addPoints(points, options, hasPathOptions = false) {
46
45
  if (!options.ribbonOptions) {
47
- // eslint-disable-next-line no-throw-literal
48
46
  throw "addPoints() on GreasedLineRibbonMesh instance requires 'GreasedLineMeshOptions.ribbonOptions'.";
49
47
  }
50
48
  if (!hasPathOptions) {
@@ -110,7 +108,6 @@ export class GreasedLineRibbonMesh extends GreasedLineBaseMesh {
110
108
  }
111
109
  _setPoints(points, _options) {
112
110
  if (!this._options.ribbonOptions) {
113
- // eslint-disable-next-line no-throw-literal
114
111
  throw "No 'GreasedLineMeshOptions.ribbonOptions' provided.";
115
112
  }
116
113
  this._points = points;
@@ -128,7 +125,6 @@ export class GreasedLineRibbonMesh extends GreasedLineBaseMesh {
128
125
  else {
129
126
  if (pathOptions.ribbonOptions?.directionsAutoMode === 99 /* GreasedLineRibbonAutoDirectionMode.AUTO_DIRECTIONS_NONE */) {
130
127
  if (!pathOptions.ribbonOptions.directions) {
131
- // eslint-disable-next-line no-throw-literal
132
128
  throw "In GreasedLineRibbonAutoDirectionMode.AUTO_DIRECTIONS_NONE 'GreasedLineMeshOptions.ribbonOptions.directions' must be defined.";
133
129
  }
134
130
  directionPlanes = GreasedLineRibbonMesh._GetDirectionPlanesFromDirectionsOption(subPoints.length, pathOptions.ribbonOptions.directions);
@@ -154,7 +150,6 @@ export class GreasedLineRibbonMesh extends GreasedLineBaseMesh {
154
150
  static _CreateRibbonVertexData(pathArray, options) {
155
151
  const numOfPaths = pathArray.length;
156
152
  if (numOfPaths < 2) {
157
- // eslint-disable-next-line no-throw-literal
158
153
  throw "Minimum of two paths are required to create a GreasedLineRibbonMesh.";
159
154
  }
160
155
  const positions = [];
@@ -221,7 +216,6 @@ export class GreasedLineRibbonMesh extends GreasedLineBaseMesh {
221
216
  const ribbonVertexData = GreasedLineRibbonMesh._CreateRibbonVertexData(pathArray, options);
222
217
  const positions = ribbonVertexData.positions;
223
218
  if (!this._options.widths) {
224
- // eslint-disable-next-line no-throw-literal
225
219
  throw "No 'GreasedLineMeshOptions.widths' table is specified.";
226
220
  }
227
221
  const vertexPositions = Array.isArray(this._vertexPositions) ? this._vertexPositions : Array.from(this._vertexPositions);
@@ -280,7 +274,6 @@ export class GreasedLineRibbonMesh extends GreasedLineBaseMesh {
280
274
  }
281
275
  static _ConvertToRibbonPath(points, ribbonInfo, rightHandedSystem, directionPlane) {
282
276
  if (ribbonInfo.pointsMode === 0 /* GreasedLineRibbonPointsMode.POINTS_MODE_POINTS */ && !ribbonInfo.width) {
283
- // eslint-disable-next-line no-throw-literal
284
277
  throw "'GreasedLineMeshOptions.ribbonOptiosn.width' must be specified in GreasedLineRibbonPointsMode.POINTS_MODE_POINTS.";
285
278
  }
286
279
  const path1 = [];
@@ -295,7 +288,6 @@ export class GreasedLineRibbonMesh extends GreasedLineBaseMesh {
295
288
  directionPlane = GreasedLineRibbonMesh._GetDirectionFromPoints(pointVectors[0], pointVectors[1], null);
296
289
  }
297
290
  if (ribbonInfo.directionsAutoMode === 3 /* GreasedLineRibbonAutoDirectionMode.AUTO_DIRECTIONS_FACE_TO */ && !(ribbonInfo.directions instanceof Vector3)) {
298
- // eslint-disable-next-line no-throw-literal
299
291
  throw "In GreasedLineRibbonAutoDirectionMode.AUTO_DIRECTIONS_FACE_TO 'GreasedLineMeshOptions.ribbonOptions.directions' must be a Vector3.";
300
292
  }
301
293
  TmpVectors.Vector3[1] = ribbonInfo.directions instanceof Vector3 ? ribbonInfo.directions : GreasedLineRibbonMesh.DIRECTION_XZ;