@babylonjs/core 5.35.0 → 5.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/Audio/sound.d.ts +5 -0
  2. package/Audio/sound.js +7 -0
  3. package/Audio/sound.js.map +1 -1
  4. package/Debug/physicsViewer.d.ts +4 -3
  5. package/Debug/physicsViewer.js +2 -2
  6. package/Debug/physicsViewer.js.map +1 -1
  7. package/Engines/Extensions/engine.renderTarget.js +15 -15
  8. package/Engines/Extensions/engine.renderTarget.js.map +1 -1
  9. package/Engines/Extensions/engine.renderTargetCube.d.ts +1 -1
  10. package/Engines/Extensions/engine.renderTargetCube.js.map +1 -1
  11. package/Engines/Extensions/engine.views.d.ts +4 -0
  12. package/Engines/Extensions/engine.views.js +61 -42
  13. package/Engines/Extensions/engine.views.js.map +1 -1
  14. package/Engines/Native/nativeHardwareTexture.d.ts +14 -0
  15. package/Engines/Native/nativeHardwareTexture.js +24 -0
  16. package/Engines/Native/nativeHardwareTexture.js.map +1 -0
  17. package/Engines/Native/nativeInterfaces.d.ts +22 -15
  18. package/Engines/Native/nativeInterfaces.js.map +1 -1
  19. package/Engines/Native/nativePipelineContext.d.ts +252 -0
  20. package/Engines/Native/nativePipelineContext.js +502 -0
  21. package/Engines/Native/nativePipelineContext.js.map +1 -0
  22. package/Engines/Native/nativeRenderTargetWrapper.d.ts +16 -0
  23. package/Engines/Native/nativeRenderTargetWrapper.js +33 -0
  24. package/Engines/Native/nativeRenderTargetWrapper.js.map +1 -0
  25. package/Engines/WebGPU/Extensions/engine.renderTarget.js +3 -3
  26. package/Engines/WebGPU/Extensions/engine.renderTarget.js.map +1 -1
  27. package/Engines/WebGPU/Extensions/engine.renderTargetCube.js.map +1 -1
  28. package/Engines/engine.d.ts +1 -0
  29. package/Engines/engine.js +24 -18
  30. package/Engines/engine.js.map +1 -1
  31. package/Engines/nativeEngine.d.ts +18 -17
  32. package/Engines/nativeEngine.js +100 -598
  33. package/Engines/nativeEngine.js.map +1 -1
  34. package/Engines/nullEngine.d.ts +1 -1
  35. package/Engines/nullEngine.js.map +1 -1
  36. package/Engines/thinEngine.d.ts +1 -1
  37. package/Engines/thinEngine.js +41 -38
  38. package/Engines/thinEngine.js.map +1 -1
  39. package/Engines/webgpuEngine.js.map +1 -1
  40. package/Gizmos/planeRotationGizmo.js +3 -1
  41. package/Gizmos/planeRotationGizmo.js.map +1 -1
  42. package/Inputs/scene.inputManager.js +4 -4
  43. package/Inputs/scene.inputManager.js.map +1 -1
  44. package/Loading/Plugins/babylonFileLoader.js +3 -3
  45. package/Loading/Plugins/babylonFileLoader.js.map +1 -1
  46. package/Materials/Node/Blocks/Dual/textureBlock.js +1 -1
  47. package/Materials/Node/Blocks/Dual/textureBlock.js.map +1 -1
  48. package/Materials/Node/nodeMaterial.d.ts +19 -1
  49. package/Materials/Node/nodeMaterial.js +30 -0
  50. package/Materials/Node/nodeMaterial.js.map +1 -1
  51. package/Materials/Node/nodeMaterialBuildStateSharedData.d.ts +2 -8
  52. package/Materials/Node/nodeMaterialBuildStateSharedData.js.map +1 -1
  53. package/Materials/Textures/baseTexture.d.ts +2 -1
  54. package/Materials/Textures/baseTexture.js +3 -2
  55. package/Materials/Textures/baseTexture.js.map +1 -1
  56. package/Materials/Textures/internalTexture.d.ts +2 -0
  57. package/Materials/Textures/internalTexture.js +4 -0
  58. package/Materials/Textures/internalTexture.js.map +1 -1
  59. package/Materials/Textures/mirrorTexture.js +0 -2
  60. package/Materials/Textures/mirrorTexture.js.map +1 -1
  61. package/Materials/Textures/renderTargetTexture.d.ts +53 -3
  62. package/Materials/Textures/renderTargetTexture.js +25 -25
  63. package/Materials/Textures/renderTargetTexture.js.map +1 -1
  64. package/Materials/Textures/texture.d.ts +2 -0
  65. package/Materials/Textures/texture.js +35 -7
  66. package/Materials/Textures/texture.js.map +1 -1
  67. package/Materials/Textures/textureCreationOptions.d.ts +4 -1
  68. package/Materials/Textures/textureCreationOptions.js.map +1 -1
  69. package/Materials/material.js +1 -1
  70. package/Materials/material.js.map +1 -1
  71. package/Meshes/abstractMesh.d.ts +4 -4
  72. package/Meshes/abstractMesh.js +4 -4
  73. package/Meshes/abstractMesh.js.map +1 -1
  74. package/Meshes/mesh.d.ts +2 -2
  75. package/Meshes/mesh.js +1 -1
  76. package/Meshes/mesh.js.map +1 -1
  77. package/Misc/copyTextureToTexture.d.ts +9 -2
  78. package/Misc/copyTextureToTexture.js +23 -1
  79. package/Misc/copyTextureToTexture.js.map +1 -1
  80. package/Particles/IParticleSystem.d.ts +15 -1
  81. package/Particles/IParticleSystem.js.map +1 -1
  82. package/Particles/gpuParticleSystem.d.ts +24 -2
  83. package/Particles/gpuParticleSystem.js +98 -43
  84. package/Particles/gpuParticleSystem.js.map +1 -1
  85. package/Particles/particleSystem.d.ts +6 -1
  86. package/Particles/particleSystem.js +7 -2
  87. package/Particles/particleSystem.js.map +1 -1
  88. package/Physics/IPhysicsEngine.d.ts +8 -108
  89. package/Physics/IPhysicsEngine.js.map +1 -1
  90. package/Physics/Plugins/ammoJSPlugin.d.ts +1 -389
  91. package/Physics/Plugins/ammoJSPlugin.js +2 -1414
  92. package/Physics/Plugins/ammoJSPlugin.js.map +1 -1
  93. package/Physics/Plugins/cannonJSPlugin.d.ts +1 -75
  94. package/Physics/Plugins/cannonJSPlugin.js +2 -664
  95. package/Physics/Plugins/cannonJSPlugin.js.map +1 -1
  96. package/Physics/Plugins/oimoJSPlugin.d.ts +1 -59
  97. package/Physics/Plugins/oimoJSPlugin.js +2 -432
  98. package/Physics/Plugins/oimoJSPlugin.js.map +1 -1
  99. package/Physics/index.d.ts +3 -6
  100. package/Physics/index.js +3 -6
  101. package/Physics/index.js.map +1 -1
  102. package/Physics/physicsEngine.d.ts +1 -135
  103. package/Physics/physicsEngine.js +2 -221
  104. package/Physics/physicsEngine.js.map +1 -1
  105. package/Physics/physicsEngineComponent.d.ts +7 -42
  106. package/Physics/physicsEngineComponent.js +11 -71
  107. package/Physics/physicsEngineComponent.js.map +1 -1
  108. package/Physics/physicsHelper.d.ts +1 -411
  109. package/Physics/physicsHelper.js +2 -708
  110. package/Physics/physicsHelper.js.map +1 -1
  111. package/Physics/physicsImpostor.d.ts +1 -640
  112. package/Physics/physicsImpostor.js +2 -1004
  113. package/Physics/physicsImpostor.js.map +1 -1
  114. package/Physics/physicsJoint.d.ts +1 -275
  115. package/Physics/physicsJoint.js +2 -222
  116. package/Physics/physicsJoint.js.map +1 -1
  117. package/Physics/v1/IPhysicsEnginePlugin.d.ts +73 -0
  118. package/Physics/v1/IPhysicsEnginePlugin.js +2 -0
  119. package/Physics/v1/IPhysicsEnginePlugin.js.map +1 -0
  120. package/Physics/v1/Plugins/ammoJSPlugin.d.ts +401 -0
  121. package/Physics/v1/Plugins/ammoJSPlugin.js +1431 -0
  122. package/Physics/v1/Plugins/ammoJSPlugin.js.map +1 -0
  123. package/Physics/v1/Plugins/cannonJSPlugin.d.ts +87 -0
  124. package/Physics/v1/Plugins/cannonJSPlugin.js +683 -0
  125. package/Physics/v1/Plugins/cannonJSPlugin.js.map +1 -0
  126. package/Physics/{Plugins → v1/Plugins}/index.d.ts +0 -0
  127. package/Physics/{Plugins → v1/Plugins}/index.js +0 -0
  128. package/Physics/v1/Plugins/index.js.map +1 -0
  129. package/Physics/v1/Plugins/oimoJSPlugin.d.ts +71 -0
  130. package/Physics/v1/Plugins/oimoJSPlugin.js +450 -0
  131. package/Physics/v1/Plugins/oimoJSPlugin.js.map +1 -0
  132. package/Physics/v1/index.d.ts +7 -0
  133. package/Physics/v1/index.js +9 -0
  134. package/Physics/v1/index.js.map +1 -0
  135. package/Physics/v1/physicsEngine.d.ts +147 -0
  136. package/Physics/v1/physicsEngine.js +237 -0
  137. package/Physics/v1/physicsEngine.js.map +1 -0
  138. package/Physics/v1/physicsEngineComponent.d.ts +45 -0
  139. package/Physics/v1/physicsEngineComponent.js +70 -0
  140. package/Physics/v1/physicsEngineComponent.js.map +1 -0
  141. package/Physics/v1/physicsHelper.d.ts +411 -0
  142. package/Physics/v1/physicsHelper.js +709 -0
  143. package/Physics/v1/physicsHelper.js.map +1 -0
  144. package/Physics/v1/physicsImpostor.d.ts +636 -0
  145. package/Physics/v1/physicsImpostor.js +1001 -0
  146. package/Physics/v1/physicsImpostor.js.map +1 -0
  147. package/Physics/v1/physicsJoint.d.ts +275 -0
  148. package/Physics/v1/physicsJoint.js +223 -0
  149. package/Physics/v1/physicsJoint.js.map +1 -0
  150. package/Physics/v2/IPhysicsEnginePlugin.d.ts +170 -0
  151. package/Physics/v2/IPhysicsEnginePlugin.js +47 -0
  152. package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -0
  153. package/Physics/v2/Plugins/index.d.ts +0 -0
  154. package/Physics/v2/Plugins/index.js +2 -0
  155. package/Physics/v2/Plugins/index.js.map +1 -0
  156. package/Physics/v2/index.d.ts +6 -0
  157. package/Physics/v2/index.js +8 -0
  158. package/Physics/v2/index.js.map +1 -0
  159. package/Physics/v2/physicsAggregate.d.ts +114 -0
  160. package/Physics/v2/physicsAggregate.js +46 -0
  161. package/Physics/v2/physicsAggregate.js.map +1 -0
  162. package/Physics/v2/physicsBody.d.ts +109 -0
  163. package/Physics/v2/physicsBody.js +158 -0
  164. package/Physics/v2/physicsBody.js.map +1 -0
  165. package/Physics/v2/physicsConstraint.d.ts +184 -0
  166. package/Physics/v2/physicsConstraint.js +257 -0
  167. package/Physics/v2/physicsConstraint.js.map +1 -0
  168. package/Physics/v2/physicsEngine.d.ts +103 -0
  169. package/Physics/v2/physicsEngine.js +146 -0
  170. package/Physics/v2/physicsEngine.js.map +1 -0
  171. package/Physics/v2/physicsEngineComponent.d.ts +31 -0
  172. package/Physics/v2/physicsEngineComponent.js +50 -0
  173. package/Physics/v2/physicsEngineComponent.js.map +1 -0
  174. package/Physics/v2/physicsMaterial.d.ts +45 -0
  175. package/Physics/v2/physicsMaterial.js +67 -0
  176. package/Physics/v2/physicsMaterial.js.map +1 -0
  177. package/Physics/v2/physicsShape.d.ts +182 -0
  178. package/Physics/v2/physicsShape.js +229 -0
  179. package/Physics/v2/physicsShape.js.map +1 -0
  180. package/PostProcesses/postProcess.d.ts +3 -1
  181. package/PostProcesses/postProcess.js +4 -1
  182. package/PostProcesses/postProcess.js.map +1 -1
  183. package/Rendering/fluidRenderer/fluidRenderer.d.ts +153 -0
  184. package/Rendering/fluidRenderer/fluidRenderer.js +410 -0
  185. package/Rendering/fluidRenderer/fluidRenderer.js.map +1 -0
  186. package/Rendering/fluidRenderer/fluidRenderingDepthTextureCopy.d.ts +13 -0
  187. package/Rendering/fluidRenderer/fluidRenderingDepthTextureCopy.js +31 -0
  188. package/Rendering/fluidRenderer/fluidRenderingDepthTextureCopy.js.map +1 -0
  189. package/Rendering/fluidRenderer/fluidRenderingObject.d.ts +81 -0
  190. package/Rendering/fluidRenderer/fluidRenderingObject.js +180 -0
  191. package/Rendering/fluidRenderer/fluidRenderingObject.js.map +1 -0
  192. package/Rendering/fluidRenderer/fluidRenderingObjectCustomParticles.d.ts +63 -0
  193. package/Rendering/fluidRenderer/fluidRenderingObjectCustomParticles.js +130 -0
  194. package/Rendering/fluidRenderer/fluidRenderingObjectCustomParticles.js.map +1 -0
  195. package/Rendering/fluidRenderer/fluidRenderingObjectParticleSystem.d.ts +64 -0
  196. package/Rendering/fluidRenderer/fluidRenderingObjectParticleSystem.js +104 -0
  197. package/Rendering/fluidRenderer/fluidRenderingObjectParticleSystem.js.map +1 -0
  198. package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.d.ts +234 -0
  199. package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js +690 -0
  200. package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js.map +1 -0
  201. package/Rendering/fluidRenderer/fluidRenderingTextures.d.ts +56 -0
  202. package/Rendering/fluidRenderer/fluidRenderingTextures.js +261 -0
  203. package/Rendering/fluidRenderer/fluidRenderingTextures.js.map +1 -0
  204. package/Rendering/fluidRenderer/index.d.ts +5 -0
  205. package/Rendering/fluidRenderer/index.js +6 -0
  206. package/Rendering/fluidRenderer/index.js.map +1 -0
  207. package/Rendering/index.d.ts +1 -0
  208. package/Rendering/index.js +2 -0
  209. package/Rendering/index.js.map +1 -1
  210. package/Shaders/copyTextureToTexture.fragment.js +4 -1
  211. package/Shaders/copyTextureToTexture.fragment.js.map +1 -1
  212. package/Shaders/fluidRenderingBilateralBlur.fragment.d.ts +5 -0
  213. package/Shaders/fluidRenderingBilateralBlur.fragment.js +9 -0
  214. package/Shaders/fluidRenderingBilateralBlur.fragment.js.map +1 -0
  215. package/Shaders/fluidRenderingParticleDepth.fragment.d.ts +5 -0
  216. package/Shaders/fluidRenderingParticleDepth.fragment.js +17 -0
  217. package/Shaders/fluidRenderingParticleDepth.fragment.js.map +1 -0
  218. package/Shaders/fluidRenderingParticleDepth.vertex.d.ts +5 -0
  219. package/Shaders/fluidRenderingParticleDepth.vertex.js +13 -0
  220. package/Shaders/fluidRenderingParticleDepth.vertex.js.map +1 -0
  221. package/Shaders/fluidRenderingParticleDiffuse.fragment.d.ts +5 -0
  222. package/Shaders/fluidRenderingParticleDiffuse.fragment.js +9 -0
  223. package/Shaders/fluidRenderingParticleDiffuse.fragment.js.map +1 -0
  224. package/Shaders/fluidRenderingParticleDiffuse.vertex.d.ts +5 -0
  225. package/Shaders/fluidRenderingParticleDiffuse.vertex.js +4 -0
  226. package/Shaders/fluidRenderingParticleDiffuse.vertex.js.map +1 -0
  227. package/Shaders/fluidRenderingParticleThickness.fragment.d.ts +5 -0
  228. package/Shaders/fluidRenderingParticleThickness.fragment.js +9 -0
  229. package/Shaders/fluidRenderingParticleThickness.fragment.js.map +1 -0
  230. package/Shaders/fluidRenderingParticleThickness.vertex.d.ts +5 -0
  231. package/Shaders/fluidRenderingParticleThickness.vertex.js +9 -0
  232. package/Shaders/fluidRenderingParticleThickness.vertex.js.map +1 -0
  233. package/Shaders/fluidRenderingRender.fragment.d.ts +5 -0
  234. package/Shaders/fluidRenderingRender.fragment.js +46 -0
  235. package/Shaders/fluidRenderingRender.fragment.js.map +1 -0
  236. package/Shaders/fluidRenderingStandardBlur.fragment.d.ts +5 -0
  237. package/Shaders/fluidRenderingStandardBlur.fragment.js +9 -0
  238. package/Shaders/fluidRenderingStandardBlur.fragment.js.map +1 -0
  239. package/XR/features/WebXRControllerPhysics.d.ts +1 -1
  240. package/XR/features/WebXRControllerPhysics.js +1 -1
  241. package/XR/features/WebXRControllerPhysics.js.map +1 -1
  242. package/XR/features/WebXRHandTracking.js +1 -1
  243. package/XR/features/WebXRHandTracking.js.map +1 -1
  244. package/package.json +1 -1
  245. package/scene.js +6 -1
  246. package/scene.js.map +1 -1
  247. package/sceneComponent.d.ts +3 -0
  248. package/sceneComponent.js +3 -0
  249. package/sceneComponent.js.map +1 -1
  250. package/Physics/Plugins/index.js.map +0 -1
@@ -0,0 +1,147 @@
1
+ import type { Nullable } from "../../types";
2
+ import { Vector3 } from "../../Maths/math.vector";
3
+ import type { IPhysicsEnginePlugin } from "./IPhysicsEnginePlugin";
4
+ import type { IPhysicsEngine } from "../IPhysicsEngine";
5
+ import type { PhysicsImpostor, IPhysicsEnabledObject } from "./physicsImpostor";
6
+ import type { PhysicsJoint } from "./physicsJoint";
7
+ import type { PhysicsRaycastResult } from "../physicsRaycastResult";
8
+ /**
9
+ * Class used to control physics engine
10
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
11
+ */
12
+ export declare class PhysicsEngine implements IPhysicsEngine {
13
+ private _physicsPlugin;
14
+ /**
15
+ * Global value used to control the smallest number supported by the simulation
16
+ */
17
+ private _impostors;
18
+ private _joints;
19
+ private _subTimeStep;
20
+ private _uniqueIdCounter;
21
+ /**
22
+ * Gets the gravity vector used by the simulation
23
+ */
24
+ gravity: Vector3;
25
+ /**
26
+ *
27
+ * @returns version
28
+ */
29
+ getPluginVersion(): number;
30
+ /**
31
+ * Factory used to create the default physics plugin.
32
+ * @returns The default physics plugin
33
+ */
34
+ static DefaultPluginFactory(): IPhysicsEnginePlugin;
35
+ /**
36
+ * Creates a new Physics Engine
37
+ * @param gravity defines the gravity vector used by the simulation
38
+ * @param _physicsPlugin defines the plugin to use (CannonJS by default)
39
+ */
40
+ constructor(gravity: Nullable<Vector3>, _physicsPlugin?: IPhysicsEnginePlugin);
41
+ /**
42
+ * Sets the gravity vector used by the simulation
43
+ * @param gravity defines the gravity vector to use
44
+ */
45
+ setGravity(gravity: Vector3): void;
46
+ /**
47
+ * Set the time step of the physics engine.
48
+ * Default is 1/60.
49
+ * To slow it down, enter 1/600 for example.
50
+ * To speed it up, 1/30
51
+ * @param newTimeStep defines the new timestep to apply to this world.
52
+ */
53
+ setTimeStep(newTimeStep?: number): void;
54
+ /**
55
+ * Get the time step of the physics engine.
56
+ * @returns the current time step
57
+ */
58
+ getTimeStep(): number;
59
+ /**
60
+ * Set the sub time step of the physics engine.
61
+ * Default is 0 meaning there is no sub steps
62
+ * To increase physics resolution precision, set a small value (like 1 ms)
63
+ * @param subTimeStep defines the new sub timestep used for physics resolution.
64
+ */
65
+ setSubTimeStep(subTimeStep?: number): void;
66
+ /**
67
+ * Get the sub time step of the physics engine.
68
+ * @returns the current sub time step
69
+ */
70
+ getSubTimeStep(): number;
71
+ /**
72
+ * Release all resources
73
+ */
74
+ dispose(): void;
75
+ /**
76
+ * Gets the name of the current physics plugin
77
+ * @returns the name of the plugin
78
+ */
79
+ getPhysicsPluginName(): string;
80
+ /**
81
+ * Adding a new impostor for the impostor tracking.
82
+ * This will be done by the impostor itself.
83
+ * @param impostor the impostor to add
84
+ */
85
+ addImpostor(impostor: PhysicsImpostor): void;
86
+ /**
87
+ * Remove an impostor from the engine.
88
+ * This impostor and its mesh will not longer be updated by the physics engine.
89
+ * @param impostor the impostor to remove
90
+ */
91
+ removeImpostor(impostor: PhysicsImpostor): void;
92
+ /**
93
+ * Add a joint to the physics engine
94
+ * @param mainImpostor defines the main impostor to which the joint is added.
95
+ * @param connectedImpostor defines the impostor that is connected to the main impostor using this joint
96
+ * @param joint defines the joint that will connect both impostors.
97
+ */
98
+ addJoint(mainImpostor: PhysicsImpostor, connectedImpostor: PhysicsImpostor, joint: PhysicsJoint): void;
99
+ /**
100
+ * Removes a joint from the simulation
101
+ * @param mainImpostor defines the impostor used with the joint
102
+ * @param connectedImpostor defines the other impostor connected to the main one by the joint
103
+ * @param joint defines the joint to remove
104
+ */
105
+ removeJoint(mainImpostor: PhysicsImpostor, connectedImpostor: PhysicsImpostor, joint: PhysicsJoint): void;
106
+ /**
107
+ * Called by the scene. No need to call it.
108
+ * @param delta defines the timespan between frames
109
+ */
110
+ _step(delta: number): void;
111
+ /**
112
+ * Gets the current plugin used to run the simulation
113
+ * @returns current plugin
114
+ */
115
+ getPhysicsPlugin(): IPhysicsEnginePlugin;
116
+ /**
117
+ * Gets the list of physic impostors
118
+ * @returns an array of PhysicsImpostor
119
+ */
120
+ getImpostors(): Array<PhysicsImpostor>;
121
+ /**
122
+ * Gets the impostor for a physics enabled object
123
+ * @param object defines the object impersonated by the impostor
124
+ * @returns the PhysicsImpostor or null if not found
125
+ */
126
+ getImpostorForPhysicsObject(object: IPhysicsEnabledObject): Nullable<PhysicsImpostor>;
127
+ /**
128
+ * Gets the impostor for a physics body object
129
+ * @param body defines physics body used by the impostor
130
+ * @returns the PhysicsImpostor or null if not found
131
+ */
132
+ getImpostorWithPhysicsBody(body: any): Nullable<PhysicsImpostor>;
133
+ /**
134
+ * Does a raycast in the physics world
135
+ * @param from when should the ray start?
136
+ * @param to when should the ray end?
137
+ * @returns PhysicsRaycastResult
138
+ */
139
+ raycast(from: Vector3, to: Vector3): PhysicsRaycastResult;
140
+ /**
141
+ * Does a raycast in the physics world
142
+ * @param from when should the ray start?
143
+ * @param to when should the ray end?
144
+ * @param result resulting PhysicsRaycastResult
145
+ */
146
+ raycastToRef(from: Vector3, to: Vector3, result: PhysicsRaycastResult): void;
147
+ }
@@ -0,0 +1,237 @@
1
+ import { Vector3 } from "../../Maths/math.vector.js";
2
+ import { _WarnImport } from "../../Misc/devTools.js";
3
+ /**
4
+ * Class used to control physics engine
5
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
6
+ */
7
+ export class PhysicsEngine {
8
+ /**
9
+ * Creates a new Physics Engine
10
+ * @param gravity defines the gravity vector used by the simulation
11
+ * @param _physicsPlugin defines the plugin to use (CannonJS by default)
12
+ */
13
+ constructor(gravity, _physicsPlugin = PhysicsEngine.DefaultPluginFactory()) {
14
+ this._physicsPlugin = _physicsPlugin;
15
+ /**
16
+ * Global value used to control the smallest number supported by the simulation
17
+ */
18
+ this._impostors = [];
19
+ this._joints = [];
20
+ this._subTimeStep = 0;
21
+ this._uniqueIdCounter = 0;
22
+ if (!this._physicsPlugin.isSupported()) {
23
+ throw new Error("Physics Engine " + this._physicsPlugin.name + " cannot be found. " + "Please make sure it is included.");
24
+ }
25
+ gravity = gravity || new Vector3(0, -9.807, 0);
26
+ this.setGravity(gravity);
27
+ this.setTimeStep();
28
+ }
29
+ /**
30
+ *
31
+ * @returns version
32
+ */
33
+ getPluginVersion() {
34
+ return this._physicsPlugin.getPluginVersion();
35
+ }
36
+ /**
37
+ * Factory used to create the default physics plugin.
38
+ * @returns The default physics plugin
39
+ */
40
+ static DefaultPluginFactory() {
41
+ throw _WarnImport("CannonJSPlugin");
42
+ }
43
+ /**
44
+ * Sets the gravity vector used by the simulation
45
+ * @param gravity defines the gravity vector to use
46
+ */
47
+ setGravity(gravity) {
48
+ this.gravity = gravity;
49
+ this._physicsPlugin.setGravity(this.gravity);
50
+ }
51
+ /**
52
+ * Set the time step of the physics engine.
53
+ * Default is 1/60.
54
+ * To slow it down, enter 1/600 for example.
55
+ * To speed it up, 1/30
56
+ * @param newTimeStep defines the new timestep to apply to this world.
57
+ */
58
+ setTimeStep(newTimeStep = 1 / 60) {
59
+ this._physicsPlugin.setTimeStep(newTimeStep);
60
+ }
61
+ /**
62
+ * Get the time step of the physics engine.
63
+ * @returns the current time step
64
+ */
65
+ getTimeStep() {
66
+ return this._physicsPlugin.getTimeStep();
67
+ }
68
+ /**
69
+ * Set the sub time step of the physics engine.
70
+ * Default is 0 meaning there is no sub steps
71
+ * To increase physics resolution precision, set a small value (like 1 ms)
72
+ * @param subTimeStep defines the new sub timestep used for physics resolution.
73
+ */
74
+ setSubTimeStep(subTimeStep = 0) {
75
+ this._subTimeStep = subTimeStep;
76
+ }
77
+ /**
78
+ * Get the sub time step of the physics engine.
79
+ * @returns the current sub time step
80
+ */
81
+ getSubTimeStep() {
82
+ return this._subTimeStep;
83
+ }
84
+ /**
85
+ * Release all resources
86
+ */
87
+ dispose() {
88
+ this._impostors.forEach(function (impostor) {
89
+ impostor.dispose();
90
+ });
91
+ this._physicsPlugin.dispose();
92
+ }
93
+ /**
94
+ * Gets the name of the current physics plugin
95
+ * @returns the name of the plugin
96
+ */
97
+ getPhysicsPluginName() {
98
+ return this._physicsPlugin.name;
99
+ }
100
+ /**
101
+ * Adding a new impostor for the impostor tracking.
102
+ * This will be done by the impostor itself.
103
+ * @param impostor the impostor to add
104
+ */
105
+ addImpostor(impostor) {
106
+ this._impostors.push(impostor);
107
+ impostor.uniqueId = this._uniqueIdCounter++;
108
+ //if no parent, generate the body
109
+ if (!impostor.parent) {
110
+ this._physicsPlugin.generatePhysicsBody(impostor);
111
+ }
112
+ }
113
+ /**
114
+ * Remove an impostor from the engine.
115
+ * This impostor and its mesh will not longer be updated by the physics engine.
116
+ * @param impostor the impostor to remove
117
+ */
118
+ removeImpostor(impostor) {
119
+ const index = this._impostors.indexOf(impostor);
120
+ if (index > -1) {
121
+ const removed = this._impostors.splice(index, 1);
122
+ //Is it needed?
123
+ if (removed.length) {
124
+ this.getPhysicsPlugin().removePhysicsBody(impostor);
125
+ }
126
+ }
127
+ }
128
+ /**
129
+ * Add a joint to the physics engine
130
+ * @param mainImpostor defines the main impostor to which the joint is added.
131
+ * @param connectedImpostor defines the impostor that is connected to the main impostor using this joint
132
+ * @param joint defines the joint that will connect both impostors.
133
+ */
134
+ addJoint(mainImpostor, connectedImpostor, joint) {
135
+ const impostorJoint = {
136
+ mainImpostor: mainImpostor,
137
+ connectedImpostor: connectedImpostor,
138
+ joint: joint,
139
+ };
140
+ joint.physicsPlugin = this._physicsPlugin;
141
+ this._joints.push(impostorJoint);
142
+ this._physicsPlugin.generateJoint(impostorJoint);
143
+ }
144
+ /**
145
+ * Removes a joint from the simulation
146
+ * @param mainImpostor defines the impostor used with the joint
147
+ * @param connectedImpostor defines the other impostor connected to the main one by the joint
148
+ * @param joint defines the joint to remove
149
+ */
150
+ removeJoint(mainImpostor, connectedImpostor, joint) {
151
+ const matchingJoints = this._joints.filter(function (impostorJoint) {
152
+ return impostorJoint.connectedImpostor === connectedImpostor && impostorJoint.joint === joint && impostorJoint.mainImpostor === mainImpostor;
153
+ });
154
+ if (matchingJoints.length) {
155
+ this._physicsPlugin.removeJoint(matchingJoints[0]);
156
+ //TODO remove it from the list as well
157
+ }
158
+ }
159
+ /**
160
+ * Called by the scene. No need to call it.
161
+ * @param delta defines the timespan between frames
162
+ */
163
+ _step(delta) {
164
+ //check if any mesh has no body / requires an update
165
+ this._impostors.forEach((impostor) => {
166
+ if (impostor.isBodyInitRequired()) {
167
+ this._physicsPlugin.generatePhysicsBody(impostor);
168
+ }
169
+ });
170
+ if (delta > 0.1) {
171
+ delta = 0.1;
172
+ }
173
+ else if (delta <= 0) {
174
+ delta = 1.0 / 60.0;
175
+ }
176
+ this._physicsPlugin.executeStep(delta, this._impostors);
177
+ }
178
+ /**
179
+ * Gets the current plugin used to run the simulation
180
+ * @returns current plugin
181
+ */
182
+ getPhysicsPlugin() {
183
+ return this._physicsPlugin;
184
+ }
185
+ /**
186
+ * Gets the list of physic impostors
187
+ * @returns an array of PhysicsImpostor
188
+ */
189
+ getImpostors() {
190
+ return this._impostors;
191
+ }
192
+ /**
193
+ * Gets the impostor for a physics enabled object
194
+ * @param object defines the object impersonated by the impostor
195
+ * @returns the PhysicsImpostor or null if not found
196
+ */
197
+ getImpostorForPhysicsObject(object) {
198
+ for (let i = 0; i < this._impostors.length; ++i) {
199
+ if (this._impostors[i].object === object) {
200
+ return this._impostors[i];
201
+ }
202
+ }
203
+ return null;
204
+ }
205
+ /**
206
+ * Gets the impostor for a physics body object
207
+ * @param body defines physics body used by the impostor
208
+ * @returns the PhysicsImpostor or null if not found
209
+ */
210
+ getImpostorWithPhysicsBody(body) {
211
+ for (let i = 0; i < this._impostors.length; ++i) {
212
+ if (this._impostors[i].physicsBody === body) {
213
+ return this._impostors[i];
214
+ }
215
+ }
216
+ return null;
217
+ }
218
+ /**
219
+ * Does a raycast in the physics world
220
+ * @param from when should the ray start?
221
+ * @param to when should the ray end?
222
+ * @returns PhysicsRaycastResult
223
+ */
224
+ raycast(from, to) {
225
+ return this._physicsPlugin.raycast(from, to);
226
+ }
227
+ /**
228
+ * Does a raycast in the physics world
229
+ * @param from when should the ray start?
230
+ * @param to when should the ray end?
231
+ * @param result resulting PhysicsRaycastResult
232
+ */
233
+ raycastToRef(from, to, result) {
234
+ return this._physicsPlugin.raycastToRef(from, to, result);
235
+ }
236
+ }
237
+ //# sourceMappingURL=physicsEngine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"physicsEngine.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v1/physicsEngine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAMlD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD;;;GAGG;AACH,MAAM,OAAO,aAAa;IA6BtB;;;;OAIG;IACH,YAAY,OAA0B,EAAU,iBAAuC,aAAa,CAAC,oBAAoB,EAAE;QAA3E,mBAAc,GAAd,cAAc,CAA6D;QAjC3H;;WAEG;QACK,eAAU,GAA2B,EAAE,CAAC;QACxC,YAAO,GAAgC,EAAE,CAAC;QAC1C,iBAAY,GAAW,CAAC,CAAC;QACzB,qBAAgB,GAAG,CAAC,CAAC;QA4BzB,IAAI,CAAC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E,CAAC,EAAE;YAC7C,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,EAAE;gBACtC,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;aAC7B;SACJ;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACI,0BAA0B,CAAC,IAAS;QACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;YAC7C,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,WAAW,KAAK,IAAI,EAAE;gBACzC,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;aAC7B;SACJ;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACI,OAAO,CAAC,IAAa,EAAE,EAAW;QACrC,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACjD,CAAC;IAED;;;;;OAKG;IACI,YAAY,CAAC,IAAa,EAAE,EAAW,EAAE,MAA4B;QACxE,OAAO,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../../types\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { PhysicsImpostorJoint, IPhysicsEnginePlugin } from \"./IPhysicsEnginePlugin\";\r\nimport type { IPhysicsEngine } from \"../IPhysicsEngine\";\r\nimport type { PhysicsImpostor, IPhysicsEnabledObject } from \"./physicsImpostor\";\r\nimport type { PhysicsJoint } from \"./physicsJoint\";\r\nimport type { PhysicsRaycastResult } from \"../physicsRaycastResult\";\r\nimport { _WarnImport } from \"../../Misc/devTools\";\r\n\r\n/**\r\n * Class used to control physics engine\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine\r\n */\r\nexport class PhysicsEngine implements IPhysicsEngine {\r\n /**\r\n * Global value used to control the smallest number supported by the simulation\r\n */\r\n private _impostors: Array<PhysicsImpostor> = [];\r\n private _joints: Array<PhysicsImpostorJoint> = [];\r\n private _subTimeStep: number = 0;\r\n private _uniqueIdCounter = 0;\r\n\r\n /**\r\n * Gets the gravity vector used by the simulation\r\n */\r\n public gravity: Vector3;\r\n\r\n /**\r\n *\r\n * @returns version\r\n */\r\n public getPluginVersion(): number {\r\n return this._physicsPlugin.getPluginVersion();\r\n }\r\n /**\r\n * Factory used to create the default physics plugin.\r\n * @returns The default physics plugin\r\n */\r\n public static DefaultPluginFactory(): IPhysicsEnginePlugin {\r\n throw _WarnImport(\"CannonJSPlugin\");\r\n }\r\n\r\n /**\r\n * Creates a new Physics Engine\r\n * @param gravity defines the gravity vector used by the simulation\r\n * @param _physicsPlugin defines the plugin to use (CannonJS by default)\r\n */\r\n constructor(gravity: Nullable<Vector3>, private _physicsPlugin: IPhysicsEnginePlugin = PhysicsEngine.DefaultPluginFactory()) {\r\n if (!this._physicsPlugin.isSupported()) {\r\n throw new Error(\"Physics Engine \" + this._physicsPlugin.name + \" cannot be found. \" + \"Please make sure it is included.\");\r\n }\r\n gravity = gravity || new Vector3(0, -9.807, 0);\r\n this.setGravity(gravity);\r\n this.setTimeStep();\r\n }\r\n\r\n /**\r\n * Sets the gravity vector used by the simulation\r\n * @param gravity defines the gravity vector to use\r\n */\r\n public setGravity(gravity: Vector3): void {\r\n this.gravity = gravity;\r\n this._physicsPlugin.setGravity(this.gravity);\r\n }\r\n\r\n /**\r\n * Set the time step of the physics engine.\r\n * Default is 1/60.\r\n * To slow it down, enter 1/600 for example.\r\n * To speed it up, 1/30\r\n * @param newTimeStep defines the new timestep to apply to this world.\r\n */\r\n public setTimeStep(newTimeStep: number = 1 / 60) {\r\n this._physicsPlugin.setTimeStep(newTimeStep);\r\n }\r\n\r\n /**\r\n * Get the time step of the physics engine.\r\n * @returns the current time step\r\n */\r\n public getTimeStep(): number {\r\n return this._physicsPlugin.getTimeStep();\r\n }\r\n\r\n /**\r\n * Set the sub time step of the physics engine.\r\n * Default is 0 meaning there is no sub steps\r\n * To increase physics resolution precision, set a small value (like 1 ms)\r\n * @param subTimeStep defines the new sub timestep used for physics resolution.\r\n */\r\n public setSubTimeStep(subTimeStep: number = 0) {\r\n this._subTimeStep = subTimeStep;\r\n }\r\n\r\n /**\r\n * Get the sub time step of the physics engine.\r\n * @returns the current sub time step\r\n */\r\n public getSubTimeStep() {\r\n return this._subTimeStep;\r\n }\r\n\r\n /**\r\n * Release all resources\r\n */\r\n public dispose(): void {\r\n this._impostors.forEach(function (impostor) {\r\n impostor.dispose();\r\n });\r\n this._physicsPlugin.dispose();\r\n }\r\n\r\n /**\r\n * Gets the name of the current physics plugin\r\n * @returns the name of the plugin\r\n */\r\n public getPhysicsPluginName(): string {\r\n return this._physicsPlugin.name;\r\n }\r\n\r\n /**\r\n * Adding a new impostor for the impostor tracking.\r\n * This will be done by the impostor itself.\r\n * @param impostor the impostor to add\r\n */\r\n public addImpostor(impostor: PhysicsImpostor) {\r\n this._impostors.push(impostor);\r\n impostor.uniqueId = this._uniqueIdCounter++;\r\n //if no parent, generate the body\r\n if (!impostor.parent) {\r\n this._physicsPlugin.generatePhysicsBody(impostor);\r\n }\r\n }\r\n\r\n /**\r\n * Remove an impostor from the engine.\r\n * This impostor and its mesh will not longer be updated by the physics engine.\r\n * @param impostor the impostor to remove\r\n */\r\n public removeImpostor(impostor: PhysicsImpostor) {\r\n const index = this._impostors.indexOf(impostor);\r\n if (index > -1) {\r\n const removed = this._impostors.splice(index, 1);\r\n //Is it needed?\r\n if (removed.length) {\r\n this.getPhysicsPlugin().removePhysicsBody(impostor);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Add a joint to the physics engine\r\n * @param mainImpostor defines the main impostor to which the joint is added.\r\n * @param connectedImpostor defines the impostor that is connected to the main impostor using this joint\r\n * @param joint defines the joint that will connect both impostors.\r\n */\r\n public addJoint(mainImpostor: PhysicsImpostor, connectedImpostor: PhysicsImpostor, joint: PhysicsJoint) {\r\n const impostorJoint = {\r\n mainImpostor: mainImpostor,\r\n connectedImpostor: connectedImpostor,\r\n joint: joint,\r\n };\r\n joint.physicsPlugin = this._physicsPlugin;\r\n this._joints.push(impostorJoint);\r\n this._physicsPlugin.generateJoint(impostorJoint);\r\n }\r\n\r\n /**\r\n * Removes a joint from the simulation\r\n * @param mainImpostor defines the impostor used with the joint\r\n * @param connectedImpostor defines the other impostor connected to the main one by the joint\r\n * @param joint defines the joint to remove\r\n */\r\n public removeJoint(mainImpostor: PhysicsImpostor, connectedImpostor: PhysicsImpostor, joint: PhysicsJoint) {\r\n const matchingJoints = this._joints.filter(function (impostorJoint) {\r\n return impostorJoint.connectedImpostor === connectedImpostor && impostorJoint.joint === joint && impostorJoint.mainImpostor === mainImpostor;\r\n });\r\n if (matchingJoints.length) {\r\n this._physicsPlugin.removeJoint(matchingJoints[0]);\r\n //TODO remove it from the list as well\r\n }\r\n }\r\n\r\n /**\r\n * Called by the scene. No need to call it.\r\n * @param delta defines the timespan between frames\r\n */\r\n public _step(delta: number) {\r\n //check if any mesh has no body / requires an update\r\n this._impostors.forEach((impostor) => {\r\n if (impostor.isBodyInitRequired()) {\r\n this._physicsPlugin.generatePhysicsBody(impostor);\r\n }\r\n });\r\n\r\n if (delta > 0.1) {\r\n delta = 0.1;\r\n } else if (delta <= 0) {\r\n delta = 1.0 / 60.0;\r\n }\r\n\r\n this._physicsPlugin.executeStep(delta, this._impostors);\r\n }\r\n\r\n /**\r\n * Gets the current plugin used to run the simulation\r\n * @returns current plugin\r\n */\r\n public getPhysicsPlugin(): IPhysicsEnginePlugin {\r\n return this._physicsPlugin;\r\n }\r\n\r\n /**\r\n * Gets the list of physic impostors\r\n * @returns an array of PhysicsImpostor\r\n */\r\n public getImpostors(): Array<PhysicsImpostor> {\r\n return this._impostors;\r\n }\r\n\r\n /**\r\n * Gets the impostor for a physics enabled object\r\n * @param object defines the object impersonated by the impostor\r\n * @returns the PhysicsImpostor or null if not found\r\n */\r\n public getImpostorForPhysicsObject(object: IPhysicsEnabledObject): Nullable<PhysicsImpostor> {\r\n for (let i = 0; i < this._impostors.length; ++i) {\r\n if (this._impostors[i].object === object) {\r\n return this._impostors[i];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Gets the impostor for a physics body object\r\n * @param body defines physics body used by the impostor\r\n * @returns the PhysicsImpostor or null if not found\r\n */\r\n public getImpostorWithPhysicsBody(body: any): Nullable<PhysicsImpostor> {\r\n for (let i = 0; i < this._impostors.length; ++i) {\r\n if (this._impostors[i].physicsBody === body) {\r\n return this._impostors[i];\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Does a raycast in the physics world\r\n * @param from when should the ray start?\r\n * @param to when should the ray end?\r\n * @returns PhysicsRaycastResult\r\n */\r\n public raycast(from: Vector3, to: Vector3): PhysicsRaycastResult {\r\n return this._physicsPlugin.raycast(from, to);\r\n }\r\n\r\n /**\r\n * Does a raycast in the physics world\r\n * @param from when should the ray start?\r\n * @param to when should the ray end?\r\n * @param result resulting PhysicsRaycastResult\r\n */\r\n public raycastToRef(from: Vector3, to: Vector3, result: PhysicsRaycastResult) {\r\n return this._physicsPlugin.raycastToRef(from, to, result);\r\n }\r\n}\r\n"]}
@@ -0,0 +1,45 @@
1
+ import type { Nullable } from "../../types";
2
+ import type { Observer } from "../../Misc/observable";
3
+ import type { Vector3 } from "../../Maths/math.vector";
4
+ import type { Mesh } from "../../Meshes/mesh";
5
+ import type { Node } from "../../node";
6
+ import type { PhysicsImpostor } from "./physicsImpostor";
7
+ declare module "../../Meshes/abstractMesh" {
8
+ /**
9
+ *
10
+ */
11
+ interface AbstractMesh {
12
+ /** @internal */
13
+ _physicsImpostor: Nullable<PhysicsImpostor>;
14
+ /**
15
+ * Gets or sets impostor used for physic simulation
16
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/physics
17
+ */
18
+ physicsImpostor: Nullable<PhysicsImpostor>;
19
+ /**
20
+ * Gets the current physics impostor
21
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/physics
22
+ * @returns a physics impostor or null
23
+ */
24
+ getPhysicsImpostor(): Nullable<PhysicsImpostor>;
25
+ /** Apply a physic impulse to the mesh
26
+ * @param force defines the force to apply
27
+ * @param contactPoint defines where to apply the force
28
+ * @returns the current mesh
29
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
30
+ */
31
+ applyImpulse(force: Vector3, contactPoint: Vector3): AbstractMesh;
32
+ /**
33
+ * Creates a physic joint between two meshes
34
+ * @param otherMesh defines the other mesh to use
35
+ * @param pivot1 defines the pivot to use on this mesh
36
+ * @param pivot2 defines the pivot to use on the other mesh
37
+ * @param options defines additional options (can be plugin dependent)
38
+ * @returns the current mesh
39
+ * @see https://www.babylonjs-playground.com/#0BS5U0#0
40
+ */
41
+ setPhysicsLinkWith(otherMesh: Mesh, pivot1: Vector3, pivot2: Vector3, options?: any): AbstractMesh;
42
+ /** @internal */
43
+ _disposePhysicsObserver: Nullable<Observer<Node>>;
44
+ }
45
+ }
@@ -0,0 +1,70 @@
1
+ import { AbstractMesh } from "../../Meshes/abstractMesh.js";
2
+ import { PhysicsJoint } from "./physicsJoint.js";
3
+ Object.defineProperty(AbstractMesh.prototype, "physicsImpostor", {
4
+ get: function () {
5
+ return this._physicsImpostor;
6
+ },
7
+ set: function (value) {
8
+ if (this._physicsImpostor === value) {
9
+ return;
10
+ }
11
+ if (this._disposePhysicsObserver) {
12
+ this.onDisposeObservable.remove(this._disposePhysicsObserver);
13
+ }
14
+ this._physicsImpostor = value;
15
+ if (value) {
16
+ this._disposePhysicsObserver = this.onDisposeObservable.add(() => {
17
+ // Physics
18
+ if (this.physicsImpostor) {
19
+ this.physicsImpostor.dispose( /*!doNotRecurse*/);
20
+ this.physicsImpostor = null;
21
+ }
22
+ });
23
+ }
24
+ },
25
+ enumerable: true,
26
+ configurable: true,
27
+ });
28
+ /**
29
+ * Gets the current physics impostor
30
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/physics
31
+ * @returns a physics impostor or null
32
+ */
33
+ AbstractMesh.prototype.getPhysicsImpostor = function () {
34
+ return this.physicsImpostor;
35
+ };
36
+ /**
37
+ * Apply a physic impulse to the mesh
38
+ * @param force defines the force to apply
39
+ * @param contactPoint defines where to apply the force
40
+ * @returns the current mesh
41
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
42
+ */
43
+ AbstractMesh.prototype.applyImpulse = function (force, contactPoint) {
44
+ if (!this.physicsImpostor) {
45
+ return this;
46
+ }
47
+ this.physicsImpostor.applyImpulse(force, contactPoint);
48
+ return this;
49
+ };
50
+ /**
51
+ * Creates a physic joint between two meshes
52
+ * @param otherMesh defines the other mesh to use
53
+ * @param pivot1 defines the pivot to use on this mesh
54
+ * @param pivot2 defines the pivot to use on the other mesh
55
+ * @param options defines additional options (can be plugin dependent)
56
+ * @returns the current mesh
57
+ * @see https://www.babylonjs-playground.com/#0BS5U0#0
58
+ */
59
+ AbstractMesh.prototype.setPhysicsLinkWith = function (otherMesh, pivot1, pivot2, options) {
60
+ if (!this.physicsImpostor || !otherMesh.physicsImpostor) {
61
+ return this;
62
+ }
63
+ this.physicsImpostor.createJoint(otherMesh.physicsImpostor, PhysicsJoint.HingeJoint, {
64
+ mainPivot: pivot1,
65
+ connectedPivot: pivot2,
66
+ nativeParams: options,
67
+ });
68
+ return this;
69
+ };
70
+ //# sourceMappingURL=physicsEngineComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"physicsEngineComponent.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v1/physicsEngineComponent.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AA+C9C,MAAM,CAA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EAAE,MAAe,EAAE,OAAa;IAClH,IAAI,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE;QACrD,OAAO,IAAI,CAAC;KACf;IACD,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,SAAS,CAAC,eAAe,EAAE,YAAY,CAAC,UAAU,EAAE;QACjF,SAAS,EAAE,MAAM;QACjB,cAAc,EAAE,MAAM;QACtB,YAAY,EAAE,OAAO;KACxB,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"../../types\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Node } from \"../../node\";\r\nimport type { PhysicsImpostor } from \"./physicsImpostor\";\r\nimport { PhysicsJoint } from \"./physicsJoint\";\r\n\r\ndeclare module \"../../Meshes/abstractMesh\" {\r\n /**\r\n *\r\n */\r\n export interface AbstractMesh {\r\n /** @internal */\r\n _physicsImpostor: Nullable<PhysicsImpostor>;\r\n\r\n /**\r\n * Gets or sets impostor used for physic simulation\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/physics\r\n */\r\n physicsImpostor: Nullable<PhysicsImpostor>;\r\n\r\n /**\r\n * Gets the current physics impostor\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/physics\r\n * @returns a physics impostor or null\r\n */\r\n getPhysicsImpostor(): Nullable<PhysicsImpostor>;\r\n\r\n /** Apply a physic impulse to the mesh\r\n * @param force defines the force to apply\r\n * @param contactPoint defines where to apply the force\r\n * @returns the current mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine\r\n */\r\n applyImpulse(force: Vector3, contactPoint: Vector3): AbstractMesh;\r\n\r\n /**\r\n * Creates a physic joint between two meshes\r\n * @param otherMesh defines the other mesh to use\r\n * @param pivot1 defines the pivot to use on this mesh\r\n * @param pivot2 defines the pivot to use on the other mesh\r\n * @param options defines additional options (can be plugin dependent)\r\n * @returns the current mesh\r\n * @see https://www.babylonjs-playground.com/#0BS5U0#0\r\n */\r\n setPhysicsLinkWith(otherMesh: Mesh, pivot1: Vector3, pivot2: Vector3, options?: any): AbstractMesh;\r\n\r\n /** @internal */\r\n _disposePhysicsObserver: Nullable<Observer<Node>>;\r\n }\r\n}\r\n\r\nObject.defineProperty(AbstractMesh.prototype, \"physicsImpostor\", {\r\n get: function (this: AbstractMesh) {\r\n return this._physicsImpostor;\r\n },\r\n set: function (this: AbstractMesh, value: Nullable<PhysicsImpostor>) {\r\n if (this._physicsImpostor === value) {\r\n return;\r\n }\r\n if (this._disposePhysicsObserver) {\r\n this.onDisposeObservable.remove(this._disposePhysicsObserver);\r\n }\r\n\r\n this._physicsImpostor = value;\r\n\r\n if (value) {\r\n this._disposePhysicsObserver = this.onDisposeObservable.add(() => {\r\n // Physics\r\n if (this.physicsImpostor) {\r\n this.physicsImpostor.dispose(/*!doNotRecurse*/);\r\n this.physicsImpostor = null;\r\n }\r\n });\r\n }\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n\r\n/**\r\n * Gets the current physics impostor\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/physics\r\n * @returns a physics impostor or null\r\n */\r\nAbstractMesh.prototype.getPhysicsImpostor = function (): Nullable<PhysicsImpostor> {\r\n return this.physicsImpostor;\r\n};\r\n\r\n/**\r\n * Apply a physic impulse to the mesh\r\n * @param force defines the force to apply\r\n * @param contactPoint defines where to apply the force\r\n * @returns the current mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine\r\n */\r\nAbstractMesh.prototype.applyImpulse = function (force: Vector3, contactPoint: Vector3): AbstractMesh {\r\n if (!this.physicsImpostor) {\r\n return this;\r\n }\r\n this.physicsImpostor.applyImpulse(force, contactPoint);\r\n return this;\r\n};\r\n\r\n/**\r\n * Creates a physic joint between two meshes\r\n * @param otherMesh defines the other mesh to use\r\n * @param pivot1 defines the pivot to use on this mesh\r\n * @param pivot2 defines the pivot to use on the other mesh\r\n * @param options defines additional options (can be plugin dependent)\r\n * @returns the current mesh\r\n * @see https://www.babylonjs-playground.com/#0BS5U0#0\r\n */\r\nAbstractMesh.prototype.setPhysicsLinkWith = function (otherMesh: Mesh, pivot1: Vector3, pivot2: Vector3, options?: any): AbstractMesh {\r\n if (!this.physicsImpostor || !otherMesh.physicsImpostor) {\r\n return this;\r\n }\r\n this.physicsImpostor.createJoint(otherMesh.physicsImpostor, PhysicsJoint.HingeJoint, {\r\n mainPivot: pivot1,\r\n connectedPivot: pivot2,\r\n nativeParams: options,\r\n });\r\n return this;\r\n};\r\n"]}