@babylonjs/core 5.51.0 → 5.53.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 (107) hide show
  1. package/Animations/animatable.d.ts +5 -3
  2. package/Animations/animatable.js +11 -8
  3. package/Animations/animatable.js.map +1 -1
  4. package/Animations/animationGroup.js +3 -1
  5. package/Animations/animationGroup.js.map +1 -1
  6. package/Animations/runtimeAnimation.d.ts +1 -0
  7. package/Animations/runtimeAnimation.js +1 -0
  8. package/Animations/runtimeAnimation.js.map +1 -1
  9. package/Collisions/pickingInfo.d.ts +2 -1
  10. package/Collisions/pickingInfo.js +4 -3
  11. package/Collisions/pickingInfo.js.map +1 -1
  12. package/DeviceInput/eventFactory.js +4 -0
  13. package/DeviceInput/eventFactory.js.map +1 -1
  14. package/DeviceInput/webDeviceInputSystem.js +17 -9
  15. package/DeviceInput/webDeviceInputSystem.js.map +1 -1
  16. package/Engines/engine.d.ts +2 -0
  17. package/Engines/engine.js +5 -0
  18. package/Engines/engine.js.map +1 -1
  19. package/Engines/thinEngine.js +3 -3
  20. package/Engines/thinEngine.js.map +1 -1
  21. package/Inputs/scene.inputManager.js +5 -12
  22. package/Inputs/scene.inputManager.js.map +1 -1
  23. package/Materials/Node/Blocks/Dual/sceneDepthBlock.d.ts +4 -0
  24. package/Materials/Node/Blocks/Dual/sceneDepthBlock.js +37 -2
  25. package/Materials/Node/Blocks/Dual/sceneDepthBlock.js.map +1 -1
  26. package/Materials/Node/nodeMaterialDecorator.d.ts +1 -1
  27. package/Materials/Node/nodeMaterialDecorator.js.map +1 -1
  28. package/Materials/PBR/pbrMaterial.js +1 -0
  29. package/Materials/PBR/pbrMaterial.js.map +1 -1
  30. package/Materials/Textures/Filtering/hdrFiltering.js +4 -0
  31. package/Materials/Textures/Filtering/hdrFiltering.js.map +1 -1
  32. package/Materials/Textures/cubeTexture.js +7 -1
  33. package/Materials/Textures/cubeTexture.js.map +1 -1
  34. package/Materials/materialPluginBase.d.ts +3 -2
  35. package/Materials/materialPluginBase.js.map +1 -1
  36. package/Materials/materialPluginManager.js +13 -3
  37. package/Materials/materialPluginManager.js.map +1 -1
  38. package/Materials/uniformBuffer.d.ts +2 -0
  39. package/Materials/uniformBuffer.js +4 -0
  40. package/Materials/uniformBuffer.js.map +1 -1
  41. package/Maths/math.frustum.d.ts +8 -1
  42. package/Maths/math.frustum.js +14 -0
  43. package/Maths/math.frustum.js.map +1 -1
  44. package/Meshes/instancedMesh.d.ts +2 -1
  45. package/Meshes/instancedMesh.js +3 -2
  46. package/Meshes/instancedMesh.js.map +1 -1
  47. package/Meshes/mesh.d.ts +10 -5
  48. package/Meshes/mesh.js +40 -16
  49. package/Meshes/mesh.js.map +1 -1
  50. package/Misc/environmentTextureTools.js +7 -0
  51. package/Misc/environmentTextureTools.js.map +1 -1
  52. package/Misc/filesInput.d.ts +5 -2
  53. package/Misc/filesInput.js +39 -20
  54. package/Misc/filesInput.js.map +1 -1
  55. package/Misc/observable.js +3 -0
  56. package/Misc/observable.js.map +1 -1
  57. package/Misc/sceneOptimizer.js +3 -0
  58. package/Misc/sceneOptimizer.js.map +1 -1
  59. package/Misc/virtualJoystick.js +2 -2
  60. package/Misc/virtualJoystick.js.map +1 -1
  61. package/Particles/gpuParticleSystem.js +18 -14
  62. package/Particles/gpuParticleSystem.js.map +1 -1
  63. package/Physics/v2/IPhysicsEnginePlugin.d.ts +126 -19
  64. package/Physics/v2/IPhysicsEnginePlugin.js +6 -0
  65. package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
  66. package/Physics/v2/physicsAggregate.d.ts +7 -1
  67. package/Physics/v2/physicsAggregate.js +23 -9
  68. package/Physics/v2/physicsAggregate.js.map +1 -1
  69. package/Physics/v2/physicsBody.d.ts +50 -31
  70. package/Physics/v2/physicsBody.js +75 -34
  71. package/Physics/v2/physicsBody.js.map +1 -1
  72. package/Physics/v2/physicsConstraint.d.ts +6 -6
  73. package/Physics/v2/physicsConstraint.js +6 -6
  74. package/Physics/v2/physicsConstraint.js.map +1 -1
  75. package/Physics/v2/physicsEngineComponent.d.ts +10 -0
  76. package/Physics/v2/physicsEngineComponent.js +27 -0
  77. package/Physics/v2/physicsEngineComponent.js.map +1 -1
  78. package/Physics/v2/physicsMaterial.d.ts +52 -46
  79. package/Physics/v2/physicsMaterial.js +23 -80
  80. package/Physics/v2/physicsMaterial.js.map +1 -1
  81. package/Physics/v2/physicsShape.d.ts +34 -9
  82. package/Physics/v2/physicsShape.js +59 -8
  83. package/Physics/v2/physicsShape.js.map +1 -1
  84. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.d.ts +59 -13
  85. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js +131 -54
  86. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js.map +1 -1
  87. package/Rendering/depthRenderer.js +1 -1
  88. package/Rendering/depthRenderer.js.map +1 -1
  89. package/Rendering/depthRendererSceneComponent.d.ts +2 -1
  90. package/Rendering/depthRendererSceneComponent.js +2 -2
  91. package/Rendering/depthRendererSceneComponent.js.map +1 -1
  92. package/Shaders/sprites.fragment.js +6 -1
  93. package/Shaders/sprites.fragment.js.map +1 -1
  94. package/Shaders/ssao2.fragment.js +0 -2
  95. package/Shaders/ssao2.fragment.js.map +1 -1
  96. package/Sprites/spriteManager.d.ts +7 -0
  97. package/Sprites/spriteManager.js +27 -0
  98. package/Sprites/spriteManager.js.map +1 -1
  99. package/Sprites/spriteRenderer.d.ts +8 -0
  100. package/Sprites/spriteRenderer.js +42 -19
  101. package/Sprites/spriteRenderer.js.map +1 -1
  102. package/XR/features/WebXRControllerTeleportation.d.ts +9 -0
  103. package/XR/features/WebXRControllerTeleportation.js +28 -4
  104. package/XR/features/WebXRControllerTeleportation.js.map +1 -1
  105. package/assetContainer.js +1 -1
  106. package/assetContainer.js.map +1 -1
  107. package/package.json +1 -1
@@ -1,12 +1,11 @@
1
- import type { MassProperties } from "./IPhysicsEnginePlugin";
1
+ import type { IPhysicsCollisionEvent, MassProperties, PhysicsMotionType } from "./IPhysicsEnginePlugin";
2
2
  import type { PhysicsShape } from "./physicsShape";
3
3
  import { Vector3, Quaternion } from "../../Maths/math.vector";
4
4
  import type { Scene } from "../../scene";
5
- import type { Nullable } from "../../types.js";
5
+ import type { TransformNode, AbstractMesh } from "../../Meshes";
6
6
  import type { PhysicsConstraint } from "./physicsConstraint";
7
7
  import type { Bone } from "../../Bones/bone.js";
8
- import type { TransformNode } from "../../Meshes/transformNode.js";
9
- import type { AbstractMesh } from "../../Meshes/abstractMesh.js";
8
+ import type { Observable } from "../../Misc/observable";
10
9
  /**
11
10
  * PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows
12
11
  * the user to set the mass and velocity of the body, which can then be used to calculate the
@@ -40,20 +39,33 @@ export declare class PhysicsBody {
40
39
  disablePreStep: boolean;
41
40
  private static _DEFAULT_OBJECT_SIZE;
42
41
  private static _IDENTITY_QUATERNION;
42
+ private _nodeDisposeObserver;
43
43
  /**
44
44
  * Constructs a new physics body for the given node.
45
45
  * @param transformNode - The Transform Node to construct the physics body for.
46
+ * @param motionType - The motion type of the physics body.
46
47
  * @param scene - The scene containing the physics engine.
47
48
  *
48
49
  * This code is useful for creating a physics body for a given Transform Node in a scene.
49
50
  * It checks the version of the physics engine and the physics plugin, and initializes the body accordingly.
50
51
  * It also sets the node's rotation quaternion if it is not already set. Finally, it adds the body to the physics engine.
51
52
  */
52
- constructor(transformNode: TransformNode, scene: Scene);
53
+ constructor(transformNode: TransformNode, motionType: PhysicsMotionType, scene: Scene);
54
+ /**
55
+ * Clone the PhysicsBody to a new body and assign it to the transformNode parameter
56
+ * @param transformNode transformNode that will be used for the cloned PhysicsBody
57
+ * @returns the newly cloned PhysicsBody
58
+ */
59
+ clone(transformNode: TransformNode): PhysicsBody;
53
60
  /**
54
61
  * If a physics body is connected to an instanced node, update the number physic instances to match the number of node instances.
55
62
  */
56
63
  updateBodyInstances(): void;
64
+ /**
65
+ * Adds the physics shape associated with the transform node to this body
66
+ * @param shapeNode - A node with a physics shape. Should be a child of the body node
67
+ */
68
+ addNodeShape(shapeNode: TransformNode): void;
57
69
  /**
58
70
  * Sets the shape of the physics body.
59
71
  * @param shape - The shape of the physics body.
@@ -61,7 +73,7 @@ export declare class PhysicsBody {
61
73
  * 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.
62
74
  * The shape is used to calculate the body's mass, inertia, and other properties.
63
75
  */
64
- setShape(shape: PhysicsShape): void;
76
+ set shape(shape: PhysicsShape);
65
77
  /**
66
78
  * Retrieves the physics shape associated with this object.
67
79
  *
@@ -71,7 +83,7 @@ export declare class PhysicsBody {
71
83
  * This method is useful for retrieving the physics shape associated with this object,
72
84
  * which can be used to apply physical forces to the object or to detect collisions.
73
85
  */
74
- getShape(): PhysicsShape | undefined;
86
+ get shape(): PhysicsShape;
75
87
  /**
76
88
  * Sets the filter group of the physics body.
77
89
  * @param group - The filter group of the physics body.
@@ -80,7 +92,7 @@ export declare class PhysicsBody {
80
92
  * The filter group is used to determine which bodies should collide with each other.
81
93
  * This allows for more control over the physics engine and can be used to create more realistic simulations.
82
94
  */
83
- setFilterGroup(group: number): void;
95
+ set filterGroup(group: number);
84
96
  /**
85
97
  * Gets the filter group of the physics engine.
86
98
  *
@@ -90,7 +102,7 @@ export declare class PhysicsBody {
90
102
  * which is used to determine which objects will interact with each other.
91
103
  * This is important for creating realistic physics simulations.
92
104
  */
93
- getFilterGroup(): number;
105
+ get filterGroup(): number;
94
106
  /**
95
107
  * Sets the event mask for the physics engine.
96
108
  *
@@ -99,7 +111,7 @@ export declare class PhysicsBody {
99
111
  * This method is useful for setting the event mask for the physics engine, which determines which events
100
112
  * will be sent to the physics engine. This allows the user to control which events the physics engine will respond to.
101
113
  */
102
- setEventMask(eventMask: number): void;
114
+ set eventMask(eventMask: number);
103
115
  /**
104
116
  * Gets the event mask of the physics engine.
105
117
  *
@@ -110,7 +122,23 @@ export declare class PhysicsBody {
110
122
  * This is important for ensuring that the engine is responding to the correct events and not
111
123
  * wasting resources on unnecessary events.
112
124
  */
113
- getEventMask(): number;
125
+ get eventMask(): number;
126
+ /**
127
+ * Sets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.
128
+ */
129
+ set motionType(motionType: PhysicsMotionType);
130
+ /**
131
+ * Gets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.
132
+ */
133
+ get motionType(): PhysicsMotionType;
134
+ /**
135
+ * Computes the mass properties of the physics object, based on the set of physics shapes this body uses.
136
+ * This method is useful for computing the initial mass properties of a physics object, such as its mass,
137
+ * inertia, and center of mass; these values are important for accurately simulating the physics of the
138
+ * object in the physics engine, and computing values based on the shape will provide you with reasonable
139
+ * intial values, which you can then customize.
140
+ */
141
+ computeMassProperties(): MassProperties;
114
142
  /**
115
143
  * Sets the mass properties of the physics object.
116
144
  *
@@ -119,19 +147,18 @@ export declare class PhysicsBody {
119
147
  * This method is useful for setting the mass properties of a physics object, such as its mass,
120
148
  * inertia, and center of mass. This is important for accurately simulating the physics of the object in the physics engine.
121
149
  */
122
- setMassProperties(massProps: MassProperties): void;
150
+ set massProperties(massProps: MassProperties);
123
151
  /**
124
152
  * Retrieves the mass properties of the object.
125
153
  *
126
- * @returns The mass properties of the object, or `undefined` if the physics
127
- * plugin does not support mass properties.
154
+ * @returns The mass properties of the object.
128
155
  *
129
156
  * This method is useful for physics simulations, as it allows the user to
130
157
  * retrieve the mass properties of the object, such as its mass, center of mass,
131
158
  * and moment of inertia. This information is necessary for accurate physics
132
159
  * simulations.
133
160
  */
134
- getMassProperties(): MassProperties | undefined;
161
+ get massProperties(): MassProperties;
135
162
  /**
136
163
  * Sets the linear damping of the physics body.
137
164
  *
@@ -141,7 +168,7 @@ export declare class PhysicsBody {
141
168
  * which is the rate at which the body's velocity decreases over time. This is useful for simulating
142
169
  * the effects of air resistance or other forms of friction.
143
170
  */
144
- setLinearDamping(damping: number): void;
171
+ set linearDamping(damping: number);
145
172
  /**
146
173
  * Gets the linear damping of the physics body.
147
174
  * @returns The linear damping of the physics body.
@@ -150,7 +177,7 @@ export declare class PhysicsBody {
150
177
  * resistance the body has to linear motion. This is useful for simulating realistic physics behavior
151
178
  * in a game.
152
179
  */
153
- getLinearDamping(): number;
180
+ get linearDamping(): number;
154
181
  /**
155
182
  * Sets the angular damping of the physics body.
156
183
  * @param damping The angular damping of the body.
@@ -159,7 +186,7 @@ export declare class PhysicsBody {
159
186
  * By setting the damping, the body's angular velocity will be reduced over time, simulating the effect of friction.
160
187
  * This can be used to create realistic physical behavior in a physics engine.
161
188
  */
162
- setAngularDamping(damping: number): void;
189
+ set angularDamping(damping: number);
163
190
  /**
164
191
  * Gets the angular damping of the physics body.
165
192
  *
@@ -169,7 +196,7 @@ export declare class PhysicsBody {
169
196
  * which is the rate of reduction of the angular velocity over time.
170
197
  * This is important for simulating realistic physics behavior in a game.
171
198
  */
172
- getAngularDamping(): number;
199
+ get angularDamping(): number;
173
200
  /**
174
201
  * Sets the linear velocity of the physics object.
175
202
  * @param linVel - The linear velocity to set.
@@ -233,21 +260,13 @@ export declare class PhysicsBody {
233
260
  */
234
261
  getGeometry(): {};
235
262
  /**
236
- * Register a collision callback that is called when the body collides
237
- * Filtering by body is inefficient. It's more preferable to register a collision callback for the entire world
238
- * and do the filtering on the user side.
239
- */
240
- registerOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
241
- /**
242
- * Unregister a collision callback that is called when the body collides
263
+ * Returns an observable that will be notified for all collisions happening for event-enabled bodies
264
+ * @returns Observable
243
265
  */
244
- unregisterOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
266
+ getCollisionObservable(): Observable<IPhysicsCollisionEvent>;
245
267
  /**
246
268
  * Enable or disable collision callback for this PhysicsBody.
247
- * `registerOnCollide` method will enable collision callback and `unregisterOnCollide` will disable them.
248
- * Registering a collision callback on the plugin and enabling collision per body is faster than
249
- * registering callback per PhysicsBody.
250
- * @param enabled true if PhysicsBody's collision will rise a collision event and call the callback
269
+ * @param enabled true if PhysicsBody's collision will rise a collision event and notifies the observable
251
270
  */
252
271
  setCollisionCallbackEnabled(enabled: boolean): void;
253
272
  /**
@@ -9,13 +9,14 @@ export class PhysicsBody {
9
9
  /**
10
10
  * Constructs a new physics body for the given node.
11
11
  * @param transformNode - The Transform Node to construct the physics body for.
12
+ * @param motionType - The motion type of the physics body.
12
13
  * @param scene - The scene containing the physics engine.
13
14
  *
14
15
  * This code is useful for creating a physics body for a given Transform Node in a scene.
15
16
  * It checks the version of the physics engine and the physics plugin, and initializes the body accordingly.
16
17
  * It also sets the node's rotation quaternion if it is not already set. Finally, it adds the body to the physics engine.
17
18
  */
18
- constructor(transformNode, scene) {
19
+ constructor(transformNode, motionType, scene) {
19
20
  /**
20
21
  * V2 Physics plugin private data for single Transform
21
22
  */
@@ -51,15 +52,28 @@ export class PhysicsBody {
51
52
  // instances?
52
53
  const m = transformNode;
53
54
  if (m.hasThinInstances) {
54
- this._physicsPlugin.initBodyInstances(this, m);
55
+ this._physicsPlugin.initBodyInstances(this, motionType, m);
55
56
  }
56
57
  else {
57
58
  // single instance
58
- this._physicsPlugin.initBody(this, transformNode.position, transformNode.rotationQuaternion);
59
+ this._physicsPlugin.initBody(this, motionType, transformNode.position, transformNode.rotationQuaternion);
59
60
  }
60
61
  this.transformNode = transformNode;
61
62
  transformNode.physicsBody = this;
62
63
  physicsEngine.addBody(this);
64
+ this._nodeDisposeObserver = transformNode.onDisposeObservable.add(() => {
65
+ this.dispose();
66
+ });
67
+ }
68
+ /**
69
+ * Clone the PhysicsBody to a new body and assign it to the transformNode parameter
70
+ * @param transformNode transformNode that will be used for the cloned PhysicsBody
71
+ * @returns the newly cloned PhysicsBody
72
+ */
73
+ clone(transformNode) {
74
+ const clonedBody = new PhysicsBody(transformNode, this.motionType, this.transformNode.getScene());
75
+ clonedBody.shape = this.shape;
76
+ return clonedBody;
63
77
  }
64
78
  /**
65
79
  * If a physics body is connected to an instanced node, update the number physic instances to match the number of node instances.
@@ -70,6 +84,13 @@ export class PhysicsBody {
70
84
  this._physicsPlugin.updateBodyInstances(this, m);
71
85
  }
72
86
  }
87
+ /**
88
+ * Adds the physics shape associated with the transform node to this body
89
+ * @param shapeNode - A node with a physics shape. Should be a child of the body node
90
+ */
91
+ addNodeShape(shapeNode) {
92
+ this._physicsPlugin.addNodeShape(this, shapeNode);
93
+ }
73
94
  /**
74
95
  * Sets the shape of the physics body.
75
96
  * @param shape - The shape of the physics body.
@@ -77,7 +98,7 @@ export class PhysicsBody {
77
98
  * 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.
78
99
  * The shape is used to calculate the body's mass, inertia, and other properties.
79
100
  */
80
- setShape(shape) {
101
+ set shape(shape) {
81
102
  this._physicsPlugin.setShape(this, shape);
82
103
  }
83
104
  /**
@@ -89,7 +110,7 @@ export class PhysicsBody {
89
110
  * This method is useful for retrieving the physics shape associated with this object,
90
111
  * which can be used to apply physical forces to the object or to detect collisions.
91
112
  */
92
- getShape() {
113
+ get shape() {
93
114
  return this._physicsPlugin.getShape(this);
94
115
  }
95
116
  /**
@@ -100,7 +121,7 @@ export class PhysicsBody {
100
121
  * The filter group is used to determine which bodies should collide with each other.
101
122
  * This allows for more control over the physics engine and can be used to create more realistic simulations.
102
123
  */
103
- setFilterGroup(group) {
124
+ set filterGroup(group) {
104
125
  this._physicsPlugin.setFilterGroup(this, group);
105
126
  }
106
127
  /**
@@ -112,7 +133,7 @@ export class PhysicsBody {
112
133
  * which is used to determine which objects will interact with each other.
113
134
  * This is important for creating realistic physics simulations.
114
135
  */
115
- getFilterGroup() {
136
+ get filterGroup() {
116
137
  return this._physicsPlugin.getFilterGroup(this);
117
138
  }
118
139
  /**
@@ -123,7 +144,7 @@ export class PhysicsBody {
123
144
  * This method is useful for setting the event mask for the physics engine, which determines which events
124
145
  * will be sent to the physics engine. This allows the user to control which events the physics engine will respond to.
125
146
  */
126
- setEventMask(eventMask) {
147
+ set eventMask(eventMask) {
127
148
  this._physicsPlugin.setEventMask(this, eventMask);
128
149
  }
129
150
  /**
@@ -136,9 +157,31 @@ export class PhysicsBody {
136
157
  * This is important for ensuring that the engine is responding to the correct events and not
137
158
  * wasting resources on unnecessary events.
138
159
  */
139
- getEventMask() {
160
+ get eventMask() {
140
161
  return this._physicsPlugin.getEventMask(this);
141
162
  }
163
+ /**
164
+ * Sets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.
165
+ */
166
+ set motionType(motionType) {
167
+ this._physicsPlugin.setMotionType(this, motionType);
168
+ }
169
+ /**
170
+ * Gets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.
171
+ */
172
+ get motionType() {
173
+ return this._physicsPlugin.getMotionType(this);
174
+ }
175
+ /**
176
+ * Computes the mass properties of the physics object, based on the set of physics shapes this body uses.
177
+ * This method is useful for computing the initial mass properties of a physics object, such as its mass,
178
+ * inertia, and center of mass; these values are important for accurately simulating the physics of the
179
+ * object in the physics engine, and computing values based on the shape will provide you with reasonable
180
+ * intial values, which you can then customize.
181
+ */
182
+ computeMassProperties() {
183
+ return this._physicsPlugin.computeMassProperties(this);
184
+ }
142
185
  /**
143
186
  * Sets the mass properties of the physics object.
144
187
  *
@@ -147,21 +190,20 @@ export class PhysicsBody {
147
190
  * This method is useful for setting the mass properties of a physics object, such as its mass,
148
191
  * inertia, and center of mass. This is important for accurately simulating the physics of the object in the physics engine.
149
192
  */
150
- setMassProperties(massProps) {
193
+ set massProperties(massProps) {
151
194
  this._physicsPlugin.setMassProperties(this, massProps);
152
195
  }
153
196
  /**
154
197
  * Retrieves the mass properties of the object.
155
198
  *
156
- * @returns The mass properties of the object, or `undefined` if the physics
157
- * plugin does not support mass properties.
199
+ * @returns The mass properties of the object.
158
200
  *
159
201
  * This method is useful for physics simulations, as it allows the user to
160
202
  * retrieve the mass properties of the object, such as its mass, center of mass,
161
203
  * and moment of inertia. This information is necessary for accurate physics
162
204
  * simulations.
163
205
  */
164
- getMassProperties() {
206
+ get massProperties() {
165
207
  return this._physicsPlugin.getMassProperties(this);
166
208
  }
167
209
  /**
@@ -173,7 +215,7 @@ export class PhysicsBody {
173
215
  * which is the rate at which the body's velocity decreases over time. This is useful for simulating
174
216
  * the effects of air resistance or other forms of friction.
175
217
  */
176
- setLinearDamping(damping) {
218
+ set linearDamping(damping) {
177
219
  this._physicsPlugin.setLinearDamping(this, damping);
178
220
  }
179
221
  /**
@@ -184,7 +226,7 @@ export class PhysicsBody {
184
226
  * resistance the body has to linear motion. This is useful for simulating realistic physics behavior
185
227
  * in a game.
186
228
  */
187
- getLinearDamping() {
229
+ get linearDamping() {
188
230
  return this._physicsPlugin.getLinearDamping(this);
189
231
  }
190
232
  /**
@@ -195,7 +237,7 @@ export class PhysicsBody {
195
237
  * By setting the damping, the body's angular velocity will be reduced over time, simulating the effect of friction.
196
238
  * This can be used to create realistic physical behavior in a physics engine.
197
239
  */
198
- setAngularDamping(damping) {
240
+ set angularDamping(damping) {
199
241
  this._physicsPlugin.setAngularDamping(this, damping);
200
242
  }
201
243
  /**
@@ -207,7 +249,7 @@ export class PhysicsBody {
207
249
  * which is the rate of reduction of the angular velocity over time.
208
250
  * This is important for simulating realistic physics behavior in a game.
209
251
  */
210
- getAngularDamping() {
252
+ get angularDamping() {
211
253
  return this._physicsPlugin.getAngularDamping(this);
212
254
  }
213
255
  /**
@@ -287,25 +329,15 @@ export class PhysicsBody {
287
329
  return this._physicsPlugin.getBodyGeometry(this);
288
330
  }
289
331
  /**
290
- * Register a collision callback that is called when the body collides
291
- * Filtering by body is inefficient. It's more preferable to register a collision callback for the entire world
292
- * and do the filtering on the user side.
332
+ * Returns an observable that will be notified for all collisions happening for event-enabled bodies
333
+ * @returns Observable
293
334
  */
294
- registerOnCollide(func) {
295
- return this._physicsPlugin.registerOnBodyCollide(this, func);
296
- }
297
- /**
298
- * Unregister a collision callback that is called when the body collides
299
- */
300
- unregisterOnCollide(func) {
301
- return this._physicsPlugin.unregisterOnBodyCollide(this, func);
335
+ getCollisionObservable() {
336
+ return this._physicsPlugin.getCollisionObservable(this);
302
337
  }
303
338
  /**
304
339
  * Enable or disable collision callback for this PhysicsBody.
305
- * `registerOnCollide` method will enable collision callback and `unregisterOnCollide` will disable them.
306
- * Registering a collision callback on the plugin and enabling collision per body is faster than
307
- * registering callback per PhysicsBody.
308
- * @param enabled true if PhysicsBody's collision will rise a collision event and call the callback
340
+ * @param enabled true if PhysicsBody's collision will rise a collision event and notifies the observable
309
341
  */
310
342
  setCollisionCallbackEnabled(enabled) {
311
343
  return this._physicsPlugin.setCollisionCallbackEnabled(this, enabled);
@@ -369,8 +401,13 @@ export class PhysicsBody {
369
401
  * @returns geometric center of the associated mesh
370
402
  */
371
403
  getObjectCenter() {
372
- // TODO
373
- return new Vector3(0, 0, 0);
404
+ if (this.transformNode.getBoundingInfo) {
405
+ const boundingInfo = this.transformNode.getBoundingInfo();
406
+ return boundingInfo.boundingBox.centerWorld;
407
+ }
408
+ else {
409
+ return this.transformNode.position;
410
+ }
374
411
  }
375
412
  /**
376
413
  * Adds a constraint to the physics engine.
@@ -429,6 +466,10 @@ export class PhysicsBody {
429
466
  * 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.
430
467
  */
431
468
  dispose() {
469
+ if (this._nodeDisposeObserver) {
470
+ this.transformNode.onDisposeObservable.remove(this._nodeDisposeObserver);
471
+ this._nodeDisposeObserver = null;
472
+ }
432
473
  this._physicsEngine.removeBody(this);
433
474
  this._physicsPlugin.removeBody(this);
434
475
  this._physicsPlugin.disposeBody(this);
@@ -1 +1 @@
1
- {"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsBody.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAM1E,OAAO,EAAE,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,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;IACzC,CAAC;;AAncc,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, TmpVectors } from \"../../Maths/math.vector\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PhysicsEngine } from \"./physicsEngine\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { PhysicsConstraint } from \"./physicsConstraint\";\r\nimport type { Bone } from \"core/Bones/bone\";\r\nimport { Space } from \"core/Maths/math.axis\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\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 * If a physics body is connected to an instanced node, update the number physic instances to match the number of node instances.\r\n */\r\n public updateBodyInstances() {\r\n const m = this.transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.updateBodyInstances(this, m);\r\n }\r\n }\r\n\r\n /**\r\n * 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 impulse The impulse vector.\r\n * @param location The location of the impulse.\r\n *\r\n * This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyImpulse(impulse: Vector3, location: Vector3): void {\r\n this._physicsPlugin.applyImpulse(this, impulse, location);\r\n }\r\n\r\n /**\r\n * Applies a force to the physics object.\r\n *\r\n * @param force The force vector.\r\n * @param location The location of the force.\r\n *\r\n * This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyForce(force: Vector3, location: Vector3): void {\r\n this._physicsPlugin.applyForce(this, force, location);\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 * Enable or disable collision callback for this PhysicsBody.\r\n * `registerOnCollide` method will enable collision callback and `unregisterOnCollide` will disable them.\r\n * Registering a collision callback on the plugin and enabling collision per body is faster than\r\n * registering callback per PhysicsBody.\r\n * @param enabled true if PhysicsBody's collision will rise a collision event and call the callback\r\n */\r\n public setCollisionCallbackEnabled(enabled: boolean): void {\r\n return this._physicsPlugin.setCollisionCallbackEnabled(this, enabled);\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 tmAbstractMesh.refreshBoundingInfo();\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 * returns the delta between the object bounding box center and the mesh origin\r\n * @returns delta between object bounding box center and origin\r\n */\r\n public getObjectCenterDelta(): Vector3 {\r\n const tmAbstractMesh = this.transformNode as AbstractMesh;\r\n if (tmAbstractMesh.getBoundingInfo) {\r\n const delta = new Vector3();\r\n const boundingInfo = tmAbstractMesh.getBoundingInfo();\r\n this.transformNode.computeWorldMatrix(true);\r\n tmAbstractMesh.refreshBoundingInfo();\r\n delta.copyFrom(boundingInfo.boundingBox.centerWorld);\r\n delta.subtractInPlace(tmAbstractMesh.getAbsolutePosition());\r\n delta.x /= tmAbstractMesh.scaling.x;\r\n delta.y /= tmAbstractMesh.scaling.y;\r\n delta.z /= tmAbstractMesh.scaling.z;\r\n return delta;\r\n } else {\r\n return Vector3.Zero();\r\n }\r\n }\r\n\r\n /**\r\n * @returns 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 * Adds a constraint to the physics engine.\r\n *\r\n * @param childBody - The body to which the constraint will be applied.\r\n * @param constraint - The constraint to be applied.\r\n *\r\n */\r\n public addConstraint(childBody: PhysicsBody, constraint: PhysicsConstraint): void {\r\n this._physicsPlugin.addConstraint(this, childBody, constraint);\r\n }\r\n\r\n /**\r\n * Sync with a bone\r\n * @param bone The bone that the impostor will be synced to.\r\n * @param boneMesh The mesh that the bone is influencing.\r\n * @param jointPivot The pivot of the joint / bone in local space.\r\n * @param distToJoint Optional distance from the impostor to the joint.\r\n * @param adjustRotation Optional quaternion for adjusting the local rotation of the bone.\r\n * @param boneAxis Optional vector3 axis the bone is aligned with\r\n */\r\n public syncWithBone(bone: Bone, boneMesh: AbstractMesh, jointPivot: Vector3, distToJoint?: number, adjustRotation?: Quaternion, boneAxis?: Vector3) {\r\n const mesh = this.transformNode;\r\n\r\n if (mesh.rotationQuaternion) {\r\n if (adjustRotation) {\r\n const tempQuat = TmpVectors.Quaternion[0];\r\n bone.getRotationQuaternionToRef(Space.WORLD, boneMesh, tempQuat);\r\n tempQuat.multiplyToRef(adjustRotation, mesh.rotationQuaternion);\r\n } else {\r\n bone.getRotationQuaternionToRef(Space.WORLD, boneMesh, mesh.rotationQuaternion);\r\n }\r\n }\r\n\r\n const pos = TmpVectors.Vector3[0];\r\n const boneDir = TmpVectors.Vector3[1];\r\n\r\n if (!boneAxis) {\r\n boneAxis = TmpVectors.Vector3[2];\r\n boneAxis.x = 0;\r\n boneAxis.y = 1;\r\n boneAxis.z = 0;\r\n }\r\n\r\n bone.getDirectionToRef(boneAxis, boneMesh, boneDir);\r\n bone.getAbsolutePositionToRef(boneMesh, pos);\r\n\r\n if ((distToJoint === undefined || distToJoint === null) && jointPivot) {\r\n distToJoint = jointPivot.length();\r\n }\r\n\r\n if (distToJoint !== undefined && distToJoint !== null) {\r\n pos.x += boneDir.x * distToJoint;\r\n pos.y += boneDir.y * distToJoint;\r\n pos.z += boneDir.z * distToJoint;\r\n }\r\n\r\n mesh.setAbsolutePosition(pos);\r\n }\r\n\r\n /**\r\n * 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 this._pluginData = null;\r\n this._pluginDataInstances.length = 0;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsBody.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAO1E,OAAO,EAAE,KAAK,EAAE,iCAA6B;AAI7C;;;;GAIG;AACH,MAAM,OAAO,WAAW;IA+BpB;;;;;;;;;OASG;IACH,YAAY,aAA4B,EAAE,UAA6B,EAAE,KAAY;QAxCrF;;WAEG;QACI,gBAAW,GAAQ,SAAS,CAAC;QACpC;;WAEG;QACI,yBAAoB,GAAe,EAAE,CAAC;QAa7C;;;WAGG;QACH,mBAAc,GAAY,IAAI,CAAC;QAiB3B,IAAI,CAAC,KAAK,EAAE;YACR,OAAO;SACV;QACD,MAAM,aAAa,GAAG,KAAK,CAAC,gBAAgB,EAAmB,CAAC;QAChE,IAAI,CAAC,aAAa,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACnD;QACD,IAAI,CAAC,cAAc,GAAG,aAAa,CA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GAAG,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,GAAG,WAAW,CAAC;YACjC,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,GAAG,WAAW,CAAC;SACpC;QAED,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC3B,IAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YACzE,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;SACpC;QACD,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;IACzC,CAAC;;AAjfc,gCAAoB,GAAY,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACrD,gCAAoB,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC","sourcesContent":["import type { IPhysicsCollisionEvent, IPhysicsEnginePluginV2, MassProperties, PhysicsMotionType } from \"./IPhysicsEnginePlugin\";\r\nimport type { PhysicsShape } from \"./physicsShape\";\r\nimport { Vector3, Quaternion, TmpVectors } from \"../../Maths/math.vector\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { PhysicsEngine } from \"./physicsEngine\";\r\nimport type { Mesh, TransformNode, AbstractMesh } from \"../../Meshes\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { PhysicsConstraint } from \"./physicsConstraint\";\r\nimport type { Bone } from \"core/Bones/bone\";\r\nimport { Space } from \"core/Maths/math.axis\";\r\nimport type { Observable, Observer } from \"../../Misc/observable\";\r\nimport type { Node } from \"../../node\";\r\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 private _nodeDisposeObserver: Nullable<Observer<Node>>;\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 motionType - The motion type of the physics body.\r\n * @param scene - The scene containing the physics engine.\r\n *\r\n * This code is useful for creating a physics body for a given Transform Node in a scene.\r\n * It checks the version of the physics engine and the physics plugin, and initializes the body accordingly.\r\n * It also sets the node's rotation quaternion if it is not already set. Finally, it adds the body to the physics engine.\r\n */\r\n constructor(transformNode: TransformNode, motionType: PhysicsMotionType, 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, motionType, m);\r\n } else {\r\n // single instance\r\n this._physicsPlugin.initBody(this, motionType, 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 this._nodeDisposeObserver = transformNode.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n /**\r\n * Clone the PhysicsBody to a new body and assign it to the transformNode parameter\r\n * @param transformNode transformNode that will be used for the cloned PhysicsBody\r\n * @returns the newly cloned PhysicsBody\r\n */\r\n public clone(transformNode: TransformNode): PhysicsBody {\r\n const clonedBody = new PhysicsBody(transformNode, this.motionType, this.transformNode.getScene());\r\n clonedBody.shape = this.shape;\r\n return clonedBody;\r\n }\r\n\r\n /**\r\n * If a physics body is connected to an instanced node, update the number physic instances to match the number of node instances.\r\n */\r\n public updateBodyInstances() {\r\n const m = this.transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.updateBodyInstances(this, m);\r\n }\r\n }\r\n\r\n /**\r\n * Adds the physics shape associated with the transform node to this body\r\n * @param shapeNode - A node with a physics shape. Should be a child of the body node\r\n */\r\n public addNodeShape(shapeNode: TransformNode) {\r\n this._physicsPlugin.addNodeShape(this, shapeNode);\r\n }\r\n\r\n /**\r\n * Sets the shape of the physics body.\r\n * @param shape - The shape of the physics body.\r\n *\r\n * This method is useful for setting the shape of the physics body, which is necessary for the physics engine to accurately simulate the body's behavior.\r\n * The shape is used to calculate the body's mass, inertia, and other properties.\r\n */\r\n public set shape(shape: PhysicsShape) {\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 get shape(): PhysicsShape {\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 set filterGroup(group: number) {\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 get filterGroup(): 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 set eventMask(eventMask: number) {\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 get eventMask(): number {\r\n return this._physicsPlugin.getEventMask(this);\r\n }\r\n\r\n /**\r\n * Sets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.\r\n */\r\n public set motionType(motionType: PhysicsMotionType) {\r\n this._physicsPlugin.setMotionType(this, motionType);\r\n }\r\n\r\n /**\r\n * Gets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.\r\n */\r\n public get motionType(): PhysicsMotionType {\r\n return this._physicsPlugin.getMotionType(this);\r\n }\r\n\r\n /**\r\n * Computes the mass properties of the physics object, based on the set of physics shapes this body uses.\r\n * This method is useful for computing the initial mass properties of a physics object, such as its mass,\r\n * inertia, and center of mass; these values are important for accurately simulating the physics of the\r\n * object in the physics engine, and computing values based on the shape will provide you with reasonable\r\n * intial values, which you can then customize.\r\n */\r\n public computeMassProperties(): MassProperties {\r\n return this._physicsPlugin.computeMassProperties(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 set massProperties(massProps: MassProperties) {\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.\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 get massProperties(): MassProperties {\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 set linearDamping(damping: number) {\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 get linearDamping(): 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 set angularDamping(damping: number) {\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 get angularDamping(): 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 impulse The impulse vector.\r\n * @param location The location of the impulse.\r\n *\r\n * This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyImpulse(impulse: Vector3, location: Vector3): void {\r\n this._physicsPlugin.applyImpulse(this, impulse, location);\r\n }\r\n\r\n /**\r\n * Applies a force to the physics object.\r\n *\r\n * @param force The force vector.\r\n * @param location The location of the force.\r\n *\r\n * This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyForce(force: Vector3, location: Vector3): void {\r\n this._physicsPlugin.applyForce(this, force, location);\r\n }\r\n\r\n /**\r\n * Retrieves the geometry of the body from the physics plugin.\r\n *\r\n * @returns The geometry of the body.\r\n *\r\n * This method is useful for retrieving the geometry of the body from the physics plugin, which can be used for various physics calculations.\r\n */\r\n public getGeometry(): {} {\r\n return this._physicsPlugin.getBodyGeometry(this);\r\n }\r\n\r\n /**\r\n * Returns an observable that will be notified for all collisions happening for event-enabled bodies\r\n * @returns Observable\r\n */\r\n public getCollisionObservable(): Observable<IPhysicsCollisionEvent> {\r\n return this._physicsPlugin.getCollisionObservable(this);\r\n }\r\n\r\n /**\r\n * Enable or disable collision callback for this PhysicsBody.\r\n * @param enabled true if PhysicsBody's collision will rise a collision event and notifies the observable\r\n */\r\n public setCollisionCallbackEnabled(enabled: boolean): void {\r\n return this._physicsPlugin.setCollisionCallbackEnabled(this, enabled);\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 tmAbstractMesh.refreshBoundingInfo();\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 * returns the delta between the object bounding box center and the mesh origin\r\n * @returns delta between object bounding box center and origin\r\n */\r\n public getObjectCenterDelta(): Vector3 {\r\n const tmAbstractMesh = this.transformNode as AbstractMesh;\r\n if (tmAbstractMesh.getBoundingInfo) {\r\n const delta = new Vector3();\r\n const boundingInfo = tmAbstractMesh.getBoundingInfo();\r\n this.transformNode.computeWorldMatrix(true);\r\n tmAbstractMesh.refreshBoundingInfo();\r\n delta.copyFrom(boundingInfo.boundingBox.centerWorld);\r\n delta.subtractInPlace(tmAbstractMesh.getAbsolutePosition());\r\n delta.x /= tmAbstractMesh.scaling.x;\r\n delta.y /= tmAbstractMesh.scaling.y;\r\n delta.z /= tmAbstractMesh.scaling.z;\r\n return delta;\r\n } else {\r\n return Vector3.Zero();\r\n }\r\n }\r\n\r\n /**\r\n * @returns geometric center of the associated mesh\r\n */\r\n public getObjectCenter(): Vector3 {\r\n if ((<any>this.transformNode).getBoundingInfo) {\r\n const boundingInfo = (<any>this.transformNode).getBoundingInfo();\r\n return boundingInfo.boundingBox.centerWorld;\r\n } else {\r\n return this.transformNode.position;\r\n }\r\n }\r\n\r\n /**\r\n * Adds a constraint to the physics engine.\r\n *\r\n * @param childBody - The body to which the constraint will be applied.\r\n * @param constraint - The constraint to be applied.\r\n *\r\n */\r\n public addConstraint(childBody: PhysicsBody, constraint: PhysicsConstraint): void {\r\n this._physicsPlugin.addConstraint(this, childBody, constraint);\r\n }\r\n\r\n /**\r\n * Sync with a bone\r\n * @param bone The bone that the impostor will be synced to.\r\n * @param boneMesh The mesh that the bone is influencing.\r\n * @param jointPivot The pivot of the joint / bone in local space.\r\n * @param distToJoint Optional distance from the impostor to the joint.\r\n * @param adjustRotation Optional quaternion for adjusting the local rotation of the bone.\r\n * @param boneAxis Optional vector3 axis the bone is aligned with\r\n */\r\n public syncWithBone(bone: Bone, boneMesh: AbstractMesh, jointPivot: Vector3, distToJoint?: number, adjustRotation?: Quaternion, boneAxis?: Vector3) {\r\n const mesh = this.transformNode;\r\n\r\n if (mesh.rotationQuaternion) {\r\n if (adjustRotation) {\r\n const tempQuat = TmpVectors.Quaternion[0];\r\n bone.getRotationQuaternionToRef(Space.WORLD, boneMesh, tempQuat);\r\n tempQuat.multiplyToRef(adjustRotation, mesh.rotationQuaternion);\r\n } else {\r\n bone.getRotationQuaternionToRef(Space.WORLD, boneMesh, mesh.rotationQuaternion);\r\n }\r\n }\r\n\r\n const pos = TmpVectors.Vector3[0];\r\n const boneDir = TmpVectors.Vector3[1];\r\n\r\n if (!boneAxis) {\r\n boneAxis = TmpVectors.Vector3[2];\r\n boneAxis.x = 0;\r\n boneAxis.y = 1;\r\n boneAxis.z = 0;\r\n }\r\n\r\n bone.getDirectionToRef(boneAxis, boneMesh, boneDir);\r\n bone.getAbsolutePositionToRef(boneMesh, pos);\r\n\r\n if ((distToJoint === undefined || distToJoint === null) && jointPivot) {\r\n distToJoint = jointPivot.length();\r\n }\r\n\r\n if (distToJoint !== undefined && distToJoint !== null) {\r\n pos.x += boneDir.x * distToJoint;\r\n pos.y += boneDir.y * distToJoint;\r\n pos.z += boneDir.z * distToJoint;\r\n }\r\n\r\n mesh.setAbsolutePosition(pos);\r\n }\r\n\r\n /**\r\n * Disposes the body from the physics engine.\r\n *\r\n * This method is useful for cleaning up the physics engine when a body is no longer needed. Disposing the body will free up resources and prevent memory leaks.\r\n */\r\n public dispose() {\r\n if (this._nodeDisposeObserver) {\r\n this.transformNode.onDisposeObservable.remove(this._nodeDisposeObserver);\r\n this._nodeDisposeObserver = null;\r\n }\r\n this._physicsEngine.removeBody(this);\r\n this._physicsPlugin.removeBody(this);\r\n this._physicsPlugin.disposeBody(this);\r\n this._pluginData = null;\r\n this._pluginDataInstances.length = 0;\r\n }\r\n}\r\n"]}
@@ -34,38 +34,38 @@ export declare class PhysicsConstraint {
34
34
  * @returns The type of the constraint.
35
35
  *
36
36
  */
37
- getType(): ConstraintType;
37
+ get type(): ConstraintType;
38
38
  /**
39
39
  * Retrieves the options of the physics constraint.
40
40
  *
41
41
  * @returns The physics constraint parameters.
42
42
  *
43
43
  */
44
- getOptions(): PhysicsConstraintParameters;
44
+ get options(): PhysicsConstraintParameters;
45
45
  /**
46
46
  * Enable/disable the constraint
47
47
  * @param isEnabled value for the constraint
48
48
  */
49
- setEnabled(isEnabled: boolean): void;
49
+ set isEnabled(isEnabled: boolean);
50
50
  /**
51
51
  *
52
52
  * @returns true if constraint is enabled
53
53
  */
54
- getEnabled(): boolean;
54
+ get isEnabled(): boolean;
55
55
  /**
56
56
  * Enables or disables collisions for the physics engine.
57
57
  *
58
58
  * @param isEnabled - A boolean value indicating whether collisions should be enabled or disabled.
59
59
  *
60
60
  */
61
- setCollisionsEnabled(isEnabled: boolean): void;
61
+ set isCollisionsEnabled(isEnabled: boolean);
62
62
  /**
63
63
  * Gets whether collisions are enabled for this physics object.
64
64
  *
65
65
  * @returns `true` if collisions are enabled, `false` otherwise.
66
66
  *
67
67
  */
68
- getCollisionsEnabled(): boolean;
68
+ get isCollisionsEnabled(): boolean;
69
69
  /**
70
70
  * Sets the friction of the given axis of the physics engine.
71
71
  * @param axis - The axis of the physics engine to set the friction for.