@babylonjs/core 7.8.0 → 7.8.2

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 (182) hide show
  1. package/Behaviors/Meshes/sixDofDragBehavior.js +1 -1
  2. package/Behaviors/Meshes/sixDofDragBehavior.js.map +1 -1
  3. package/Cameras/Inputs/BaseCameraPointersInput.js +5 -1
  4. package/Cameras/Inputs/BaseCameraPointersInput.js.map +1 -1
  5. package/Engines/AbstractEngine/abstractEngine.states.d.ts +1 -0
  6. package/Engines/AbstractEngine/abstractEngine.states.js +1 -0
  7. package/Engines/AbstractEngine/abstractEngine.states.js.map +1 -1
  8. package/Engines/{Extensions/engine.views.d.ts → AbstractEngine/abstractEngine.views.d.ts} +1 -2
  9. package/Engines/{Extensions/engine.views.js → AbstractEngine/abstractEngine.views.js} +10 -10
  10. package/Engines/AbstractEngine/abstractEngine.views.js.map +1 -0
  11. package/Engines/AbstractEngine/index.d.ts +1 -0
  12. package/Engines/AbstractEngine/index.js +1 -0
  13. package/Engines/AbstractEngine/index.js.map +1 -1
  14. package/Engines/Extensions/engine.alpha.d.ts +2 -2
  15. package/Engines/Extensions/engine.alpha.js.map +1 -1
  16. package/Engines/Extensions/engine.cubeTexture.d.ts +10 -4
  17. package/Engines/Extensions/engine.cubeTexture.js +10 -0
  18. package/Engines/Extensions/engine.cubeTexture.js.map +1 -1
  19. package/Engines/Extensions/engine.dynamicBuffer.d.ts +2 -2
  20. package/Engines/Extensions/engine.dynamicBuffer.js.map +1 -1
  21. package/Engines/Extensions/engine.dynamicTexture.d.ts +2 -2
  22. package/Engines/Extensions/engine.dynamicTexture.js.map +1 -1
  23. package/Engines/Extensions/engine.multiRender.d.ts +2 -2
  24. package/Engines/Extensions/engine.multiRender.js.map +1 -1
  25. package/Engines/Extensions/engine.prefilteredCubeTexture.d.ts +22 -0
  26. package/Engines/Extensions/engine.prefilteredCubeTexture.js +88 -0
  27. package/Engines/Extensions/engine.prefilteredCubeTexture.js.map +1 -0
  28. package/Engines/Extensions/engine.rawTexture.d.ts +2 -63
  29. package/Engines/Extensions/engine.rawTexture.js.map +1 -1
  30. package/Engines/Extensions/engine.readTexture.d.ts +2 -2
  31. package/Engines/Extensions/engine.readTexture.js.map +1 -1
  32. package/Engines/Extensions/engine.renderTarget.d.ts +5 -11
  33. package/Engines/Extensions/engine.renderTarget.js +37 -0
  34. package/Engines/Extensions/engine.renderTarget.js.map +1 -1
  35. package/Engines/Extensions/engine.renderTargetCube.d.ts +2 -2
  36. package/Engines/Extensions/engine.renderTargetCube.js.map +1 -1
  37. package/Engines/Extensions/engine.renderTargetTexture.d.ts +14 -0
  38. package/Engines/Extensions/engine.renderTargetTexture.js +16 -0
  39. package/Engines/Extensions/engine.renderTargetTexture.js.map +1 -0
  40. package/Engines/Extensions/engine.videoTexture.d.ts +2 -2
  41. package/Engines/Extensions/engine.videoTexture.js.map +1 -1
  42. package/Engines/Extensions/index.d.ts +2 -1
  43. package/Engines/Extensions/index.js +2 -1
  44. package/Engines/Extensions/index.js.map +1 -1
  45. package/Engines/WebGPU/Extensions/engine.alpha.d.ts +3 -27
  46. package/Engines/WebGPU/Extensions/engine.alpha.js +1 -0
  47. package/Engines/WebGPU/Extensions/engine.alpha.js.map +1 -1
  48. package/Engines/WebGPU/Extensions/engine.cubeTexture.d.ts +10 -4
  49. package/Engines/WebGPU/Extensions/engine.cubeTexture.js +9 -0
  50. package/Engines/WebGPU/Extensions/engine.cubeTexture.js.map +1 -1
  51. package/Engines/WebGPU/Extensions/engine.dynamicTexture.d.ts +2 -2
  52. package/Engines/WebGPU/Extensions/engine.dynamicTexture.js.map +1 -1
  53. package/Engines/WebGPU/Extensions/engine.multiRender.d.ts +2 -2
  54. package/Engines/WebGPU/Extensions/engine.multiRender.js.map +1 -1
  55. package/Engines/WebGPU/Extensions/engine.rawTexture.d.ts +2 -50
  56. package/Engines/WebGPU/Extensions/engine.rawTexture.js.map +1 -1
  57. package/Engines/WebGPU/Extensions/engine.readTexture.d.ts +2 -2
  58. package/Engines/WebGPU/Extensions/engine.readTexture.js.map +1 -1
  59. package/Engines/WebGPU/Extensions/engine.renderTarget.d.ts +3 -11
  60. package/Engines/WebGPU/Extensions/engine.renderTarget.js +1 -0
  61. package/Engines/WebGPU/Extensions/engine.renderTarget.js.map +1 -1
  62. package/Engines/WebGPU/Extensions/engine.renderTargetCube.d.ts +2 -2
  63. package/Engines/WebGPU/Extensions/engine.renderTargetCube.js.map +1 -1
  64. package/Engines/WebGPU/Extensions/engine.renderTargetTexture.d.ts +14 -0
  65. package/Engines/WebGPU/Extensions/engine.renderTargetTexture.js +10 -0
  66. package/Engines/WebGPU/Extensions/engine.renderTargetTexture.js.map +1 -0
  67. package/Engines/WebGPU/Extensions/engine.videoTexture.d.ts +2 -2
  68. package/Engines/WebGPU/Extensions/engine.videoTexture.js.map +1 -1
  69. package/Engines/WebGPU/Extensions/index.d.ts +1 -0
  70. package/Engines/WebGPU/Extensions/index.js +1 -0
  71. package/Engines/WebGPU/Extensions/index.js.map +1 -1
  72. package/Engines/WebGPU/webgpuShaderProcessorsWGSL.d.ts +4 -0
  73. package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js +4 -0
  74. package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js.map +1 -1
  75. package/Engines/abstractEngine.d.ts +13 -351
  76. package/Engines/abstractEngine.js +90 -5
  77. package/Engines/abstractEngine.js.map +1 -1
  78. package/Engines/engine.d.ts +11 -30
  79. package/Engines/engine.js +0 -69
  80. package/Engines/engine.js.map +1 -1
  81. package/Engines/nativeEngine.d.ts +4 -7
  82. package/Engines/nativeEngine.js +3 -8
  83. package/Engines/nativeEngine.js.map +1 -1
  84. package/Engines/thinEngine.d.ts +7 -18
  85. package/Engines/thinEngine.js +4 -146
  86. package/Engines/thinEngine.js.map +1 -1
  87. package/Engines/webgpuEngine.d.ts +4 -26
  88. package/Engines/webgpuEngine.js +3 -51
  89. package/Engines/webgpuEngine.js.map +1 -1
  90. package/Materials/Node/Blocks/Fragment/TBNBlock.js +14 -7
  91. package/Materials/Node/Blocks/Fragment/TBNBlock.js.map +1 -1
  92. package/Materials/Node/Blocks/Fragment/heightToNormalBlock.js +19 -11
  93. package/Materials/Node/Blocks/Fragment/heightToNormalBlock.js.map +1 -1
  94. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js +47 -20
  95. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
  96. package/Materials/Node/Blocks/Fragment/screenSizeBlock.js +3 -1
  97. package/Materials/Node/Blocks/Fragment/screenSizeBlock.js.map +1 -1
  98. package/Materials/Node/Blocks/Fragment/screenSpaceBlock.js +4 -4
  99. package/Materials/Node/Blocks/Fragment/screenSpaceBlock.js.map +1 -1
  100. package/Materials/Node/Blocks/biPlanarBlock.js +1 -2
  101. package/Materials/Node/Blocks/biPlanarBlock.js.map +1 -1
  102. package/Materials/Node/Blocks/cloudBlock.js +1 -1
  103. package/Materials/Node/Blocks/cloudBlock.js.map +1 -1
  104. package/Materials/Node/Blocks/triPlanarBlock.js +1 -1
  105. package/Materials/Node/Blocks/triPlanarBlock.js.map +1 -1
  106. package/Materials/Node/nodeMaterialBuildState.d.ts +2 -0
  107. package/Materials/Node/nodeMaterialBuildState.js +7 -0
  108. package/Materials/Node/nodeMaterialBuildState.js.map +1 -1
  109. package/Materials/Textures/Filtering/hdrFiltering.d.ts +1 -0
  110. package/Materials/Textures/Filtering/hdrFiltering.js +2 -1
  111. package/Materials/Textures/Filtering/hdrFiltering.js.map +1 -1
  112. package/Materials/Textures/Loaders/basisTextureLoader.d.ts +1 -0
  113. package/Materials/Textures/Loaders/basisTextureLoader.js +1 -0
  114. package/Materials/Textures/Loaders/basisTextureLoader.js.map +1 -1
  115. package/Materials/Textures/Loaders/ddsTextureLoader.d.ts +1 -0
  116. package/Materials/Textures/Loaders/ddsTextureLoader.js +1 -0
  117. package/Materials/Textures/Loaders/ddsTextureLoader.js.map +1 -1
  118. package/Materials/Textures/Loaders/ktxTextureLoader.d.ts +1 -0
  119. package/Materials/Textures/Loaders/ktxTextureLoader.js +1 -0
  120. package/Materials/Textures/Loaders/ktxTextureLoader.js.map +1 -1
  121. package/Materials/Textures/baseTexture.d.ts +1 -0
  122. package/Materials/Textures/baseTexture.js +1 -0
  123. package/Materials/Textures/baseTexture.js.map +1 -1
  124. package/Materials/Textures/cubeTexture.d.ts +2 -1
  125. package/Materials/Textures/cubeTexture.js +3 -2
  126. package/Materials/Textures/cubeTexture.js.map +1 -1
  127. package/Materials/Textures/dynamicTexture.d.ts +1 -1
  128. package/Materials/Textures/dynamicTexture.js.map +1 -1
  129. package/Materials/Textures/renderTargetTexture.d.ts +11 -0
  130. package/Materials/Textures/renderTargetTexture.js +10 -0
  131. package/Materials/Textures/renderTargetTexture.js.map +1 -1
  132. package/Materials/effect.d.ts +8 -23
  133. package/Materials/effect.js +2 -25
  134. package/Materials/effect.js.map +1 -1
  135. package/Misc/dds.d.ts +2 -22
  136. package/Misc/dds.js +0 -95
  137. package/Misc/dds.js.map +1 -1
  138. package/Misc/minMaxReducer.d.ts +1 -0
  139. package/Misc/minMaxReducer.js +1 -0
  140. package/Misc/minMaxReducer.js.map +1 -1
  141. package/Misc/screenshotTools.d.ts +1 -0
  142. package/Misc/screenshotTools.js +1 -0
  143. package/Misc/screenshotTools.js.map +1 -1
  144. package/Morph/morphTargetManager.d.ts +6 -0
  145. package/Morph/morphTargetManager.js +13 -0
  146. package/Morph/morphTargetManager.js.map +1 -1
  147. package/Physics/v2/IPhysicsEnginePlugin.d.ts +1 -0
  148. package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
  149. package/Physics/v2/Plugins/havokPlugin.d.ts +11 -1
  150. package/Physics/v2/Plugins/havokPlugin.js +25 -1
  151. package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
  152. package/Physics/v2/physicsAggregate.js +3 -3
  153. package/Physics/v2/physicsAggregate.js.map +1 -1
  154. package/Physics/v2/physicsBody.d.ts +6 -0
  155. package/Physics/v2/physicsBody.js +7 -0
  156. package/Physics/v2/physicsBody.js.map +1 -1
  157. package/PostProcesses/postProcess.d.ts +37 -2
  158. package/PostProcesses/postProcess.js +34 -0
  159. package/PostProcesses/postProcess.js.map +1 -1
  160. package/Rendering/depthPeelingRenderer.d.ts +1 -0
  161. package/Rendering/depthPeelingRenderer.js +1 -0
  162. package/Rendering/depthPeelingRenderer.js.map +1 -1
  163. package/Rendering/geometryBufferRenderer.d.ts +1 -0
  164. package/Rendering/geometryBufferRenderer.js +1 -0
  165. package/Rendering/geometryBufferRenderer.js.map +1 -1
  166. package/Rendering/prePassRenderer.d.ts +1 -0
  167. package/Rendering/prePassRenderer.js +1 -0
  168. package/Rendering/prePassRenderer.js.map +1 -1
  169. package/ShadersWGSL/ShadersInclude/bumpFragment.d.ts +5 -0
  170. package/ShadersWGSL/ShadersInclude/bumpFragment.js +61 -0
  171. package/ShadersWGSL/ShadersInclude/bumpFragment.js.map +1 -0
  172. package/ShadersWGSL/ShadersInclude/bumpFragmentFunctions.d.ts +6 -0
  173. package/ShadersWGSL/ShadersInclude/bumpFragmentFunctions.js +40 -0
  174. package/ShadersWGSL/ShadersInclude/bumpFragmentFunctions.js.map +1 -0
  175. package/ShadersWGSL/ShadersInclude/bumpFragmentMainFunctions.d.ts +5 -0
  176. package/ShadersWGSL/ShadersInclude/bumpFragmentMainFunctions.js +69 -0
  177. package/ShadersWGSL/ShadersInclude/bumpFragmentMainFunctions.js.map +1 -0
  178. package/ShadersWGSL/ShadersInclude/samplerFragmentDeclaration.d.ts +5 -0
  179. package/ShadersWGSL/ShadersInclude/samplerFragmentDeclaration.js +27 -0
  180. package/ShadersWGSL/ShadersInclude/samplerFragmentDeclaration.js.map +1 -0
  181. package/package.json +1 -1
  182. package/Engines/Extensions/engine.views.js.map +0 -1
@@ -86,18 +86,18 @@ export class PhysicsAggregate {
86
86
  const extents = TmpVectors.Vector3[0];
87
87
  extents.copyFrom(bb.extendSize);
88
88
  extents.scaleInPlace(2);
89
- extents.multiplyInPlace(this.transformNode.scaling);
89
+ extents.multiplyInPlace(this.transformNode.absoluteScaling);
90
90
  // In case we had any negative scaling, we need to take the absolute value of the extents.
91
91
  extents.x = Math.abs(extents.x);
92
92
  extents.y = Math.abs(extents.y);
93
93
  extents.z = Math.abs(extents.z);
94
94
  const min = TmpVectors.Vector3[1];
95
95
  min.copyFrom(bb.minimum);
96
- min.multiplyInPlace(this.transformNode.scaling);
96
+ min.multiplyInPlace(this.transformNode.absoluteScaling);
97
97
  if (!this._options.center) {
98
98
  const center = new Vector3();
99
99
  center.copyFrom(bb.center);
100
- center.multiplyInPlace(this.transformNode.scaling);
100
+ center.multiplyInPlace(this.transformNode.absoluteScaling);
101
101
  this._options.center = center;
102
102
  }
103
103
  switch (this.type) {
@@ -1 +1 @@
1
- {"version":3,"file":"physicsAggregate.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/physicsAggregate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAM7E,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAkExD;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAoBzB;IACI;;OAEG;IACI,aAA4B;IACnC;;OAEG;IACI,IAAqC,EACpC,WAAuC,EAAE,IAAI,EAAE,CAAC,EAAE,EAClD,MAAc;QANf,kBAAa,GAAb,aAAa,CAAe;QAI5B,SAAI,GAAJ,IAAI,CAAiC;QACpC,aAAQ,GAA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I,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;oBACtE,MAAM,IAAI,KAAK,CACX,oJAAoJ,CACvJ,CAAC;iBACL;gBACD,MAAM;YACV,KAAK,gBAAgB,CAAC,GAAG;gBACrB,IAAI,CAAC,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;gBAC9F,IAAI,CAAC,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;gBACzE,MAAM;SACb;IACL,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC3B,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YAC9E,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;SACpC;QACD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACpB,IAAI,IAAI,CAAC,yBAAyB,EAAE;YAChC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;SACxB;IACL,CAAC;CACJ","sourcesContent":["import { PhysicsBody } from \"./physicsBody\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport { PhysicsShape } from \"./physicsShape\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { Quaternion, TmpVectors, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport { PhysicsMotionType, PhysicsShapeType } from \"./IPhysicsEnginePlugin\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Node } from \"../../node\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { BoundingBox } from \"../../Culling/boundingBox\";\r\n\r\n/**\r\n * The interface for the physics aggregate parameters\r\n */\r\nexport interface PhysicsAggregateParameters {\r\n /**\r\n * The mass of the physics aggregate\r\n */\r\n mass: number;\r\n\r\n /**\r\n * The friction of the physics aggregate\r\n */\r\n friction?: number;\r\n\r\n /**\r\n * The coefficient of restitution of the physics aggregate\r\n */\r\n restitution?: number;\r\n\r\n /**\r\n * Radius for sphere, cylinder and capsule\r\n */\r\n radius?: number;\r\n\r\n /**\r\n * Starting point for cylinder/capsule\r\n */\r\n pointA?: Vector3;\r\n\r\n /**\r\n * Ending point for cylinder/capsule\r\n */\r\n pointB?: Vector3;\r\n\r\n /**\r\n * Extents for box\r\n */\r\n extents?: Vector3;\r\n\r\n /**\r\n * Orientation for box\r\n */\r\n rotation?: Quaternion;\r\n\r\n /**\r\n * mesh local center\r\n */\r\n center?: Vector3;\r\n\r\n /**\r\n * mesh object. Used for mesh and convex hull aggregates.\r\n */\r\n mesh?: Mesh;\r\n\r\n /**\r\n * Physics engine will try to make this body sleeping and not active\r\n */\r\n startAsleep?: boolean;\r\n\r\n /**\r\n * If true, mark the created shape as a trigger shape\r\n */\r\n isTriggerShape?: boolean;\r\n}\r\n/**\r\n * Helper class to create and interact with a PhysicsAggregate.\r\n * This is a transition object that works like Physics Plugin V1 Impostors.\r\n * This helper instanciate all mandatory physics objects to get a body/shape and material.\r\n * It's less efficient that handling body and shapes independently but for prototyping or\r\n * a small numbers of physics objects, it's good enough.\r\n */\r\nexport class PhysicsAggregate {\r\n /**\r\n * The body that is associated with this aggregate\r\n */\r\n public body: PhysicsBody;\r\n\r\n /**\r\n * The shape that is associated with this aggregate\r\n */\r\n public shape: PhysicsShape;\r\n\r\n /**\r\n * The material that is associated with this aggregate\r\n */\r\n public material: PhysicsMaterial;\r\n\r\n private _disposeShapeWhenDisposed = true;\r\n\r\n private _nodeDisposeObserver: Nullable<Observer<Node>>;\r\n\r\n constructor(\r\n /**\r\n * The physics-enabled object used as the physics aggregate\r\n */\r\n public transformNode: TransformNode,\r\n /**\r\n * The type of the physics aggregate\r\n */\r\n public type: PhysicsShapeType | PhysicsShape,\r\n private _options: PhysicsAggregateParameters = { mass: 0 },\r\n private _scene?: Scene\r\n ) {\r\n //sanity check!\r\n if (!this.transformNode) {\r\n Logger.Error(\"No object was provided. A physics object is obligatory\");\r\n return;\r\n }\r\n const m = transformNode as Mesh;\r\n if (this.transformNode.parent && this._options.mass !== 0 && m.hasThinInstances) {\r\n Logger.Warn(\r\n \"A physics body has been created for an object which has a parent and thin instances. Babylon physics currently works in local space so unexpected issues may occur.\"\r\n );\r\n }\r\n\r\n // Legacy support for old syntax.\r\n if (!this._scene && transformNode.getScene) {\r\n this._scene = transformNode.getScene();\r\n }\r\n\r\n if (!this._scene) {\r\n return;\r\n }\r\n\r\n //default options params\r\n this._options.mass = _options.mass === void 0 ? 0 : _options.mass;\r\n this._options.friction = _options.friction === void 0 ? 0.2 : _options.friction;\r\n this._options.restitution = _options.restitution === void 0 ? 0.2 : _options.restitution;\r\n\r\n const motionType = this._options.mass === 0 ? PhysicsMotionType.STATIC : PhysicsMotionType.DYNAMIC;\r\n const startAsleep = this._options.startAsleep ?? false;\r\n this.body = new PhysicsBody(transformNode, motionType, startAsleep, this._scene);\r\n this._addSizeOptions();\r\n if ((type as any).getClassName && (type as any).getClassName() === \"PhysicsShape\") {\r\n this.shape = type as PhysicsShape;\r\n this._disposeShapeWhenDisposed = false;\r\n } else {\r\n this.shape = new PhysicsShape({ type: type as PhysicsShapeType, parameters: this._options as any }, this._scene);\r\n }\r\n\r\n if (this._options.isTriggerShape) {\r\n this.shape.isTrigger = true;\r\n }\r\n\r\n this.material = { friction: this._options.friction, restitution: this._options.restitution };\r\n this.body.shape = this.shape;\r\n this.shape.material = this.material;\r\n\r\n this.body.setMassProperties({ mass: this._options.mass });\r\n\r\n this._nodeDisposeObserver = this.transformNode.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n private _getObjectBoundingBox() {\r\n if ((this.transformNode as AbstractMesh).getRawBoundingInfo) {\r\n return (this.transformNode as AbstractMesh).getRawBoundingInfo().boundingBox;\r\n } else {\r\n return new BoundingBox(new Vector3(-0.5, -0.5, -0.5), new Vector3(0.5, 0.5, 0.5));\r\n }\r\n }\r\n\r\n private _hasVertices(node: TransformNode): boolean {\r\n return (node as any)?.getTotalVertices() > 0;\r\n }\r\n\r\n private _addSizeOptions(): void {\r\n this.transformNode.computeWorldMatrix(true);\r\n const bb = this._getObjectBoundingBox();\r\n const extents = TmpVectors.Vector3[0];\r\n extents.copyFrom(bb.extendSize);\r\n extents.scaleInPlace(2);\r\n extents.multiplyInPlace(this.transformNode.scaling);\r\n // In case we had any negative scaling, we need to take the absolute value of the extents.\r\n extents.x = Math.abs(extents.x);\r\n extents.y = Math.abs(extents.y);\r\n extents.z = Math.abs(extents.z);\r\n\r\n const min = TmpVectors.Vector3[1];\r\n min.copyFrom(bb.minimum);\r\n min.multiplyInPlace(this.transformNode.scaling);\r\n\r\n if (!this._options.center) {\r\n const center = new Vector3();\r\n center.copyFrom(bb.center);\r\n center.multiplyInPlace(this.transformNode.scaling);\r\n this._options.center = center;\r\n }\r\n\r\n switch (this.type) {\r\n case PhysicsShapeType.SPHERE:\r\n if (!this._options.radius && Scalar.WithinEpsilon(extents.x, extents.y, 0.0001) && Scalar.WithinEpsilon(extents.x, extents.z, 0.0001)) {\r\n this._options.radius = extents.x / 2;\r\n } else if (!this._options.radius) {\r\n Logger.Warn(\"Non uniform scaling is unsupported for sphere shapes. Setting the radius to the biggest bounding box extent.\");\r\n this._options.radius = Math.max(extents.x, extents.y, extents.z) / 2;\r\n }\r\n break;\r\n case PhysicsShapeType.CAPSULE:\r\n {\r\n const capRadius = extents.x / 2;\r\n this._options.radius = this._options.radius ?? capRadius;\r\n this._options.pointA = this._options.pointA ?? new Vector3(0, min.y + capRadius, 0);\r\n this._options.pointB = this._options.pointB ?? new Vector3(0, min.y + extents.y - capRadius, 0);\r\n }\r\n break;\r\n case PhysicsShapeType.CYLINDER:\r\n {\r\n const capRadius = extents.x / 2;\r\n this._options.radius = this._options.radius ?? capRadius;\r\n this._options.pointA = this._options.pointA ?? new Vector3(0, min.y, 0);\r\n this._options.pointB = this._options.pointB ?? new Vector3(0, min.y + extents.y, 0);\r\n }\r\n break;\r\n case PhysicsShapeType.MESH:\r\n case PhysicsShapeType.CONVEX_HULL:\r\n if (!this._options.mesh && this._hasVertices(this.transformNode)) {\r\n this._options.mesh = this.transformNode as Mesh;\r\n } else if (!this._options.mesh || !this._hasVertices(this._options.mesh)) {\r\n throw new Error(\r\n \"No valid mesh was provided for mesh or convex hull shape parameter. Please provide a mesh with valid geometry (number of vertices greater than 0).\"\r\n );\r\n }\r\n break;\r\n case PhysicsShapeType.BOX:\r\n this._options.extents = this._options.extents ?? new Vector3(extents.x, extents.y, extents.z);\r\n this._options.rotation = this._options.rotation ?? Quaternion.Identity();\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Releases the body, shape and material\r\n */\r\n public dispose(): void {\r\n if (this._nodeDisposeObserver) {\r\n this.body.transformNode.onDisposeObservable.remove(this._nodeDisposeObserver);\r\n this._nodeDisposeObserver = null;\r\n }\r\n this.body.dispose();\r\n if (this._disposeShapeWhenDisposed) {\r\n this.shape.dispose();\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"physicsAggregate.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/physicsAggregate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,OAA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EAAE,CAAC;QACpB,IAAI,IAAI,CAAC,yBAAyB,EAAE;YAChC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;SACxB;IACL,CAAC;CACJ","sourcesContent":["import { PhysicsBody } from \"./physicsBody\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport { PhysicsShape } from \"./physicsShape\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { Quaternion, TmpVectors, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport { PhysicsMotionType, PhysicsShapeType } from \"./IPhysicsEnginePlugin\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Node } from \"../../node\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { BoundingBox } from \"../../Culling/boundingBox\";\r\n\r\n/**\r\n * The interface for the physics aggregate parameters\r\n */\r\nexport interface PhysicsAggregateParameters {\r\n /**\r\n * The mass of the physics aggregate\r\n */\r\n mass: number;\r\n\r\n /**\r\n * The friction of the physics aggregate\r\n */\r\n friction?: number;\r\n\r\n /**\r\n * The coefficient of restitution of the physics aggregate\r\n */\r\n restitution?: number;\r\n\r\n /**\r\n * Radius for sphere, cylinder and capsule\r\n */\r\n radius?: number;\r\n\r\n /**\r\n * Starting point for cylinder/capsule\r\n */\r\n pointA?: Vector3;\r\n\r\n /**\r\n * Ending point for cylinder/capsule\r\n */\r\n pointB?: Vector3;\r\n\r\n /**\r\n * Extents for box\r\n */\r\n extents?: Vector3;\r\n\r\n /**\r\n * Orientation for box\r\n */\r\n rotation?: Quaternion;\r\n\r\n /**\r\n * mesh local center\r\n */\r\n center?: Vector3;\r\n\r\n /**\r\n * mesh object. Used for mesh and convex hull aggregates.\r\n */\r\n mesh?: Mesh;\r\n\r\n /**\r\n * Physics engine will try to make this body sleeping and not active\r\n */\r\n startAsleep?: boolean;\r\n\r\n /**\r\n * If true, mark the created shape as a trigger shape\r\n */\r\n isTriggerShape?: boolean;\r\n}\r\n/**\r\n * Helper class to create and interact with a PhysicsAggregate.\r\n * This is a transition object that works like Physics Plugin V1 Impostors.\r\n * This helper instanciate all mandatory physics objects to get a body/shape and material.\r\n * It's less efficient that handling body and shapes independently but for prototyping or\r\n * a small numbers of physics objects, it's good enough.\r\n */\r\nexport class PhysicsAggregate {\r\n /**\r\n * The body that is associated with this aggregate\r\n */\r\n public body: PhysicsBody;\r\n\r\n /**\r\n * The shape that is associated with this aggregate\r\n */\r\n public shape: PhysicsShape;\r\n\r\n /**\r\n * The material that is associated with this aggregate\r\n */\r\n public material: PhysicsMaterial;\r\n\r\n private _disposeShapeWhenDisposed = true;\r\n\r\n private _nodeDisposeObserver: Nullable<Observer<Node>>;\r\n\r\n constructor(\r\n /**\r\n * The physics-enabled object used as the physics aggregate\r\n */\r\n public transformNode: TransformNode,\r\n /**\r\n * The type of the physics aggregate\r\n */\r\n public type: PhysicsShapeType | PhysicsShape,\r\n private _options: PhysicsAggregateParameters = { mass: 0 },\r\n private _scene?: Scene\r\n ) {\r\n //sanity check!\r\n if (!this.transformNode) {\r\n Logger.Error(\"No object was provided. A physics object is obligatory\");\r\n return;\r\n }\r\n const m = transformNode as Mesh;\r\n if (this.transformNode.parent && this._options.mass !== 0 && m.hasThinInstances) {\r\n Logger.Warn(\r\n \"A physics body has been created for an object which has a parent and thin instances. Babylon physics currently works in local space so unexpected issues may occur.\"\r\n );\r\n }\r\n\r\n // Legacy support for old syntax.\r\n if (!this._scene && transformNode.getScene) {\r\n this._scene = transformNode.getScene();\r\n }\r\n\r\n if (!this._scene) {\r\n return;\r\n }\r\n\r\n //default options params\r\n this._options.mass = _options.mass === void 0 ? 0 : _options.mass;\r\n this._options.friction = _options.friction === void 0 ? 0.2 : _options.friction;\r\n this._options.restitution = _options.restitution === void 0 ? 0.2 : _options.restitution;\r\n\r\n const motionType = this._options.mass === 0 ? PhysicsMotionType.STATIC : PhysicsMotionType.DYNAMIC;\r\n const startAsleep = this._options.startAsleep ?? false;\r\n this.body = new PhysicsBody(transformNode, motionType, startAsleep, this._scene);\r\n this._addSizeOptions();\r\n if ((type as any).getClassName && (type as any).getClassName() === \"PhysicsShape\") {\r\n this.shape = type as PhysicsShape;\r\n this._disposeShapeWhenDisposed = false;\r\n } else {\r\n this.shape = new PhysicsShape({ type: type as PhysicsShapeType, parameters: this._options as any }, this._scene);\r\n }\r\n\r\n if (this._options.isTriggerShape) {\r\n this.shape.isTrigger = true;\r\n }\r\n\r\n this.material = { friction: this._options.friction, restitution: this._options.restitution };\r\n this.body.shape = this.shape;\r\n this.shape.material = this.material;\r\n\r\n this.body.setMassProperties({ mass: this._options.mass });\r\n\r\n this._nodeDisposeObserver = this.transformNode.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n private _getObjectBoundingBox() {\r\n if ((this.transformNode as AbstractMesh).getRawBoundingInfo) {\r\n return (this.transformNode as AbstractMesh).getRawBoundingInfo().boundingBox;\r\n } else {\r\n return new BoundingBox(new Vector3(-0.5, -0.5, -0.5), new Vector3(0.5, 0.5, 0.5));\r\n }\r\n }\r\n\r\n private _hasVertices(node: TransformNode): boolean {\r\n return (node as any)?.getTotalVertices() > 0;\r\n }\r\n\r\n private _addSizeOptions(): void {\r\n this.transformNode.computeWorldMatrix(true);\r\n const bb = this._getObjectBoundingBox();\r\n const extents = TmpVectors.Vector3[0];\r\n extents.copyFrom(bb.extendSize);\r\n extents.scaleInPlace(2);\r\n extents.multiplyInPlace(this.transformNode.absoluteScaling);\r\n // In case we had any negative scaling, we need to take the absolute value of the extents.\r\n extents.x = Math.abs(extents.x);\r\n extents.y = Math.abs(extents.y);\r\n extents.z = Math.abs(extents.z);\r\n\r\n const min = TmpVectors.Vector3[1];\r\n min.copyFrom(bb.minimum);\r\n min.multiplyInPlace(this.transformNode.absoluteScaling);\r\n\r\n if (!this._options.center) {\r\n const center = new Vector3();\r\n center.copyFrom(bb.center);\r\n center.multiplyInPlace(this.transformNode.absoluteScaling);\r\n this._options.center = center;\r\n }\r\n\r\n switch (this.type) {\r\n case PhysicsShapeType.SPHERE:\r\n if (!this._options.radius && Scalar.WithinEpsilon(extents.x, extents.y, 0.0001) && Scalar.WithinEpsilon(extents.x, extents.z, 0.0001)) {\r\n this._options.radius = extents.x / 2;\r\n } else if (!this._options.radius) {\r\n Logger.Warn(\"Non uniform scaling is unsupported for sphere shapes. Setting the radius to the biggest bounding box extent.\");\r\n this._options.radius = Math.max(extents.x, extents.y, extents.z) / 2;\r\n }\r\n break;\r\n case PhysicsShapeType.CAPSULE:\r\n {\r\n const capRadius = extents.x / 2;\r\n this._options.radius = this._options.radius ?? capRadius;\r\n this._options.pointA = this._options.pointA ?? new Vector3(0, min.y + capRadius, 0);\r\n this._options.pointB = this._options.pointB ?? new Vector3(0, min.y + extents.y - capRadius, 0);\r\n }\r\n break;\r\n case PhysicsShapeType.CYLINDER:\r\n {\r\n const capRadius = extents.x / 2;\r\n this._options.radius = this._options.radius ?? capRadius;\r\n this._options.pointA = this._options.pointA ?? new Vector3(0, min.y, 0);\r\n this._options.pointB = this._options.pointB ?? new Vector3(0, min.y + extents.y, 0);\r\n }\r\n break;\r\n case PhysicsShapeType.MESH:\r\n case PhysicsShapeType.CONVEX_HULL:\r\n if (!this._options.mesh && this._hasVertices(this.transformNode)) {\r\n this._options.mesh = this.transformNode as Mesh;\r\n } else if (!this._options.mesh || !this._hasVertices(this._options.mesh)) {\r\n throw new Error(\r\n \"No valid mesh was provided for mesh or convex hull shape parameter. Please provide a mesh with valid geometry (number of vertices greater than 0).\"\r\n );\r\n }\r\n break;\r\n case PhysicsShapeType.BOX:\r\n this._options.extents = this._options.extents ?? new Vector3(extents.x, extents.y, extents.z);\r\n this._options.rotation = this._options.rotation ?? Quaternion.Identity();\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Releases the body, shape and material\r\n */\r\n public dispose(): void {\r\n if (this._nodeDisposeObserver) {\r\n this.body.transformNode.onDisposeObservable.remove(this._nodeDisposeObserver);\r\n this._nodeDisposeObserver = null;\r\n }\r\n this.body.dispose();\r\n if (this._disposeShapeWhenDisposed) {\r\n this.shape.dispose();\r\n }\r\n }\r\n}\r\n"]}
@@ -9,6 +9,7 @@ import type { Bone } from "../../Bones/bone.js";
9
9
  import type { Observable } from "../../Misc/observable";
10
10
  import type { AbstractMesh } from "../../Meshes/abstractMesh";
11
11
  import type { TransformNode } from "../../Meshes/transformNode";
12
+ import type { BoundingBox } from "../../Culling/boundingBox.js";
12
13
  /**
13
14
  * PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows
14
15
  * the user to set the mass and velocity of the body, which can then be used to calculate the
@@ -116,6 +117,11 @@ export declare class PhysicsBody {
116
117
  * which can be used to apply physical forces to the object or to detect collisions.
117
118
  */
118
119
  get shape(): Nullable<PhysicsShape>;
120
+ /**
121
+ * Returns the bounding box of the physics body.
122
+ * @returns The bounding box of the physics body.
123
+ */
124
+ getBoundingBox(): BoundingBox;
119
125
  /**
120
126
  * Sets the event mask for the physics engine.
121
127
  *
@@ -158,6 +158,13 @@ export class PhysicsBody {
158
158
  get shape() {
159
159
  return this._shape;
160
160
  }
161
+ /**
162
+ * Returns the bounding box of the physics body.
163
+ * @returns The bounding box of the physics body.
164
+ */
165
+ getBoundingBox() {
166
+ return this._physicsPlugin.getBodyBoundingBox(this);
167
+ }
161
168
  /**
162
169
  * Sets the event mask for the physics engine.
163
170
  *
@@ -1 +1 @@
1
- {"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/physicsBody.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAM1E,OAAO,E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G,IAAI,CAAC;SACpC;QACD,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,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 } 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\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 * 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 disablePreStep: boolean = true;\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 _motionType: PhysicsMotionType;\r\n\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 as IPhysicsEnginePluginV2;\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 this._motionType = motionType;\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._motionType;\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 * 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.\r\n */\r\n public setMotionType(motionType: PhysicsMotionType, instanceIndex?: number) {\r\n this.disableSync = 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 * 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(): {} {\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,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAM1E,OAAO,EAAE,KAAK,EAAE,iCAA6B;AAQ7C;;;;GAIG;AACH,MAAM,OAAO,WAAW;IAqDpB;;;;;;;;;;;;;OAaG;IACH,YAAY,aAA4B,EAAE,UAA6B,EAAE,YAAqB,EAAE,KAAY;QAlE5G;;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;QAKlD;;;WAGG;QACH,mBAAc,GAAY,IAAI,CAAC;QAE/B;;WAEG;QACH,gBAAW,GAAY,KAAK,CAAC;QASrB,gBAAW,GAAG,KAAK,CAAC;QAEpB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C,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 } 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 * 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 disablePreStep: boolean = true;\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 _motionType: PhysicsMotionType;\r\n\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 as IPhysicsEnginePluginV2;\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 this._motionType = motionType;\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._motionType;\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.\r\n */\r\n public setMotionType(motionType: PhysicsMotionType, instanceIndex?: number) {\r\n this.disableSync = 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 * 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(): {} {\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"]}
@@ -3,7 +3,7 @@ import { SmartArray } from "../Misc/smartArray";
3
3
  import { Observable } from "../Misc/observable";
4
4
  import { Vector2 } from "../Maths/math.vector";
5
5
  import type { Camera } from "../Cameras/camera";
6
- import type { Effect } from "../Materials/effect";
6
+ import { Effect } from "../Materials/effect";
7
7
  import "../Shaders/postprocess.vertex";
8
8
  import type { IInspectable } from "../Misc/iInspectable";
9
9
  import type { Color4 } from "../Maths/math.color";
@@ -17,7 +17,42 @@ import type { InternalTexture } from "../Materials/Textures/internalTexture";
17
17
  import type { Animation } from "../Animations/animation";
18
18
  import type { PrePassRenderer } from "../Rendering/prePassRenderer";
19
19
  import type { PrePassEffectConfiguration } from "../Rendering/prePassEffectConfiguration";
20
- import type { AbstractEngine } from "../Engines/abstractEngine";
20
+ import { AbstractEngine } from "../Engines/abstractEngine";
21
+ declare module "../Engines/abstractEngine" {
22
+ interface AbstractEngine {
23
+ /**
24
+ * Sets a texture to the context from a postprocess
25
+ * @param channel defines the channel to use
26
+ * @param postProcess defines the source postprocess
27
+ * @param name name of the channel
28
+ */
29
+ setTextureFromPostProcess(channel: number, postProcess: Nullable<PostProcess>, name: string): void;
30
+ /**
31
+ * Binds the output of the passed in post process to the texture channel specified
32
+ * @param channel The channel the texture should be bound to
33
+ * @param postProcess The post process which's output should be bound
34
+ * @param name name of the channel
35
+ */
36
+ setTextureFromPostProcessOutput(channel: number, postProcess: Nullable<PostProcess>, name: string): void;
37
+ }
38
+ }
39
+ declare module "../Materials/effect" {
40
+ interface Effect {
41
+ /**
42
+ * Sets a texture to be the input of the specified post process. (To use the output, pass in the next post process in the pipeline)
43
+ * @param channel Name of the sampler variable.
44
+ * @param postProcess Post process to get the input texture from.
45
+ */
46
+ setTextureFromPostProcess(channel: string, postProcess: Nullable<PostProcess>): void;
47
+ /**
48
+ * (Warning! setTextureFromPostProcessOutput may be desired instead)
49
+ * Sets the input texture of the passed in post process to be input of this effect. (To use the output of the passed in post process use setTextureFromPostProcessOutput)
50
+ * @param channel Name of the sampler variable.
51
+ * @param postProcess Post process to get the output texture from.
52
+ */
53
+ setTextureFromPostProcessOutput(channel: string, postProcess: Nullable<PostProcess>): void;
54
+ }
55
+ }
21
56
  /**
22
57
  * Allows for custom processing of the shader code used by a post process
23
58
  */
@@ -2,6 +2,7 @@ import { __decorate } from "../tslib.es6.js";
2
2
  import { SmartArray } from "../Misc/smartArray.js";
3
3
  import { Observable } from "../Misc/observable.js";
4
4
  import { Vector2 } from "../Maths/math.vector.js";
5
+ import { Effect } from "../Materials/effect.js";
5
6
 
6
7
  import "../Shaders/postprocess.vertex.js";
7
8
  import "../Engines/Extensions/engine.renderTarget.js";
@@ -10,7 +11,40 @@ import { SerializationHelper } from "../Misc/decorators.serialization.js";
10
11
  import { GetClass, RegisterClass } from "../Misc/typeStore.js";
11
12
  import { DrawWrapper } from "../Materials/drawWrapper.js";
12
13
  import { ShaderLanguage } from "../Materials/shaderLanguage.js";
14
+ import { AbstractEngine } from "../Engines/abstractEngine.js";
13
15
  import { GetExponentOfTwo } from "../Misc/tools.functions.js";
16
+ AbstractEngine.prototype.setTextureFromPostProcess = function (channel, postProcess, name) {
17
+ let postProcessInput = null;
18
+ if (postProcess) {
19
+ if (postProcess._forcedOutputTexture) {
20
+ postProcessInput = postProcess._forcedOutputTexture;
21
+ }
22
+ else if (postProcess._textures.data[postProcess._currentRenderTextureInd]) {
23
+ postProcessInput = postProcess._textures.data[postProcess._currentRenderTextureInd];
24
+ }
25
+ }
26
+ this._bindTexture(channel, postProcessInput?.texture ?? null, name);
27
+ };
28
+ AbstractEngine.prototype.setTextureFromPostProcessOutput = function (channel, postProcess, name) {
29
+ this._bindTexture(channel, postProcess?._outputTexture?.texture ?? null, name);
30
+ };
31
+ /**
32
+ * Sets a texture to be the input of the specified post process. (To use the output, pass in the next post process in the pipeline)
33
+ * @param channel Name of the sampler variable.
34
+ * @param postProcess Post process to get the input texture from.
35
+ */
36
+ Effect.prototype.setTextureFromPostProcess = function (channel, postProcess) {
37
+ this._engine.setTextureFromPostProcess(this._samplers[channel], postProcess, channel);
38
+ };
39
+ /**
40
+ * (Warning! setTextureFromPostProcessOutput may be desired instead)
41
+ * Sets the input texture of the passed in post process to be input of this effect. (To use the output of the passed in post process use setTextureFromPostProcessOutput)
42
+ * @param channel Name of the sampler variable.
43
+ * @param postProcess Post process to get the output texture from.
44
+ */
45
+ Effect.prototype.setTextureFromPostProcessOutput = function (channel, postProcess) {
46
+ this._engine.setTextureFromPostProcessOutput(this._samplers[channel], postProcess, channel);
47
+ };
14
48
  /**
15
49
  * PostProcess can be used to apply a shader to a texture after it has been rendered
16
50
  * See https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/usePostProcesses