@babylonjs/core 5.45.0 → 5.45.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 (55) hide show
  1. package/Engines/thinEngine.js +2 -2
  2. package/Engines/thinEngine.js.map +1 -1
  3. package/Inputs/scene.inputManager.js +12 -1
  4. package/Inputs/scene.inputManager.js.map +1 -1
  5. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.d.ts +7 -0
  6. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js +30 -1
  7. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
  8. package/Materials/Textures/texture.d.ts +2 -2
  9. package/Materials/Textures/texture.js +2 -2
  10. package/Materials/Textures/texture.js.map +1 -1
  11. package/Materials/Textures/videoTexture.d.ts +1 -0
  12. package/Materials/Textures/videoTexture.js +19 -8
  13. package/Materials/Textures/videoTexture.js.map +1 -1
  14. package/Materials/clipPlaneMaterialHelper.js +22 -19
  15. package/Materials/clipPlaneMaterialHelper.js.map +1 -1
  16. package/Misc/khronosTextureContainer2.js +3 -5
  17. package/Misc/khronosTextureContainer2.js.map +1 -1
  18. package/Physics/index.d.ts +1 -0
  19. package/Physics/index.js +1 -0
  20. package/Physics/index.js.map +1 -1
  21. package/Physics/physicsHelper.d.ts +452 -1
  22. package/Physics/physicsHelper.js +877 -2
  23. package/Physics/physicsHelper.js.map +1 -1
  24. package/Physics/v1/index.d.ts +0 -1
  25. package/Physics/v1/index.js +0 -1
  26. package/Physics/v1/index.js.map +1 -1
  27. package/Physics/v2/IPhysicsEnginePlugin.d.ts +8 -1
  28. package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
  29. package/Physics/v2/index.d.ts +1 -0
  30. package/Physics/v2/index.js +1 -0
  31. package/Physics/v2/index.js.map +1 -1
  32. package/Physics/v2/physicsAggregate.d.ts +39 -19
  33. package/Physics/v2/physicsAggregate.js +61 -5
  34. package/Physics/v2/physicsAggregate.js.map +1 -1
  35. package/Physics/v2/physicsBody.d.ts +37 -1
  36. package/Physics/v2/physicsBody.js +71 -1
  37. package/Physics/v2/physicsBody.js.map +1 -1
  38. package/Physics/v2/physicsEngine.d.ts +7 -2
  39. package/Physics/v2/physicsEngine.js +9 -2
  40. package/Physics/v2/physicsEngine.js.map +1 -1
  41. package/Physics/v2/physicsShape.d.ts +30 -44
  42. package/Physics/v2/physicsShape.js +30 -44
  43. package/Physics/v2/physicsShape.js.map +1 -1
  44. package/Shaders/ShadersInclude/bumpFragment.js +1 -0
  45. package/Shaders/ShadersInclude/bumpFragment.js.map +1 -1
  46. package/Shaders/ShadersInclude/bumpFragmentMainFunctions.js +4 -1
  47. package/Shaders/ShadersInclude/bumpFragmentMainFunctions.js.map +1 -1
  48. package/Shaders/sprites.fragment.js +1 -1
  49. package/Shaders/sprites.fragment.js.map +1 -1
  50. package/assetContainer.js +1 -1
  51. package/assetContainer.js.map +1 -1
  52. package/package.json +1 -1
  53. package/Physics/v1/physicsHelper.d.ts +0 -411
  54. package/Physics/v1/physicsHelper.js +0 -709
  55. package/Physics/v1/physicsHelper.js.map +0 -1
@@ -1,8 +1,9 @@
1
1
  import type { MassProperties } from "./IPhysicsEnginePlugin";
2
2
  import type { PhysicsShape } from "./physicsShape";
3
- import type { Vector3 } from "../../Maths/math.vector";
3
+ import { Vector3 } from "../../Maths/math.vector";
4
4
  import type { Scene } from "../../scene";
5
5
  import type { TransformNode } from "../../Meshes";
6
+ import type { Nullable } from "../../types.js";
6
7
  /**
7
8
  * PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows
8
9
  * the user to set the mass and velocity of the body, which can then be used to calculate the
@@ -21,6 +22,10 @@ export declare class PhysicsBody {
21
22
  * The V2 plugin used to create and manage this Physics Body
22
23
  */
23
24
  private _physicsPlugin;
25
+ /**
26
+ * The engine used to create and manage this Physics Body
27
+ */
28
+ private _physicsEngine;
24
29
  /**
25
30
  * The transform node associated with this Physics Body
26
31
  */
@@ -30,6 +35,8 @@ export declare class PhysicsBody {
30
35
  * True by default for maximum performance.
31
36
  */
32
37
  disablePreStep: boolean;
38
+ private static _DEFAULT_OBJECT_SIZE;
39
+ private static _IDENTITY_QUATERNION;
33
40
  /**
34
41
  * Constructs a new physics body for the given node.
35
42
  * @param transformNode - The Transform Node to construct the physics body for.
@@ -200,6 +207,16 @@ export declare class PhysicsBody {
200
207
  * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.
201
208
  */
202
209
  applyImpulse(location: Vector3, impulse: Vector3): void;
210
+ /**
211
+ * Applies a force to the physics object.
212
+ *
213
+ * @param location The location of the force.
214
+ * @param force The force vector.
215
+ *
216
+ * This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,
217
+ * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.
218
+ */
219
+ applyForce(location: Vector3, force: Vector3): void;
203
220
  /**
204
221
  * Retrieves the geometry of the body from the physics plugin.
205
222
  *
@@ -208,6 +225,25 @@ export declare class PhysicsBody {
208
225
  * This method is useful for retrieving the geometry of the body from the physics plugin, which can be used for various physics calculations.
209
226
  */
210
227
  getGeometry(): {};
228
+ /**
229
+ * Register a collision callback that is called when the body collides
230
+ * Filtering by body is inefficient. It's more preferable to register a collision callback for the entire world
231
+ * and do the filtering on the user side.
232
+ */
233
+ registerOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
234
+ /**
235
+ * Unregister a collision callback that is called when the body collides
236
+ */
237
+ unregisterOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
238
+ /**
239
+ * Gets the object extents
240
+ * @returns the object extents
241
+ */
242
+ getObjectExtents(): Vector3;
243
+ /**
244
+ * return geometric center of the associated mesh
245
+ */
246
+ getObjectCenter(): Vector3;
211
247
  /**
212
248
  * Disposes the body from the physics engine.
213
249
  *
@@ -1,4 +1,4 @@
1
- import { Quaternion } from "../../Maths/math.vector.js";
1
+ import { Vector3, Quaternion } from "../../Maths/math.vector.js";
2
2
  /**
3
3
  * PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows
4
4
  * the user to set the mass and velocity of the body, which can then be used to calculate the
@@ -35,6 +35,7 @@ export class PhysicsBody {
35
35
  if (!physicsEngine) {
36
36
  throw new Error("No Physics Engine available.");
37
37
  }
38
+ this._physicsEngine = physicsEngine;
38
39
  if (physicsEngine.getPluginVersion() != 2) {
39
40
  throw new Error("Plugin version is incorrect. Expected version 2.");
40
41
  }
@@ -253,6 +254,18 @@ export class PhysicsBody {
253
254
  applyImpulse(location, impulse) {
254
255
  this._physicsPlugin.applyImpulse(this, location, impulse);
255
256
  }
257
+ /**
258
+ * Applies a force to the physics object.
259
+ *
260
+ * @param location The location of the force.
261
+ * @param force The force vector.
262
+ *
263
+ * This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,
264
+ * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.
265
+ */
266
+ applyForce(location, force) {
267
+ this._physicsPlugin.applyForce(this, location, force);
268
+ }
256
269
  /**
257
270
  * Retrieves the geometry of the body from the physics plugin.
258
271
  *
@@ -263,13 +276,70 @@ export class PhysicsBody {
263
276
  getGeometry() {
264
277
  return this._physicsPlugin.getBodyGeometry(this);
265
278
  }
279
+ /**
280
+ * Register a collision callback that is called when the body collides
281
+ * Filtering by body is inefficient. It's more preferable to register a collision callback for the entire world
282
+ * and do the filtering on the user side.
283
+ */
284
+ registerOnCollide(func) {
285
+ return this._physicsPlugin.registerOnBodyCollide(this, func);
286
+ }
287
+ /**
288
+ * Unregister a collision callback that is called when the body collides
289
+ */
290
+ unregisterOnCollide(func) {
291
+ return this._physicsPlugin.unregisterOnBodyCollide(this, func);
292
+ }
293
+ /**
294
+ * Gets the object extents
295
+ * @returns the object extents
296
+ */
297
+ getObjectExtents() {
298
+ const tmAbstractMesh = this.transformNode;
299
+ if (tmAbstractMesh.getBoundingInfo) {
300
+ const q = this.transformNode.rotationQuaternion;
301
+ const scaling = this.transformNode.scaling.clone();
302
+ //reset rotation
303
+ this.transformNode.rotationQuaternion = PhysicsBody._IDENTITY_QUATERNION;
304
+ //calculate the world matrix with no rotation
305
+ const worldMatrix = this.transformNode.computeWorldMatrix && this.transformNode.computeWorldMatrix(true);
306
+ if (worldMatrix) {
307
+ worldMatrix.decompose(scaling, undefined, undefined);
308
+ }
309
+ const boundingInfo = tmAbstractMesh.getBoundingInfo();
310
+ // get the global scaling of the object
311
+ const size = boundingInfo.boundingBox.extendSize.scale(2).multiplyInPlace(scaling);
312
+ size.x = Math.abs(size.x);
313
+ size.y = Math.abs(size.y);
314
+ size.z = Math.abs(size.z);
315
+ //bring back the rotation
316
+ this.transformNode.rotationQuaternion = q;
317
+ //calculate the world matrix with the new rotation
318
+ this.transformNode.computeWorldMatrix && this.transformNode.computeWorldMatrix(true);
319
+ return size;
320
+ }
321
+ else {
322
+ return PhysicsBody._DEFAULT_OBJECT_SIZE;
323
+ }
324
+ }
325
+ /**
326
+ * return geometric center of the associated mesh
327
+ */
328
+ getObjectCenter() {
329
+ // TODO
330
+ return new Vector3(0, 0, 0);
331
+ }
266
332
  /**
267
333
  * Disposes the body from the physics engine.
268
334
  *
269
335
  * 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.
270
336
  */
271
337
  dispose() {
338
+ this._physicsEngine.removeBody(this);
339
+ this._physicsPlugin.removeBody(this);
272
340
  this._physicsPlugin.disposeBody(this);
273
341
  }
274
342
  }
343
+ PhysicsBody._DEFAULT_OBJECT_SIZE = new Vector3(1, 1, 1);
344
+ PhysicsBody._IDENTITY_QUATERNION = Quaternion.Identity();
275
345
  //# sourceMappingURL=physicsBody.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsBody.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAKrD;;;;GAIG;AACH,MAAM,OAAO,WA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sourcesContent":["import type { IPhysicsEnginePluginV2, MassProperties } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsShape } from \"./physicsShape\";\r\nimport type { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Quaternion } from \"../../Maths/math.vector\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PhysicsEngine } from \"./physicsEngine\";\r\nimport type { Mesh, TransformNode } from \"../../Meshes\";\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 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 * Constructs a new physics body for the given node.\r\n * @param transformNode - The Transform Node to construct the physics body for.\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, 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 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 // instances?\r\n const m = transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.initBodyInstances(this, m);\r\n } else {\r\n // single instance\r\n this._physicsPlugin.initBody(this, transformNode.position, transformNode.rotationQuaternion);\r\n }\r\n this.transformNode = transformNode;\r\n transformNode.physicsBody = this;\r\n physicsEngine.addBody(this);\r\n }\r\n\r\n /**\r\n * Sets the shape of the physics body.\r\n * @param shape - The shape of the physics body.\r\n *\r\n * This method is useful for setting the shape of the physics body, which is necessary for the physics engine to accurately simulate the body's behavior.\r\n * The shape is used to calculate the body's mass, inertia, and other properties.\r\n */\r\n public setShape(shape: PhysicsShape): void {\r\n this._physicsPlugin.setShape(this, shape);\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 getShape(): PhysicsShape | undefined {\r\n return this._physicsPlugin.getShape(this);\r\n }\r\n\r\n /**\r\n * Sets the filter group of the physics body.\r\n * @param group - The filter group of the physics body.\r\n *\r\n * This method is useful for setting the filter group of the physics body.\r\n * The filter group is used to determine which bodies should collide with each other.\r\n * This allows for more control over the physics engine and can be used to create more realistic simulations.\r\n */\r\n public setFilterGroup(group: number): void {\r\n this._physicsPlugin.setFilterGroup(this, group);\r\n }\r\n\r\n /**\r\n * Gets the filter group of the physics engine.\r\n *\r\n * @returns The filter group of the physics engine.\r\n *\r\n * This method is useful for getting the filter group of the physics engine,\r\n * which is used to determine which objects will interact with each other.\r\n * This is important for creating realistic physics simulations.\r\n */\r\n public getFilterGroup(): number {\r\n return this._physicsPlugin.getFilterGroup(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 *\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): void {\r\n this._physicsPlugin.setEventMask(this, eventMask);\r\n }\r\n\r\n /**\r\n * Gets the event mask of the physics engine.\r\n *\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(): number {\r\n return this._physicsPlugin.getEventMask(this);\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 *\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: MassProperties): void {\r\n this._physicsPlugin.setMassProperties(this, massProps);\r\n }\r\n\r\n /**\r\n * Retrieves the mass properties of the object.\r\n *\r\n * @returns The mass properties of the object, or `undefined` if the physics\r\n * plugin does not support mass properties.\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(): MassProperties | undefined {\r\n return this._physicsPlugin.getMassProperties(this);\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 *\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): void {\r\n this._physicsPlugin.setLinearDamping(this, damping);\r\n }\r\n\r\n /**\r\n * Gets the linear damping of the physics body.\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(): number {\r\n return this._physicsPlugin.getLinearDamping(this);\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 *\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): void {\r\n this._physicsPlugin.setAngularDamping(this, damping);\r\n }\r\n\r\n /**\r\n * Gets the angular damping of the physics body.\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(): number {\r\n return this._physicsPlugin.getAngularDamping(this);\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 *\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): void {\r\n this._physicsPlugin.setLinearVelocity(this, linVel);\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 *\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 public getLinearVelocityToRef(linVel: Vector3): void {\r\n return this._physicsPlugin.getLinearVelocityToRef(this, linVel);\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 *\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): void {\r\n this._physicsPlugin.setAngularVelocity(this, angVel);\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 *\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): void {\r\n return this._physicsPlugin.getAngularVelocityToRef(this, angVel);\r\n }\r\n\r\n /**\r\n * Applies an impulse to the physics object.\r\n *\r\n * @param location The location of the impulse.\r\n * @param impulse The impulse vector.\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(location: Vector3, impulse: Vector3): void {\r\n this._physicsPlugin.applyImpulse(this, location, impulse);\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 * 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 this._physicsPlugin.disposeBody(this);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsBody.ts"],"names":[],"mappings":"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,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC1B,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC1B,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC1B,yBAAyB;YACzB,IAAI,CAAC,aAAa,CAAC,kBAAkB,GAAG,CAAC,CAAC;YAC1C,kDAAkD;YAClD,IAAI,CAAC,aAAa,CAAC,kBAAkB,IAAI,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;YACrF,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,WAAW,CAAC,oBAAoB,CAAC;SAC3C;IACL,CAAC;IAED;;OAEG;IACI,eAAe;QAClB,OAAO;QACP,OAAO,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACI,OAAO;QACV,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;IAC1C,CAAC;;AA1Vc,gCAAoB,GAAY,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACrD,gCAAoB,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC","sourcesContent":["import type { IPhysicsEnginePluginV2, MassProperties } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsShape } from \"./physicsShape\";\r\nimport { Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PhysicsEngine } from \"./physicsEngine\";\r\nimport type { Mesh, TransformNode, AbstractMesh } from \"../../Meshes\";\r\nimport type { Nullable } from \"core/types\";\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 * 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 private static _DEFAULT_OBJECT_SIZE: Vector3 = new Vector3(1, 1, 1);\r\n private static _IDENTITY_QUATERNION = Quaternion.Identity();\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.\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, 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 // instances?\r\n const m = transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.initBodyInstances(this, m);\r\n } else {\r\n // single instance\r\n this._physicsPlugin.initBody(this, transformNode.position, transformNode.rotationQuaternion);\r\n }\r\n this.transformNode = transformNode;\r\n transformNode.physicsBody = this;\r\n physicsEngine.addBody(this);\r\n }\r\n\r\n /**\r\n * Sets the shape of the physics body.\r\n * @param shape - The shape of the physics body.\r\n *\r\n * This method is useful for setting the shape of the physics body, which is necessary for the physics engine to accurately simulate the body's behavior.\r\n * The shape is used to calculate the body's mass, inertia, and other properties.\r\n */\r\n public setShape(shape: PhysicsShape): void {\r\n this._physicsPlugin.setShape(this, shape);\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 getShape(): PhysicsShape | undefined {\r\n return this._physicsPlugin.getShape(this);\r\n }\r\n\r\n /**\r\n * Sets the filter group of the physics body.\r\n * @param group - The filter group of the physics body.\r\n *\r\n * This method is useful for setting the filter group of the physics body.\r\n * The filter group is used to determine which bodies should collide with each other.\r\n * This allows for more control over the physics engine and can be used to create more realistic simulations.\r\n */\r\n public setFilterGroup(group: number): void {\r\n this._physicsPlugin.setFilterGroup(this, group);\r\n }\r\n\r\n /**\r\n * Gets the filter group of the physics engine.\r\n *\r\n * @returns The filter group of the physics engine.\r\n *\r\n * This method is useful for getting the filter group of the physics engine,\r\n * which is used to determine which objects will interact with each other.\r\n * This is important for creating realistic physics simulations.\r\n */\r\n public getFilterGroup(): number {\r\n return this._physicsPlugin.getFilterGroup(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 *\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): void {\r\n this._physicsPlugin.setEventMask(this, eventMask);\r\n }\r\n\r\n /**\r\n * Gets the event mask of the physics engine.\r\n *\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(): number {\r\n return this._physicsPlugin.getEventMask(this);\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 *\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: MassProperties): void {\r\n this._physicsPlugin.setMassProperties(this, massProps);\r\n }\r\n\r\n /**\r\n * Retrieves the mass properties of the object.\r\n *\r\n * @returns The mass properties of the object, or `undefined` if the physics\r\n * plugin does not support mass properties.\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(): MassProperties | undefined {\r\n return this._physicsPlugin.getMassProperties(this);\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 *\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): void {\r\n this._physicsPlugin.setLinearDamping(this, damping);\r\n }\r\n\r\n /**\r\n * Gets the linear damping of the physics body.\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(): number {\r\n return this._physicsPlugin.getLinearDamping(this);\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 *\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): void {\r\n this._physicsPlugin.setAngularDamping(this, damping);\r\n }\r\n\r\n /**\r\n * Gets the angular damping of the physics body.\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(): number {\r\n return this._physicsPlugin.getAngularDamping(this);\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 *\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): void {\r\n this._physicsPlugin.setLinearVelocity(this, linVel);\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 *\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 public getLinearVelocityToRef(linVel: Vector3): void {\r\n return this._physicsPlugin.getLinearVelocityToRef(this, linVel);\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 *\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): void {\r\n this._physicsPlugin.setAngularVelocity(this, angVel);\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 *\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): void {\r\n return this._physicsPlugin.getAngularVelocityToRef(this, angVel);\r\n }\r\n\r\n /**\r\n * Applies an impulse to the physics object.\r\n *\r\n * @param location The location of the impulse.\r\n * @param impulse The impulse vector.\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(location: Vector3, impulse: Vector3): void {\r\n this._physicsPlugin.applyImpulse(this, location, impulse);\r\n }\r\n\r\n /**\r\n * Applies a force to the physics object.\r\n *\r\n * @param location The location of the force.\r\n * @param force The force vector.\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(location: Vector3, force: Vector3): void {\r\n this._physicsPlugin.applyForce(this, location, force);\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 * Register a collision callback that is called when the body collides\r\n * Filtering by body is inefficient. It's more preferable to register a collision callback for the entire world\r\n * and do the filtering on the user side.\r\n */\r\n public registerOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void {\r\n return this._physicsPlugin.registerOnBodyCollide(this, func);\r\n }\r\n\r\n /**\r\n * Unregister a collision callback that is called when the body collides\r\n */\r\n public unregisterOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void {\r\n return this._physicsPlugin.unregisterOnBodyCollide(this, func);\r\n }\r\n\r\n /**\r\n * Gets the object extents\r\n * @returns the object extents\r\n */\r\n public getObjectExtents(): Vector3 {\r\n const tmAbstractMesh = this.transformNode as AbstractMesh;\r\n if (tmAbstractMesh.getBoundingInfo) {\r\n const q = this.transformNode.rotationQuaternion;\r\n const scaling = this.transformNode.scaling.clone();\r\n //reset rotation\r\n this.transformNode.rotationQuaternion = PhysicsBody._IDENTITY_QUATERNION;\r\n //calculate the world matrix with no rotation\r\n const worldMatrix = this.transformNode.computeWorldMatrix && this.transformNode.computeWorldMatrix(true);\r\n if (worldMatrix) {\r\n worldMatrix.decompose(scaling, undefined, undefined);\r\n }\r\n const boundingInfo = tmAbstractMesh.getBoundingInfo();\r\n // get the global scaling of the object\r\n const size = boundingInfo.boundingBox.extendSize.scale(2).multiplyInPlace(scaling);\r\n size.x = Math.abs(size.x);\r\n size.y = Math.abs(size.y);\r\n size.z = Math.abs(size.z);\r\n //bring back the rotation\r\n this.transformNode.rotationQuaternion = q;\r\n //calculate the world matrix with the new rotation\r\n this.transformNode.computeWorldMatrix && this.transformNode.computeWorldMatrix(true);\r\n return size;\r\n } else {\r\n return PhysicsBody._DEFAULT_OBJECT_SIZE;\r\n }\r\n }\r\n\r\n /**\r\n * return geometric center of the associated mesh\r\n */\r\n public getObjectCenter(): Vector3 {\r\n // TODO\r\n return new Vector3(0, 0, 0);\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 this._physicsEngine.removeBody(this);\r\n this._physicsPlugin.removeBody(this);\r\n this._physicsPlugin.disposeBody(this);\r\n }\r\n}\r\n"]}
@@ -84,14 +84,19 @@ export declare class PhysicsEngine implements IPhysicsEngine {
84
84
  */
85
85
  _step(delta: number): void;
86
86
  /**
87
- *
87
+ * Add a body as an active component of this engine
88
88
  * @param body
89
89
  */
90
90
  addBody(physicsBody: PhysicsBody): void;
91
91
  /**
92
- *
92
+ * Removes a particular body from this engine
93
93
  */
94
94
  removeBody(physicsBody: PhysicsBody): void;
95
+ /**
96
+ * Returns an array of bodies added to this engine
97
+
98
+ */
99
+ getBodies(): Array<PhysicsBody>;
95
100
  /**
96
101
  * Gets the current plugin used to run the simulation
97
102
  * @returns current plugin
@@ -108,14 +108,14 @@ export class PhysicsEngine {
108
108
  this._physicsPlugin.executeStep(delta, this._physicsBodies);
109
109
  }
110
110
  /**
111
- *
111
+ * Add a body as an active component of this engine
112
112
  * @param body
113
113
  */
114
114
  addBody(physicsBody) {
115
115
  this._physicsBodies.push(physicsBody);
116
116
  }
117
117
  /**
118
- *
118
+ * Removes a particular body from this engine
119
119
  */
120
120
  removeBody(physicsBody) {
121
121
  const index = this._physicsBodies.indexOf(physicsBody);
@@ -123,6 +123,13 @@ export class PhysicsEngine {
123
123
  /*const removed =*/ this._physicsBodies.splice(index, 1);
124
124
  }
125
125
  }
126
+ /**
127
+ * Returns an array of bodies added to this engine
128
+
129
+ */
130
+ getBodies() {
131
+ return this._physicsBodies;
132
+ }
126
133
  /**
127
134
  * Gets the current plugin used to run the simulation
128
135
  * @returns current plugin
@@ -1 +1 @@
1
- {"version":3,"file":"physicsEngine.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsEngine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGlD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBA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,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;QAC9C,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../../types\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { IPhysicsEngine } from \"../IPhysicsEngine\";\r\nimport type { IPhysicsEnginePluginV2 } from \"./IPhysicsEnginePlugin\";\r\nimport { PhysicsRaycastResult } from \"../physicsRaycastResult\";\r\nimport { _WarnImport } from \"../../Misc/devTools\";\r\nimport type { PhysicsBody } from \"./physicsBody\";\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\n/** @internal */\r\nexport class PhysicsEngine implements IPhysicsEngine {\r\n /** @internal */\r\n private _physicsBodies: Array<PhysicsBody> = [];\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 physics plugin 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(): IPhysicsEnginePluginV2 {\r\n throw _WarnImport(\"\");\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: IPhysicsEnginePluginV2 = PhysicsEngine.DefaultPluginFactory()) {\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._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\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 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._physicsBodies);\r\n }\r\n\r\n /**\r\n *\r\n * @param body\r\n */\r\n public addBody(physicsBody: PhysicsBody): void {\r\n this._physicsBodies.push(physicsBody);\r\n }\r\n /**\r\n *\r\n */\r\n public removeBody(physicsBody: PhysicsBody): void {\r\n const index = this._physicsBodies.indexOf(physicsBody);\r\n if (index > -1) {\r\n /*const removed =*/ this._physicsBodies.splice(index, 1);\r\n }\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(): IPhysicsEnginePluginV2 {\r\n return this._physicsPlugin;\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): void {\r\n this._physicsPlugin.raycast(from, to, result);\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 const result = new PhysicsRaycastResult();\r\n this._physicsPlugin.raycast(from, to, result);\r\n return result;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"physicsEngine.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsEngine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGlD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD;;;GAGG;AACH,gBAAgB;AAChB,MAAM,OAAO,aAAa;IA0BtB;;;;OAIG;IACH,YAAY,OAA0B,EAAU,iBAAyC,aAAa,CAAC,oBAAoB,EAAE;QAA7E,mBAAc,GAAd,cAAc,CAA+D;QA9B7H,gBAAgB;QACR,mBAAc,GAAuB,EAAE,CAAC;QACxC,iBAAY,GAAW,CAAC,CAAC;QA6B7B,OAAO,GAAG,OAAO,IAAI,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC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IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;IAChE,CAAC;IAED;;;OAGG;IACI,OAAO,CAAC,WAAwB;QACnC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC1C,CAAC;IACD;;OAEG;IACI,UAAU,CAAC,WAAwB;QACtC,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACvD,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;YACZ,mBAAmB,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;SAC5D;IACL,CAAC;IACD;;;OAGG;IACI,SAAS;QACZ,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACI,gBAAgB;QACnB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;IAED;;;;;OAKG;IACI,YAAY,CAAC,IAAa,EAAE,EAAW,EAAE,MAA4B;QACxE,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;IAClD,CAAC;IAED;;;;;OAKG;IACI,OAAO,CAAC,IAAa,EAAE,EAAW;QACrC,MAAM,MAAM,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAC1C,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;QAC9C,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../../types\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { IPhysicsEngine } from \"../IPhysicsEngine\";\r\nimport type { IPhysicsEnginePluginV2 } from \"./IPhysicsEnginePlugin\";\r\nimport { PhysicsRaycastResult } from \"../physicsRaycastResult\";\r\nimport { _WarnImport } from \"../../Misc/devTools\";\r\nimport type { PhysicsBody } from \"./physicsBody\";\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\n/** @internal */\r\nexport class PhysicsEngine implements IPhysicsEngine {\r\n /** @internal */\r\n private _physicsBodies: Array<PhysicsBody> = [];\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 physics plugin 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(): IPhysicsEnginePluginV2 {\r\n throw _WarnImport(\"\");\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: IPhysicsEnginePluginV2 = PhysicsEngine.DefaultPluginFactory()) {\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._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\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 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._physicsBodies);\r\n }\r\n\r\n /**\r\n * Add a body as an active component of this engine\r\n * @param body\r\n */\r\n public addBody(physicsBody: PhysicsBody): void {\r\n this._physicsBodies.push(physicsBody);\r\n }\r\n /**\r\n * Removes a particular body from this engine\r\n */\r\n public removeBody(physicsBody: PhysicsBody): void {\r\n const index = this._physicsBodies.indexOf(physicsBody);\r\n if (index > -1) {\r\n /*const removed =*/ this._physicsBodies.splice(index, 1);\r\n }\r\n }\r\n /**\r\n * Returns an array of bodies added to this engine\r\n\r\n */\r\n public getBodies(): Array<PhysicsBody> {\r\n return this._physicsBodies;\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(): IPhysicsEnginePluginV2 {\r\n return this._physicsPlugin;\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): void {\r\n this._physicsPlugin.raycast(from, to, result);\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 const result = new PhysicsRaycastResult();\r\n this._physicsPlugin.raycast(from, to, result);\r\n return result;\r\n }\r\n}\r\n"]}
@@ -92,100 +92,86 @@ export declare class PhysicsShape {
92
92
  dispose(): void;
93
93
  }
94
94
  /**
95
- *
95
+ * Helper object to create a sphere shape
96
96
  */
97
- /** @internal */
98
97
  export declare class PhysicsShapeSphere extends PhysicsShape {
99
98
  /** @internal */
100
99
  /**
101
- *
102
- * @param center
103
- * @param radius
104
- * @param scene
100
+ * Constructor for the Sphere Shape
101
+ * @param center local center of the sphere
102
+ * @param radius radius
103
+ * @param scene scene to attach to
105
104
  */
106
105
  constructor(center: Vector3, radius: number, scene: Scene);
107
106
  }
108
107
  /***
109
- *
108
+ * Helper object to create a capsule shape
110
109
  */
111
- /** @internal */
112
110
  export declare class PhysicsShapeCapsule extends PhysicsShape {
113
- /** @internal */
114
111
  /**
115
112
  *
116
- * @param pointA
117
- * @param pointB
118
- * @param radius
119
- * @param scene
113
+ * @param pointA Starting point that defines the capsule segment
114
+ * @param pointB ending point of that same segment
115
+ * @param radius radius
116
+ * @param scene scene to attach to
120
117
  */
121
118
  constructor(pointA: Vector3, pointB: Vector3, radius: number, scene: Scene);
122
119
  }
123
120
  /**
124
- *
121
+ * Helper object to create a cylinder shape
125
122
  */
126
- /** @internal */
127
123
  export declare class PhysicsShapeCylinder extends PhysicsShape {
128
- /** @internal */
129
124
  /**
130
125
  *
131
- * @param pointA
132
- * @param pointB
133
- * @param radius
134
- * @param scene
126
+ * @param pointA Starting point that defines the cylinder segment
127
+ * @param pointB ending point of that same segment
128
+ * @param radius radius
129
+ * @param scene scene to attach to
135
130
  */
136
131
  constructor(pointA: Vector3, pointB: Vector3, radius: number, scene: Scene);
137
132
  }
138
133
  /**
139
- *
134
+ * Helper object to create a box shape
140
135
  */
141
- /** @internal */
142
136
  export declare class PhysicsShapeBox extends PhysicsShape {
143
- /** @internal */
144
137
  /**
145
138
  *
146
- * @param center
147
- * @param rotation
148
- * @param extents
149
- * @param scene
139
+ * @param center local center of the sphere
140
+ * @param rotation local orientation
141
+ * @param extents size of the box in each direction
142
+ * @param scene scene to attach to
150
143
  */
151
144
  constructor(center: Vector3, rotation: Quaternion, extents: Vector3, scene: Scene);
152
145
  }
153
146
  /**
154
- *
147
+ * Helper object to create a convex hull shape
155
148
  */
156
- /** @internal */
157
149
  export declare class PhysicsShapeConvexHull extends PhysicsShape {
158
- /** @internal */
159
150
  /**
160
151
  *
161
- * @param mesh
162
- * @param scene
152
+ * @param mesh the mesh to be used as topology infos for the convex hull
153
+ * @param scene scene to attach to
163
154
  */
164
155
  constructor(mesh: Mesh, scene: Scene);
165
156
  }
166
157
  /**
167
- *
158
+ * Helper object to create a mesh shape
168
159
  */
169
- /** @internal */
170
160
  export declare class PhysicsShapeMesh extends PhysicsShape {
171
- /** @internal */
172
161
  /**
173
162
  *
174
- * @param mesh
175
- * @param scene
163
+ * @param mesh the mesh topology that will be used to create the shape
164
+ * @param scene scene to attach to
176
165
  */
177
166
  constructor(mesh: Mesh, scene: Scene);
178
167
  }
179
168
  /**
180
- *
169
+ * A shape container holds a variable number of shapes. Use AddChild to append to newly created parent container.
181
170
  */
182
- /** @internal */
183
171
  export declare class PhysicsShapeContainer extends PhysicsShape {
184
- /** @internal */
185
172
  /**
186
- *
187
- * @param mesh
188
- * @param scene
173
+ * Constructor of the Shape container
174
+ * @param scene scene to attach to
189
175
  */
190
- constructor(mesh: Mesh, scene: Scene);
176
+ constructor(scene: Scene);
191
177
  }
@@ -121,114 +121,100 @@ export class PhysicsShape {
121
121
  }
122
122
  }
123
123
  /**
124
- *
124
+ * Helper object to create a sphere shape
125
125
  */
126
- /** @internal */
127
126
  export class PhysicsShapeSphere extends PhysicsShape {
128
127
  /** @internal */
129
128
  /**
130
- *
131
- * @param center
132
- * @param radius
133
- * @param scene
129
+ * Constructor for the Sphere Shape
130
+ * @param center local center of the sphere
131
+ * @param radius radius
132
+ * @param scene scene to attach to
134
133
  */
135
134
  constructor(center, radius, scene) {
136
135
  super(ShapeType.SPHERE, { center: center, radius: radius }, scene);
137
136
  }
138
137
  }
139
138
  /***
140
- *
139
+ * Helper object to create a capsule shape
141
140
  */
142
- /** @internal */
143
141
  export class PhysicsShapeCapsule extends PhysicsShape {
144
- /** @internal */
145
142
  /**
146
143
  *
147
- * @param pointA
148
- * @param pointB
149
- * @param radius
150
- * @param scene
144
+ * @param pointA Starting point that defines the capsule segment
145
+ * @param pointB ending point of that same segment
146
+ * @param radius radius
147
+ * @param scene scene to attach to
151
148
  */
152
149
  constructor(pointA, pointB, radius, scene) {
153
150
  super(ShapeType.CAPSULE, { pointA: pointA, pointB: pointB, radius: radius }, scene);
154
151
  }
155
152
  }
156
153
  /**
157
- *
154
+ * Helper object to create a cylinder shape
158
155
  */
159
- /** @internal */
160
156
  export class PhysicsShapeCylinder extends PhysicsShape {
161
- /** @internal */
162
157
  /**
163
158
  *
164
- * @param pointA
165
- * @param pointB
166
- * @param radius
167
- * @param scene
159
+ * @param pointA Starting point that defines the cylinder segment
160
+ * @param pointB ending point of that same segment
161
+ * @param radius radius
162
+ * @param scene scene to attach to
168
163
  */
169
164
  constructor(pointA, pointB, radius, scene) {
170
165
  super(ShapeType.CYLINDER, { pointA: pointA, pointB: pointB, radius: radius }, scene);
171
166
  }
172
167
  }
173
168
  /**
174
- *
169
+ * Helper object to create a box shape
175
170
  */
176
- /** @internal */
177
171
  export class PhysicsShapeBox extends PhysicsShape {
178
- /** @internal */
179
172
  /**
180
173
  *
181
- * @param center
182
- * @param rotation
183
- * @param extents
184
- * @param scene
174
+ * @param center local center of the sphere
175
+ * @param rotation local orientation
176
+ * @param extents size of the box in each direction
177
+ * @param scene scene to attach to
185
178
  */
186
179
  constructor(center, rotation, extents, scene) {
187
180
  super(ShapeType.BOX, { center: center, rotation: rotation, extents: extents }, scene);
188
181
  }
189
182
  }
190
183
  /**
191
- *
184
+ * Helper object to create a convex hull shape
192
185
  */
193
- /** @internal */
194
186
  export class PhysicsShapeConvexHull extends PhysicsShape {
195
- /** @internal */
196
187
  /**
197
188
  *
198
- * @param mesh
199
- * @param scene
189
+ * @param mesh the mesh to be used as topology infos for the convex hull
190
+ * @param scene scene to attach to
200
191
  */
201
192
  constructor(mesh, scene) {
202
193
  super(ShapeType.CONVEX_HULL, { mesh: mesh }, scene);
203
194
  }
204
195
  }
205
196
  /**
206
- *
197
+ * Helper object to create a mesh shape
207
198
  */
208
- /** @internal */
209
199
  export class PhysicsShapeMesh extends PhysicsShape {
210
- /** @internal */
211
200
  /**
212
201
  *
213
- * @param mesh
214
- * @param scene
202
+ * @param mesh the mesh topology that will be used to create the shape
203
+ * @param scene scene to attach to
215
204
  */
216
205
  constructor(mesh, scene) {
217
206
  super(ShapeType.MESH, { mesh: mesh }, scene);
218
207
  }
219
208
  }
220
209
  /**
221
- *
210
+ * A shape container holds a variable number of shapes. Use AddChild to append to newly created parent container.
222
211
  */
223
- /** @internal */
224
212
  export class PhysicsShapeContainer extends PhysicsShape {
225
- /** @internal */
226
213
  /**
227
- *
228
- * @param mesh
229
- * @param scene
214
+ * Constructor of the Shape container
215
+ * @param scene scene to attach to
230
216
  */
231
- constructor(mesh, scene) {
217
+ constructor(scene) {
232
218
  super(ShapeType.CONTAINER, {}, scene);
233
219
  }
234
220
  }