@babylonjs/core 8.46.2 → 8.47.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/Behaviors/Cameras/geospatialClippingBehavior.d.ts +39 -0
  2. package/Behaviors/Cameras/geospatialClippingBehavior.js +75 -0
  3. package/Behaviors/Cameras/geospatialClippingBehavior.js.map +1 -0
  4. package/Behaviors/Cameras/index.d.ts +2 -0
  5. package/Behaviors/Cameras/index.js +2 -0
  6. package/Behaviors/Cameras/index.js.map +1 -1
  7. package/Cameras/Inputs/geospatialCameraPointersInput.js +6 -4
  8. package/Cameras/Inputs/geospatialCameraPointersInput.js.map +1 -1
  9. package/Cameras/Limits/geospatialLimits.d.ts +25 -1
  10. package/Cameras/Limits/geospatialLimits.js +60 -3
  11. package/Cameras/Limits/geospatialLimits.js.map +1 -1
  12. package/Cameras/geospatialCamera.d.ts +33 -9
  13. package/Cameras/geospatialCamera.js +114 -42
  14. package/Cameras/geospatialCamera.js.map +1 -1
  15. package/Cameras/geospatialCameraMovement.d.ts +1 -3
  16. package/Cameras/geospatialCameraMovement.js +10 -4
  17. package/Cameras/geospatialCameraMovement.js.map +1 -1
  18. package/Debug/debugLayer.js +11 -3
  19. package/Debug/debugLayer.js.map +1 -1
  20. package/Engines/abstractEngine.js +2 -2
  21. package/Engines/abstractEngine.js.map +1 -1
  22. package/Engines/constants.d.ts +1 -1
  23. package/Engines/constants.js +1 -1
  24. package/Engines/constants.js.map +1 -1
  25. package/Engines/thinEngine.d.ts +3 -2
  26. package/Engines/thinEngine.js.map +1 -1
  27. package/IAssetContainer.d.ts +5 -0
  28. package/IAssetContainer.js.map +1 -1
  29. package/Lights/Clustered/clusteredLightContainer.js +1 -1
  30. package/Lights/Clustered/clusteredLightContainer.js.map +1 -1
  31. package/Lights/areaLight.d.ts +1 -1
  32. package/Lights/areaLight.js +1 -1
  33. package/Lights/areaLight.js.map +1 -1
  34. package/Lights/rectAreaLight.d.ts +20 -0
  35. package/Lights/rectAreaLight.js +45 -0
  36. package/Lights/rectAreaLight.js.map +1 -1
  37. package/Loading/Plugins/babylonFileLoader.js +2 -0
  38. package/Loading/Plugins/babylonFileLoader.js.map +1 -1
  39. package/Materials/Node/Blocks/Dual/lightBlock.js +1 -1
  40. package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
  41. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js +1 -1
  42. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
  43. package/Materials/Node/Blocks/Fragment/imageProcessingBlock.js +6 -3
  44. package/Materials/Node/Blocks/Fragment/imageProcessingBlock.js.map +1 -1
  45. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +1 -1
  46. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
  47. package/Materials/PBR/openpbrMaterial.d.ts +135 -5
  48. package/Materials/PBR/openpbrMaterial.js +205 -22
  49. package/Materials/PBR/openpbrMaterial.js.map +1 -1
  50. package/Materials/effectRenderer.d.ts +2 -1
  51. package/Materials/effectRenderer.js +2 -12
  52. package/Materials/effectRenderer.js.map +1 -1
  53. package/Materials/material.d.ts +1 -1
  54. package/Materials/material.js +1 -1
  55. package/Materials/material.js.map +1 -1
  56. package/Materials/materialHelper.functions.d.ts +2 -1
  57. package/Materials/materialHelper.functions.js +7 -2
  58. package/Materials/materialHelper.functions.js.map +1 -1
  59. package/Materials/materialPluginManager.js +2 -2
  60. package/Materials/materialPluginManager.js.map +1 -1
  61. package/Meshes/GaussianSplatting/gaussianSplattingMesh.d.ts +6 -1
  62. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +21 -17
  63. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
  64. package/Misc/HighDynamicRange/cubemapToSphericalPolynomial.js +1 -5
  65. package/Misc/HighDynamicRange/cubemapToSphericalPolynomial.js.map +1 -1
  66. package/Misc/areaLightsTextureTools.d.ts +52 -0
  67. package/Misc/areaLightsTextureTools.js +227 -0
  68. package/Misc/areaLightsTextureTools.js.map +1 -0
  69. package/Misc/decorators.serialization.js +6 -1
  70. package/Misc/decorators.serialization.js.map +1 -1
  71. package/Misc/index.d.ts +3 -0
  72. package/Misc/index.js +4 -0
  73. package/Misc/index.js.map +1 -1
  74. package/Misc/sceneRecorder.d.ts +6 -2
  75. package/Misc/sceneRecorder.js +7 -0
  76. package/Misc/sceneRecorder.js.map +1 -1
  77. package/Particles/Node/Blocks/index.d.ts +3 -0
  78. package/Particles/Node/Blocks/index.js +3 -0
  79. package/Particles/Node/Blocks/index.js.map +1 -1
  80. package/Particles/Node/Blocks/particleNLerpBlock.d.ts +35 -0
  81. package/Particles/Node/Blocks/particleNLerpBlock.js +97 -0
  82. package/Particles/Node/Blocks/particleNLerpBlock.js.map +1 -0
  83. package/Particles/Node/Blocks/particleSmoothStepBlock.d.ts +34 -0
  84. package/Particles/Node/Blocks/particleSmoothStepBlock.js +91 -0
  85. package/Particles/Node/Blocks/particleSmoothStepBlock.js.map +1 -0
  86. package/Particles/Node/Blocks/particleSourceTextureBlock.d.ts +4 -0
  87. package/Particles/Node/Blocks/particleSourceTextureBlock.js +9 -3
  88. package/Particles/Node/Blocks/particleSourceTextureBlock.js.map +1 -1
  89. package/Particles/Node/Blocks/particleStepBlock.d.ts +30 -0
  90. package/Particles/Node/Blocks/particleStepBlock.js +84 -0
  91. package/Particles/Node/Blocks/particleStepBlock.js.map +1 -0
  92. package/Particles/Node/nodeParticleSystemSet.d.ts +2 -0
  93. package/Particles/Node/nodeParticleSystemSet.js.map +1 -1
  94. package/Particles/solidParticleSystem.d.ts +3 -0
  95. package/Particles/solidParticleSystem.js +7 -4
  96. package/Particles/solidParticleSystem.js.map +1 -1
  97. package/Physics/v2/IPhysicsEnginePlugin.d.ts +1 -0
  98. package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
  99. package/Physics/v2/Plugins/havokPlugin.d.ts +10 -0
  100. package/Physics/v2/Plugins/havokPlugin.js +13 -0
  101. package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
  102. package/Physics/v2/physicsBody.d.ts +10 -0
  103. package/Physics/v2/physicsBody.js +12 -0
  104. package/Physics/v2/physicsBody.js.map +1 -1
  105. package/Physics/v2/physicsEngineComponent.d.ts +5 -0
  106. package/Physics/v2/physicsEngineComponent.js +13 -0
  107. package/Physics/v2/physicsEngineComponent.js.map +1 -1
  108. package/Rendering/IBLShadows/iblShadowsPluginMaterial.js +8 -10
  109. package/Rendering/IBLShadows/iblShadowsPluginMaterial.js.map +1 -1
  110. package/Rendering/utilityLayerRenderer.d.ts +6 -0
  111. package/Rendering/utilityLayerRenderer.js +14 -5
  112. package/Rendering/utilityLayerRenderer.js.map +1 -1
  113. package/Shaders/ShadersInclude/hdrFilteringFunctions.js +7 -9
  114. package/Shaders/ShadersInclude/hdrFilteringFunctions.js.map +1 -1
  115. package/Shaders/ShadersInclude/helperFunctions.js +4 -0
  116. package/Shaders/ShadersInclude/helperFunctions.js.map +1 -1
  117. package/Shaders/ShadersInclude/lightFragment.js +13 -0
  118. package/Shaders/ShadersInclude/lightFragment.js.map +1 -1
  119. package/Shaders/ShadersInclude/lightFragmentDeclaration.js +3 -0
  120. package/Shaders/ShadersInclude/lightFragmentDeclaration.js.map +1 -1
  121. package/Shaders/ShadersInclude/lightUboDeclaration.js +3 -0
  122. package/Shaders/ShadersInclude/lightUboDeclaration.js.map +1 -1
  123. package/Shaders/ShadersInclude/lightsFragmentFunctions.js +6 -0
  124. package/Shaders/ShadersInclude/lightsFragmentFunctions.js.map +1 -1
  125. package/Shaders/ShadersInclude/ltcHelperFunctions.js +17 -1
  126. package/Shaders/ShadersInclude/ltcHelperFunctions.js.map +1 -1
  127. package/Shaders/ShadersInclude/{openpbrBlockAmbientOcclusion.d.ts → openpbrAmbientOcclusionData.d.ts} +1 -1
  128. package/Shaders/ShadersInclude/openpbrAmbientOcclusionData.js +15 -0
  129. package/Shaders/ShadersInclude/openpbrAmbientOcclusionData.js.map +1 -0
  130. package/{ShadersWGSL/ShadersInclude/openpbrBlockAmbientOcclusion.d.ts → Shaders/ShadersInclude/openpbrAmbientOcclusionFunctions.d.ts} +1 -1
  131. package/Shaders/ShadersInclude/openpbrAmbientOcclusionFunctions.js +13 -0
  132. package/Shaders/ShadersInclude/openpbrAmbientOcclusionFunctions.js.map +1 -0
  133. package/Shaders/ShadersInclude/openpbrBackgroundTransmission.d.ts +5 -0
  134. package/Shaders/ShadersInclude/openpbrBackgroundTransmission.js +26 -0
  135. package/Shaders/ShadersInclude/openpbrBackgroundTransmission.js.map +1 -0
  136. package/Shaders/ShadersInclude/openpbrBaseLayerData.js +18 -7
  137. package/Shaders/ShadersInclude/openpbrBaseLayerData.js.map +1 -1
  138. package/Shaders/ShadersInclude/openpbrDirectLighting.js +52 -6
  139. package/Shaders/ShadersInclude/openpbrDirectLighting.js.map +1 -1
  140. package/Shaders/ShadersInclude/openpbrEnvironmentLighting.js +109 -6
  141. package/Shaders/ShadersInclude/openpbrEnvironmentLighting.js.map +1 -1
  142. package/Shaders/ShadersInclude/openpbrFragmentDeclaration.d.ts +1 -0
  143. package/Shaders/ShadersInclude/openpbrFragmentDeclaration.js +24 -4
  144. package/Shaders/ShadersInclude/openpbrFragmentDeclaration.js.map +1 -1
  145. package/Shaders/ShadersInclude/openpbrFragmentSamplersDeclaration.js +10 -1
  146. package/Shaders/ShadersInclude/openpbrFragmentSamplersDeclaration.js.map +1 -1
  147. package/Shaders/ShadersInclude/openpbrIblFunctions.js +9 -2
  148. package/Shaders/ShadersInclude/openpbrIblFunctions.js.map +1 -1
  149. package/Shaders/ShadersInclude/openpbrThinFilmLayerData.js +1 -0
  150. package/Shaders/ShadersInclude/openpbrThinFilmLayerData.js.map +1 -1
  151. package/Shaders/ShadersInclude/openpbrTransmissionLayerData.d.ts +5 -0
  152. package/Shaders/ShadersInclude/openpbrTransmissionLayerData.js +47 -0
  153. package/Shaders/ShadersInclude/openpbrTransmissionLayerData.js.map +1 -0
  154. package/Shaders/ShadersInclude/openpbrUboDeclaration.js +1 -1
  155. package/Shaders/ShadersInclude/openpbrUboDeclaration.js.map +1 -1
  156. package/Shaders/ShadersInclude/openpbrVertexDeclaration.d.ts +1 -0
  157. package/Shaders/ShadersInclude/openpbrVertexDeclaration.js +17 -4
  158. package/Shaders/ShadersInclude/openpbrVertexDeclaration.js.map +1 -1
  159. package/Shaders/ShadersInclude/pbrDirectLightingFunctions.js +1 -1
  160. package/Shaders/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
  161. package/Shaders/ShadersInclude/pbrDirectLightingSetupFunctions.js +6 -0
  162. package/Shaders/ShadersInclude/pbrDirectLightingSetupFunctions.js.map +1 -1
  163. package/Shaders/ShadersInclude/pbrHelperFunctions.js +1 -1
  164. package/Shaders/ShadersInclude/pbrHelperFunctions.js.map +1 -1
  165. package/Shaders/areaLightTextureProcessing.fragment.d.ts +5 -0
  166. package/Shaders/areaLightTextureProcessing.fragment.js +13 -0
  167. package/Shaders/areaLightTextureProcessing.fragment.js.map +1 -0
  168. package/Shaders/openpbr.fragment.d.ts +4 -1
  169. package/Shaders/openpbr.fragment.js +33 -15
  170. package/Shaders/openpbr.fragment.js.map +1 -1
  171. package/Shaders/openpbr.vertex.js +30 -18
  172. package/Shaders/openpbr.vertex.js.map +1 -1
  173. package/ShadersWGSL/ShadersInclude/hdrFilteringFunctions.js +10 -12
  174. package/ShadersWGSL/ShadersInclude/hdrFilteringFunctions.js.map +1 -1
  175. package/ShadersWGSL/ShadersInclude/helperFunctions.js +4 -0
  176. package/ShadersWGSL/ShadersInclude/helperFunctions.js.map +1 -1
  177. package/ShadersWGSL/ShadersInclude/importanceSampling.js +1 -1
  178. package/ShadersWGSL/ShadersInclude/importanceSampling.js.map +1 -1
  179. package/ShadersWGSL/ShadersInclude/lightFragment.js +14 -0
  180. package/ShadersWGSL/ShadersInclude/lightFragment.js.map +1 -1
  181. package/ShadersWGSL/ShadersInclude/lightUboDeclaration.js +3 -0
  182. package/ShadersWGSL/ShadersInclude/lightUboDeclaration.js.map +1 -1
  183. package/ShadersWGSL/ShadersInclude/lightsFragmentFunctions.js +6 -0
  184. package/ShadersWGSL/ShadersInclude/lightsFragmentFunctions.js.map +1 -1
  185. package/ShadersWGSL/ShadersInclude/ltcHelperFunctions.js +19 -1
  186. package/ShadersWGSL/ShadersInclude/ltcHelperFunctions.js.map +1 -1
  187. package/ShadersWGSL/ShadersInclude/openpbrAmbientOcclusionData.d.ts +5 -0
  188. package/ShadersWGSL/ShadersInclude/openpbrAmbientOcclusionData.js +15 -0
  189. package/ShadersWGSL/ShadersInclude/openpbrAmbientOcclusionData.js.map +1 -0
  190. package/ShadersWGSL/ShadersInclude/openpbrAmbientOcclusionFunctions.d.ts +5 -0
  191. package/ShadersWGSL/ShadersInclude/openpbrAmbientOcclusionFunctions.js +13 -0
  192. package/ShadersWGSL/ShadersInclude/openpbrAmbientOcclusionFunctions.js.map +1 -0
  193. package/ShadersWGSL/ShadersInclude/openpbrBackgroundTransmission.d.ts +5 -0
  194. package/ShadersWGSL/ShadersInclude/openpbrBackgroundTransmission.js +25 -0
  195. package/ShadersWGSL/ShadersInclude/openpbrBackgroundTransmission.js.map +1 -0
  196. package/ShadersWGSL/ShadersInclude/openpbrBaseLayerData.js +18 -7
  197. package/ShadersWGSL/ShadersInclude/openpbrBaseLayerData.js.map +1 -1
  198. package/ShadersWGSL/ShadersInclude/openpbrDirectLighting.js +52 -6
  199. package/ShadersWGSL/ShadersInclude/openpbrDirectLighting.js.map +1 -1
  200. package/ShadersWGSL/ShadersInclude/openpbrEnvironmentLighting.js +115 -7
  201. package/ShadersWGSL/ShadersInclude/openpbrEnvironmentLighting.js.map +1 -1
  202. package/ShadersWGSL/ShadersInclude/openpbrFragmentSamplersDeclaration.js +10 -1
  203. package/ShadersWGSL/ShadersInclude/openpbrFragmentSamplersDeclaration.js.map +1 -1
  204. package/ShadersWGSL/ShadersInclude/openpbrFuzzLayerData.js +4 -4
  205. package/ShadersWGSL/ShadersInclude/openpbrFuzzLayerData.js.map +1 -1
  206. package/ShadersWGSL/ShadersInclude/openpbrIblFunctions.js +10 -3
  207. package/ShadersWGSL/ShadersInclude/openpbrIblFunctions.js.map +1 -1
  208. package/ShadersWGSL/ShadersInclude/openpbrThinFilmLayerData.js +1 -0
  209. package/ShadersWGSL/ShadersInclude/openpbrThinFilmLayerData.js.map +1 -1
  210. package/ShadersWGSL/ShadersInclude/openpbrTransmissionLayerData.d.ts +5 -0
  211. package/ShadersWGSL/ShadersInclude/openpbrTransmissionLayerData.js +47 -0
  212. package/ShadersWGSL/ShadersInclude/openpbrTransmissionLayerData.js.map +1 -0
  213. package/ShadersWGSL/ShadersInclude/openpbrUboDeclaration.js +1 -1
  214. package/ShadersWGSL/ShadersInclude/openpbrUboDeclaration.js.map +1 -1
  215. package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js +1 -1
  216. package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
  217. package/ShadersWGSL/ShadersInclude/pbrDirectLightingSetupFunctions.js +5 -0
  218. package/ShadersWGSL/ShadersInclude/pbrDirectLightingSetupFunctions.js.map +1 -1
  219. package/ShadersWGSL/ShadersInclude/pbrHelperFunctions.js +1 -1
  220. package/ShadersWGSL/ShadersInclude/pbrHelperFunctions.js.map +1 -1
  221. package/ShadersWGSL/areaLightTextureProcessing.fragment.d.ts +5 -0
  222. package/ShadersWGSL/areaLightTextureProcessing.fragment.js +12 -0
  223. package/ShadersWGSL/areaLightTextureProcessing.fragment.js.map +1 -0
  224. package/ShadersWGSL/iblVoxelGrid.vertex.js +2 -2
  225. package/ShadersWGSL/iblVoxelGrid.vertex.js.map +1 -1
  226. package/ShadersWGSL/openpbr.fragment.d.ts +4 -1
  227. package/ShadersWGSL/openpbr.fragment.js +33 -15
  228. package/ShadersWGSL/openpbr.fragment.js.map +1 -1
  229. package/ShadersWGSL/openpbr.vertex.js +12 -0
  230. package/ShadersWGSL/openpbr.vertex.js.map +1 -1
  231. package/Sprites/spriteManager.d.ts +3 -0
  232. package/Sprites/spriteManager.js +9 -0
  233. package/Sprites/spriteManager.js.map +1 -1
  234. package/States/alphaCullingState.js +0 -1
  235. package/States/alphaCullingState.js.map +1 -1
  236. package/assetContainer.d.ts +5 -0
  237. package/assetContainer.js +32 -0
  238. package/assetContainer.js.map +1 -1
  239. package/package.json +2 -2
  240. package/Shaders/ShadersInclude/openpbrBlockAmbientOcclusion.js +0 -35
  241. package/Shaders/ShadersInclude/openpbrBlockAmbientOcclusion.js.map +0 -1
  242. package/ShadersWGSL/ShadersInclude/openpbrBlockAmbientOcclusion.js +0 -36
  243. package/ShadersWGSL/ShadersInclude/openpbrBlockAmbientOcclusion.js.map +0 -1
@@ -313,6 +313,16 @@ export declare class PhysicsBody {
313
313
  * @param instanceIndex For a instanced body, the instance to where the impulse should be applied. If not specified, the impulse is applied to all instances.
314
314
  */
315
315
  applyAngularImpulse(angularImpulse: Vector3, instanceIndex?: number): void;
316
+ /**
317
+ * Applies a torque to the physics body.
318
+ *
319
+ * @param torque The torque vector.
320
+ * @param instanceIndex For a instanced body, the instance to where the torque should be applied. If not specified, the torque is applied to all instances.
321
+ *
322
+ * This method is useful for applying a torque to a physics body, which can be used to simulate rotational forces such as motors,
323
+ * angular momentum, and rotational dynamics. This can be used to create realistic physics simulations in a game or other application.
324
+ */
325
+ applyTorque(torque: Vector3, instanceIndex?: number): void;
316
326
  /**
317
327
  * Applies a force to the physics object.
318
328
  *
@@ -406,6 +406,18 @@ export class PhysicsBody {
406
406
  applyAngularImpulse(angularImpulse, instanceIndex) {
407
407
  this._physicsPlugin.applyAngularImpulse(this, angularImpulse, instanceIndex);
408
408
  }
409
+ /**
410
+ * Applies a torque to the physics body.
411
+ *
412
+ * @param torque The torque vector.
413
+ * @param instanceIndex For a instanced body, the instance to where the torque should be applied. If not specified, the torque is applied to all instances.
414
+ *
415
+ * This method is useful for applying a torque to a physics body, which can be used to simulate rotational forces such as motors,
416
+ * angular momentum, and rotational dynamics. This can be used to create realistic physics simulations in a game or other application.
417
+ */
418
+ applyTorque(torque, instanceIndex) {
419
+ this._physicsPlugin.applyTorque(this, torque, instanceIndex);
420
+ }
409
421
  /**
410
422
  * Applies a force to the physics object.
411
423
  *
@@ -1 +1 @@
1
- {"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/physicsBody.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAc1E;;;;GAIG;AACH,MAAM,OAAO,WAAW;IA8BpB;;;OAGG;IACH,IAAW,cAAc;QACrB,OAAO,IAAI,CAAC,YAAY,IAAI,kBAAkB,CAAC,QAAQ,CAAC;IAC5D,CAAC;IAED,IAAW,cAAc,CAAC,KAAc;QACpC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC;IAC1F,CAAC;IAmBD;;;;;;;;;;;;;OAaG;IACH,YAAY,aAA4B,EAAE,UAA6B,EAAE,YAAqB,EAAE,KAAY;QAxE5G;;WAEG;QACI,gBAAW,GAAQ,SAAS,CAAC;QACpC;;WAEG;QACI,yBAAoB,GAAe,EAAE,CAAC;QAS7C;;WAEG;QACK,wBAAmB,GAAY,KAAK,CAAC;QAC7C;;WAEG;QACK,6BAAwB,GAAY,KAAK,CAAC;QAkBlD;;WAEG;QACH,gBAAW,GAAY,KAAK,CAAC;QASrB,gBAAW,GAAG,KAAK,CAAC;QAEpB,WAAM,GAA2B,IAAI,CAAC;QAEtC,iBAAY,GAAuB,kBAAkB,CAAC,QAAQ,CAAC;QAgBnE,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,OAAO;QACX,CAAC;QACD,MAAM,aAAa,GAAG,K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AI,CAAC,CAAC;QACrC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,aAAa,CAAC,WAAW,GAAG,IAAI,CAAC;QACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;QACrC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACtB,CAAC;CACJ","sourcesContent":["import type { IBasePhysicsCollisionEvent, IPhysicsCollisionEvent, IPhysicsEnginePluginV2, PhysicsMassProperties } from \"./IPhysicsEnginePlugin\";\r\nimport { PhysicsMotionType, PhysicsPrestepType } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsShape } from \"./physicsShape\";\r\nimport { Vector3, Quaternion, TmpVectors } from \"../../Maths/math.vector\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PhysicsEngine } from \"./physicsEngine\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { PhysicsConstraint } from \"./physicsConstraint\";\r\nimport type { Bone } from \"core/Bones/bone\";\r\nimport { Space } from \"core/Maths/math.axis\";\r\nimport type { Observable, Observer } from \"../../Misc/observable\";\r\nimport type { Node } from \"../../node\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { BoundingBox } from \"core/Culling/boundingBox\";\r\n\r\n/**\r\n * PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows\r\n * the user to set the mass and velocity of the body, which can then be used to calculate the\r\n * motion of the body in the physics engine.\r\n */\r\nexport class PhysicsBody {\r\n /**\r\n * V2 Physics plugin private data for single Transform\r\n */\r\n public _pluginData: any = undefined;\r\n /**\r\n * V2 Physics plugin private data for instances\r\n */\r\n public _pluginDataInstances: Array<any> = [];\r\n /**\r\n * The V2 plugin used to create and manage this Physics Body\r\n */\r\n private _physicsPlugin: IPhysicsEnginePluginV2;\r\n /**\r\n * The engine used to create and manage this Physics Body\r\n */\r\n private _physicsEngine: PhysicsEngine;\r\n /**\r\n * If the collision callback is enabled\r\n */\r\n private _collisionCBEnabled: boolean = false;\r\n /**\r\n * If the collision ended callback is enabled\r\n */\r\n private _collisionEndedCBEnabled: boolean = false;\r\n /**\r\n * The transform node associated with this Physics Body\r\n */\r\n transformNode: TransformNode;\r\n\r\n /**\r\n * Disable pre-step that consists in updating Physics Body from Transform Node Translation/Orientation.\r\n * True by default for maximum performance.\r\n */\r\n public get disablePreStep(): boolean {\r\n return this._prestepType == PhysicsPrestepType.DISABLED;\r\n }\r\n\r\n public set disablePreStep(value: boolean) {\r\n this._prestepType = value ? PhysicsPrestepType.DISABLED : PhysicsPrestepType.TELEPORT;\r\n }\r\n\r\n /**\r\n * Disable sync from physics to transformNode. This value is set to true at body creation or at motionType setting when the body is not dynamic.\r\n */\r\n disableSync: boolean = false;\r\n\r\n /**\r\n * Physics engine will try to make this body sleeping and not active\r\n */\r\n public startAsleep: boolean;\r\n\r\n private _nodeDisposeObserver: Nullable<Observer<Node>>;\r\n\r\n private _isDisposed = false;\r\n\r\n private _shape: Nullable<PhysicsShape> = null;\r\n\r\n private _prestepType: PhysicsPrestepType = PhysicsPrestepType.DISABLED;\r\n /**\r\n * Constructs a new physics body for the given node.\r\n * @param transformNode - The Transform Node to construct the physics body for. For better performance, it is advised that this node does not have a parent.\r\n * @param motionType - The motion type of the physics body. The options are:\r\n * - PhysicsMotionType.STATIC - Static bodies are not moving and unaffected by forces or collisions. They are good for level boundaries or terrain.\r\n * - PhysicsMotionType.DYNAMIC - Dynamic bodies are fully simulated. They can move and collide with other objects.\r\n * - PhysicsMotionType.ANIMATED - They behave like dynamic bodies, but they won't be affected by other bodies, but still push other bodies out of the way.\r\n * @param startsAsleep - Whether the physics body should start in a sleeping state (not a guarantee). Defaults to false.\r\n * @param scene - The scene containing the physics engine.\r\n *\r\n * This code is useful for creating a physics body for a given Transform Node in a scene.\r\n * It checks the version of the physics engine and the physics plugin, and initializes the body accordingly.\r\n * It also sets the node's rotation quaternion if it is not already set. Finally, it adds the body to the physics engine.\r\n */\r\n constructor(transformNode: TransformNode, motionType: PhysicsMotionType, startsAsleep: boolean, scene: Scene) {\r\n if (!scene) {\r\n return;\r\n }\r\n const physicsEngine = scene.getPhysicsEngine() as PhysicsEngine;\r\n if (!physicsEngine) {\r\n throw new Error(\"No Physics Engine available.\");\r\n }\r\n this._physicsEngine = physicsEngine;\r\n if (physicsEngine.getPluginVersion() != 2) {\r\n throw new Error(\"Plugin version is incorrect. Expected version 2.\");\r\n }\r\n const physicsPlugin = physicsEngine.getPhysicsPlugin();\r\n if (!physicsPlugin) {\r\n throw new Error(\"No Physics Plugin available.\");\r\n }\r\n\r\n this._physicsPlugin = physicsPlugin;\r\n if (!transformNode.rotationQuaternion) {\r\n transformNode.rotationQuaternion = Quaternion.FromEulerAngles(transformNode.rotation.x, transformNode.rotation.y, transformNode.rotation.z);\r\n }\r\n\r\n this.startAsleep = startsAsleep;\r\n\r\n // only dynamic and animated body needs sync from physics to transformNode\r\n this.disableSync = motionType == PhysicsMotionType.STATIC;\r\n\r\n // instances?\r\n const m = transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.initBodyInstances(this, motionType, m);\r\n } else {\r\n // single instance\r\n if (transformNode.parent) {\r\n // Force computation of world matrix so that the parent transforms are correctly reflected in absolutePosition/absoluteRotationQuaternion.\r\n transformNode.computeWorldMatrix(true);\r\n }\r\n this._physicsPlugin.initBody(this, motionType, transformNode.absolutePosition, transformNode.absoluteRotationQuaternion);\r\n }\r\n this.transformNode = transformNode;\r\n transformNode.physicsBody = this;\r\n physicsEngine.addBody(this);\r\n\r\n this._nodeDisposeObserver = transformNode.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n /**\r\n * Returns the string \"PhysicsBody\".\r\n * @returns \"PhysicsBody\"\r\n */\r\n public getClassName() {\r\n return \"PhysicsBody\";\r\n }\r\n\r\n /**\r\n * Clone the PhysicsBody to a new body and assign it to the transformNode parameter\r\n * @param transformNode transformNode that will be used for the cloned PhysicsBody\r\n * @returns the newly cloned PhysicsBody\r\n */\r\n public clone(transformNode: TransformNode): PhysicsBody {\r\n const clonedBody = new PhysicsBody(transformNode, this.getMotionType(), this.startAsleep, this.transformNode.getScene());\r\n clonedBody.shape = this.shape;\r\n clonedBody.setMassProperties(this.getMassProperties());\r\n clonedBody.setLinearDamping(this.getLinearDamping());\r\n clonedBody.setAngularDamping(this.getAngularDamping());\r\n return clonedBody;\r\n }\r\n\r\n /**\r\n * If a physics body is connected to an instanced node, update the number physic instances to match the number of node instances.\r\n */\r\n public updateBodyInstances() {\r\n const m = this.transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.updateBodyInstances(this, m);\r\n }\r\n }\r\n\r\n /**\r\n * This returns the number of internal instances of the physics body\r\n */\r\n public get numInstances(): number {\r\n return this._pluginDataInstances.length;\r\n }\r\n\r\n /**\r\n * Get the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.\r\n */\r\n public get motionType(): PhysicsMotionType {\r\n return this._physicsPlugin.getMotionType(this);\r\n }\r\n\r\n /**\r\n * Sets the shape of the physics body.\r\n * @param shape - The shape of the physics body.\r\n *\r\n * This method is useful for setting the shape of the physics body, which is necessary for the physics engine to accurately simulate the body's behavior.\r\n * The shape is used to calculate the body's mass, inertia, and other properties.\r\n */\r\n public set shape(shape: Nullable<PhysicsShape>) {\r\n this._shape = shape;\r\n if (shape) {\r\n this._physicsPlugin.setShape(this, shape);\r\n }\r\n }\r\n\r\n /**\r\n * Retrieves the physics shape associated with this object.\r\n *\r\n * @returns The physics shape associated with this object, or `undefined` if no\r\n * shape is associated.\r\n *\r\n * This method is useful for retrieving the physics shape associated with this object,\r\n * which can be used to apply physical forces to the object or to detect collisions.\r\n */\r\n public get shape(): Nullable<PhysicsShape> {\r\n return this._shape;\r\n }\r\n\r\n /**\r\n * Returns the bounding box of the physics body.\r\n * @returns The bounding box of the physics body.\r\n */\r\n public getBoundingBox(): BoundingBox {\r\n return this._physicsPlugin.getBodyBoundingBox(this);\r\n }\r\n\r\n /**\r\n * Sets the event mask for the physics engine.\r\n *\r\n * @param eventMask - A bitmask that determines which events will be sent to the physics engine.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the event mask for.\r\n *\r\n * This method is useful for setting the event mask for the physics engine, which determines which events\r\n * will be sent to the physics engine. This allows the user to control which events the physics engine will respond to.\r\n */\r\n public setEventMask(eventMask: number, instanceIndex?: number) {\r\n this._physicsPlugin.setEventMask(this, eventMask, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the event mask of the physics engine.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the event mask for.\r\n * @returns The event mask of the physics engine.\r\n *\r\n * This method is useful for getting the event mask of the physics engine,\r\n * which is used to determine which events the engine will respond to.\r\n * This is important for ensuring that the engine is responding to the correct events and not\r\n * wasting resources on unnecessary events.\r\n */\r\n public getEventMask(instanceIndex?: number): number {\r\n return this._physicsPlugin.getEventMask(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.\r\n * @param motionType - The motion type to set.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the motion type for. If body is instanced but instanceIndex is undefined, the motion type will be set for all instances.\r\n */\r\n public setMotionType(motionType: PhysicsMotionType, instanceIndex?: number) {\r\n this.disableSync = instanceIndex === undefined && motionType == PhysicsMotionType.STATIC;\r\n this._physicsPlugin.setMotionType(this, motionType, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the motion type for.\r\n * @returns The motion type of the physics body.\r\n */\r\n public getMotionType(instanceIndex?: number): PhysicsMotionType {\r\n return this._physicsPlugin.getMotionType(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Set the prestep type of the body\r\n * @param prestepType prestep type provided by PhysicsPrestepType\r\n */\r\n public setPrestepType(prestepType: PhysicsPrestepType): void {\r\n this._prestepType = prestepType;\r\n }\r\n\r\n /**\r\n * Get the current prestep type of the body\r\n * @returns the type of prestep associated with the body and its instance index\r\n */\r\n public getPrestepType(): PhysicsPrestepType {\r\n return this._prestepType;\r\n }\r\n\r\n /**\r\n * Computes the mass properties of the physics object, based on the set of physics shapes this body uses.\r\n * This method is useful for computing the initial mass properties of a physics object, such as its mass,\r\n * inertia, and center of mass; these values are important for accurately simulating the physics of the\r\n * object in the physics engine, and computing values based on the shape will provide you with reasonable\r\n * initial values, which you can then customize.\r\n * @param instanceIndex - The index of the instance to compute the mass properties for.\r\n * @returns The mass properties of the object.\r\n */\r\n public computeMassProperties(instanceIndex?: number): PhysicsMassProperties {\r\n return this._physicsPlugin.computeMassProperties(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the mass properties of the physics object.\r\n *\r\n * @param massProps - The mass properties to set.\r\n * @param instanceIndex - The index of the instance to set the mass properties for. If not defined, the mass properties will be set for all instances.\r\n *\r\n * This method is useful for setting the mass properties of a physics object, such as its mass,\r\n * inertia, and center of mass. This is important for accurately simulating the physics of the object in the physics engine.\r\n */\r\n public setMassProperties(massProps: PhysicsMassProperties, instanceIndex?: number): void {\r\n this._physicsPlugin.setMassProperties(this, massProps, instanceIndex);\r\n }\r\n\r\n /**\r\n * Retrieves the mass properties of the object.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the mass properties for.\r\n * @returns The mass properties of the object.\r\n *\r\n * This method is useful for physics simulations, as it allows the user to\r\n * retrieve the mass properties of the object, such as its mass, center of mass,\r\n * and moment of inertia. This information is necessary for accurate physics\r\n * simulations.\r\n */\r\n public getMassProperties(instanceIndex?: number): PhysicsMassProperties {\r\n return this._physicsPlugin.getMassProperties(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the linear damping of the physics body.\r\n *\r\n * @param damping - The linear damping value.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the linear damping for.\r\n *\r\n * This method is useful for controlling the linear damping of the physics body,\r\n * which is the rate at which the body's velocity decreases over time. This is useful for simulating\r\n * the effects of air resistance or other forms of friction.\r\n */\r\n public setLinearDamping(damping: number, instanceIndex?: number) {\r\n this._physicsPlugin.setLinearDamping(this, damping, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the linear damping of the physics body.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the linear damping for.\r\n * @returns The linear damping of the physics body.\r\n *\r\n * This method is useful for retrieving the linear damping of the physics body, which is the amount of\r\n * resistance the body has to linear motion. This is useful for simulating realistic physics behavior\r\n * in a game.\r\n */\r\n public getLinearDamping(instanceIndex?: number): number {\r\n return this._physicsPlugin.getLinearDamping(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the angular damping of the physics body.\r\n * @param damping The angular damping of the body.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the angular damping for.\r\n *\r\n * This method is useful for controlling the angular velocity of a physics body.\r\n * By setting the damping, the body's angular velocity will be reduced over time, simulating the effect of friction.\r\n * This can be used to create realistic physical behavior in a physics engine.\r\n */\r\n public setAngularDamping(damping: number, instanceIndex?: number) {\r\n this._physicsPlugin.setAngularDamping(this, damping, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the angular damping of the physics body.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the angular damping for.\r\n *\r\n * @returns The angular damping of the physics body.\r\n *\r\n * This method is useful for getting the angular damping of the physics body,\r\n * which is the rate of reduction of the angular velocity over time.\r\n * This is important for simulating realistic physics behavior in a game.\r\n */\r\n public getAngularDamping(instanceIndex?: number): number {\r\n return this._physicsPlugin.getAngularDamping(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the linear velocity of the physics object.\r\n * @param linVel - The linear velocity to set.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the linear velocity for.\r\n *\r\n * This method is useful for setting the linear velocity of a physics object,\r\n * which is necessary for simulating realistic physics in a game engine.\r\n * By setting the linear velocity, the physics object will move in the direction and speed specified by the vector.\r\n * This allows for realistic physics simulations, such as simulating the motion of a ball rolling down a hill.\r\n */\r\n public setLinearVelocity(linVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.setLinearVelocity(this, linVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the linear velocity of the physics body and stores it in the given vector3.\r\n * @param linVel - The vector3 to store the linear velocity in.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the linear velocity for.\r\n *\r\n * This method is useful for getting the linear velocity of a physics body in a physics engine.\r\n * This can be used to determine the speed and direction of the body, which can be used to calculate the motion of the body.\r\n */\r\n public getLinearVelocityToRef(linVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.getLinearVelocityToRef(this, linVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the linear velocity of the physics body as a new vector3.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the linear velocity for.\r\n * @returns The linear velocity of the physics body.\r\n *\r\n * This method is useful for getting the linear velocity of a physics body in a physics engine.\r\n * This can be used to determine the speed and direction of the body, which can be used to calculate the motion of the body.\r\n */\r\n public getLinearVelocity(instanceIndex?: number): Vector3 {\r\n const ref = new Vector3();\r\n this.getLinearVelocityToRef(ref, instanceIndex);\r\n return ref;\r\n }\r\n\r\n /**\r\n * Sets the angular velocity of the physics object.\r\n * @param angVel - The angular velocity to set.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the angular velocity for.\r\n *\r\n * This method is useful for setting the angular velocity of a physics object, which is necessary for\r\n * simulating realistic physics behavior. The angular velocity is used to determine the rate of rotation of the object,\r\n * which is important for simulating realistic motion.\r\n */\r\n public setAngularVelocity(angVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.setAngularVelocity(this, angVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the angular velocity of the physics body and stores it in the given vector3.\r\n * @param angVel - The vector3 to store the angular velocity in.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the angular velocity for.\r\n *\r\n * This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's\r\n * rotational speed. This information can be used to create realistic physics simulations.\r\n */\r\n public getAngularVelocityToRef(angVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.getAngularVelocityToRef(this, angVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the angular velocity of the physics body as a new vector3.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the angular velocity for.\r\n * @returns The angular velocity of the physics body.\r\n *\r\n * This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's\r\n * rotational speed. This information can be used to create realistic physics simulations.\r\n */\r\n public getAngularVelocity(instanceIndex?: number): Vector3 {\r\n const ref = new Vector3();\r\n this.getAngularVelocityToRef(ref, instanceIndex);\r\n return ref;\r\n }\r\n\r\n /**\r\n * Applies an impulse to the physics object.\r\n *\r\n * @param impulse The impulse vector.\r\n * @param location The location of the impulse.\r\n * @param instanceIndex For a instanced body, the instance to where the impulse should be applied. If not specified, the impulse is applied to all instances.\r\n *\r\n * This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyImpulse(impulse: Vector3, location: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyImpulse(this, impulse, location, instanceIndex);\r\n }\r\n\r\n /**\r\n * Add torque to a physics body\r\n * @param angularImpulse The angular impulse vector.\r\n * @param instanceIndex For a instanced body, the instance to where the impulse should be applied. If not specified, the impulse is applied to all instances.\r\n */\r\n public applyAngularImpulse(angularImpulse: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyAngularImpulse(this, angularImpulse, instanceIndex);\r\n }\r\n\r\n /**\r\n * Applies a force to the physics object.\r\n *\r\n * @param force The force vector.\r\n * @param location The location of the force.\r\n * @param instanceIndex For a instanced body, the instance to where the force should be applied. If not specified, the force is applied to all instances.\r\n *\r\n * This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyForce(force: Vector3, location: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyForce(this, force, location, instanceIndex);\r\n }\r\n\r\n /**\r\n * Retrieves the geometry of the body from the physics plugin.\r\n *\r\n * @returns The geometry of the body.\r\n *\r\n * This method is useful for retrieving the geometry of the body from the physics plugin, which can be used for various physics calculations.\r\n */\r\n public getGeometry(): object {\r\n return this._physicsPlugin.getBodyGeometry(this);\r\n }\r\n\r\n /**\r\n * Returns an observable that will be notified for when a collision starts or continues for this PhysicsBody\r\n * @returns Observable\r\n */\r\n public getCollisionObservable(): Observable<IPhysicsCollisionEvent> {\r\n return this._physicsPlugin.getCollisionObservable(this);\r\n }\r\n\r\n /**\r\n * Returns an observable that will be notified when the body has finished colliding with another body\r\n * @returns\r\n */\r\n public getCollisionEndedObservable(): Observable<IBasePhysicsCollisionEvent> {\r\n return this._physicsPlugin.getCollisionEndedObservable(this);\r\n }\r\n\r\n /**\r\n * Enable or disable collision callback for this PhysicsBody.\r\n * @param enabled true if PhysicsBody's collision will rise a collision event and notifies the observable\r\n */\r\n public setCollisionCallbackEnabled(enabled: boolean): void {\r\n this._collisionCBEnabled = enabled;\r\n this._physicsPlugin.setCollisionCallbackEnabled(this, enabled);\r\n }\r\n\r\n /**\r\n * Enable or disable collision ended callback for this PhysicsBody.\r\n * @param enabled true if PhysicsBody's collision ended will rise a collision event and notifies the observable\r\n */\r\n public setCollisionEndedCallbackEnabled(enabled: boolean): void {\r\n this._collisionEndedCBEnabled = enabled;\r\n this._physicsPlugin.setCollisionEndedCallbackEnabled(this, enabled);\r\n }\r\n\r\n /**\r\n * Get the center of the object in world space.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the center for.\r\n * @returns geometric center of the associated mesh\r\n */\r\n public getObjectCenterWorld(instanceIndex?: number): Vector3 {\r\n const ref = new Vector3();\r\n return this.getObjectCenterWorldToRef(ref, instanceIndex);\r\n }\r\n\r\n /**\r\n * Get the center of the object in world space.\r\n * @param ref - The vector3 to store the result in.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the center for.\r\n * @returns geometric center of the associated mesh\r\n */\r\n public getObjectCenterWorldToRef(ref: Vector3, instanceIndex?: number): Vector3 {\r\n if (this._pluginDataInstances?.length > 0) {\r\n const index = instanceIndex || 0;\r\n const matrixData = (this.transformNode as Mesh)._thinInstanceDataStorage.matrixData;\r\n if (matrixData) {\r\n ref.set(matrixData[index * 16 + 12], matrixData[index * 16 + 13], matrixData[index * 16 + 14]);\r\n }\r\n } else {\r\n ref.copyFrom(this.transformNode.position);\r\n }\r\n return ref;\r\n }\r\n\r\n /**\r\n * Adds a constraint to the physics engine.\r\n *\r\n * @param childBody - The body to which the constraint will be applied.\r\n * @param constraint - The constraint to be applied.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.\r\n * @param childInstanceIndex - If the child body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.\r\n *\r\n */\r\n public addConstraint(childBody: PhysicsBody, constraint: PhysicsConstraint, instanceIndex?: number, childInstanceIndex?: number): void {\r\n this._physicsPlugin.addConstraint(this, childBody, constraint, instanceIndex, childInstanceIndex);\r\n }\r\n\r\n /**\r\n * Sync with a bone\r\n * @param bone The bone that the impostor will be synced to.\r\n * @param boneMesh The mesh that the bone is influencing.\r\n * @param jointPivot The pivot of the joint / bone in local space.\r\n * @param distToJoint Optional distance from the impostor to the joint.\r\n * @param adjustRotation Optional quaternion for adjusting the local rotation of the bone.\r\n * @param boneAxis Optional vector3 axis the bone is aligned with\r\n */\r\n public syncWithBone(bone: Bone, boneMesh: AbstractMesh, jointPivot: Vector3, distToJoint?: number, adjustRotation?: Quaternion, boneAxis?: Vector3) {\r\n const mesh = this.transformNode;\r\n\r\n if (mesh.rotationQuaternion) {\r\n if (adjustRotation) {\r\n const tempQuat = TmpVectors.Quaternion[0];\r\n bone.getRotationQuaternionToRef(Space.WORLD, boneMesh, tempQuat);\r\n tempQuat.multiplyToRef(adjustRotation, mesh.rotationQuaternion);\r\n } else {\r\n bone.getRotationQuaternionToRef(Space.WORLD, boneMesh, mesh.rotationQuaternion);\r\n }\r\n }\r\n\r\n const pos = TmpVectors.Vector3[0];\r\n const boneDir = TmpVectors.Vector3[1];\r\n\r\n if (!boneAxis) {\r\n boneAxis = TmpVectors.Vector3[2];\r\n boneAxis.x = 0;\r\n boneAxis.y = 1;\r\n boneAxis.z = 0;\r\n }\r\n\r\n bone.getDirectionToRef(boneAxis, boneMesh, boneDir);\r\n bone.getAbsolutePositionToRef(boneMesh, pos);\r\n\r\n if ((distToJoint === undefined || distToJoint === null) && jointPivot) {\r\n distToJoint = jointPivot.length();\r\n }\r\n\r\n if (distToJoint !== undefined && distToJoint !== null) {\r\n pos.x += boneDir.x * distToJoint;\r\n pos.y += boneDir.y * distToJoint;\r\n pos.z += boneDir.z * distToJoint;\r\n }\r\n\r\n mesh.setAbsolutePosition(pos);\r\n }\r\n\r\n /**\r\n * Executes a callback on the body or all of the instances of a body\r\n * @param callback the callback to execute\r\n */\r\n public iterateOverAllInstances(callback: (body: PhysicsBody, instanceIndex?: number) => void) {\r\n if (this._pluginDataInstances?.length > 0) {\r\n for (let i = 0; i < this._pluginDataInstances.length; i++) {\r\n callback(this, i);\r\n }\r\n } else {\r\n callback(this, undefined);\r\n }\r\n }\r\n\r\n /**\r\n * Sets the gravity factor of the physics body\r\n * @param factor the gravity factor to set\r\n * @param instanceIndex the instance of the body to set, if undefined all instances will be set\r\n */\r\n public setGravityFactor(factor: number, instanceIndex?: number) {\r\n this._physicsPlugin.setGravityFactor(this, factor, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the gravity factor of the physics body\r\n * @param instanceIndex the instance of the body to get, if undefined the value of first instance will be returned\r\n * @returns the gravity factor\r\n */\r\n public getGravityFactor(instanceIndex?: number): number {\r\n return this._physicsPlugin.getGravityFactor(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Set the target transformation (position and rotation) of the body, such that the body will set its velocity to reach that target\r\n * @param position The target position\r\n * @param rotation The target rotation\r\n * @param instanceIndex The index of the instance in an instanced body\r\n */\r\n public setTargetTransform(position: Vector3, rotation: Quaternion, instanceIndex?: number) {\r\n this._physicsPlugin.setTargetTransform(this, position, rotation, instanceIndex);\r\n }\r\n\r\n /**\r\n * Returns if the body has been disposed.\r\n * @returns true if disposed, false otherwise.\r\n */\r\n public get isDisposed() {\r\n return this._isDisposed;\r\n }\r\n\r\n /**\r\n * Disposes the body from the physics engine.\r\n *\r\n * This method is useful for cleaning up the physics engine when a body is no longer needed. Disposing the body will free up resources and prevent memory leaks.\r\n */\r\n public dispose() {\r\n if (this._isDisposed) {\r\n return;\r\n }\r\n // Disable collisions CB so it doesn't fire when the body is disposed\r\n if (this._collisionCBEnabled) {\r\n this.setCollisionCallbackEnabled(false);\r\n }\r\n if (this._collisionEndedCBEnabled) {\r\n this.setCollisionEndedCallbackEnabled(false);\r\n }\r\n if (this._nodeDisposeObserver) {\r\n this.transformNode.onDisposeObservable.remove(this._nodeDisposeObserver);\r\n this._nodeDisposeObserver = null;\r\n }\r\n this._physicsEngine.removeBody(this);\r\n this._physicsPlugin.removeBody(this);\r\n this._physicsPlugin.disposeBody(this);\r\n this.transformNode.physicsBody = null;\r\n this._pluginData = null;\r\n this._pluginDataInstances.length = 0;\r\n this._isDisposed = true;\r\n this.shape = null;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/physicsBody.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,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C;QACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;QACrC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACtB,CAAC;CACJ","sourcesContent":["import type { IBasePhysicsCollisionEvent, IPhysicsCollisionEvent, IPhysicsEnginePluginV2, PhysicsMassProperties } from \"./IPhysicsEnginePlugin\";\r\nimport { PhysicsMotionType, PhysicsPrestepType } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsShape } from \"./physicsShape\";\r\nimport { Vector3, Quaternion, TmpVectors } from \"../../Maths/math.vector\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PhysicsEngine } from \"./physicsEngine\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { PhysicsConstraint } from \"./physicsConstraint\";\r\nimport type { Bone } from \"core/Bones/bone\";\r\nimport { Space } from \"core/Maths/math.axis\";\r\nimport type { Observable, Observer } from \"../../Misc/observable\";\r\nimport type { Node } from \"../../node\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { BoundingBox } from \"core/Culling/boundingBox\";\r\n\r\n/**\r\n * PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows\r\n * the user to set the mass and velocity of the body, which can then be used to calculate the\r\n * motion of the body in the physics engine.\r\n */\r\nexport class PhysicsBody {\r\n /**\r\n * V2 Physics plugin private data for single Transform\r\n */\r\n public _pluginData: any = undefined;\r\n /**\r\n * V2 Physics plugin private data for instances\r\n */\r\n public _pluginDataInstances: Array<any> = [];\r\n /**\r\n * The V2 plugin used to create and manage this Physics Body\r\n */\r\n private _physicsPlugin: IPhysicsEnginePluginV2;\r\n /**\r\n * The engine used to create and manage this Physics Body\r\n */\r\n private _physicsEngine: PhysicsEngine;\r\n /**\r\n * If the collision callback is enabled\r\n */\r\n private _collisionCBEnabled: boolean = false;\r\n /**\r\n * If the collision ended callback is enabled\r\n */\r\n private _collisionEndedCBEnabled: boolean = false;\r\n /**\r\n * The transform node associated with this Physics Body\r\n */\r\n transformNode: TransformNode;\r\n\r\n /**\r\n * Disable pre-step that consists in updating Physics Body from Transform Node Translation/Orientation.\r\n * True by default for maximum performance.\r\n */\r\n public get disablePreStep(): boolean {\r\n return this._prestepType == PhysicsPrestepType.DISABLED;\r\n }\r\n\r\n public set disablePreStep(value: boolean) {\r\n this._prestepType = value ? PhysicsPrestepType.DISABLED : PhysicsPrestepType.TELEPORT;\r\n }\r\n\r\n /**\r\n * Disable sync from physics to transformNode. This value is set to true at body creation or at motionType setting when the body is not dynamic.\r\n */\r\n disableSync: boolean = false;\r\n\r\n /**\r\n * Physics engine will try to make this body sleeping and not active\r\n */\r\n public startAsleep: boolean;\r\n\r\n private _nodeDisposeObserver: Nullable<Observer<Node>>;\r\n\r\n private _isDisposed = false;\r\n\r\n private _shape: Nullable<PhysicsShape> = null;\r\n\r\n private _prestepType: PhysicsPrestepType = PhysicsPrestepType.DISABLED;\r\n /**\r\n * Constructs a new physics body for the given node.\r\n * @param transformNode - The Transform Node to construct the physics body for. For better performance, it is advised that this node does not have a parent.\r\n * @param motionType - The motion type of the physics body. The options are:\r\n * - PhysicsMotionType.STATIC - Static bodies are not moving and unaffected by forces or collisions. They are good for level boundaries or terrain.\r\n * - PhysicsMotionType.DYNAMIC - Dynamic bodies are fully simulated. They can move and collide with other objects.\r\n * - PhysicsMotionType.ANIMATED - They behave like dynamic bodies, but they won't be affected by other bodies, but still push other bodies out of the way.\r\n * @param startsAsleep - Whether the physics body should start in a sleeping state (not a guarantee). Defaults to false.\r\n * @param scene - The scene containing the physics engine.\r\n *\r\n * This code is useful for creating a physics body for a given Transform Node in a scene.\r\n * It checks the version of the physics engine and the physics plugin, and initializes the body accordingly.\r\n * It also sets the node's rotation quaternion if it is not already set. Finally, it adds the body to the physics engine.\r\n */\r\n constructor(transformNode: TransformNode, motionType: PhysicsMotionType, startsAsleep: boolean, scene: Scene) {\r\n if (!scene) {\r\n return;\r\n }\r\n const physicsEngine = scene.getPhysicsEngine() as PhysicsEngine;\r\n if (!physicsEngine) {\r\n throw new Error(\"No Physics Engine available.\");\r\n }\r\n this._physicsEngine = physicsEngine;\r\n if (physicsEngine.getPluginVersion() != 2) {\r\n throw new Error(\"Plugin version is incorrect. Expected version 2.\");\r\n }\r\n const physicsPlugin = physicsEngine.getPhysicsPlugin();\r\n if (!physicsPlugin) {\r\n throw new Error(\"No Physics Plugin available.\");\r\n }\r\n\r\n this._physicsPlugin = physicsPlugin;\r\n if (!transformNode.rotationQuaternion) {\r\n transformNode.rotationQuaternion = Quaternion.FromEulerAngles(transformNode.rotation.x, transformNode.rotation.y, transformNode.rotation.z);\r\n }\r\n\r\n this.startAsleep = startsAsleep;\r\n\r\n // only dynamic and animated body needs sync from physics to transformNode\r\n this.disableSync = motionType == PhysicsMotionType.STATIC;\r\n\r\n // instances?\r\n const m = transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.initBodyInstances(this, motionType, m);\r\n } else {\r\n // single instance\r\n if (transformNode.parent) {\r\n // Force computation of world matrix so that the parent transforms are correctly reflected in absolutePosition/absoluteRotationQuaternion.\r\n transformNode.computeWorldMatrix(true);\r\n }\r\n this._physicsPlugin.initBody(this, motionType, transformNode.absolutePosition, transformNode.absoluteRotationQuaternion);\r\n }\r\n this.transformNode = transformNode;\r\n transformNode.physicsBody = this;\r\n physicsEngine.addBody(this);\r\n\r\n this._nodeDisposeObserver = transformNode.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n /**\r\n * Returns the string \"PhysicsBody\".\r\n * @returns \"PhysicsBody\"\r\n */\r\n public getClassName() {\r\n return \"PhysicsBody\";\r\n }\r\n\r\n /**\r\n * Clone the PhysicsBody to a new body and assign it to the transformNode parameter\r\n * @param transformNode transformNode that will be used for the cloned PhysicsBody\r\n * @returns the newly cloned PhysicsBody\r\n */\r\n public clone(transformNode: TransformNode): PhysicsBody {\r\n const clonedBody = new PhysicsBody(transformNode, this.getMotionType(), this.startAsleep, this.transformNode.getScene());\r\n clonedBody.shape = this.shape;\r\n clonedBody.setMassProperties(this.getMassProperties());\r\n clonedBody.setLinearDamping(this.getLinearDamping());\r\n clonedBody.setAngularDamping(this.getAngularDamping());\r\n return clonedBody;\r\n }\r\n\r\n /**\r\n * If a physics body is connected to an instanced node, update the number physic instances to match the number of node instances.\r\n */\r\n public updateBodyInstances() {\r\n const m = this.transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.updateBodyInstances(this, m);\r\n }\r\n }\r\n\r\n /**\r\n * This returns the number of internal instances of the physics body\r\n */\r\n public get numInstances(): number {\r\n return this._pluginDataInstances.length;\r\n }\r\n\r\n /**\r\n * Get the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.\r\n */\r\n public get motionType(): PhysicsMotionType {\r\n return this._physicsPlugin.getMotionType(this);\r\n }\r\n\r\n /**\r\n * Sets the shape of the physics body.\r\n * @param shape - The shape of the physics body.\r\n *\r\n * This method is useful for setting the shape of the physics body, which is necessary for the physics engine to accurately simulate the body's behavior.\r\n * The shape is used to calculate the body's mass, inertia, and other properties.\r\n */\r\n public set shape(shape: Nullable<PhysicsShape>) {\r\n this._shape = shape;\r\n if (shape) {\r\n this._physicsPlugin.setShape(this, shape);\r\n }\r\n }\r\n\r\n /**\r\n * Retrieves the physics shape associated with this object.\r\n *\r\n * @returns The physics shape associated with this object, or `undefined` if no\r\n * shape is associated.\r\n *\r\n * This method is useful for retrieving the physics shape associated with this object,\r\n * which can be used to apply physical forces to the object or to detect collisions.\r\n */\r\n public get shape(): Nullable<PhysicsShape> {\r\n return this._shape;\r\n }\r\n\r\n /**\r\n * Returns the bounding box of the physics body.\r\n * @returns The bounding box of the physics body.\r\n */\r\n public getBoundingBox(): BoundingBox {\r\n return this._physicsPlugin.getBodyBoundingBox(this);\r\n }\r\n\r\n /**\r\n * Sets the event mask for the physics engine.\r\n *\r\n * @param eventMask - A bitmask that determines which events will be sent to the physics engine.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the event mask for.\r\n *\r\n * This method is useful for setting the event mask for the physics engine, which determines which events\r\n * will be sent to the physics engine. This allows the user to control which events the physics engine will respond to.\r\n */\r\n public setEventMask(eventMask: number, instanceIndex?: number) {\r\n this._physicsPlugin.setEventMask(this, eventMask, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the event mask of the physics engine.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the event mask for.\r\n * @returns The event mask of the physics engine.\r\n *\r\n * This method is useful for getting the event mask of the physics engine,\r\n * which is used to determine which events the engine will respond to.\r\n * This is important for ensuring that the engine is responding to the correct events and not\r\n * wasting resources on unnecessary events.\r\n */\r\n public getEventMask(instanceIndex?: number): number {\r\n return this._physicsPlugin.getEventMask(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.\r\n * @param motionType - The motion type to set.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the motion type for. If body is instanced but instanceIndex is undefined, the motion type will be set for all instances.\r\n */\r\n public setMotionType(motionType: PhysicsMotionType, instanceIndex?: number) {\r\n this.disableSync = instanceIndex === undefined && motionType == PhysicsMotionType.STATIC;\r\n this._physicsPlugin.setMotionType(this, motionType, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the motion type for.\r\n * @returns The motion type of the physics body.\r\n */\r\n public getMotionType(instanceIndex?: number): PhysicsMotionType {\r\n return this._physicsPlugin.getMotionType(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Set the prestep type of the body\r\n * @param prestepType prestep type provided by PhysicsPrestepType\r\n */\r\n public setPrestepType(prestepType: PhysicsPrestepType): void {\r\n this._prestepType = prestepType;\r\n }\r\n\r\n /**\r\n * Get the current prestep type of the body\r\n * @returns the type of prestep associated with the body and its instance index\r\n */\r\n public getPrestepType(): PhysicsPrestepType {\r\n return this._prestepType;\r\n }\r\n\r\n /**\r\n * Computes the mass properties of the physics object, based on the set of physics shapes this body uses.\r\n * This method is useful for computing the initial mass properties of a physics object, such as its mass,\r\n * inertia, and center of mass; these values are important for accurately simulating the physics of the\r\n * object in the physics engine, and computing values based on the shape will provide you with reasonable\r\n * initial values, which you can then customize.\r\n * @param instanceIndex - The index of the instance to compute the mass properties for.\r\n * @returns The mass properties of the object.\r\n */\r\n public computeMassProperties(instanceIndex?: number): PhysicsMassProperties {\r\n return this._physicsPlugin.computeMassProperties(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the mass properties of the physics object.\r\n *\r\n * @param massProps - The mass properties to set.\r\n * @param instanceIndex - The index of the instance to set the mass properties for. If not defined, the mass properties will be set for all instances.\r\n *\r\n * This method is useful for setting the mass properties of a physics object, such as its mass,\r\n * inertia, and center of mass. This is important for accurately simulating the physics of the object in the physics engine.\r\n */\r\n public setMassProperties(massProps: PhysicsMassProperties, instanceIndex?: number): void {\r\n this._physicsPlugin.setMassProperties(this, massProps, instanceIndex);\r\n }\r\n\r\n /**\r\n * Retrieves the mass properties of the object.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the mass properties for.\r\n * @returns The mass properties of the object.\r\n *\r\n * This method is useful for physics simulations, as it allows the user to\r\n * retrieve the mass properties of the object, such as its mass, center of mass,\r\n * and moment of inertia. This information is necessary for accurate physics\r\n * simulations.\r\n */\r\n public getMassProperties(instanceIndex?: number): PhysicsMassProperties {\r\n return this._physicsPlugin.getMassProperties(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the linear damping of the physics body.\r\n *\r\n * @param damping - The linear damping value.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the linear damping for.\r\n *\r\n * This method is useful for controlling the linear damping of the physics body,\r\n * which is the rate at which the body's velocity decreases over time. This is useful for simulating\r\n * the effects of air resistance or other forms of friction.\r\n */\r\n public setLinearDamping(damping: number, instanceIndex?: number) {\r\n this._physicsPlugin.setLinearDamping(this, damping, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the linear damping of the physics body.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the linear damping for.\r\n * @returns The linear damping of the physics body.\r\n *\r\n * This method is useful for retrieving the linear damping of the physics body, which is the amount of\r\n * resistance the body has to linear motion. This is useful for simulating realistic physics behavior\r\n * in a game.\r\n */\r\n public getLinearDamping(instanceIndex?: number): number {\r\n return this._physicsPlugin.getLinearDamping(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the angular damping of the physics body.\r\n * @param damping The angular damping of the body.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the angular damping for.\r\n *\r\n * This method is useful for controlling the angular velocity of a physics body.\r\n * By setting the damping, the body's angular velocity will be reduced over time, simulating the effect of friction.\r\n * This can be used to create realistic physical behavior in a physics engine.\r\n */\r\n public setAngularDamping(damping: number, instanceIndex?: number) {\r\n this._physicsPlugin.setAngularDamping(this, damping, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the angular damping of the physics body.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the angular damping for.\r\n *\r\n * @returns The angular damping of the physics body.\r\n *\r\n * This method is useful for getting the angular damping of the physics body,\r\n * which is the rate of reduction of the angular velocity over time.\r\n * This is important for simulating realistic physics behavior in a game.\r\n */\r\n public getAngularDamping(instanceIndex?: number): number {\r\n return this._physicsPlugin.getAngularDamping(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the linear velocity of the physics object.\r\n * @param linVel - The linear velocity to set.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the linear velocity for.\r\n *\r\n * This method is useful for setting the linear velocity of a physics object,\r\n * which is necessary for simulating realistic physics in a game engine.\r\n * By setting the linear velocity, the physics object will move in the direction and speed specified by the vector.\r\n * This allows for realistic physics simulations, such as simulating the motion of a ball rolling down a hill.\r\n */\r\n public setLinearVelocity(linVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.setLinearVelocity(this, linVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the linear velocity of the physics body and stores it in the given vector3.\r\n * @param linVel - The vector3 to store the linear velocity in.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the linear velocity for.\r\n *\r\n * This method is useful for getting the linear velocity of a physics body in a physics engine.\r\n * This can be used to determine the speed and direction of the body, which can be used to calculate the motion of the body.\r\n */\r\n public getLinearVelocityToRef(linVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.getLinearVelocityToRef(this, linVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the linear velocity of the physics body as a new vector3.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the linear velocity for.\r\n * @returns The linear velocity of the physics body.\r\n *\r\n * This method is useful for getting the linear velocity of a physics body in a physics engine.\r\n * This can be used to determine the speed and direction of the body, which can be used to calculate the motion of the body.\r\n */\r\n public getLinearVelocity(instanceIndex?: number): Vector3 {\r\n const ref = new Vector3();\r\n this.getLinearVelocityToRef(ref, instanceIndex);\r\n return ref;\r\n }\r\n\r\n /**\r\n * Sets the angular velocity of the physics object.\r\n * @param angVel - The angular velocity to set.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the angular velocity for.\r\n *\r\n * This method is useful for setting the angular velocity of a physics object, which is necessary for\r\n * simulating realistic physics behavior. The angular velocity is used to determine the rate of rotation of the object,\r\n * which is important for simulating realistic motion.\r\n */\r\n public setAngularVelocity(angVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.setAngularVelocity(this, angVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the angular velocity of the physics body and stores it in the given vector3.\r\n * @param angVel - The vector3 to store the angular velocity in.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the angular velocity for.\r\n *\r\n * This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's\r\n * rotational speed. This information can be used to create realistic physics simulations.\r\n */\r\n public getAngularVelocityToRef(angVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.getAngularVelocityToRef(this, angVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the angular velocity of the physics body as a new vector3.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the angular velocity for.\r\n * @returns The angular velocity of the physics body.\r\n *\r\n * This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's\r\n * rotational speed. This information can be used to create realistic physics simulations.\r\n */\r\n public getAngularVelocity(instanceIndex?: number): Vector3 {\r\n const ref = new Vector3();\r\n this.getAngularVelocityToRef(ref, instanceIndex);\r\n return ref;\r\n }\r\n\r\n /**\r\n * Applies an impulse to the physics object.\r\n *\r\n * @param impulse The impulse vector.\r\n * @param location The location of the impulse.\r\n * @param instanceIndex For a instanced body, the instance to where the impulse should be applied. If not specified, the impulse is applied to all instances.\r\n *\r\n * This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyImpulse(impulse: Vector3, location: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyImpulse(this, impulse, location, instanceIndex);\r\n }\r\n\r\n /**\r\n * Add torque to a physics body\r\n * @param angularImpulse The angular impulse vector.\r\n * @param instanceIndex For a instanced body, the instance to where the impulse should be applied. If not specified, the impulse is applied to all instances.\r\n */\r\n public applyAngularImpulse(angularImpulse: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyAngularImpulse(this, angularImpulse, instanceIndex);\r\n }\r\n\r\n /**\r\n * Applies a torque to the physics body.\r\n *\r\n * @param torque The torque vector.\r\n * @param instanceIndex For a instanced body, the instance to where the torque should be applied. If not specified, the torque is applied to all instances.\r\n *\r\n * This method is useful for applying a torque to a physics body, which can be used to simulate rotational forces such as motors,\r\n * angular momentum, and rotational dynamics. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyTorque(torque: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyTorque(this, torque, instanceIndex);\r\n }\r\n\r\n /**\r\n * Applies a force to the physics object.\r\n *\r\n * @param force The force vector.\r\n * @param location The location of the force.\r\n * @param instanceIndex For a instanced body, the instance to where the force should be applied. If not specified, the force is applied to all instances.\r\n *\r\n * This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyForce(force: Vector3, location: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyForce(this, force, location, instanceIndex);\r\n }\r\n\r\n /**\r\n * Retrieves the geometry of the body from the physics plugin.\r\n *\r\n * @returns The geometry of the body.\r\n *\r\n * This method is useful for retrieving the geometry of the body from the physics plugin, which can be used for various physics calculations.\r\n */\r\n public getGeometry(): object {\r\n return this._physicsPlugin.getBodyGeometry(this);\r\n }\r\n\r\n /**\r\n * Returns an observable that will be notified for when a collision starts or continues for this PhysicsBody\r\n * @returns Observable\r\n */\r\n public getCollisionObservable(): Observable<IPhysicsCollisionEvent> {\r\n return this._physicsPlugin.getCollisionObservable(this);\r\n }\r\n\r\n /**\r\n * Returns an observable that will be notified when the body has finished colliding with another body\r\n * @returns\r\n */\r\n public getCollisionEndedObservable(): Observable<IBasePhysicsCollisionEvent> {\r\n return this._physicsPlugin.getCollisionEndedObservable(this);\r\n }\r\n\r\n /**\r\n * Enable or disable collision callback for this PhysicsBody.\r\n * @param enabled true if PhysicsBody's collision will rise a collision event and notifies the observable\r\n */\r\n public setCollisionCallbackEnabled(enabled: boolean): void {\r\n this._collisionCBEnabled = enabled;\r\n this._physicsPlugin.setCollisionCallbackEnabled(this, enabled);\r\n }\r\n\r\n /**\r\n * Enable or disable collision ended callback for this PhysicsBody.\r\n * @param enabled true if PhysicsBody's collision ended will rise a collision event and notifies the observable\r\n */\r\n public setCollisionEndedCallbackEnabled(enabled: boolean): void {\r\n this._collisionEndedCBEnabled = enabled;\r\n this._physicsPlugin.setCollisionEndedCallbackEnabled(this, enabled);\r\n }\r\n\r\n /**\r\n * Get the center of the object in world space.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the center for.\r\n * @returns geometric center of the associated mesh\r\n */\r\n public getObjectCenterWorld(instanceIndex?: number): Vector3 {\r\n const ref = new Vector3();\r\n return this.getObjectCenterWorldToRef(ref, instanceIndex);\r\n }\r\n\r\n /**\r\n * Get the center of the object in world space.\r\n * @param ref - The vector3 to store the result in.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the center for.\r\n * @returns geometric center of the associated mesh\r\n */\r\n public getObjectCenterWorldToRef(ref: Vector3, instanceIndex?: number): Vector3 {\r\n if (this._pluginDataInstances?.length > 0) {\r\n const index = instanceIndex || 0;\r\n const matrixData = (this.transformNode as Mesh)._thinInstanceDataStorage.matrixData;\r\n if (matrixData) {\r\n ref.set(matrixData[index * 16 + 12], matrixData[index * 16 + 13], matrixData[index * 16 + 14]);\r\n }\r\n } else {\r\n ref.copyFrom(this.transformNode.position);\r\n }\r\n return ref;\r\n }\r\n\r\n /**\r\n * Adds a constraint to the physics engine.\r\n *\r\n * @param childBody - The body to which the constraint will be applied.\r\n * @param constraint - The constraint to be applied.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.\r\n * @param childInstanceIndex - If the child body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.\r\n *\r\n */\r\n public addConstraint(childBody: PhysicsBody, constraint: PhysicsConstraint, instanceIndex?: number, childInstanceIndex?: number): void {\r\n this._physicsPlugin.addConstraint(this, childBody, constraint, instanceIndex, childInstanceIndex);\r\n }\r\n\r\n /**\r\n * Sync with a bone\r\n * @param bone The bone that the impostor will be synced to.\r\n * @param boneMesh The mesh that the bone is influencing.\r\n * @param jointPivot The pivot of the joint / bone in local space.\r\n * @param distToJoint Optional distance from the impostor to the joint.\r\n * @param adjustRotation Optional quaternion for adjusting the local rotation of the bone.\r\n * @param boneAxis Optional vector3 axis the bone is aligned with\r\n */\r\n public syncWithBone(bone: Bone, boneMesh: AbstractMesh, jointPivot: Vector3, distToJoint?: number, adjustRotation?: Quaternion, boneAxis?: Vector3) {\r\n const mesh = this.transformNode;\r\n\r\n if (mesh.rotationQuaternion) {\r\n if (adjustRotation) {\r\n const tempQuat = TmpVectors.Quaternion[0];\r\n bone.getRotationQuaternionToRef(Space.WORLD, boneMesh, tempQuat);\r\n tempQuat.multiplyToRef(adjustRotation, mesh.rotationQuaternion);\r\n } else {\r\n bone.getRotationQuaternionToRef(Space.WORLD, boneMesh, mesh.rotationQuaternion);\r\n }\r\n }\r\n\r\n const pos = TmpVectors.Vector3[0];\r\n const boneDir = TmpVectors.Vector3[1];\r\n\r\n if (!boneAxis) {\r\n boneAxis = TmpVectors.Vector3[2];\r\n boneAxis.x = 0;\r\n boneAxis.y = 1;\r\n boneAxis.z = 0;\r\n }\r\n\r\n bone.getDirectionToRef(boneAxis, boneMesh, boneDir);\r\n bone.getAbsolutePositionToRef(boneMesh, pos);\r\n\r\n if ((distToJoint === undefined || distToJoint === null) && jointPivot) {\r\n distToJoint = jointPivot.length();\r\n }\r\n\r\n if (distToJoint !== undefined && distToJoint !== null) {\r\n pos.x += boneDir.x * distToJoint;\r\n pos.y += boneDir.y * distToJoint;\r\n pos.z += boneDir.z * distToJoint;\r\n }\r\n\r\n mesh.setAbsolutePosition(pos);\r\n }\r\n\r\n /**\r\n * Executes a callback on the body or all of the instances of a body\r\n * @param callback the callback to execute\r\n */\r\n public iterateOverAllInstances(callback: (body: PhysicsBody, instanceIndex?: number) => void) {\r\n if (this._pluginDataInstances?.length > 0) {\r\n for (let i = 0; i < this._pluginDataInstances.length; i++) {\r\n callback(this, i);\r\n }\r\n } else {\r\n callback(this, undefined);\r\n }\r\n }\r\n\r\n /**\r\n * Sets the gravity factor of the physics body\r\n * @param factor the gravity factor to set\r\n * @param instanceIndex the instance of the body to set, if undefined all instances will be set\r\n */\r\n public setGravityFactor(factor: number, instanceIndex?: number) {\r\n this._physicsPlugin.setGravityFactor(this, factor, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the gravity factor of the physics body\r\n * @param instanceIndex the instance of the body to get, if undefined the value of first instance will be returned\r\n * @returns the gravity factor\r\n */\r\n public getGravityFactor(instanceIndex?: number): number {\r\n return this._physicsPlugin.getGravityFactor(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Set the target transformation (position and rotation) of the body, such that the body will set its velocity to reach that target\r\n * @param position The target position\r\n * @param rotation The target rotation\r\n * @param instanceIndex The index of the instance in an instanced body\r\n */\r\n public setTargetTransform(position: Vector3, rotation: Quaternion, instanceIndex?: number) {\r\n this._physicsPlugin.setTargetTransform(this, position, rotation, instanceIndex);\r\n }\r\n\r\n /**\r\n * Returns if the body has been disposed.\r\n * @returns true if disposed, false otherwise.\r\n */\r\n public get isDisposed() {\r\n return this._isDisposed;\r\n }\r\n\r\n /**\r\n * Disposes the body from the physics engine.\r\n *\r\n * This method is useful for cleaning up the physics engine when a body is no longer needed. Disposing the body will free up resources and prevent memory leaks.\r\n */\r\n public dispose() {\r\n if (this._isDisposed) {\r\n return;\r\n }\r\n // Disable collisions CB so it doesn't fire when the body is disposed\r\n if (this._collisionCBEnabled) {\r\n this.setCollisionCallbackEnabled(false);\r\n }\r\n if (this._collisionEndedCBEnabled) {\r\n this.setCollisionEndedCallbackEnabled(false);\r\n }\r\n if (this._nodeDisposeObserver) {\r\n this.transformNode.onDisposeObservable.remove(this._nodeDisposeObserver);\r\n this._nodeDisposeObserver = null;\r\n }\r\n this._physicsEngine.removeBody(this);\r\n this._physicsPlugin.removeBody(this);\r\n this._physicsPlugin.disposeBody(this);\r\n this.transformNode.physicsBody = null;\r\n this._pluginData = null;\r\n this._pluginDataInstances.length = 0;\r\n this._isDisposed = true;\r\n this.shape = null;\r\n }\r\n}\r\n"]}
@@ -27,6 +27,11 @@ declare module "../../Meshes/transformNode.js" {
27
27
  * @returns the current mesh
28
28
  */
29
29
  applyAngularImpulse(angularImpulse: Vector3): TransformNode;
30
+ /** Apply a physic torque to the mesh
31
+ * @param torque defines the torque to apply
32
+ * @returns the current mesh
33
+ */
34
+ applyTorque(torque: Vector3): TransformNode;
30
35
  /** @internal */
31
36
  _disposePhysicsObserver: Nullable<Observer<Node>>;
32
37
  }
@@ -59,4 +59,17 @@ TransformNode.prototype.applyAngularImpulse = function (angularImpulse) {
59
59
  this.physicsBody.applyAngularImpulse(angularImpulse);
60
60
  return this;
61
61
  };
62
+ /**
63
+ * Apply a physic torque to the mesh
64
+ * @param torque defines the torque to apply
65
+ * @returns the current mesh
66
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
67
+ */
68
+ TransformNode.prototype.applyTorque = function (torque) {
69
+ if (!this.physicsBody) {
70
+ throw new Error("No Physics Body for TransformNode");
71
+ }
72
+ this.physicsBody.applyTorque(torque);
73
+ return this;
74
+ };
62
75
  //# sourceMappingURL=physicsEngineComponent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"physicsEngineComponent.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/physicsEngineComponent.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAI3D,OAAO,iCAAiC,CAAC;AAoCzC,MAAM,CAAC,cAAc,CAAC,aAAa,CAAC,SAAS,EAAE,aAAa,EAAE;IAC1D,GAAG,EAAE;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IACD,GAAG,EAAE,UAA+B,KAA4B;QAC5D,IAAI,IAAI,CAAC,YAAY,KAAK,KAAK,EAAE,CAAC;YAC9B,OAAO;QACX,CAAC;QACD,IAAI,IAAI,CAAC,uBAAuB,EAAE,CAAC;YAC/B,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;QAClE,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAE1B,IAAI,KAAK,EAAE,CAAC;YACR,IAAI,CAAC,uBAAuB,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,EAAE;gBAC7D,UAAU;gBACV,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;oBACnB,IAAI,CAAC,WAAW,CAAC,OAAO,EAAC,iBAAiB,CAAC,CAAC;oBAC5C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;gBAC5B,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IACD,UAAU,EAAE,IAAI;IAChB,YAAY,EAAE,IAAI;CACrB,CAAC,CAAC;AAEH;;;GAGG;AACH,aAAa,CAAC,SAAS,CAAC,cAAc,GAAG;IACrC,OAAO,IAAI,CAAC,WAAW,CAAC;AAC5B,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,aAAa,CAAC,SAAS,CAAC,YAAY,GAAG,UAAU,KAAc,EAAE,YAAqB;IAClF,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACzD,CAAC;IACD,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IACnD,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,aAAa,CAAC,SAAS,CAAC,mBAAmB,GAAG,UAAU,cAAuB;IAC3E,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACzD,CAAC;IACD,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;IACrD,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"../../types\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { Vector3 } from \"../../Maths/math.vector\";\r\nimport { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { Node } from \"../../node\";\r\nimport type { PhysicsBody } from \"./physicsBody\";\r\n\r\nimport \"../joinedPhysicsEngineComponent\";\r\n\r\ndeclare module \"../../Meshes/transformNode\" {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n export interface TransformNode {\r\n /** @internal */\r\n _physicsBody: Nullable<PhysicsBody>;\r\n\r\n /**\r\n * @see\r\n */\r\n physicsBody: Nullable<PhysicsBody>;\r\n\r\n /**\r\n *\r\n */\r\n getPhysicsBody(): Nullable<PhysicsBody>;\r\n\r\n /** Apply a physic impulse to the mesh\r\n * @param force defines the force to apply\r\n * @param contactPoint defines where to apply the force\r\n * @returns the current mesh\r\n */\r\n applyImpulse(force: Vector3, contactPoint: Vector3): TransformNode;\r\n\r\n /** Apply a physic angular impulse to the mesh\r\n * @param angularImpulse defines the torque to apply\r\n * @returns the current mesh\r\n */\r\n applyAngularImpulse(angularImpulse: Vector3): TransformNode;\r\n\r\n /** @internal */\r\n _disposePhysicsObserver: Nullable<Observer<Node>>;\r\n }\r\n}\r\n\r\nObject.defineProperty(TransformNode.prototype, \"physicsBody\", {\r\n get: function (this: TransformNode) {\r\n return this._physicsBody;\r\n },\r\n set: function (this: TransformNode, value: Nullable<PhysicsBody>) {\r\n if (this._physicsBody === value) {\r\n return;\r\n }\r\n if (this._disposePhysicsObserver) {\r\n this.onDisposeObservable.remove(this._disposePhysicsObserver);\r\n }\r\n\r\n this._physicsBody = value;\r\n\r\n if (value) {\r\n this._disposePhysicsObserver = this.onDisposeObservable.add(() => {\r\n // Physics\r\n if (this.physicsBody) {\r\n this.physicsBody.dispose(/*!doNotRecurse*/);\r\n this.physicsBody = null;\r\n }\r\n });\r\n }\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n\r\n/**\r\n * Gets the current physics body\r\n * @returns a physics body or null\r\n */\r\nTransformNode.prototype.getPhysicsBody = function (): Nullable<PhysicsBody> {\r\n return this.physicsBody;\r\n};\r\n\r\n/**\r\n * Apply a physic impulse to the mesh\r\n * @param force defines the force to apply\r\n * @param contactPoint defines where to apply the force\r\n * @returns the current mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine\r\n */\r\nTransformNode.prototype.applyImpulse = function (force: Vector3, contactPoint: Vector3): TransformNode {\r\n if (!this.physicsBody) {\r\n throw new Error(\"No Physics Body for TransformNode\");\r\n }\r\n this.physicsBody.applyImpulse(force, contactPoint);\r\n return this;\r\n};\r\n\r\n/**\r\n * Apply a physic angular impulse to the mesh\r\n * @param angularImpulse defines the torque to apply\r\n * @returns the current mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine\r\n */\r\nTransformNode.prototype.applyAngularImpulse = function (angularImpulse: Vector3): TransformNode {\r\n if (!this.physicsBody) {\r\n throw new Error(\"No Physics Body for TransformNode\");\r\n }\r\n this.physicsBody.applyAngularImpulse(angularImpulse);\r\n return this;\r\n};\r\n"]}
1
+ {"version":3,"file":"physicsEngineComponent.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/physicsEngineComponent.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAI3D,OAAO,iCAAiC,CAAC;AA0CzC,MAAM,CAAC,cAAc,CAAC,aAAa,CAAC,SAAS,EAAE,aAAa,EAAE;IAC1D,GAAG,EAAE;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IACD,GAAG,EAAE,UAA+B,KAA4B;QAC5D,IAAI,IAAI,CAAC,YAAY,KAAK,KAAK,EAAE,CAAC;YAC9B,OAAO;QACX,CAAC;QACD,IAAI,IAAI,CAAC,uBAAuB,EAAE,CAAC;YAC/B,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;QAClE,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;Q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,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACzD,CAAC;IACD,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACrC,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"../../types\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { Vector3 } from \"../../Maths/math.vector\";\r\nimport { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { Node } from \"../../node\";\r\nimport type { PhysicsBody } from \"./physicsBody\";\r\n\r\nimport \"../joinedPhysicsEngineComponent\";\r\n\r\ndeclare module \"../../Meshes/transformNode\" {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n export interface TransformNode {\r\n /** @internal */\r\n _physicsBody: Nullable<PhysicsBody>;\r\n\r\n /**\r\n * @see\r\n */\r\n physicsBody: Nullable<PhysicsBody>;\r\n\r\n /**\r\n *\r\n */\r\n getPhysicsBody(): Nullable<PhysicsBody>;\r\n\r\n /** Apply a physic impulse to the mesh\r\n * @param force defines the force to apply\r\n * @param contactPoint defines where to apply the force\r\n * @returns the current mesh\r\n */\r\n applyImpulse(force: Vector3, contactPoint: Vector3): TransformNode;\r\n\r\n /** Apply a physic angular impulse to the mesh\r\n * @param angularImpulse defines the torque to apply\r\n * @returns the current mesh\r\n */\r\n applyAngularImpulse(angularImpulse: Vector3): TransformNode;\r\n\r\n /** Apply a physic torque to the mesh\r\n * @param torque defines the torque to apply\r\n * @returns the current mesh\r\n */\r\n applyTorque(torque: Vector3): TransformNode;\r\n\r\n /** @internal */\r\n _disposePhysicsObserver: Nullable<Observer<Node>>;\r\n }\r\n}\r\n\r\nObject.defineProperty(TransformNode.prototype, \"physicsBody\", {\r\n get: function (this: TransformNode) {\r\n return this._physicsBody;\r\n },\r\n set: function (this: TransformNode, value: Nullable<PhysicsBody>) {\r\n if (this._physicsBody === value) {\r\n return;\r\n }\r\n if (this._disposePhysicsObserver) {\r\n this.onDisposeObservable.remove(this._disposePhysicsObserver);\r\n }\r\n\r\n this._physicsBody = value;\r\n\r\n if (value) {\r\n this._disposePhysicsObserver = this.onDisposeObservable.add(() => {\r\n // Physics\r\n if (this.physicsBody) {\r\n this.physicsBody.dispose(/*!doNotRecurse*/);\r\n this.physicsBody = null;\r\n }\r\n });\r\n }\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n\r\n/**\r\n * Gets the current physics body\r\n * @returns a physics body or null\r\n */\r\nTransformNode.prototype.getPhysicsBody = function (): Nullable<PhysicsBody> {\r\n return this.physicsBody;\r\n};\r\n\r\n/**\r\n * Apply a physic impulse to the mesh\r\n * @param force defines the force to apply\r\n * @param contactPoint defines where to apply the force\r\n * @returns the current mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine\r\n */\r\nTransformNode.prototype.applyImpulse = function (force: Vector3, contactPoint: Vector3): TransformNode {\r\n if (!this.physicsBody) {\r\n throw new Error(\"No Physics Body for TransformNode\");\r\n }\r\n this.physicsBody.applyImpulse(force, contactPoint);\r\n return this;\r\n};\r\n\r\n/**\r\n * Apply a physic angular impulse to the mesh\r\n * @param angularImpulse defines the torque to apply\r\n * @returns the current mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine\r\n */\r\nTransformNode.prototype.applyAngularImpulse = function (angularImpulse: Vector3): TransformNode {\r\n if (!this.physicsBody) {\r\n throw new Error(\"No Physics Body for TransformNode\");\r\n }\r\n this.physicsBody.applyAngularImpulse(angularImpulse);\r\n return this;\r\n};\r\n\r\n/**\r\n * Apply a physic torque to the mesh\r\n * @param torque defines the torque to apply\r\n * @returns the current mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine\r\n */\r\nTransformNode.prototype.applyTorque = function (torque: Vector3): TransformNode {\r\n if (!this.physicsBody) {\r\n throw new Error(\"No Physics Body for TransformNode\");\r\n }\r\n this.physicsBody.applyTorque(torque);\r\n return this;\r\n};\r\n"]}
@@ -140,16 +140,15 @@ export class IBLShadowsPluginMaterial extends MaterialPluginBase {
140
140
  #ifdef REFLECTION
141
141
  #ifdef COLORED_IBL_SHADOWS
142
142
  var shadowValue: vec3f = computeIndirectShadow();
143
- slab_diffuse_ibl *= shadowValue;
144
- slab_glossy_ibl *= mix(vec3f(1.0), shadowValue, specularAlphaG);
143
+ ambient_occlusion = min(ambient_occlusion, shadowValue);
145
144
  #else
146
145
  var shadowValue: vec2f = computeIndirectShadow();
147
- slab_diffuse_ibl *= vec3f(shadowValue.x);
148
- slab_glossy_ibl *= vec3f(mix(pow(shadowValue.y, 4.0), shadowValue.x, specularAlphaG));
146
+ ambient_occlusion = min(ambient_occlusion, vec3f(shadowValue.x));
147
+ specular_ambient_occlusion = min(specular_ambient_occlusion, pow(shadowValue.y, 4.0));
149
148
  #endif
150
149
  #endif
151
150
  #else
152
- slab_diffuse_ibl *= computeIndirectShadow().x;
151
+ ambient_occlusion = min(ambient_occlusion, vec3f(computeIndirectShadow().x));
153
152
  #endif
154
153
  #endif
155
154
  `;
@@ -220,16 +219,15 @@ export class IBLShadowsPluginMaterial extends MaterialPluginBase {
220
219
  #ifdef REFLECTION
221
220
  #ifdef COLORED_IBL_SHADOWS
222
221
  vec3 shadowValue = computeIndirectShadow();
223
- slab_diffuse_ibl.rgb *= shadowValue.rgb;
224
- slab_glossy_ibl *= mix(vec3(1.0), shadowValue.rgb, specularAlphaG);
222
+ ambient_occlusion = min(ambient_occlusion, shadowValue);
225
223
  #else
226
224
  vec2 shadowValue = computeIndirectShadow();
227
- slab_diffuse_ibl *= shadowValue.x;
228
- slab_glossy_ibl *= mix(pow(shadowValue.y, 4.0), shadowValue.x, specularAlphaG);
225
+ ambient_occlusion = min(ambient_occlusion, vec3(shadowValue.x));
226
+ specular_ambient_occlusion = min(specular_ambient_occlusion, pow(shadowValue.y, 4.0));
229
227
  #endif
230
228
  #endif
231
229
  #else
232
- slab_diffuse_ibl *= computeIndirectShadow().x;
230
+ ambient_occlusion = min(ambient_occlusion, vec3(computeIndirectShadow().x));
233
231
  #endif
234
232
  #endif
235
233
  `;
@@ -1 +1 @@
1
- {"version":3,"file":"iblShadowsPluginMaterial.js","sourceRoot":"","sources":["../../../../../dev/core/src/Rendering/IBLShadows/iblShadowsPluginMaterial.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,2CAAuC;AACjE,OAAO,EAAE,kBAAkB,EAAE,8CAA0C;AAGvE,OAAO,EAAE,SAAS,EAAE,mCAA+B;AAEnD,OAAO,EAAE,eAAe,EAAE,+CAA2C;AAErE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,iCAA6B;AACnE,OAAO,EAAE,aAAa,EAAE,gCAA4B;AAGpD,OAAO,EAAE,eAAe,EAAE,+CAA2C;AACrE;;GAEG;AACH,MAAM,+BAAgC,SAAQ,eAAe;IAA7D;;QACW,4BAAuB,GAAG,KAAK,CAAC;QAChC,wBAAmB,GAAG,KAAK,CAAC;IACvC,CAAC;CAAA;AAED;;GAEG;AACH,MAAM,OAAO,wBAAyB,SAAQ,kBAAkB;IAmB5D,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IACD,IAAW,SAAS,CAAC,KAAc;QAC/B,IAAI,IAAI,CAAC,UAAU,KAAK,KAAK,EAAE,CAAC;YAC5B,OAAO;QACX,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC,gCAAgC,EAAE,CAAC;IAC5C,CAAC;IAQS,gCAAgC;QACtC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC9B,IAAI,CAAC,wCAAwC,EAAE,CAAC;IACpD,CAAC;IAID;;;OAGG;IACa,YAAY;QACxB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,YAAY,QAAyE;QACjF,KAAK,CAAC,QAAQ,EAAE,wBAAwB,CAAC,IAAI,EAAE,GAAG,EAAE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AC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACjD,CAAC;;AA7PD;;GAEG;AACoB,6BAAI,GAAG,0BAA0B,AAA7B,CAA8B;AAWlD;IADN,SAAS,EAAE;+DACuB;AAmB5B;IAFN,SAAS,EAAE;IACX,gBAAgB,CAAC,kCAAkC,CAAC;2DAC5B;AA+N7B,aAAa,CAAC,kCAAkC,EAAE,wBAAwB,CAAC,CAAC","sourcesContent":["import { MaterialDefines } from \"core/Materials/materialDefines\";\r\nimport { MaterialPluginBase } from \"core/Materials/materialPluginBase\";\r\nimport type { InternalTexture } from \"core/Materials/Textures/internalTexture\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport type { StandardMaterial } from \"core/Materials/standardMaterial\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { UniformBuffer } from \"core/Materials/uniformBuffer\";\r\nimport { expandToProperty, serialize } from \"core/Misc/decorators\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\n\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial\";\r\n/**\r\n * @internal\r\n */\r\nclass MaterialIBLShadowsRenderDefines extends MaterialDefines {\r\n public RENDER_WITH_IBL_SHADOWS = false;\r\n public COLORED_IBL_SHADOWS = false;\r\n}\r\n\r\n/**\r\n * Plugin used to render the contribution from IBL shadows.\r\n */\r\nexport class IBLShadowsPluginMaterial extends MaterialPluginBase {\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public static readonly Name = \"IBLShadowsPluginMaterial\";\r\n\r\n /**\r\n * The texture containing the contribution from IBL shadows.\r\n */\r\n public iblShadowsTexture: InternalTexture;\r\n\r\n /**\r\n * The opacity of the shadows.\r\n */\r\n @serialize()\r\n public shadowOpacity: number = 1.0;\r\n\r\n private _isEnabled = false;\r\n private _isColored = false;\r\n public get isColored(): boolean {\r\n return this._isColored;\r\n }\r\n public set isColored(value: boolean) {\r\n if (this._isColored === value) {\r\n return;\r\n }\r\n this._isColored = value;\r\n this._markAllSubMeshesAsTexturesDirty();\r\n }\r\n /**\r\n * Defines if the plugin is enabled in the material.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public isEnabled = false;\r\n\r\n protected _markAllSubMeshesAsTexturesDirty(): void {\r\n this._enable(this._isEnabled);\r\n this._internalMarkAllSubMeshesAsTexturesDirty();\r\n }\r\n\r\n private _internalMarkAllSubMeshesAsTexturesDirty: () => void;\r\n\r\n /**\r\n * Gets a boolean indicating that the plugin is compatible with a give shader language.\r\n * @returns true if the plugin is compatible with the shader language\r\n */\r\n public override isCompatible(): boolean {\r\n return true;\r\n }\r\n\r\n constructor(material: Material | StandardMaterial | PBRBaseMaterial | OpenPBRMaterial) {\r\n super(material, IBLShadowsPluginMaterial.Name, 310, new MaterialIBLShadowsRenderDefines());\r\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag];\r\n }\r\n\r\n public override prepareDefines(defines: MaterialIBLShadowsRenderDefines) {\r\n defines.RENDER_WITH_IBL_SHADOWS = this._isEnabled;\r\n defines.COLORED_IBL_SHADOWS = this.isColored;\r\n }\r\n\r\n public override getClassName() {\r\n return \"IBLShadowsPluginMaterial\";\r\n }\r\n\r\n public override getUniforms() {\r\n return {\r\n ubo: [\r\n { name: \"renderTargetSize\", size: 2, type: \"vec2\" },\r\n { name: \"shadowOpacity\", size: 1, type: \"float\" },\r\n ],\r\n fragment: `#ifdef RENDER_WITH_IBL_SHADOWS\r\n uniform vec2 renderTargetSize;\r\n uniform float shadowOpacity;\r\n #endif`,\r\n };\r\n }\r\n\r\n public override getSamplers(samplers: string[]) {\r\n samplers.push(\"iblShadowsTexture\");\r\n }\r\n\r\n public override bindForSubMesh(uniformBuffer: UniformBuffer) {\r\n if (this._isEnabled) {\r\n uniformBuffer.bindTexture(\"iblShadowsTexture\", this.iblShadowsTexture);\r\n uniformBuffer.updateFloat2(\"renderTargetSize\", this._material.getScene().getEngine().getRenderWidth(), this._material.getScene().getEngine().getRenderHeight());\r\n uniformBuffer.updateFloat(\"shadowOpacity\", this.shadowOpacity);\r\n }\r\n }\r\n\r\n public override getCustomCode(shaderType: string, shaderLanguage: ShaderLanguage) {\r\n let frag: { [name: string]: string };\r\n\r\n if (shaderLanguage === ShaderLanguage.WGSL) {\r\n frag = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CUSTOM_FRAGMENT_DEFINITIONS: `\r\n #ifdef RENDER_WITH_IBL_SHADOWS\r\n var iblShadowsTextureSampler: sampler;\r\n var iblShadowsTexture: texture_2d<f32>;\r\n\r\n #ifdef COLORED_IBL_SHADOWS\r\n fn computeIndirectShadow() -> vec3f {\r\n var uv = fragmentInputs.position.xy / uniforms.renderTargetSize;\r\n var shadowValue: vec3f = textureSample(iblShadowsTexture, iblShadowsTextureSampler, uv).rgb;\r\n return mix(shadowValue, vec3f(1.0), 1.0 - uniforms.shadowOpacity);\r\n }\r\n #else\r\n fn computeIndirectShadow() -> vec2f {\r\n var uv = fragmentInputs.position.xy / uniforms.renderTargetSize;\r\n var shadowValue: vec2f = textureSample(iblShadowsTexture, iblShadowsTextureSampler, uv).rg;\r\n return mix(shadowValue, vec2f(1.0), 1.0 - uniforms.shadowOpacity);\r\n }\r\n #endif\r\n #endif\r\n `,\r\n };\r\n\r\n if (this._material instanceof PBRBaseMaterial) {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n frag[\"CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION\"] = `\r\n #ifdef RENDER_WITH_IBL_SHADOWS\r\n #ifndef UNLIT\r\n #ifdef REFLECTION\r\n #ifdef COLORED_IBL_SHADOWS\r\n var shadowValue: vec3f = computeIndirectShadow();\r\n finalIrradiance *= shadowValue;\r\n finalRadianceScaled *= mix(vec3f(1.0), shadowValue, roughness);\r\n #else\r\n var shadowValue: vec2f = computeIndirectShadow();\r\n finalIrradiance *= vec3f(shadowValue.x);\r\n finalRadianceScaled *= vec3f(mix(pow(shadowValue.y, 4.0), shadowValue.x, roughness));\r\n #endif\r\n #endif\r\n #else\r\n finalDiffuse *= computeIndirectShadow().x;\r\n #endif\r\n #endif\r\n `;\r\n } else if (this._material instanceof OpenPBRMaterial) {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n frag[\"CUSTOM_FRAGMENT_BEFORE_IBLLAYERCOMPOSITION\"] = `\r\n #ifdef RENDER_WITH_IBL_SHADOWS\r\n #ifndef UNLIT\r\n #ifdef REFLECTION\r\n #ifdef COLORED_IBL_SHADOWS\r\n var shadowValue: vec3f = computeIndirectShadow();\r\n slab_diffuse_ibl *= shadowValue;\r\n slab_glossy_ibl *= mix(vec3f(1.0), shadowValue, specularAlphaG);\r\n #else\r\n var shadowValue: vec2f = computeIndirectShadow();\r\n slab_diffuse_ibl *= vec3f(shadowValue.x);\r\n slab_glossy_ibl *= vec3f(mix(pow(shadowValue.y, 4.0), shadowValue.x, specularAlphaG));\r\n #endif\r\n #endif\r\n #else\r\n slab_diffuse_ibl *= computeIndirectShadow().x;\r\n #endif\r\n #endif\r\n `;\r\n } else {\r\n frag[\"CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR\"] = `\r\n #ifdef RENDER_WITH_IBL_SHADOWS\r\n #ifdef COLORED_IBL_SHADOWS\r\n var shadowValue: vec3f = computeIndirectShadow();\r\n color *= toGammaSpace(vec4f(shadowValue, 1.0f));\r\n #else\r\n var shadowValue: vec2f = computeIndirectShadow();\r\n color *= toGammaSpace(vec4f(shadowValue.x, shadowValue.x, shadowValue.x, 1.0f));\r\n #endif\r\n #endif\r\n `;\r\n }\r\n } else {\r\n frag = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CUSTOM_FRAGMENT_DEFINITIONS: `\r\n #ifdef RENDER_WITH_IBL_SHADOWS\r\n uniform sampler2D iblShadowsTexture;\r\n #ifdef COLORED_IBL_SHADOWS\r\n vec3 computeIndirectShadow() {\r\n vec2 uv = gl_FragCoord.xy / renderTargetSize;\r\n vec3 shadowValue = texture2D(iblShadowsTexture, uv).rgb;\r\n return mix(shadowValue.rgb, vec3(1.0), 1.0 - shadowOpacity);\r\n }\r\n #else\r\n vec2 computeIndirectShadow() {\r\n vec2 uv = gl_FragCoord.xy / renderTargetSize;\r\n vec2 shadowValue = texture2D(iblShadowsTexture, uv).rg;\r\n return mix(shadowValue.rg, vec2(1.0), 1.0 - shadowOpacity);\r\n }\r\n #endif\r\n #endif\r\n `,\r\n };\r\n\r\n if (this._material instanceof PBRBaseMaterial) {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n frag[\"CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION\"] = `\r\n #ifdef RENDER_WITH_IBL_SHADOWS\r\n #ifndef UNLIT\r\n #ifdef REFLECTION\r\n #ifdef COLORED_IBL_SHADOWS\r\n vec3 shadowValue = computeIndirectShadow();\r\n finalIrradiance.rgb *= shadowValue.rgb;\r\n finalRadianceScaled *= mix(vec3(1.0), shadowValue.rgb, roughness);\r\n #else\r\n vec2 shadowValue = computeIndirectShadow();\r\n finalIrradiance *= shadowValue.x;\r\n finalRadianceScaled *= mix(pow(shadowValue.y, 4.0), shadowValue.x, roughness);\r\n #endif\r\n #endif\r\n #else\r\n finalDiffuse *= computeIndirectShadow().x;\r\n #endif\r\n #endif\r\n `;\r\n } else if (this._material instanceof OpenPBRMaterial) {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n frag[\"CUSTOM_FRAGMENT_BEFORE_IBLLAYERCOMPOSITION\"] = `\r\n #ifdef RENDER_WITH_IBL_SHADOWS\r\n #ifndef UNLIT\r\n #ifdef REFLECTION\r\n #ifdef COLORED_IBL_SHADOWS\r\n vec3 shadowValue = computeIndirectShadow();\r\n slab_diffuse_ibl.rgb *= shadowValue.rgb;\r\n slab_glossy_ibl *= mix(vec3(1.0), shadowValue.rgb, specularAlphaG);\r\n #else\r\n vec2 shadowValue = computeIndirectShadow();\r\n slab_diffuse_ibl *= shadowValue.x;\r\n slab_glossy_ibl *= mix(pow(shadowValue.y, 4.0), shadowValue.x, specularAlphaG);\r\n #endif\r\n #endif\r\n #else\r\n slab_diffuse_ibl *= computeIndirectShadow().x;\r\n #endif\r\n #endif\r\n `;\r\n } else {\r\n frag[\"CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR\"] = `\r\n #ifdef RENDER_WITH_IBL_SHADOWS\r\n #ifdef COLORED_IBL_SHADOWS\r\n vec3 shadowValue = computeIndirectShadow();\r\n color.rgb *= toGammaSpace(shadowValue.rgb);\r\n #else\r\n vec2 shadowValue = computeIndirectShadow();\r\n color.rgb *= toGammaSpace(shadowValue.x);\r\n #endif\r\n #endif\r\n `;\r\n }\r\n }\r\n\r\n return shaderType === \"vertex\" ? null : frag;\r\n }\r\n}\r\n\r\nRegisterClass(`BABYLON.IBLShadowsPluginMaterial`, IBLShadowsPluginMaterial);\r\n"]}
1
+ {"version":3,"file":"iblShadowsPluginMaterial.js","sourceRoot":"","sources":["../../../../../dev/core/src/Rendering/IBLShadows/iblShadowsPluginMaterial.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,2CAAuC;AACjE,OAAO,EAAE,kBAAkB,EAAE,8CAA0C;AAGvE,OAAO,EAAE,SAAS,EAAE,mCAA+B;AAEnD,OAAO,EAAE,eAAe,EAAE,+CAA2C;AAErE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,iCAA6B;AACnE,OAAO,EAAE,aAAa,EAAE,gCAA4B;AAGpD,OAAO,EAAE,eAAe,EAAE,+CAA2C;AACrE;;GAEG;AACH,MAAM,+BAAgC,SAAQ,eAAe;IAA7D;;QACW,4BAAuB,GAAG,KAAK,CAAC;QAChC,wBAAmB,GAAG,KAAK,CAAC;IACvC,CAAC;CAAA;AAED;;GAEG;AACH,MAAM,OAAO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C;QACL,CAAC;aAAM,CAAC;YACJ,IAAI,GAAG;gBACH,gEAAgE;gBAChE,2BAA2B,EAAE;;;;;;;;;;;;;;;;;aAiBhC;aACA,CAAC;YAEF,IAAI,IAAI,CAAC,SAAS,YAAY,eAAe,EAAE,CAAC;gBAC5C,gEAAgE;gBAChE,IAAI,CAAC,8CAA8C,CAAC,GAAG;;;;;;;;;;;;;;;;;;aAkB1D,CAAC;YACF,CAAC;iBAAM,IAAI,IAAI,CAAC,SAAS,YAAY,eAAe,EAAE,CAAC;gBACnD,gEAAgE;gBAChE,IAAI,CAAC,4CAA4C,CAAC,GAAG;;;;;;;;;;;;;;;;;aAiBxD,CAAC;YACF,CAAC;iBAAM,CAAC;gBACJ,IAAI,CAAC,kCAAkC,CAAC,GAAG;;;;;;;;;;aAU9C,CAAC;YACF,CAAC;QACL,CAAC;QAED,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACjD,CAAC;;AA3PD;;GAEG;AACoB,6BAAI,GAAG,0BAA0B,AAA7B,CAA8B;AAWlD;IADN,SAAS,EAAE;+DACuB;AAmB5B;IAFN,SAAS,EAAE;IACX,gBAAgB,CAAC,kCAAkC,CAAC;2DAC5B;AA6N7B,aAAa,CAAC,kCAAkC,EAAE,wBAAwB,CAAC,CAAC","sourcesContent":["import { MaterialDefines } from \"core/Materials/materialDefines\";\r\nimport { MaterialPluginBase } from \"core/Materials/materialPluginBase\";\r\nimport type { InternalTexture } from \"core/Materials/Textures/internalTexture\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport type { StandardMaterial } from \"core/Materials/standardMaterial\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { UniformBuffer } from \"core/Materials/uniformBuffer\";\r\nimport { expandToProperty, serialize } from \"core/Misc/decorators\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\n\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial\";\r\n/**\r\n * @internal\r\n */\r\nclass MaterialIBLShadowsRenderDefines extends MaterialDefines {\r\n public RENDER_WITH_IBL_SHADOWS = false;\r\n public COLORED_IBL_SHADOWS = false;\r\n}\r\n\r\n/**\r\n * Plugin used to render the contribution from IBL shadows.\r\n */\r\nexport class IBLShadowsPluginMaterial extends MaterialPluginBase {\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public static readonly Name = \"IBLShadowsPluginMaterial\";\r\n\r\n /**\r\n * The texture containing the contribution from IBL shadows.\r\n */\r\n public iblShadowsTexture: InternalTexture;\r\n\r\n /**\r\n * The opacity of the shadows.\r\n */\r\n @serialize()\r\n public shadowOpacity: number = 1.0;\r\n\r\n private _isEnabled = false;\r\n private _isColored = false;\r\n public get isColored(): boolean {\r\n return this._isColored;\r\n }\r\n public set isColored(value: boolean) {\r\n if (this._isColored === value) {\r\n return;\r\n }\r\n this._isColored = value;\r\n this._markAllSubMeshesAsTexturesDirty();\r\n }\r\n /**\r\n * Defines if the plugin is enabled in the material.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public isEnabled = false;\r\n\r\n protected _markAllSubMeshesAsTexturesDirty(): void {\r\n this._enable(this._isEnabled);\r\n this._internalMarkAllSubMeshesAsTexturesDirty();\r\n }\r\n\r\n private _internalMarkAllSubMeshesAsTexturesDirty: () => void;\r\n\r\n /**\r\n * Gets a boolean indicating that the plugin is compatible with a give shader language.\r\n * @returns true if the plugin is compatible with the shader language\r\n */\r\n public override isCompatible(): boolean {\r\n return true;\r\n }\r\n\r\n constructor(material: Material | StandardMaterial | PBRBaseMaterial | OpenPBRMaterial) {\r\n super(material, IBLShadowsPluginMaterial.Name, 310, new MaterialIBLShadowsRenderDefines());\r\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag];\r\n }\r\n\r\n public override prepareDefines(defines: MaterialIBLShadowsRenderDefines) {\r\n defines.RENDER_WITH_IBL_SHADOWS = this._isEnabled;\r\n defines.COLORED_IBL_SHADOWS = this.isColored;\r\n }\r\n\r\n public override getClassName() {\r\n return \"IBLShadowsPluginMaterial\";\r\n }\r\n\r\n public override getUniforms() {\r\n return {\r\n ubo: [\r\n { name: \"renderTargetSize\", size: 2, type: \"vec2\" },\r\n { name: \"shadowOpacity\", size: 1, type: \"float\" },\r\n ],\r\n fragment: `#ifdef RENDER_WITH_IBL_SHADOWS\r\n uniform vec2 renderTargetSize;\r\n uniform float shadowOpacity;\r\n #endif`,\r\n };\r\n }\r\n\r\n public override getSamplers(samplers: string[]) {\r\n samplers.push(\"iblShadowsTexture\");\r\n }\r\n\r\n public override bindForSubMesh(uniformBuffer: UniformBuffer) {\r\n if (this._isEnabled) {\r\n uniformBuffer.bindTexture(\"iblShadowsTexture\", this.iblShadowsTexture);\r\n uniformBuffer.updateFloat2(\"renderTargetSize\", this._material.getScene().getEngine().getRenderWidth(), this._material.getScene().getEngine().getRenderHeight());\r\n uniformBuffer.updateFloat(\"shadowOpacity\", this.shadowOpacity);\r\n }\r\n }\r\n\r\n public override getCustomCode(shaderType: string, shaderLanguage: ShaderLanguage) {\r\n let frag: { [name: string]: string };\r\n\r\n if (shaderLanguage === ShaderLanguage.WGSL) {\r\n frag = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CUSTOM_FRAGMENT_DEFINITIONS: `\r\n #ifdef RENDER_WITH_IBL_SHADOWS\r\n var iblShadowsTextureSampler: sampler;\r\n var iblShadowsTexture: texture_2d<f32>;\r\n\r\n #ifdef COLORED_IBL_SHADOWS\r\n fn computeIndirectShadow() -> vec3f {\r\n var uv = fragmentInputs.position.xy / uniforms.renderTargetSize;\r\n var shadowValue: vec3f = textureSample(iblShadowsTexture, iblShadowsTextureSampler, uv).rgb;\r\n return mix(shadowValue, vec3f(1.0), 1.0 - uniforms.shadowOpacity);\r\n }\r\n #else\r\n fn computeIndirectShadow() -> vec2f {\r\n var uv = fragmentInputs.position.xy / uniforms.renderTargetSize;\r\n var shadowValue: vec2f = textureSample(iblShadowsTexture, iblShadowsTextureSampler, uv).rg;\r\n return mix(shadowValue, vec2f(1.0), 1.0 - uniforms.shadowOpacity);\r\n }\r\n #endif\r\n #endif\r\n `,\r\n };\r\n\r\n if (this._material instanceof PBRBaseMaterial) {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n frag[\"CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION\"] = `\r\n #ifdef RENDER_WITH_IBL_SHADOWS\r\n #ifndef UNLIT\r\n #ifdef REFLECTION\r\n #ifdef COLORED_IBL_SHADOWS\r\n var shadowValue: vec3f = computeIndirectShadow();\r\n finalIrradiance *= shadowValue;\r\n finalRadianceScaled *= mix(vec3f(1.0), shadowValue, roughness);\r\n #else\r\n var shadowValue: vec2f = computeIndirectShadow();\r\n finalIrradiance *= vec3f(shadowValue.x);\r\n finalRadianceScaled *= vec3f(mix(pow(shadowValue.y, 4.0), shadowValue.x, roughness));\r\n #endif\r\n #endif\r\n #else\r\n finalDiffuse *= computeIndirectShadow().x;\r\n #endif\r\n #endif\r\n `;\r\n } else if (this._material instanceof OpenPBRMaterial) {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n frag[\"CUSTOM_FRAGMENT_BEFORE_IBLLAYERCOMPOSITION\"] = `\r\n #ifdef RENDER_WITH_IBL_SHADOWS\r\n #ifndef UNLIT\r\n #ifdef REFLECTION\r\n #ifdef COLORED_IBL_SHADOWS\r\n var shadowValue: vec3f = computeIndirectShadow();\r\n ambient_occlusion = min(ambient_occlusion, shadowValue);\r\n #else\r\n var shadowValue: vec2f = computeIndirectShadow();\r\n ambient_occlusion = min(ambient_occlusion, vec3f(shadowValue.x));\r\n specular_ambient_occlusion = min(specular_ambient_occlusion, pow(shadowValue.y, 4.0));\r\n #endif\r\n #endif\r\n #else\r\n ambient_occlusion = min(ambient_occlusion, vec3f(computeIndirectShadow().x));\r\n #endif\r\n #endif\r\n `;\r\n } else {\r\n frag[\"CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR\"] = `\r\n #ifdef RENDER_WITH_IBL_SHADOWS\r\n #ifdef COLORED_IBL_SHADOWS\r\n var shadowValue: vec3f = computeIndirectShadow();\r\n color *= toGammaSpace(vec4f(shadowValue, 1.0f));\r\n #else\r\n var shadowValue: vec2f = computeIndirectShadow();\r\n color *= toGammaSpace(vec4f(shadowValue.x, shadowValue.x, shadowValue.x, 1.0f));\r\n #endif\r\n #endif\r\n `;\r\n }\r\n } else {\r\n frag = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CUSTOM_FRAGMENT_DEFINITIONS: `\r\n #ifdef RENDER_WITH_IBL_SHADOWS\r\n uniform sampler2D iblShadowsTexture;\r\n #ifdef COLORED_IBL_SHADOWS\r\n vec3 computeIndirectShadow() {\r\n vec2 uv = gl_FragCoord.xy / renderTargetSize;\r\n vec3 shadowValue = texture2D(iblShadowsTexture, uv).rgb;\r\n return mix(shadowValue.rgb, vec3(1.0), 1.0 - shadowOpacity);\r\n }\r\n #else\r\n vec2 computeIndirectShadow() {\r\n vec2 uv = gl_FragCoord.xy / renderTargetSize;\r\n vec2 shadowValue = texture2D(iblShadowsTexture, uv).rg;\r\n return mix(shadowValue.rg, vec2(1.0), 1.0 - shadowOpacity);\r\n }\r\n #endif\r\n #endif\r\n `,\r\n };\r\n\r\n if (this._material instanceof PBRBaseMaterial) {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n frag[\"CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION\"] = `\r\n #ifdef RENDER_WITH_IBL_SHADOWS\r\n #ifndef UNLIT\r\n #ifdef REFLECTION\r\n #ifdef COLORED_IBL_SHADOWS\r\n vec3 shadowValue = computeIndirectShadow();\r\n finalIrradiance.rgb *= shadowValue.rgb;\r\n finalRadianceScaled *= mix(vec3(1.0), shadowValue.rgb, roughness);\r\n #else\r\n vec2 shadowValue = computeIndirectShadow();\r\n finalIrradiance *= shadowValue.x;\r\n finalRadianceScaled *= mix(pow(shadowValue.y, 4.0), shadowValue.x, roughness);\r\n #endif\r\n #endif\r\n #else\r\n finalDiffuse *= computeIndirectShadow().x;\r\n #endif\r\n #endif\r\n `;\r\n } else if (this._material instanceof OpenPBRMaterial) {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n frag[\"CUSTOM_FRAGMENT_BEFORE_IBLLAYERCOMPOSITION\"] = `\r\n #ifdef RENDER_WITH_IBL_SHADOWS\r\n #ifndef UNLIT\r\n #ifdef REFLECTION\r\n #ifdef COLORED_IBL_SHADOWS\r\n vec3 shadowValue = computeIndirectShadow();\r\n ambient_occlusion = min(ambient_occlusion, shadowValue);\r\n #else\r\n vec2 shadowValue = computeIndirectShadow();\r\n ambient_occlusion = min(ambient_occlusion, vec3(shadowValue.x));\r\n specular_ambient_occlusion = min(specular_ambient_occlusion, pow(shadowValue.y, 4.0));\r\n #endif\r\n #endif\r\n #else\r\n ambient_occlusion = min(ambient_occlusion, vec3(computeIndirectShadow().x));\r\n #endif\r\n #endif\r\n `;\r\n } else {\r\n frag[\"CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR\"] = `\r\n #ifdef RENDER_WITH_IBL_SHADOWS\r\n #ifdef COLORED_IBL_SHADOWS\r\n vec3 shadowValue = computeIndirectShadow();\r\n color.rgb *= toGammaSpace(shadowValue.rgb);\r\n #else\r\n vec2 shadowValue = computeIndirectShadow();\r\n color.rgb *= toGammaSpace(shadowValue.x);\r\n #endif\r\n #endif\r\n `;\r\n }\r\n }\r\n\r\n return shaderType === \"vertex\" ? null : frag;\r\n }\r\n}\r\n\r\nRegisterClass(`BABYLON.IBLShadowsPluginMaterial`, IBLShadowsPluginMaterial);\r\n"]}
@@ -54,6 +54,12 @@ export declare class UtilityLayerRenderer implements IDisposable {
54
54
  * A shared utility layer that can be used to embed objects into a scene (Depth map of the previous scene is not cleared before drawing on top of it)
55
55
  */
56
56
  static get DefaultKeepDepthUtilityLayer(): UtilityLayerRenderer;
57
+ /**
58
+ * Creates an utility layer, and set it as a default utility layer (Depth map of the previous scene is not cleared before drawing on top of it)
59
+ * @param scene associated scene
60
+ * @internal
61
+ */
62
+ static _CreateDefaultKeepUtilityLayerFromScene(scene: Scene): UtilityLayerRenderer;
57
63
  /**
58
64
  * The scene that is rendered on top of the original scene
59
65
  */
@@ -78,14 +78,23 @@ export class UtilityLayerRenderer {
78
78
  */
79
79
  static get DefaultKeepDepthUtilityLayer() {
80
80
  if (UtilityLayerRenderer._DefaultKeepDepthUtilityLayer == null) {
81
- UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = new UtilityLayerRenderer(EngineStore.LastCreatedScene);
82
- UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.utilityLayerScene.autoClearDepthAndStencil = false;
83
- UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.originalScene.onDisposeObservable.addOnce(() => {
84
- UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = null;
85
- });
81
+ return UtilityLayerRenderer._CreateDefaultKeepUtilityLayerFromScene(EngineStore.LastCreatedScene);
86
82
  }
87
83
  return UtilityLayerRenderer._DefaultKeepDepthUtilityLayer;
88
84
  }
85
+ /**
86
+ * Creates an utility layer, and set it as a default utility layer (Depth map of the previous scene is not cleared before drawing on top of it)
87
+ * @param scene associated scene
88
+ * @internal
89
+ */
90
+ static _CreateDefaultKeepUtilityLayerFromScene(scene) {
91
+ UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = new UtilityLayerRenderer(scene);
92
+ UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.utilityLayerScene.autoClearDepthAndStencil = false;
93
+ UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.originalScene.onDisposeObservable.addOnce(() => {
94
+ UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = null;
95
+ });
96
+ return UtilityLayerRenderer._DefaultKeepDepthUtilityLayer;
97
+ }
89
98
  /**
90
99
  * Instantiates a UtilityLayerRenderer
91
100
  * @param originalScene the original scene that will be rendered on top of