@babylonjs/core 6.19.0 → 6.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/Actions/actionManager.js +2 -2
  2. package/Actions/actionManager.js.map +1 -1
  3. package/Animations/runtimeAnimation.js +2 -2
  4. package/Animations/runtimeAnimation.js.map +1 -1
  5. package/Cameras/Inputs/BaseCameraPointersInput.d.ts +4 -4
  6. package/Cameras/Inputs/BaseCameraPointersInput.js +4 -6
  7. package/Cameras/Inputs/BaseCameraPointersInput.js.map +1 -1
  8. package/Cameras/Inputs/arcRotateCameraPointersInput.d.ts +3 -2
  9. package/Cameras/Inputs/arcRotateCameraPointersInput.js +3 -2
  10. package/Cameras/Inputs/arcRotateCameraPointersInput.js.map +1 -1
  11. package/Cameras/Inputs/flyCameraMouseInput.js +2 -7
  12. package/Cameras/Inputs/flyCameraMouseInput.js.map +1 -1
  13. package/Cameras/Inputs/freeCameraKeyboardMoveInput.js +2 -7
  14. package/Cameras/Inputs/freeCameraKeyboardMoveInput.js.map +1 -1
  15. package/Cameras/Inputs/freeCameraMouseInput.js +4 -14
  16. package/Cameras/Inputs/freeCameraMouseInput.js.map +1 -1
  17. package/Cameras/Inputs/freeCameraTouchInput.js +2 -1
  18. package/Cameras/Inputs/freeCameraTouchInput.js.map +1 -1
  19. package/Cameras/arcRotateCamera.js +2 -7
  20. package/Cameras/arcRotateCamera.js.map +1 -1
  21. package/Cameras/camera.d.ts +2 -0
  22. package/Cameras/camera.js +8 -0
  23. package/Cameras/camera.js.map +1 -1
  24. package/Compute/computeShader.d.ts +15 -0
  25. package/Compute/computeShader.js +39 -0
  26. package/Compute/computeShader.js.map +1 -1
  27. package/Debug/physicsViewer.d.ts +33 -0
  28. package/Debug/physicsViewer.js +205 -0
  29. package/Debug/physicsViewer.js.map +1 -1
  30. package/Engines/Extensions/engine.computeShader.d.ts +2 -1
  31. package/Engines/Extensions/engine.computeShader.js +1 -0
  32. package/Engines/Extensions/engine.computeShader.js.map +1 -1
  33. package/Engines/WebGPU/webgpuComputeContext.js +15 -0
  34. package/Engines/WebGPU/webgpuComputeContext.js.map +1 -1
  35. package/Engines/thinEngine.js +2 -2
  36. package/Engines/thinEngine.js.map +1 -1
  37. package/FlowGraph/Blocks/Data/flowGraphAddBlock.d.ts +23 -0
  38. package/FlowGraph/Blocks/Data/flowGraphAddBlock.js +18 -0
  39. package/FlowGraph/Blocks/Data/flowGraphAddBlock.js.map +1 -0
  40. package/FlowGraph/Blocks/Data/flowGraphConditionalDataBlock.d.ts +30 -0
  41. package/FlowGraph/Blocks/Data/flowGraphConditionalDataBlock.js +22 -0
  42. package/FlowGraph/Blocks/Data/flowGraphConditionalDataBlock.js.map +1 -0
  43. package/FlowGraph/Blocks/Data/flowGraphGetVariableBlock.d.ts +33 -0
  44. package/FlowGraph/Blocks/Data/flowGraphGetVariableBlock.js +30 -0
  45. package/FlowGraph/Blocks/Data/flowGraphGetVariableBlock.js.map +1 -0
  46. package/FlowGraph/Blocks/Data/index.d.ts +3 -1
  47. package/FlowGraph/Blocks/Data/index.js +3 -1
  48. package/FlowGraph/Blocks/Data/index.js.map +1 -1
  49. package/FlowGraph/Blocks/Event/flowGraphMeshPickEventBlock.d.ts +12 -10
  50. package/FlowGraph/Blocks/Event/flowGraphMeshPickEventBlock.js +25 -29
  51. package/FlowGraph/Blocks/Event/flowGraphMeshPickEventBlock.js.map +1 -1
  52. package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.d.ts +25 -0
  53. package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.js +31 -0
  54. package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.js.map +1 -0
  55. package/FlowGraph/Blocks/Event/flowGraphSceneReadyEventBlock.d.ts +3 -7
  56. package/FlowGraph/Blocks/Event/flowGraphSceneReadyEventBlock.js +11 -11
  57. package/FlowGraph/Blocks/Event/flowGraphSceneReadyEventBlock.js.map +1 -1
  58. package/FlowGraph/Blocks/Event/index.d.ts +1 -0
  59. package/FlowGraph/Blocks/Event/index.js +1 -0
  60. package/FlowGraph/Blocks/Event/index.js.map +1 -1
  61. package/FlowGraph/Blocks/Execution/flowGraphConditionalBlock.d.ts +24 -0
  62. package/FlowGraph/Blocks/Execution/flowGraphConditionalBlock.js +23 -0
  63. package/FlowGraph/Blocks/Execution/flowGraphConditionalBlock.js.map +1 -0
  64. package/FlowGraph/Blocks/Execution/flowGraphForLoopBlock.d.ts +10 -13
  65. package/FlowGraph/Blocks/Execution/flowGraphForLoopBlock.js +28 -22
  66. package/FlowGraph/Blocks/Execution/flowGraphForLoopBlock.js.map +1 -1
  67. package/FlowGraph/Blocks/Execution/flowGraphLogBlock.d.ts +5 -5
  68. package/FlowGraph/Blocks/Execution/flowGraphLogBlock.js +8 -6
  69. package/FlowGraph/Blocks/Execution/flowGraphLogBlock.js.map +1 -1
  70. package/FlowGraph/Blocks/Execution/flowGraphPlayAnimationBlock.d.ts +56 -0
  71. package/FlowGraph/Blocks/Execution/flowGraphPlayAnimationBlock.js +66 -0
  72. package/FlowGraph/Blocks/Execution/flowGraphPlayAnimationBlock.js.map +1 -0
  73. package/FlowGraph/Blocks/Execution/flowGraphSendCustomEventBlock.d.ts +18 -0
  74. package/FlowGraph/Blocks/Execution/flowGraphSendCustomEventBlock.js +19 -0
  75. package/FlowGraph/Blocks/Execution/flowGraphSendCustomEventBlock.js.map +1 -0
  76. package/FlowGraph/Blocks/Execution/flowGraphSetPropertyBlock.d.ts +26 -0
  77. package/FlowGraph/Blocks/Execution/flowGraphSetPropertyBlock.js +36 -0
  78. package/FlowGraph/Blocks/Execution/flowGraphSetPropertyBlock.js.map +1 -0
  79. package/FlowGraph/Blocks/Execution/flowGraphSetVariableBlock.d.ts +23 -0
  80. package/FlowGraph/Blocks/Execution/flowGraphSetVariableBlock.js +25 -0
  81. package/FlowGraph/Blocks/Execution/flowGraphSetVariableBlock.js.map +1 -0
  82. package/FlowGraph/Blocks/Execution/flowGraphStopAnimationBlock.d.ts +16 -0
  83. package/FlowGraph/Blocks/Execution/flowGraphStopAnimationBlock.js +18 -0
  84. package/FlowGraph/Blocks/Execution/flowGraphStopAnimationBlock.js.map +1 -0
  85. package/FlowGraph/Blocks/Execution/flowGraphTimerBlock.d.ts +32 -0
  86. package/FlowGraph/Blocks/Execution/flowGraphTimerBlock.js +62 -0
  87. package/FlowGraph/Blocks/Execution/flowGraphTimerBlock.js.map +1 -0
  88. package/FlowGraph/Blocks/Execution/index.d.ts +7 -0
  89. package/FlowGraph/Blocks/Execution/index.js +7 -0
  90. package/FlowGraph/Blocks/Execution/index.js.map +1 -1
  91. package/FlowGraph/flowGraph.d.ts +42 -12
  92. package/FlowGraph/flowGraph.js +37 -23
  93. package/FlowGraph/flowGraph.js.map +1 -1
  94. package/FlowGraph/flowGraphAsyncExecutionBlock.d.ts +29 -0
  95. package/FlowGraph/flowGraphAsyncExecutionBlock.js +21 -0
  96. package/FlowGraph/flowGraphAsyncExecutionBlock.js.map +1 -0
  97. package/FlowGraph/flowGraphBlock.d.ts +9 -11
  98. package/FlowGraph/flowGraphBlock.js +12 -8
  99. package/FlowGraph/flowGraphBlock.js.map +1 -1
  100. package/FlowGraph/flowGraphConnection.d.ts +17 -7
  101. package/FlowGraph/flowGraphConnection.js +26 -9
  102. package/FlowGraph/flowGraphConnection.js.map +1 -1
  103. package/FlowGraph/flowGraphContext.d.ts +102 -0
  104. package/FlowGraph/flowGraphContext.js +111 -0
  105. package/FlowGraph/flowGraphContext.js.map +1 -0
  106. package/FlowGraph/flowGraphCustomEvent.d.ts +5 -0
  107. package/FlowGraph/flowGraphCustomEvent.js +2 -0
  108. package/FlowGraph/flowGraphCustomEvent.js.map +1 -0
  109. package/FlowGraph/flowGraphDataConnection.d.ts +10 -2
  110. package/FlowGraph/flowGraphDataConnection.js +16 -8
  111. package/FlowGraph/flowGraphDataConnection.js.map +1 -1
  112. package/FlowGraph/flowGraphEventBlock.d.ts +5 -12
  113. package/FlowGraph/flowGraphEventBlock.js +5 -5
  114. package/FlowGraph/flowGraphEventBlock.js.map +1 -1
  115. package/FlowGraph/flowGraphEventCoordinator.d.ts +23 -0
  116. package/FlowGraph/flowGraphEventCoordinator.js +37 -0
  117. package/FlowGraph/flowGraphEventCoordinator.js.map +1 -0
  118. package/FlowGraph/flowGraphExecutionBlock.d.ts +5 -5
  119. package/FlowGraph/flowGraphExecutionBlock.js +3 -3
  120. package/FlowGraph/flowGraphExecutionBlock.js.map +1 -1
  121. package/FlowGraph/flowGraphRichTypes.d.ts +28 -0
  122. package/FlowGraph/flowGraphRichTypes.js +43 -0
  123. package/FlowGraph/flowGraphRichTypes.js.map +1 -0
  124. package/FlowGraph/flowGraphSignalConnection.d.ts +7 -1
  125. package/FlowGraph/flowGraphSignalConnection.js +11 -4
  126. package/FlowGraph/flowGraphSignalConnection.js.map +1 -1
  127. package/FlowGraph/flowGraphVariableDefinitions.d.ts +12 -0
  128. package/FlowGraph/flowGraphVariableDefinitions.js +22 -0
  129. package/FlowGraph/flowGraphVariableDefinitions.js.map +1 -0
  130. package/FlowGraph/flowGraphWithOnDoneExecutionBlock.d.ts +10 -2
  131. package/FlowGraph/flowGraphWithOnDoneExecutionBlock.js +8 -2
  132. package/FlowGraph/flowGraphWithOnDoneExecutionBlock.js.map +1 -1
  133. package/FlowGraph/index.d.ts +3 -0
  134. package/FlowGraph/index.js +3 -0
  135. package/FlowGraph/index.js.map +1 -1
  136. package/Materials/Node/nodeMaterial.d.ts +2 -1
  137. package/Materials/Node/nodeMaterial.js +26 -2
  138. package/Materials/Node/nodeMaterial.js.map +1 -1
  139. package/Materials/PBR/pbrBaseMaterial.d.ts +1 -0
  140. package/Materials/PBR/pbrBaseMaterial.js +1 -0
  141. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  142. package/Materials/Textures/videoTexture.d.ts +5 -0
  143. package/Materials/Textures/videoTexture.js +6 -0
  144. package/Materials/Textures/videoTexture.js.map +1 -1
  145. package/Materials/materialHelper.js +1 -0
  146. package/Materials/materialHelper.js.map +1 -1
  147. package/Materials/standardMaterial.d.ts +1 -0
  148. package/Materials/standardMaterial.js +1 -0
  149. package/Materials/standardMaterial.js.map +1 -1
  150. package/Materials/uniformBuffer.d.ts +7 -0
  151. package/Materials/uniformBuffer.js +8 -0
  152. package/Materials/uniformBuffer.js.map +1 -1
  153. package/Maths/math.vector.d.ts +5 -0
  154. package/Maths/math.vector.js +7 -0
  155. package/Maths/math.vector.js.map +1 -1
  156. package/Meshes/Node/Blocks/Instances/instantiateBlock.d.ts +11 -5
  157. package/Meshes/Node/Blocks/Instances/instantiateBlock.js +20 -10
  158. package/Meshes/Node/Blocks/Instances/instantiateBlock.js.map +1 -1
  159. package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.d.ts +15 -9
  160. package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.js +20 -11
  161. package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.js.map +1 -1
  162. package/Meshes/Node/Blocks/Instances/instantiateOnVerticesBlock.d.ts +15 -9
  163. package/Meshes/Node/Blocks/Instances/instantiateOnVerticesBlock.js +20 -11
  164. package/Meshes/Node/Blocks/Instances/instantiateOnVerticesBlock.js.map +1 -1
  165. package/Meshes/Node/Blocks/Instances/instantiateOnVolumeBlock.d.ts +15 -9
  166. package/Meshes/Node/Blocks/Instances/instantiateOnVolumeBlock.js +20 -11
  167. package/Meshes/Node/Blocks/Instances/instantiateOnVolumeBlock.js.map +1 -1
  168. package/Meshes/Node/Blocks/Set/setColorsBlock.d.ts +12 -0
  169. package/Meshes/Node/Blocks/Set/setColorsBlock.js +62 -27
  170. package/Meshes/Node/Blocks/Set/setColorsBlock.js.map +1 -1
  171. package/Meshes/Node/Blocks/Set/setMaterialIDBlock.d.ts +7 -0
  172. package/Meshes/Node/Blocks/Set/setMaterialIDBlock.js +19 -0
  173. package/Meshes/Node/Blocks/Set/setMaterialIDBlock.js.map +1 -1
  174. package/Meshes/Node/Blocks/Set/setNormalsBlock.d.ts +12 -0
  175. package/Meshes/Node/Blocks/Set/setNormalsBlock.js +62 -27
  176. package/Meshes/Node/Blocks/Set/setNormalsBlock.js.map +1 -1
  177. package/Meshes/Node/Blocks/Set/setPositionsBlock.d.ts +12 -0
  178. package/Meshes/Node/Blocks/Set/setPositionsBlock.js +54 -19
  179. package/Meshes/Node/Blocks/Set/setPositionsBlock.js.map +1 -1
  180. package/Meshes/Node/Blocks/Set/setTangentsBlock.d.ts +12 -0
  181. package/Meshes/Node/Blocks/Set/setTangentsBlock.js +62 -27
  182. package/Meshes/Node/Blocks/Set/setTangentsBlock.js.map +1 -1
  183. package/Meshes/Node/Blocks/Set/setUVsBlock.d.ts +5 -0
  184. package/Meshes/Node/Blocks/Set/setUVsBlock.js +65 -46
  185. package/Meshes/Node/Blocks/Set/setUVsBlock.js.map +1 -1
  186. package/Meshes/Node/Blocks/debugBlock.js +5 -1
  187. package/Meshes/Node/Blocks/debugBlock.js.map +1 -1
  188. package/Meshes/Node/Blocks/geometryInputBlock.js +1 -0
  189. package/Meshes/Node/Blocks/geometryInputBlock.js.map +1 -1
  190. package/Meshes/Node/Blocks/intFloatConverterBlock.js +2 -2
  191. package/Meshes/Node/Blocks/intFloatConverterBlock.js.map +1 -1
  192. package/Meshes/Node/Blocks/mapRangeBlock.js +8 -1
  193. package/Meshes/Node/Blocks/mapRangeBlock.js.map +1 -1
  194. package/Meshes/Node/Blocks/mathBlock.js +1 -0
  195. package/Meshes/Node/Blocks/mathBlock.js.map +1 -1
  196. package/Meshes/Node/Blocks/matrixComposeBlock.d.ts +30 -0
  197. package/Meshes/Node/Blocks/matrixComposeBlock.js +55 -0
  198. package/Meshes/Node/Blocks/matrixComposeBlock.js.map +1 -0
  199. package/Meshes/Node/Enums/nodeGeometryContextualSources.d.ts +3 -1
  200. package/Meshes/Node/Enums/nodeGeometryContextualSources.js +2 -0
  201. package/Meshes/Node/Enums/nodeGeometryContextualSources.js.map +1 -1
  202. package/Meshes/Node/Interfaces/nodeGeometryInstancingContext.d.ts +10 -0
  203. package/Meshes/Node/Interfaces/nodeGeometryInstancingContext.js +2 -0
  204. package/Meshes/Node/Interfaces/nodeGeometryInstancingContext.js.map +1 -0
  205. package/Meshes/Node/index.d.ts +1 -0
  206. package/Meshes/Node/index.js +1 -0
  207. package/Meshes/Node/index.js.map +1 -1
  208. package/Meshes/Node/nodeGeometry.js +2 -2
  209. package/Meshes/Node/nodeGeometry.js.map +1 -1
  210. package/Meshes/Node/nodeGeometryBuildState.d.ts +5 -0
  211. package/Meshes/Node/nodeGeometryBuildState.js +20 -0
  212. package/Meshes/Node/nodeGeometryBuildState.js.map +1 -1
  213. package/Meshes/abstractMesh.js +4 -1
  214. package/Meshes/abstractMesh.js.map +1 -1
  215. package/Meshes/geometry.js +10 -10
  216. package/Meshes/geometry.js.map +1 -1
  217. package/Meshes/mesh.js +7 -5
  218. package/Meshes/mesh.js.map +1 -1
  219. package/Misc/PerformanceViewer/performanceViewerCollectionStrategies.js +2 -1
  220. package/Misc/PerformanceViewer/performanceViewerCollectionStrategies.js.map +1 -1
  221. package/Misc/dumpTools.js +3 -2
  222. package/Misc/dumpTools.js.map +1 -1
  223. package/Misc/equirectangularCapture.d.ts +39 -0
  224. package/Misc/equirectangularCapture.js +56 -0
  225. package/Misc/equirectangularCapture.js.map +1 -0
  226. package/Misc/index.d.ts +1 -0
  227. package/Misc/index.js +1 -0
  228. package/Misc/index.js.map +1 -1
  229. package/Particles/solidParticleSystem.d.ts +4 -0
  230. package/Particles/solidParticleSystem.js +16 -1
  231. package/Particles/solidParticleSystem.js.map +1 -1
  232. package/Physics/v2/IPhysicsEnginePlugin.d.ts +10 -0
  233. package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
  234. package/Physics/v2/Plugins/havokPlugin.d.ts +8 -1
  235. package/Physics/v2/Plugins/havokPlugin.js +34 -0
  236. package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
  237. package/Physics/v2/physicsConstraint.d.ts +11 -1
  238. package/Physics/v2/physicsConstraint.js +7 -0
  239. package/Physics/v2/physicsConstraint.js.map +1 -1
  240. package/Rendering/prePassRenderer.d.ts +6 -0
  241. package/Rendering/prePassRenderer.js +14 -0
  242. package/Rendering/prePassRenderer.js.map +1 -1
  243. package/Shaders/default.fragment.js +4 -0
  244. package/Shaders/default.fragment.js.map +1 -1
  245. package/Shaders/equirectangularPanorama.fragment.d.ts +5 -0
  246. package/Shaders/equirectangularPanorama.fragment.js +17 -0
  247. package/Shaders/equirectangularPanorama.fragment.js.map +1 -0
  248. package/Shaders/pbr.fragment.js +4 -0
  249. package/Shaders/pbr.fragment.js.map +1 -1
  250. package/package.json +1 -1
  251. package/FlowGraph/Blocks/Data/flowGraphBinaryOpBlocks.d.ts +0 -34
  252. package/FlowGraph/Blocks/Data/flowGraphBinaryOpBlocks.js +0 -29
  253. package/FlowGraph/Blocks/Data/flowGraphBinaryOpBlocks.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"computeShader.js","sourceRoot":"","sources":["../../../../dev/core/src/Compute/computeShader.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAEhF,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAG9D,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAgCtE;;GAEG;AACH,MAAM,OAAO,aAAa;IAsBtB;;OAEG;IACH,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,WAAW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E,OAAO,CAAC,CAAC;YAE7E,IAAI,OAAO,CAAC,IAAI,KAAK,kBAAkB,CAAC,OAAO,EAAE;gBAC7C,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;aACpC;iBAAM,IAAI,OAAO,CAAC,IAAI,KAAK,kBAAkB,CAAC,qBAAqB,EAAE;gBAClE,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;aAC3C;iBAAM;gBACH,OAAO,CAAC,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;aAC3C;SACJ;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ;AAtWU;IADN,SAAS,EAAE;2CACQ;AAwWxB,aAAa,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import type { UniformBuffer } from \"../Materials/uniformBuffer\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport { SerializationHelper, serialize } from \"../Misc/decorators\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\nimport type { ComputeEffect, IComputeEffectCreationOptions } from \"./computeEffect\";\r\nimport type { ComputeBindingMapping } from \"../Engines/Extensions/engine.computeShader\";\r\nimport { ComputeBindingType } from \"../Engines/Extensions/engine.computeShader\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { UniqueIdGenerator } from \"../Misc/uniqueIdGenerator\";\r\nimport type { IComputeContext } from \"./IComputeContext\";\r\nimport type { StorageBuffer } from \"../Buffers/storageBuffer\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { TextureSampler } from \"../Materials/Textures/textureSampler\";\r\nimport type { DataBuffer } from \"core/Buffers/dataBuffer\";\r\n\r\n/**\r\n * Defines the options associated with the creation of a compute shader.\r\n */\r\nexport interface IComputeShaderOptions {\r\n /**\r\n * list of bindings mapping (key is property name, value is binding location)\r\n * Must be provided because browsers don't support reflection for wgsl shaders yet (so there's no way to query the binding/group from a variable name)\r\n * TODO: remove this when browsers support reflection for wgsl shaders\r\n */\r\n bindingsMapping: ComputeBindingMapping;\r\n\r\n /**\r\n * The list of defines used in the shader\r\n */\r\n defines?: string[];\r\n\r\n /**\r\n * The name of the entry point in the shader source (default: \"main\")\r\n */\r\n entryPoint?: string;\r\n\r\n /**\r\n * If provided, will be called with the shader code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: Nullable<(code: string) => string>;\r\n}\r\n\r\ntype ComputeBindingListInternal = { [key: string]: { type: ComputeBindingType; object: any; indexInGroupEntries?: number; buffer?: Nullable<DataBuffer> } };\r\n\r\n/**\r\n * The ComputeShader object lets you execute a compute shader on your GPU (if supported by the engine)\r\n */\r\nexport class ComputeShader {\r\n private _engine: ThinEngine;\r\n private _shaderPath: any;\r\n private _options: IComputeShaderOptions;\r\n private _effect: ComputeEffect;\r\n private _cachedDefines: string;\r\n private _bindings: ComputeBindingListInternal = {};\r\n private _samplers: { [key: string]: TextureSampler } = {};\r\n private _context: IComputeContext;\r\n private _contextIsDirty = false;\r\n\r\n /**\r\n * Gets the unique id of the compute shader\r\n */\r\n public readonly uniqueId: number;\r\n\r\n /**\r\n * The name of the shader\r\n */\r\n @serialize()\r\n public name: string;\r\n\r\n /**\r\n * The options used to create the shader\r\n */\r\n public get options() {\r\n return this._options;\r\n }\r\n\r\n /**\r\n * The shaderPath used to create the shader\r\n */\r\n public get shaderPath() {\r\n return this._shaderPath;\r\n }\r\n\r\n /**\r\n * Callback triggered when the shader is compiled\r\n */\r\n public onCompiled: Nullable<(effect: ComputeEffect) => void> = null;\r\n\r\n /**\r\n * Callback triggered when an error occurs\r\n */\r\n public onError: Nullable<(effect: ComputeEffect, errors: string) => void> = null;\r\n\r\n /**\r\n * Instantiates a new compute shader.\r\n * @param name Defines the name of the compute shader in the scene\r\n * @param engine Defines the engine the compute shader belongs to\r\n * @param shaderPath Defines the route to the shader code in one of three ways:\r\n * * object: \\{ compute: \"custom\" \\}, used with ShaderStore.ShadersStoreWGSL[\"customComputeShader\"]\r\n * * object: \\{ computeElement: \"HTMLElementId\" \\}, used with shader code in script tags\r\n * * object: \\{ computeSource: \"compute shader code string\" \\}, where the string contains the shader code\r\n * * string: try first to find the code in ShaderStore.ShadersStoreWGSL[shaderPath + \"ComputeShader\"]. If not, assumes it is a file with name shaderPath.compute.fx in index.html folder.\r\n * @param options Define the options used to create the shader\r\n */\r\n constructor(name: string, engine: ThinEngine, shaderPath: any, options: Partial<IComputeShaderOptions> = {}) {\r\n this.name = name;\r\n this._engine = engine;\r\n this.uniqueId = UniqueIdGenerator.UniqueId;\r\n\r\n if (!this._engine.getCaps().supportComputeShaders) {\r\n Logger.Error(\"This engine does not support compute shaders!\");\r\n return;\r\n }\r\n if (!options.bindingsMapping) {\r\n Logger.Error(\"You must provide the binding mappings as browsers don't support reflection for wgsl shaders yet!\");\r\n return;\r\n }\r\n\r\n this._context = engine.createComputeContext()!;\r\n this._shaderPath = shaderPath;\r\n this._options = {\r\n bindingsMapping: {},\r\n defines: [],\r\n ...options,\r\n };\r\n }\r\n\r\n /**\r\n * Gets the current class name of the material e.g. \"ComputeShader\"\r\n * Mainly use in serialization.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"ComputeShader\";\r\n }\r\n\r\n /**\r\n * Binds a texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n * @param bindSampler Bind the sampler corresponding to the texture (default: true). The sampler will be bound just before the binding index of the texture\r\n */\r\n public setTexture(name: string, texture: BaseTexture, bindSampler = true): void {\r\n const current = this._bindings[name];\r\n\r\n this._bindings[name] = {\r\n type: bindSampler ? ComputeBindingType.Texture : ComputeBindingType.TextureWithoutSampler,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture || current.type !== this._bindings[name].type;\r\n }\r\n\r\n /**\r\n * Binds a storage texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n */\r\n public setStorageTexture(name: string, texture: BaseTexture): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.StorageTexture,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a uniform buffer to the shader\r\n * @param name Binding name of the buffer\r\n * @param buffer Buffer to bind\r\n */\r\n public setUniformBuffer(name: string, buffer: UniformBuffer): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== buffer;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.UniformBuffer,\r\n object: buffer,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a storage buffer to the shader\r\n * @param name Binding name of the buffer\r\n * @param buffer Buffer to bind\r\n */\r\n public setStorageBuffer(name: string, buffer: StorageBuffer): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== buffer;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.StorageBuffer,\r\n object: buffer,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a texture sampler to the shader\r\n * @param name Binding name of the sampler\r\n * @param sampler Sampler to bind\r\n */\r\n public setTextureSampler(name: string, sampler: TextureSampler): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || !sampler.compareSampler(current.object);\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.Sampler,\r\n object: sampler,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Specifies that the compute shader is ready to be executed (the compute effect and all the resources are ready)\r\n * @returns true if the compute shader is ready to be executed\r\n */\r\n public isReady(): boolean {\r\n let effect = this._effect;\r\n\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key],\r\n type = binding.type,\r\n object = binding.object;\r\n\r\n switch (type) {\r\n case ComputeBindingType.Texture:\r\n case ComputeBindingType.TextureWithoutSampler:\r\n case ComputeBindingType.StorageTexture: {\r\n const texture = object as BaseTexture;\r\n if (!texture.isReady()) {\r\n return false;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n const defines = [];\r\n\r\n const shaderName = this._shaderPath;\r\n\r\n if (this._options.defines) {\r\n for (let index = 0; index < this._options.defines.length; index++) {\r\n defines.push(this._options.defines[index]);\r\n }\r\n }\r\n\r\n const join = defines.join(\"\\n\");\r\n\r\n if (this._cachedDefines !== join) {\r\n this._cachedDefines = join;\r\n\r\n effect = this._engine.createComputeEffect(shaderName, <IComputeEffectCreationOptions>{\r\n defines: join,\r\n entryPoint: this._options.entryPoint,\r\n onCompiled: this.onCompiled,\r\n onError: this.onError,\r\n });\r\n\r\n this._effect = effect;\r\n }\r\n\r\n if (!effect.isReady()) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispatches (executes) the compute shader\r\n * @param x Number of workgroups to execute on the X dimension\r\n * @param y Number of workgroups to execute on the Y dimension (default: 1)\r\n * @param z Number of workgroups to execute on the Z dimension (default: 1)\r\n * @returns True if the dispatch could be done, else false (meaning either the compute effect or at least one of the bound resources was not ready)\r\n */\r\n public dispatch(x: number, y?: number, z?: number): boolean {\r\n if (!this.isReady()) {\r\n return false;\r\n }\r\n\r\n // If the sampling parameters of a texture bound to the shader have changed, we must clear the compute context so that it is recreated with the updated values\r\n // Also, if the actual (gpu) buffer used by a uniform buffer has changed, we must clear the compute context so that it is recreated with the updated value\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key];\r\n\r\n if (!this._options.bindingsMapping[key]) {\r\n throw new Error(\"ComputeShader ('\" + this.name + \"'): No binding mapping has been provided for the property '\" + key + \"'\");\r\n }\r\n\r\n switch (binding.type) {\r\n case ComputeBindingType.Texture: {\r\n const sampler = this._samplers[key];\r\n const texture = binding.object as BaseTexture;\r\n\r\n if (!sampler || !texture._texture || !sampler.compareSampler(texture._texture)) {\r\n this._samplers[key] = new TextureSampler().setParameters(\r\n texture.wrapU,\r\n texture.wrapV,\r\n texture.wrapR,\r\n texture.anisotropicFilteringLevel,\r\n texture._texture!.samplingMode,\r\n texture._texture?._comparisonFunction\r\n );\r\n this._contextIsDirty = true;\r\n }\r\n break;\r\n }\r\n case ComputeBindingType.UniformBuffer: {\r\n const ubo = binding.object as UniformBuffer;\r\n if (ubo.getBuffer() !== binding.buffer) {\r\n binding.buffer = ubo.getBuffer();\r\n this._contextIsDirty = true;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (this._contextIsDirty) {\r\n this._contextIsDirty = false;\r\n this._context.clear();\r\n }\r\n\r\n this._engine.computeDispatch(this._effect, this._context, this._bindings, x, y, z, this._options.bindingsMapping);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Waits for the compute shader to be ready and executes it\r\n * @param x Number of workgroups to execute on the X dimension\r\n * @param y Number of workgroups to execute on the Y dimension (default: 1)\r\n * @param z Number of workgroups to execute on the Z dimension (default: 1)\r\n * @param delay Delay between the retries while the shader is not ready (in milliseconds - 10 by default)\r\n * @returns A promise that is resolved once the shader has been sent to the GPU. Note that it does not mean that the shader execution itself is finished!\r\n */\r\n public dispatchWhenReady(x: number, y?: number, z?: number, delay = 10): Promise<void> {\r\n return new Promise((resolve) => {\r\n const check = () => {\r\n if (!this.dispatch(x, y, z)) {\r\n setTimeout(check, delay);\r\n } else {\r\n resolve();\r\n }\r\n };\r\n\r\n check();\r\n });\r\n }\r\n\r\n /**\r\n * Serializes this compute shader in a JSON representation\r\n * @returns the serialized compute shader object\r\n */\r\n public serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this);\r\n\r\n serializationObject.options = this._options;\r\n serializationObject.shaderPath = this._shaderPath;\r\n serializationObject.bindings = {};\r\n serializationObject.textures = {};\r\n\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key];\r\n const object = binding.object;\r\n\r\n switch (binding.type) {\r\n case ComputeBindingType.Texture:\r\n case ComputeBindingType.TextureWithoutSampler:\r\n case ComputeBindingType.StorageTexture: {\r\n const serializedData = (object as BaseTexture).serialize();\r\n if (serializedData) {\r\n serializationObject.textures[key] = serializedData;\r\n serializationObject.bindings[key] = {\r\n type: binding.type,\r\n };\r\n }\r\n break;\r\n }\r\n\r\n case ComputeBindingType.UniformBuffer: {\r\n break;\r\n }\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Creates a compute shader from parsed compute shader data\r\n * @param source defines the JSON representation of the compute shader\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @returns a new compute shader\r\n */\r\n public static Parse(source: any, scene: Scene, rootUrl: string): ComputeShader {\r\n const compute = SerializationHelper.Parse(() => new ComputeShader(source.name, scene.getEngine(), source.shaderPath, source.options), source, scene, rootUrl);\r\n\r\n for (const key in source.textures) {\r\n const binding = source.bindings[key];\r\n const texture = <Texture>Texture.Parse(source.textures[key], scene, rootUrl);\r\n\r\n if (binding.type === ComputeBindingType.Texture) {\r\n compute.setTexture(key, texture);\r\n } else if (binding.type === ComputeBindingType.TextureWithoutSampler) {\r\n compute.setTexture(key, texture, false);\r\n } else {\r\n compute.setStorageTexture(key, texture);\r\n }\r\n }\r\n\r\n return compute;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ComputeShader\", ComputeShader);\r\n"]}
1
+ {"version":3,"file":"computeShader.js","sourceRoot":"","sources":["../../../../dev/core/src/Compute/computeShader.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;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G,CAAC,CAAC;YACrC,MAAM,OAAO,GAAY,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;YAE7E,IAAI,OAAO,CAAC,IAAI,KAAK,kBAAkB,CAAC,OAAO,EAAE;gBAC7C,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;aACpC;iBAAM,IAAI,OAAO,CAAC,IAAI,KAAK,kBAAkB,CAAC,qBAAqB,EAAE;gBAClE,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;aAC3C;iBAAM;gBACH,OAAO,CAAC,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;aAC3C;SACJ;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ;AAlZU;IADN,SAAS,EAAE;2CACQ;AAoZxB,aAAa,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import type { UniformBuffer } from \"../Materials/uniformBuffer\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport { SerializationHelper, serialize } from \"../Misc/decorators\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\nimport type { ComputeEffect, IComputeEffectCreationOptions } from \"./computeEffect\";\r\nimport type { ComputeBindingMapping } from \"../Engines/Extensions/engine.computeShader\";\r\nimport { ComputeBindingType } from \"../Engines/Extensions/engine.computeShader\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { UniqueIdGenerator } from \"../Misc/uniqueIdGenerator\";\r\nimport type { IComputeContext } from \"./IComputeContext\";\r\nimport type { StorageBuffer } from \"../Buffers/storageBuffer\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { TextureSampler } from \"../Materials/Textures/textureSampler\";\r\nimport type { DataBuffer } from \"core/Buffers/dataBuffer\";\r\nimport type { ExternalTexture } from \"core/Materials/Textures/externalTexture\";\r\nimport type { VideoTexture } from \"core/Materials/Textures/videoTexture\";\r\n\r\n/**\r\n * Defines the options associated with the creation of a compute shader.\r\n */\r\nexport interface IComputeShaderOptions {\r\n /**\r\n * list of bindings mapping (key is property name, value is binding location)\r\n * Must be provided because browsers don't support reflection for wgsl shaders yet (so there's no way to query the binding/group from a variable name)\r\n * TODO: remove this when browsers support reflection for wgsl shaders\r\n */\r\n bindingsMapping: ComputeBindingMapping;\r\n\r\n /**\r\n * The list of defines used in the shader\r\n */\r\n defines?: string[];\r\n\r\n /**\r\n * The name of the entry point in the shader source (default: \"main\")\r\n */\r\n entryPoint?: string;\r\n\r\n /**\r\n * If provided, will be called with the shader code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: Nullable<(code: string) => string>;\r\n}\r\n\r\ntype ComputeBindingListInternal = { [key: string]: { type: ComputeBindingType; object: any; indexInGroupEntries?: number; buffer?: Nullable<DataBuffer> } };\r\n\r\n/**\r\n * The ComputeShader object lets you execute a compute shader on your GPU (if supported by the engine)\r\n */\r\nexport class ComputeShader {\r\n private _engine: ThinEngine;\r\n private _shaderPath: any;\r\n private _options: IComputeShaderOptions;\r\n private _effect: ComputeEffect;\r\n private _cachedDefines: string;\r\n private _bindings: ComputeBindingListInternal = {};\r\n private _samplers: { [key: string]: TextureSampler } = {};\r\n private _context: IComputeContext;\r\n private _contextIsDirty = false;\r\n\r\n /**\r\n * Gets the unique id of the compute shader\r\n */\r\n public readonly uniqueId: number;\r\n\r\n /**\r\n * The name of the shader\r\n */\r\n @serialize()\r\n public name: string;\r\n\r\n /**\r\n * The options used to create the shader\r\n */\r\n public get options() {\r\n return this._options;\r\n }\r\n\r\n /**\r\n * The shaderPath used to create the shader\r\n */\r\n public get shaderPath() {\r\n return this._shaderPath;\r\n }\r\n\r\n /**\r\n * Callback triggered when the shader is compiled\r\n */\r\n public onCompiled: Nullable<(effect: ComputeEffect) => void> = null;\r\n\r\n /**\r\n * Callback triggered when an error occurs\r\n */\r\n public onError: Nullable<(effect: ComputeEffect, errors: string) => void> = null;\r\n\r\n /**\r\n * Instantiates a new compute shader.\r\n * @param name Defines the name of the compute shader in the scene\r\n * @param engine Defines the engine the compute shader belongs to\r\n * @param shaderPath Defines the route to the shader code in one of three ways:\r\n * * object: \\{ compute: \"custom\" \\}, used with ShaderStore.ShadersStoreWGSL[\"customComputeShader\"]\r\n * * object: \\{ computeElement: \"HTMLElementId\" \\}, used with shader code in script tags\r\n * * object: \\{ computeSource: \"compute shader code string\" \\}, where the string contains the shader code\r\n * * string: try first to find the code in ShaderStore.ShadersStoreWGSL[shaderPath + \"ComputeShader\"]. If not, assumes it is a file with name shaderPath.compute.fx in index.html folder.\r\n * @param options Define the options used to create the shader\r\n */\r\n constructor(name: string, engine: ThinEngine, shaderPath: any, options: Partial<IComputeShaderOptions> = {}) {\r\n this.name = name;\r\n this._engine = engine;\r\n this.uniqueId = UniqueIdGenerator.UniqueId;\r\n\r\n if (!this._engine.getCaps().supportComputeShaders) {\r\n Logger.Error(\"This engine does not support compute shaders!\");\r\n return;\r\n }\r\n if (!options.bindingsMapping) {\r\n Logger.Error(\"You must provide the binding mappings as browsers don't support reflection for wgsl shaders yet!\");\r\n return;\r\n }\r\n\r\n this._context = engine.createComputeContext()!;\r\n this._shaderPath = shaderPath;\r\n this._options = {\r\n bindingsMapping: {},\r\n defines: [],\r\n ...options,\r\n };\r\n }\r\n\r\n /**\r\n * Gets the current class name of the material e.g. \"ComputeShader\"\r\n * Mainly use in serialization.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"ComputeShader\";\r\n }\r\n\r\n /**\r\n * Binds a texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n * @param bindSampler Bind the sampler corresponding to the texture (default: true). The sampler will be bound just before the binding index of the texture\r\n */\r\n public setTexture(name: string, texture: BaseTexture, bindSampler = true): void {\r\n const current = this._bindings[name];\r\n\r\n this._bindings[name] = {\r\n type: bindSampler ? ComputeBindingType.Texture : ComputeBindingType.TextureWithoutSampler,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture || current.type !== this._bindings[name].type;\r\n }\r\n\r\n /**\r\n * Binds a storage texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n */\r\n public setStorageTexture(name: string, texture: BaseTexture): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.StorageTexture,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds an external texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n */\r\n public setExternalTexture(name: string, texture: ExternalTexture): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.ExternalTexture,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a video texture to the shader (by binding the external texture attached to this video)\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n * @returns true if the video texture was successfully bound, else false. false will be returned if the current engine does not support external textures\r\n */\r\n public setVideoTexture(name: string, texture: VideoTexture) {\r\n if (texture.externalTexture) {\r\n this.setExternalTexture(name, texture.externalTexture);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Binds a uniform buffer to the shader\r\n * @param name Binding name of the buffer\r\n * @param buffer Buffer to bind\r\n */\r\n public setUniformBuffer(name: string, buffer: UniformBuffer): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== buffer;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.UniformBuffer,\r\n object: buffer,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a storage buffer to the shader\r\n * @param name Binding name of the buffer\r\n * @param buffer Buffer to bind\r\n */\r\n public setStorageBuffer(name: string, buffer: StorageBuffer): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== buffer;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.StorageBuffer,\r\n object: buffer,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a texture sampler to the shader\r\n * @param name Binding name of the sampler\r\n * @param sampler Sampler to bind\r\n */\r\n public setTextureSampler(name: string, sampler: TextureSampler): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || !sampler.compareSampler(current.object);\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.Sampler,\r\n object: sampler,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Specifies that the compute shader is ready to be executed (the compute effect and all the resources are ready)\r\n * @returns true if the compute shader is ready to be executed\r\n */\r\n public isReady(): boolean {\r\n let effect = this._effect;\r\n\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key],\r\n type = binding.type,\r\n object = binding.object;\r\n\r\n switch (type) {\r\n case ComputeBindingType.Texture:\r\n case ComputeBindingType.TextureWithoutSampler:\r\n case ComputeBindingType.StorageTexture: {\r\n const texture = object as BaseTexture;\r\n if (!texture.isReady()) {\r\n return false;\r\n }\r\n break;\r\n }\r\n case ComputeBindingType.ExternalTexture: {\r\n const texture = object as ExternalTexture;\r\n if (!texture.isReady()) {\r\n return false;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n const defines = [];\r\n\r\n const shaderName = this._shaderPath;\r\n\r\n if (this._options.defines) {\r\n for (let index = 0; index < this._options.defines.length; index++) {\r\n defines.push(this._options.defines[index]);\r\n }\r\n }\r\n\r\n const join = defines.join(\"\\n\");\r\n\r\n if (this._cachedDefines !== join) {\r\n this._cachedDefines = join;\r\n\r\n effect = this._engine.createComputeEffect(shaderName, <IComputeEffectCreationOptions>{\r\n defines: join,\r\n entryPoint: this._options.entryPoint,\r\n onCompiled: this.onCompiled,\r\n onError: this.onError,\r\n });\r\n\r\n this._effect = effect;\r\n }\r\n\r\n if (!effect.isReady()) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispatches (executes) the compute shader\r\n * @param x Number of workgroups to execute on the X dimension\r\n * @param y Number of workgroups to execute on the Y dimension (default: 1)\r\n * @param z Number of workgroups to execute on the Z dimension (default: 1)\r\n * @returns True if the dispatch could be done, else false (meaning either the compute effect or at least one of the bound resources was not ready)\r\n */\r\n public dispatch(x: number, y?: number, z?: number): boolean {\r\n if (!this.isReady()) {\r\n return false;\r\n }\r\n\r\n // If the sampling parameters of a texture bound to the shader have changed, we must clear the compute context so that it is recreated with the updated values\r\n // Also, if the actual (gpu) buffer used by a uniform buffer has changed, we must clear the compute context so that it is recreated with the updated value\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key];\r\n\r\n if (!this._options.bindingsMapping[key]) {\r\n throw new Error(\"ComputeShader ('\" + this.name + \"'): No binding mapping has been provided for the property '\" + key + \"'\");\r\n }\r\n\r\n switch (binding.type) {\r\n case ComputeBindingType.Texture: {\r\n const sampler = this._samplers[key];\r\n const texture = binding.object as BaseTexture;\r\n\r\n if (!sampler || !texture._texture || !sampler.compareSampler(texture._texture)) {\r\n this._samplers[key] = new TextureSampler().setParameters(\r\n texture.wrapU,\r\n texture.wrapV,\r\n texture.wrapR,\r\n texture.anisotropicFilteringLevel,\r\n texture._texture!.samplingMode,\r\n texture._texture?._comparisonFunction\r\n );\r\n this._contextIsDirty = true;\r\n }\r\n break;\r\n }\r\n case ComputeBindingType.ExternalTexture: {\r\n // we must recreate the bind groups each time if there's an external texture, because device.importExternalTexture must be called each frame\r\n this._contextIsDirty = true;\r\n break;\r\n }\r\n case ComputeBindingType.UniformBuffer: {\r\n const ubo = binding.object as UniformBuffer;\r\n if (ubo.getBuffer() !== binding.buffer) {\r\n binding.buffer = ubo.getBuffer();\r\n this._contextIsDirty = true;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (this._contextIsDirty) {\r\n this._contextIsDirty = false;\r\n this._context.clear();\r\n }\r\n\r\n this._engine.computeDispatch(this._effect, this._context, this._bindings, x, y, z, this._options.bindingsMapping);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Waits for the compute shader to be ready and executes it\r\n * @param x Number of workgroups to execute on the X dimension\r\n * @param y Number of workgroups to execute on the Y dimension (default: 1)\r\n * @param z Number of workgroups to execute on the Z dimension (default: 1)\r\n * @param delay Delay between the retries while the shader is not ready (in milliseconds - 10 by default)\r\n * @returns A promise that is resolved once the shader has been sent to the GPU. Note that it does not mean that the shader execution itself is finished!\r\n */\r\n public dispatchWhenReady(x: number, y?: number, z?: number, delay = 10): Promise<void> {\r\n return new Promise((resolve) => {\r\n const check = () => {\r\n if (!this.dispatch(x, y, z)) {\r\n setTimeout(check, delay);\r\n } else {\r\n resolve();\r\n }\r\n };\r\n\r\n check();\r\n });\r\n }\r\n\r\n /**\r\n * Serializes this compute shader in a JSON representation\r\n * @returns the serialized compute shader object\r\n */\r\n public serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this);\r\n\r\n serializationObject.options = this._options;\r\n serializationObject.shaderPath = this._shaderPath;\r\n serializationObject.bindings = {};\r\n serializationObject.textures = {};\r\n\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key];\r\n const object = binding.object;\r\n\r\n switch (binding.type) {\r\n case ComputeBindingType.Texture:\r\n case ComputeBindingType.TextureWithoutSampler:\r\n case ComputeBindingType.StorageTexture: {\r\n const serializedData = (object as BaseTexture).serialize();\r\n if (serializedData) {\r\n serializationObject.textures[key] = serializedData;\r\n serializationObject.bindings[key] = {\r\n type: binding.type,\r\n };\r\n }\r\n break;\r\n }\r\n\r\n case ComputeBindingType.UniformBuffer: {\r\n break;\r\n }\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Creates a compute shader from parsed compute shader data\r\n * @param source defines the JSON representation of the compute shader\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @returns a new compute shader\r\n */\r\n public static Parse(source: any, scene: Scene, rootUrl: string): ComputeShader {\r\n const compute = SerializationHelper.Parse(() => new ComputeShader(source.name, scene.getEngine(), source.shaderPath, source.options), source, scene, rootUrl);\r\n\r\n for (const key in source.textures) {\r\n const binding = source.bindings[key];\r\n const texture = <Texture>Texture.Parse(source.textures[key], scene, rootUrl);\r\n\r\n if (binding.type === ComputeBindingType.Texture) {\r\n compute.setTexture(key, texture);\r\n } else if (binding.type === ComputeBindingType.TextureWithoutSampler) {\r\n compute.setTexture(key, texture, false);\r\n } else {\r\n compute.setStorageTexture(key, texture);\r\n }\r\n }\r\n\r\n return compute;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ComputeShader\", ComputeShader);\r\n"]}
@@ -2,10 +2,12 @@ import type { Nullable } from "../types";
2
2
  import type { Scene } from "../scene";
3
3
  import type { AbstractMesh } from "../Meshes/abstractMesh";
4
4
  import { Mesh } from "../Meshes/mesh";
5
+ import { Vector3 } from "../Maths/math.vector";
5
6
  import type { IPhysicsEnginePlugin as IPhysicsEnginePluginV1 } from "../Physics/v1/IPhysicsEnginePlugin";
6
7
  import type { IPhysicsEnginePluginV2 } from "../Physics/v2/IPhysicsEnginePlugin";
7
8
  import { PhysicsImpostor } from "../Physics/v1/physicsImpostor";
8
9
  import type { PhysicsBody } from "../Physics/v2/physicsBody";
10
+ import type { PhysicsConstraint } from "../Physics/v2/physicsConstraint";
9
11
  /**
10
12
  * Used to show the physics impostor around the specific mesh
11
13
  */
@@ -16,22 +18,31 @@ export declare class PhysicsViewer {
16
18
  protected _meshes: Array<Nullable<AbstractMesh>>;
17
19
  /** @internal */
18
20
  protected _bodies: Array<Nullable<PhysicsBody>>;
21
+ /** @internal */
19
22
  protected _inertiaBodies: Array<Nullable<PhysicsBody>>;
20
23
  /** @internal */
24
+ protected _constraints: Array<Nullable<PhysicsConstraint>>;
25
+ /** @internal */
21
26
  protected _bodyMeshes: Array<Nullable<AbstractMesh>>;
22
27
  /** @internal */
23
28
  protected _inertiaMeshes: Array<Nullable<AbstractMesh>>;
24
29
  /** @internal */
30
+ protected _constraintMeshes: Array<Nullable<AbstractMesh>>;
31
+ /** @internal */
25
32
  protected _scene: Nullable<Scene>;
26
33
  /** @internal */
27
34
  protected _numMeshes: number;
28
35
  /** @internal */
29
36
  protected _numBodies: number;
37
+ /** @internal */
30
38
  protected _numInertiaBodies: number;
31
39
  /** @internal */
40
+ protected _numConstraints: number;
41
+ /** @internal */
32
42
  protected _physicsEnginePlugin: IPhysicsEnginePluginV1 | IPhysicsEnginePluginV2 | null;
33
43
  private _renderFunction;
34
44
  private _inertiaRenderFunction;
45
+ private _constraintRenderFunction;
35
46
  private _utilityLayer;
36
47
  private _debugBoxMesh;
37
48
  private _debugSphereMesh;
@@ -40,6 +51,7 @@ export declare class PhysicsViewer {
40
51
  private _debugMaterial;
41
52
  private _debugInertiaMaterial;
42
53
  private _debugMeshMeshes;
54
+ private _constraintAxesSize;
43
55
  /**
44
56
  * Creates a new PhysicsViewer
45
57
  * @param scene defines the hosting scene
@@ -71,6 +83,14 @@ export declare class PhysicsViewer {
71
83
  protected _updateDebugMeshesV2(): void;
72
84
  protected _updateInertiaMeshes(): void;
73
85
  protected _updateDebugInertia(body: PhysicsBody, inertiaMesh: AbstractMesh): void;
86
+ protected _updateDebugConstraints(): void;
87
+ /**
88
+ * Given a scaling vector, make all of its components
89
+ * 1, preserving the sign
90
+ * @param scaling
91
+ */
92
+ protected _makeScalingUnitInPlace(scaling: Vector3): void;
93
+ protected _updateDebugConstraint(constraint: PhysicsConstraint, parentingMesh: AbstractMesh): void;
74
94
  /**
75
95
  * Renders a specified physic impostor
76
96
  * @param impostor defines the impostor to render
@@ -93,6 +113,12 @@ export declare class PhysicsViewer {
93
113
  * @param body
94
114
  */
95
115
  showInertia(body: PhysicsBody): Nullable<AbstractMesh>;
116
+ /**
117
+ * Shows a debug mesh for a given physics constraint.
118
+ * @param constraint the physics constraint to show
119
+ * @returns the debug mesh, or null if the constraint is already shown
120
+ */
121
+ showConstraint(constraint: PhysicsConstraint): Nullable<AbstractMesh>;
96
122
  /**
97
123
  * Hides an impostor from the scene.
98
124
  * @param impostor - The impostor to hide.
@@ -114,6 +140,11 @@ export declare class PhysicsViewer {
114
140
  */
115
141
  hideBody(body: Nullable<PhysicsBody>): void;
116
142
  hideInertia(body: Nullable<PhysicsBody>): void;
143
+ /**
144
+ * Hide a physics constraint from the viewer utility layer
145
+ * @param constraint the constraint to hide
146
+ */
147
+ hideConstraint(constraint: Nullable<PhysicsConstraint>): void;
117
148
  private _getDebugMaterial;
118
149
  private _getDebugInertiaMaterial;
119
150
  private _getDebugBoxMesh;
@@ -135,6 +166,8 @@ export declare class PhysicsViewer {
135
166
  private _getDebugBodyMesh;
136
167
  private _getMeshDebugInertiaMatrixToRef;
137
168
  private _getDebugInertiaMesh;
169
+ private _getTransformFromBodyToRef;
170
+ private _getDebugConstraintMesh;
138
171
  /**
139
172
  * Clean up physics debug display
140
173
  */
@@ -12,6 +12,9 @@ import { CreateCapsule } from "../Meshes/Builders/capsuleBuilder.js";
12
12
  import { Logger } from "../Misc/logger.js";
13
13
  import { VertexData } from "../Meshes/mesh.vertexData.js";
14
14
  import { MeshBuilder } from "../Meshes/meshBuilder.js";
15
+ import { AxesViewer } from "./axesViewer.js";
16
+ import { TransformNode } from "../Meshes/transformNode.js";
17
+ import { Epsilon } from "../Maths/math.constants.js";
15
18
  /**
16
19
  * Used to show the physics impostor around the specific mesh
17
20
  */
@@ -27,17 +30,26 @@ export class PhysicsViewer {
27
30
  this._meshes = [];
28
31
  /** @internal */
29
32
  this._bodies = [];
33
+ /** @internal */
30
34
  this._inertiaBodies = [];
31
35
  /** @internal */
36
+ this._constraints = [];
37
+ /** @internal */
32
38
  this._bodyMeshes = [];
33
39
  /** @internal */
34
40
  this._inertiaMeshes = [];
35
41
  /** @internal */
42
+ this._constraintMeshes = [];
43
+ /** @internal */
36
44
  this._numMeshes = 0;
37
45
  /** @internal */
38
46
  this._numBodies = 0;
47
+ /** @internal */
39
48
  this._numInertiaBodies = 0;
49
+ /** @internal */
50
+ this._numConstraints = 0;
40
51
  this._debugMeshMeshes = new Array();
52
+ this._constraintAxesSize = 0.4;
41
53
  this._scene = scene || EngineStore.LastCreatedScene;
42
54
  if (!this._scene) {
43
55
  return;
@@ -151,6 +163,62 @@ export class PhysicsViewer {
151
163
  inertiaMatrixRef.decomposeToTransformNode(inertiaMesh);
152
164
  }
153
165
  }
166
+ _updateDebugConstraints() {
167
+ for (let i = 0; i < this._numConstraints; i++) {
168
+ const constraint = this._constraints[i];
169
+ const mesh = this._constraintMeshes[i];
170
+ if (constraint && mesh) {
171
+ this._updateDebugConstraint(constraint, mesh);
172
+ }
173
+ }
174
+ }
175
+ /**
176
+ * Given a scaling vector, make all of its components
177
+ * 1, preserving the sign
178
+ * @param scaling
179
+ */
180
+ _makeScalingUnitInPlace(scaling) {
181
+ if (Math.abs(scaling.x - 1) > Epsilon) {
182
+ scaling.x = 1 * Math.sign(scaling.x);
183
+ }
184
+ if (Math.abs(scaling.y - 1) > Epsilon) {
185
+ scaling.y = 1 * Math.sign(scaling.y);
186
+ }
187
+ if (Math.abs(scaling.z - 1) > Epsilon) {
188
+ scaling.z = 1 * Math.sign(scaling.z);
189
+ }
190
+ }
191
+ _updateDebugConstraint(constraint, parentingMesh) {
192
+ if (!constraint._initOptions) {
193
+ return;
194
+ }
195
+ // Get constraint pivot and axes
196
+ const { pivotA, pivotB, axisA, axisB, perpAxisA, perpAxisB } = constraint._initOptions;
197
+ if (!pivotA || !pivotB || !axisA || !axisB || !perpAxisA || !perpAxisB) {
198
+ return;
199
+ }
200
+ parentingMesh.getDescendants(true).forEach((parentConstraintMesh) => {
201
+ // Get the parent transform
202
+ const parentCoordSystemNode = parentConstraintMesh.getDescendants(true)[0];
203
+ const childCoordSystemNode = parentConstraintMesh.getDescendants(true)[1];
204
+ const { parentBody, parentBodyIndex } = parentCoordSystemNode.metadata;
205
+ const { childBody, childBodyIndex } = childCoordSystemNode.metadata;
206
+ const parentTransform = this._getTransformFromBodyToRef(parentBody, TmpVectors.Matrix[0], parentBodyIndex);
207
+ const childTransform = this._getTransformFromBodyToRef(childBody, TmpVectors.Matrix[1], childBodyIndex);
208
+ parentTransform.decomposeToTransformNode(parentCoordSystemNode);
209
+ this._makeScalingUnitInPlace(parentCoordSystemNode.scaling);
210
+ childTransform.decomposeToTransformNode(childCoordSystemNode);
211
+ this._makeScalingUnitInPlace(childCoordSystemNode.scaling);
212
+ // Create a transform node and set its matrix
213
+ const parentTransformNode = parentCoordSystemNode.getDescendants(true)[0];
214
+ parentTransformNode.position.copyFrom(pivotA);
215
+ const childTransformNode = childCoordSystemNode.getDescendants(true)[0];
216
+ childTransformNode.position.copyFrom(pivotB);
217
+ // Get the transform to align the XYZ axes to the constraint axes
218
+ Quaternion.FromRotationMatrixToRef(Matrix.FromXYZAxesToRef(axisA, perpAxisA, Vector3.CrossToRef(axisA, perpAxisA, TmpVectors.Vector3[0]), TmpVectors.Matrix[0]), parentTransformNode.rotationQuaternion);
219
+ Quaternion.FromRotationMatrixToRef(Matrix.FromXYZAxesToRef(axisB, perpAxisB, Vector3.CrossToRef(axisB, perpAxisB, TmpVectors.Vector3[1]), TmpVectors.Matrix[1]), childTransformNode.rotationQuaternion);
220
+ });
221
+ }
154
222
  /**
155
223
  * Renders a specified physic impostor
156
224
  * @param impostor defines the impostor to render
@@ -233,6 +301,32 @@ export class PhysicsViewer {
233
301
  }
234
302
  return debugMesh;
235
303
  }
304
+ /**
305
+ * Shows a debug mesh for a given physics constraint.
306
+ * @param constraint the physics constraint to show
307
+ * @returns the debug mesh, or null if the constraint is already shown
308
+ */
309
+ showConstraint(constraint) {
310
+ if (!this._scene) {
311
+ return null;
312
+ }
313
+ for (let i = 0; i < this._numConstraints; i++) {
314
+ if (this._constraints[i] == constraint) {
315
+ return null;
316
+ }
317
+ }
318
+ const debugMesh = this._getDebugConstraintMesh(constraint);
319
+ if (debugMesh) {
320
+ this._constraints[this._numConstraints] = constraint;
321
+ this._constraintMeshes[this._numConstraints] = debugMesh;
322
+ if (this._numConstraints === 0) {
323
+ this._constraintRenderFunction = this._updateDebugConstraints.bind(this);
324
+ this._scene.registerBeforeRender(this._constraintRenderFunction);
325
+ }
326
+ this._numConstraints++;
327
+ }
328
+ return debugMesh;
329
+ }
236
330
  /**
237
331
  * Hides an impostor from the scene.
238
332
  * @param impostor - The impostor to hide.
@@ -346,6 +440,45 @@ export class PhysicsViewer {
346
440
  this._scene.unregisterBeforeRender(this._inertiaRenderFunction);
347
441
  }
348
442
  }
443
+ /**
444
+ * Hide a physics constraint from the viewer utility layer
445
+ * @param constraint the constraint to hide
446
+ */
447
+ hideConstraint(constraint) {
448
+ if (!constraint || !this._scene || !this._utilityLayer) {
449
+ return;
450
+ }
451
+ let removed = false;
452
+ const utilityLayerScene = this._utilityLayer.utilityLayerScene;
453
+ for (let i = 0; i < this._numConstraints; i++) {
454
+ if (this._constraints[i] === constraint) {
455
+ const mesh = this._constraintMeshes[i];
456
+ if (!mesh) {
457
+ continue;
458
+ }
459
+ utilityLayerScene.removeMesh(mesh);
460
+ mesh.dispose();
461
+ this._constraints.splice(i, 1);
462
+ this._constraintMeshes.splice(i, 1);
463
+ this._numConstraints--;
464
+ if (this._numConstraints > 0) {
465
+ this._constraints[i] = this._constraints[this._numConstraints];
466
+ this._constraintMeshes[i] = this._constraintMeshes[this._numConstraints];
467
+ this._constraints[this._numConstraints] = null;
468
+ this._constraintMeshes[this._numConstraints] = null;
469
+ }
470
+ else {
471
+ this._constraints[0] = null;
472
+ this._constraintMeshes[0] = null;
473
+ }
474
+ removed = true;
475
+ break;
476
+ }
477
+ }
478
+ if (removed && this._numConstraints === 0) {
479
+ this._scene.unregisterBeforeRender(this._constraintRenderFunction);
480
+ }
481
+ }
349
482
  _getDebugMaterial(scene) {
350
483
  if (!this._debugMaterial) {
351
484
  this._debugMaterial = new StandardMaterial("", scene);
@@ -576,6 +709,78 @@ export class PhysicsViewer {
576
709
  inertiaBoxMesh.material = this._getDebugInertiaMaterial(utilityLayerScene);
577
710
  return inertiaBoxMesh;
578
711
  }
712
+ _getTransformFromBodyToRef(body, matrix, instanceIndex) {
713
+ const tnode = body.transformNode;
714
+ if (instanceIndex && instanceIndex >= 0) {
715
+ return Matrix.FromArrayToRef(tnode._thinInstanceDataStorage.matrixData, instanceIndex, matrix);
716
+ }
717
+ else {
718
+ return matrix.copyFrom(tnode.getWorldMatrix());
719
+ }
720
+ }
721
+ _getDebugConstraintMesh(constraint) {
722
+ if (!this._utilityLayer) {
723
+ return null;
724
+ }
725
+ const utilityLayerScene = this._utilityLayer.utilityLayerScene;
726
+ if (!constraint._initOptions) {
727
+ return null;
728
+ }
729
+ // Get constraint pivot and axes
730
+ const { pivotA, pivotB, axisA, axisB, perpAxisA, perpAxisB } = constraint._initOptions;
731
+ if (!pivotA || !pivotB || !axisA || !axisB || !perpAxisA || !perpAxisB) {
732
+ return null;
733
+ }
734
+ // Create a mesh to parent all the constraint debug meshes to
735
+ const parentingMesh = new Mesh("parentingDebugConstraint", utilityLayerScene);
736
+ // First, get a reference to all physic bodies that are using this constraint
737
+ const bodiesUsingConstraint = constraint.getBodiesUsingConstraint();
738
+ for (const bodyPairInfo of bodiesUsingConstraint) {
739
+ // Create a mesh to keep the pair of constraint axes
740
+ const parentOfPair = new TransformNode("parentOfPair", utilityLayerScene);
741
+ parentOfPair.parent = parentingMesh;
742
+ const { parentBody, parentBodyIndex, childBody, childBodyIndex } = bodyPairInfo;
743
+ // Get the parent transform
744
+ const parentTransform = this._getTransformFromBodyToRef(parentBody, TmpVectors.Matrix[0], parentBodyIndex);
745
+ const childTransform = this._getTransformFromBodyToRef(childBody, TmpVectors.Matrix[1], childBodyIndex);
746
+ const parentCoordSystemNode = new TransformNode("parentCoordSystem", utilityLayerScene);
747
+ // parentCoordSystemNode.parent = parentingMesh;
748
+ parentCoordSystemNode.parent = parentOfPair;
749
+ // Save parent and index here to be able to get the transform on update
750
+ parentCoordSystemNode.metadata = { parentBody, parentBodyIndex };
751
+ parentTransform.decomposeToTransformNode(parentCoordSystemNode);
752
+ const childCoordSystemNode = new TransformNode("childCoordSystem", utilityLayerScene);
753
+ // childCoordSystemNode.parent = parentingMesh;
754
+ childCoordSystemNode.parent = parentOfPair;
755
+ // Save child and index here to be able to get the transform on update
756
+ childCoordSystemNode.metadata = { childBody, childBodyIndex };
757
+ childTransform.decomposeToTransformNode(childCoordSystemNode);
758
+ // Get the transform to align the XYZ axes to the constraint axes
759
+ const rotTransformParent = Quaternion.FromRotationMatrix(Matrix.FromXYZAxesToRef(axisA, perpAxisA, axisA.cross(perpAxisA), TmpVectors.Matrix[0]));
760
+ const rotTransformChild = Quaternion.FromRotationMatrix(Matrix.FromXYZAxesToRef(axisB, perpAxisB, axisB.cross(perpAxisB), TmpVectors.Matrix[0]));
761
+ const translateTransformParent = pivotA;
762
+ const translateTransformChild = pivotB;
763
+ // Create a transform node and set its matrix
764
+ const parentTransformNode = new TransformNode("constraint_parent", utilityLayerScene);
765
+ parentTransformNode.position.copyFrom(translateTransformParent);
766
+ parentTransformNode.rotationQuaternion = rotTransformParent;
767
+ parentTransformNode.parent = parentCoordSystemNode;
768
+ const childTransformNode = new TransformNode("constraint_child", utilityLayerScene);
769
+ childTransformNode.parent = childCoordSystemNode;
770
+ childTransformNode.position.copyFrom(translateTransformChild);
771
+ childTransformNode.rotationQuaternion = rotTransformChild;
772
+ // Create axes for the constraint
773
+ const parentAxes = new AxesViewer(utilityLayerScene, this._constraintAxesSize);
774
+ parentAxes.xAxis.parent = parentTransformNode;
775
+ parentAxes.yAxis.parent = parentTransformNode;
776
+ parentAxes.zAxis.parent = parentTransformNode;
777
+ const childAxes = new AxesViewer(utilityLayerScene, this._constraintAxesSize);
778
+ childAxes.xAxis.parent = childTransformNode;
779
+ childAxes.yAxis.parent = childTransformNode;
780
+ childAxes.zAxis.parent = childTransformNode;
781
+ }
782
+ return parentingMesh;
783
+ }
579
784
  /**
580
785
  * Clean up physics debug display
581
786
  */