@babylonjs/core 5.57.0 → 6.0.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.
- package/Engines/WebGPU/Extensions/engine.multiRender.js +51 -8
- package/Engines/WebGPU/Extensions/engine.multiRender.js.map +1 -1
- package/Engines/WebGPU/webgpuHardwareTexture.d.ts +4 -3
- package/Engines/WebGPU/webgpuHardwareTexture.js +23 -10
- package/Engines/WebGPU/webgpuHardwareTexture.js.map +1 -1
- package/Engines/WebGPU/webgpuTextureHelper.d.ts +1 -1
- package/Engines/WebGPU/webgpuTextureHelper.js +6 -14
- package/Engines/WebGPU/webgpuTextureHelper.js.map +1 -1
- package/Engines/engine.d.ts +5 -6
- package/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.js +16 -8
- package/Engines/webgpuEngine.js.map +1 -1
- package/Lights/Shadows/shadowGenerator.d.ts +2 -0
- package/Lights/Shadows/shadowGenerator.js +11 -22
- package/Lights/Shadows/shadowGenerator.js.map +1 -1
- package/Maths/math.vector.js +4 -2
- package/Maths/math.vector.js.map +1 -1
- package/Meshes/abstractMesh.d.ts +13 -0
- package/Meshes/abstractMesh.js +20 -0
- package/Meshes/abstractMesh.js.map +1 -1
- package/Meshes/thinInstanceMesh.js +4 -1
- package/Meshes/thinInstanceMesh.js.map +1 -1
- package/Particles/solidParticleSystem.d.ts +1 -1
- package/Particles/solidParticleSystem.js +1 -1
- package/Particles/solidParticleSystem.js.map +1 -1
- package/Physics/physicsEngineComponent.d.ts +1 -0
- package/Physics/physicsEngineComponent.js +1 -0
- package/Physics/physicsEngineComponent.js.map +1 -1
- package/Physics/physicsHelper.d.ts +12 -5
- package/Physics/physicsHelper.js +160 -90
- package/Physics/physicsHelper.js.map +1 -1
- package/Physics/physicsRaycastResult.d.ts +9 -0
- package/Physics/physicsRaycastResult.js.map +1 -1
- package/Physics/v2/IPhysicsEnginePlugin.d.ts +120 -77
- package/Physics/v2/IPhysicsEnginePlugin.js +119 -48
- package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
- package/Physics/v2/Plugins/havokPlugin.d.ts +687 -0
- package/Physics/v2/Plugins/havokPlugin.js +1592 -0
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -0
- package/Physics/v2/Plugins/index.d.ts +1 -0
- package/Physics/v2/Plugins/index.js +1 -1
- package/Physics/v2/Plugins/index.js.map +1 -1
- package/Physics/v2/index.d.ts +1 -0
- package/Physics/v2/index.js +2 -0
- package/Physics/v2/index.js.map +1 -1
- package/Physics/v2/physicsAggregate.d.ts +9 -2
- package/Physics/v2/physicsAggregate.js +66 -31
- package/Physics/v2/physicsAggregate.js.map +1 -1
- package/Physics/v2/physicsBody.d.ts +51 -62
- package/Physics/v2/physicsBody.js +101 -128
- package/Physics/v2/physicsBody.js.map +1 -1
- package/Physics/v2/physicsConstraint.d.ts +57 -25
- package/Physics/v2/physicsConstraint.js +32 -15
- package/Physics/v2/physicsConstraint.js.map +1 -1
- package/Physics/v2/physicsEngine.d.ts +0 -1
- package/Physics/v2/physicsEngine.js +0 -1
- package/Physics/v2/physicsEngine.js.map +1 -1
- package/Physics/v2/physicsEngineComponent.d.ts +0 -10
- package/Physics/v2/physicsEngineComponent.js +0 -29
- package/Physics/v2/physicsEngineComponent.js.map +1 -1
- package/Physics/v2/physicsShape.d.ts +52 -11
- package/Physics/v2/physicsShape.js +80 -23
- package/Physics/v2/physicsShape.js.map +1 -1
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@ export class PhysicsBody {
|
|
|
16
16
|
* It checks the version of the physics engine and the physics plugin, and initializes the body accordingly.
|
|
17
17
|
* It also sets the node's rotation quaternion if it is not already set. Finally, it adds the body to the physics engine.
|
|
18
18
|
*/
|
|
19
|
-
constructor(transformNode, motionType, scene) {
|
|
19
|
+
constructor(transformNode, motionType, startsAsleep, scene) {
|
|
20
20
|
/**
|
|
21
21
|
* V2 Physics plugin private data for single Transform
|
|
22
22
|
*/
|
|
@@ -25,6 +25,10 @@ export class PhysicsBody {
|
|
|
25
25
|
* V2 Physics plugin private data for instances
|
|
26
26
|
*/
|
|
27
27
|
this._pluginDataInstances = [];
|
|
28
|
+
/**
|
|
29
|
+
* If the collision callback is enabled
|
|
30
|
+
*/
|
|
31
|
+
this._collisionCBEnabled = false;
|
|
28
32
|
/**
|
|
29
33
|
* Disable pre-step that consists in updating Physics Body from Transform Node Translation/Orientation.
|
|
30
34
|
* True by default for maximum performance.
|
|
@@ -49,6 +53,7 @@ export class PhysicsBody {
|
|
|
49
53
|
if (!transformNode.rotationQuaternion) {
|
|
50
54
|
transformNode.rotationQuaternion = Quaternion.FromEulerAngles(transformNode.rotation.x, transformNode.rotation.y, transformNode.rotation.z);
|
|
51
55
|
}
|
|
56
|
+
this.startAsleep = startsAsleep;
|
|
52
57
|
// instances?
|
|
53
58
|
const m = transformNode;
|
|
54
59
|
if (m.hasThinInstances) {
|
|
@@ -65,13 +70,20 @@ export class PhysicsBody {
|
|
|
65
70
|
this.dispose();
|
|
66
71
|
});
|
|
67
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Returns the string "PhysicsBody".
|
|
75
|
+
* @returns "PhysicsBody"
|
|
76
|
+
*/
|
|
77
|
+
getClassName() {
|
|
78
|
+
return "PhysicsBody";
|
|
79
|
+
}
|
|
68
80
|
/**
|
|
69
81
|
* Clone the PhysicsBody to a new body and assign it to the transformNode parameter
|
|
70
82
|
* @param transformNode transformNode that will be used for the cloned PhysicsBody
|
|
71
83
|
* @returns the newly cloned PhysicsBody
|
|
72
84
|
*/
|
|
73
85
|
clone(transformNode) {
|
|
74
|
-
const clonedBody = new PhysicsBody(transformNode, this.
|
|
86
|
+
const clonedBody = new PhysicsBody(transformNode, this.getMotionType(), this.startAsleep, this.transformNode.getScene());
|
|
75
87
|
clonedBody.shape = this.shape;
|
|
76
88
|
return clonedBody;
|
|
77
89
|
}
|
|
@@ -85,11 +97,10 @@ export class PhysicsBody {
|
|
|
85
97
|
}
|
|
86
98
|
}
|
|
87
99
|
/**
|
|
88
|
-
*
|
|
89
|
-
* @param shapeNode - A node with a physics shape. Should be a child of the body node
|
|
100
|
+
* This returns the number of internal instances of the physics body
|
|
90
101
|
*/
|
|
91
|
-
|
|
92
|
-
this.
|
|
102
|
+
get numInstances() {
|
|
103
|
+
return this._pluginDataInstances.length;
|
|
93
104
|
}
|
|
94
105
|
/**
|
|
95
106
|
* Sets the shape of the physics body.
|
|
@@ -113,29 +124,6 @@ export class PhysicsBody {
|
|
|
113
124
|
get shape() {
|
|
114
125
|
return this._physicsPlugin.getShape(this);
|
|
115
126
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Sets the filter group of the physics body.
|
|
118
|
-
* @param group - The filter group of the physics body.
|
|
119
|
-
*
|
|
120
|
-
* This method is useful for setting the filter group of the physics body.
|
|
121
|
-
* The filter group is used to determine which bodies should collide with each other.
|
|
122
|
-
* This allows for more control over the physics engine and can be used to create more realistic simulations.
|
|
123
|
-
*/
|
|
124
|
-
set filterGroup(group) {
|
|
125
|
-
this._physicsPlugin.setFilterGroup(this, group);
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Gets the filter group of the physics engine.
|
|
129
|
-
*
|
|
130
|
-
* @returns The filter group of the physics engine.
|
|
131
|
-
*
|
|
132
|
-
* This method is useful for getting the filter group of the physics engine,
|
|
133
|
-
* which is used to determine which objects will interact with each other.
|
|
134
|
-
* This is important for creating realistic physics simulations.
|
|
135
|
-
*/
|
|
136
|
-
get filterGroup() {
|
|
137
|
-
return this._physicsPlugin.getFilterGroup(this);
|
|
138
|
-
}
|
|
139
127
|
/**
|
|
140
128
|
* Sets the event mask for the physics engine.
|
|
141
129
|
*
|
|
@@ -144,8 +132,8 @@ export class PhysicsBody {
|
|
|
144
132
|
* This method is useful for setting the event mask for the physics engine, which determines which events
|
|
145
133
|
* will be sent to the physics engine. This allows the user to control which events the physics engine will respond to.
|
|
146
134
|
*/
|
|
147
|
-
|
|
148
|
-
this._physicsPlugin.setEventMask(this, eventMask);
|
|
135
|
+
setEventMask(eventMask, instanceIndex) {
|
|
136
|
+
this._physicsPlugin.setEventMask(this, eventMask, instanceIndex);
|
|
149
137
|
}
|
|
150
138
|
/**
|
|
151
139
|
* Gets the event mask of the physics engine.
|
|
@@ -157,20 +145,20 @@ export class PhysicsBody {
|
|
|
157
145
|
* This is important for ensuring that the engine is responding to the correct events and not
|
|
158
146
|
* wasting resources on unnecessary events.
|
|
159
147
|
*/
|
|
160
|
-
|
|
161
|
-
return this._physicsPlugin.getEventMask(this);
|
|
148
|
+
getEventMask(instanceIndex) {
|
|
149
|
+
return this._physicsPlugin.getEventMask(this, instanceIndex);
|
|
162
150
|
}
|
|
163
151
|
/**
|
|
164
152
|
* Sets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.
|
|
165
153
|
*/
|
|
166
|
-
|
|
167
|
-
this._physicsPlugin.setMotionType(this, motionType);
|
|
154
|
+
setMotionType(motionType, instanceIndex) {
|
|
155
|
+
this._physicsPlugin.setMotionType(this, motionType, instanceIndex);
|
|
168
156
|
}
|
|
169
157
|
/**
|
|
170
158
|
* Gets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.
|
|
171
159
|
*/
|
|
172
|
-
|
|
173
|
-
return this._physicsPlugin.getMotionType(this);
|
|
160
|
+
getMotionType(instanceIndex) {
|
|
161
|
+
return this._physicsPlugin.getMotionType(this, instanceIndex);
|
|
174
162
|
}
|
|
175
163
|
/**
|
|
176
164
|
* Computes the mass properties of the physics object, based on the set of physics shapes this body uses.
|
|
@@ -179,19 +167,20 @@ export class PhysicsBody {
|
|
|
179
167
|
* object in the physics engine, and computing values based on the shape will provide you with reasonable
|
|
180
168
|
* intial values, which you can then customize.
|
|
181
169
|
*/
|
|
182
|
-
computeMassProperties() {
|
|
183
|
-
return this._physicsPlugin.computeMassProperties(this);
|
|
170
|
+
computeMassProperties(instanceIndex) {
|
|
171
|
+
return this._physicsPlugin.computeMassProperties(this, instanceIndex);
|
|
184
172
|
}
|
|
185
173
|
/**
|
|
186
174
|
* Sets the mass properties of the physics object.
|
|
187
175
|
*
|
|
188
176
|
* @param massProps - The mass properties to set.
|
|
177
|
+
* @param instanceIndex - The index of the instance to set the mass properties for. If not defined, the mass properties will be set for all instances.
|
|
189
178
|
*
|
|
190
179
|
* This method is useful for setting the mass properties of a physics object, such as its mass,
|
|
191
180
|
* inertia, and center of mass. This is important for accurately simulating the physics of the object in the physics engine.
|
|
192
181
|
*/
|
|
193
|
-
|
|
194
|
-
this._physicsPlugin.setMassProperties(this, massProps);
|
|
182
|
+
setMassProperties(massProps, instanceIndex) {
|
|
183
|
+
this._physicsPlugin.setMassProperties(this, massProps, instanceIndex);
|
|
195
184
|
}
|
|
196
185
|
/**
|
|
197
186
|
* Retrieves the mass properties of the object.
|
|
@@ -203,8 +192,8 @@ export class PhysicsBody {
|
|
|
203
192
|
* and moment of inertia. This information is necessary for accurate physics
|
|
204
193
|
* simulations.
|
|
205
194
|
*/
|
|
206
|
-
|
|
207
|
-
return this._physicsPlugin.getMassProperties(this);
|
|
195
|
+
getMassProperties(instanceIndex) {
|
|
196
|
+
return this._physicsPlugin.getMassProperties(this, instanceIndex);
|
|
208
197
|
}
|
|
209
198
|
/**
|
|
210
199
|
* Sets the linear damping of the physics body.
|
|
@@ -215,8 +204,8 @@ export class PhysicsBody {
|
|
|
215
204
|
* which is the rate at which the body's velocity decreases over time. This is useful for simulating
|
|
216
205
|
* the effects of air resistance or other forms of friction.
|
|
217
206
|
*/
|
|
218
|
-
|
|
219
|
-
this._physicsPlugin.setLinearDamping(this, damping);
|
|
207
|
+
setLinearDamping(damping, instanceIndex) {
|
|
208
|
+
this._physicsPlugin.setLinearDamping(this, damping, instanceIndex);
|
|
220
209
|
}
|
|
221
210
|
/**
|
|
222
211
|
* Gets the linear damping of the physics body.
|
|
@@ -226,8 +215,8 @@ export class PhysicsBody {
|
|
|
226
215
|
* resistance the body has to linear motion. This is useful for simulating realistic physics behavior
|
|
227
216
|
* in a game.
|
|
228
217
|
*/
|
|
229
|
-
|
|
230
|
-
return this._physicsPlugin.getLinearDamping(this);
|
|
218
|
+
getLinearDamping(instanceIndex) {
|
|
219
|
+
return this._physicsPlugin.getLinearDamping(this, instanceIndex);
|
|
231
220
|
}
|
|
232
221
|
/**
|
|
233
222
|
* Sets the angular damping of the physics body.
|
|
@@ -237,8 +226,8 @@ export class PhysicsBody {
|
|
|
237
226
|
* By setting the damping, the body's angular velocity will be reduced over time, simulating the effect of friction.
|
|
238
227
|
* This can be used to create realistic physical behavior in a physics engine.
|
|
239
228
|
*/
|
|
240
|
-
|
|
241
|
-
this._physicsPlugin.setAngularDamping(this, damping);
|
|
229
|
+
setAngularDamping(damping, instanceIndex) {
|
|
230
|
+
this._physicsPlugin.setAngularDamping(this, damping, instanceIndex);
|
|
242
231
|
}
|
|
243
232
|
/**
|
|
244
233
|
* Gets the angular damping of the physics body.
|
|
@@ -249,8 +238,8 @@ export class PhysicsBody {
|
|
|
249
238
|
* which is the rate of reduction of the angular velocity over time.
|
|
250
239
|
* This is important for simulating realistic physics behavior in a game.
|
|
251
240
|
*/
|
|
252
|
-
|
|
253
|
-
return this._physicsPlugin.getAngularDamping(this);
|
|
241
|
+
getAngularDamping(instanceIndex) {
|
|
242
|
+
return this._physicsPlugin.getAngularDamping(this, instanceIndex);
|
|
254
243
|
}
|
|
255
244
|
/**
|
|
256
245
|
* Sets the linear velocity of the physics object.
|
|
@@ -261,8 +250,8 @@ export class PhysicsBody {
|
|
|
261
250
|
* By setting the linear velocity, the physics object will move in the direction and speed specified by the vector.
|
|
262
251
|
* This allows for realistic physics simulations, such as simulating the motion of a ball rolling down a hill.
|
|
263
252
|
*/
|
|
264
|
-
setLinearVelocity(linVel) {
|
|
265
|
-
this._physicsPlugin.setLinearVelocity(this, linVel);
|
|
253
|
+
setLinearVelocity(linVel, instanceIndex) {
|
|
254
|
+
this._physicsPlugin.setLinearVelocity(this, linVel, instanceIndex);
|
|
266
255
|
}
|
|
267
256
|
/**
|
|
268
257
|
* Gets the linear velocity of the physics body and stores it in the given vector3.
|
|
@@ -270,8 +259,8 @@ export class PhysicsBody {
|
|
|
270
259
|
*
|
|
271
260
|
* This method is useful for getting the linear velocity of a physics body in a physics engine.
|
|
272
261
|
* This can be used to determine the speed and direction of the body, which can be used to calculate the motion of the body.*/
|
|
273
|
-
getLinearVelocityToRef(linVel) {
|
|
274
|
-
return this._physicsPlugin.getLinearVelocityToRef(this, linVel);
|
|
262
|
+
getLinearVelocityToRef(linVel, instanceIndex) {
|
|
263
|
+
return this._physicsPlugin.getLinearVelocityToRef(this, linVel, instanceIndex);
|
|
275
264
|
}
|
|
276
265
|
/**
|
|
277
266
|
* Sets the angular velocity of the physics object.
|
|
@@ -281,8 +270,8 @@ export class PhysicsBody {
|
|
|
281
270
|
* simulating realistic physics behavior. The angular velocity is used to determine the rate of rotation of the object,
|
|
282
271
|
* which is important for simulating realistic motion.
|
|
283
272
|
*/
|
|
284
|
-
setAngularVelocity(angVel) {
|
|
285
|
-
this._physicsPlugin.setAngularVelocity(this, angVel);
|
|
273
|
+
setAngularVelocity(angVel, instanceIndex) {
|
|
274
|
+
this._physicsPlugin.setAngularVelocity(this, angVel, instanceIndex);
|
|
286
275
|
}
|
|
287
276
|
/**
|
|
288
277
|
* Gets the angular velocity of the physics body and stores it in the given vector3.
|
|
@@ -291,32 +280,34 @@ export class PhysicsBody {
|
|
|
291
280
|
* This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's
|
|
292
281
|
* rotational speed. This information can be used to create realistic physics simulations.
|
|
293
282
|
*/
|
|
294
|
-
getAngularVelocityToRef(angVel) {
|
|
295
|
-
return this._physicsPlugin.getAngularVelocityToRef(this, angVel);
|
|
283
|
+
getAngularVelocityToRef(angVel, instanceIndex) {
|
|
284
|
+
return this._physicsPlugin.getAngularVelocityToRef(this, angVel, instanceIndex);
|
|
296
285
|
}
|
|
297
286
|
/**
|
|
298
287
|
* Applies an impulse to the physics object.
|
|
299
288
|
*
|
|
300
289
|
* @param impulse The impulse vector.
|
|
301
290
|
* @param location The location of the impulse.
|
|
291
|
+
* @param instanceIndex For a instanced body, the instance to where the impulse should be applied. If not specified, the impulse is applied to all instances.
|
|
302
292
|
*
|
|
303
293
|
* This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity,
|
|
304
294
|
* collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.
|
|
305
295
|
*/
|
|
306
|
-
applyImpulse(impulse, location) {
|
|
307
|
-
this._physicsPlugin.applyImpulse(this, impulse, location);
|
|
296
|
+
applyImpulse(impulse, location, instanceIndex) {
|
|
297
|
+
this._physicsPlugin.applyImpulse(this, impulse, location, instanceIndex);
|
|
308
298
|
}
|
|
309
299
|
/**
|
|
310
300
|
* Applies a force to the physics object.
|
|
311
301
|
*
|
|
312
302
|
* @param force The force vector.
|
|
313
303
|
* @param location The location of the force.
|
|
304
|
+
* @param instanceIndex For a instanced body, the instance to where the force should be applied. If not specified, the force is applied to all instances.
|
|
314
305
|
*
|
|
315
306
|
* This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,
|
|
316
307
|
* collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.
|
|
317
308
|
*/
|
|
318
|
-
applyForce(force, location) {
|
|
319
|
-
this._physicsPlugin.applyForce(this, force, location);
|
|
309
|
+
applyForce(force, location, instanceIndex) {
|
|
310
|
+
this._physicsPlugin.applyForce(this, force, location, instanceIndex);
|
|
320
311
|
}
|
|
321
312
|
/**
|
|
322
313
|
* Retrieves the geometry of the body from the physics plugin.
|
|
@@ -340,84 +331,49 @@ export class PhysicsBody {
|
|
|
340
331
|
* @param enabled true if PhysicsBody's collision will rise a collision event and notifies the observable
|
|
341
332
|
*/
|
|
342
333
|
setCollisionCallbackEnabled(enabled) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Gets the object extents
|
|
347
|
-
* @returns the object extents
|
|
348
|
-
*/
|
|
349
|
-
getObjectExtents() {
|
|
350
|
-
const tmAbstractMesh = this.transformNode;
|
|
351
|
-
if (tmAbstractMesh.getBoundingInfo) {
|
|
352
|
-
const q = this.transformNode.rotationQuaternion;
|
|
353
|
-
const scaling = this.transformNode.scaling.clone();
|
|
354
|
-
//reset rotation
|
|
355
|
-
this.transformNode.rotationQuaternion = PhysicsBody._IDENTITY_QUATERNION;
|
|
356
|
-
//calculate the world matrix with no rotation
|
|
357
|
-
const worldMatrix = this.transformNode.computeWorldMatrix && this.transformNode.computeWorldMatrix(true);
|
|
358
|
-
if (worldMatrix) {
|
|
359
|
-
worldMatrix.decompose(scaling, undefined, undefined);
|
|
360
|
-
}
|
|
361
|
-
tmAbstractMesh.refreshBoundingInfo();
|
|
362
|
-
const boundingInfo = tmAbstractMesh.getBoundingInfo();
|
|
363
|
-
// get the global scaling of the object
|
|
364
|
-
const size = boundingInfo.boundingBox.extendSize.scale(2).multiplyInPlace(scaling);
|
|
365
|
-
size.x = Math.abs(size.x);
|
|
366
|
-
size.y = Math.abs(size.y);
|
|
367
|
-
size.z = Math.abs(size.z);
|
|
368
|
-
//bring back the rotation
|
|
369
|
-
this.transformNode.rotationQuaternion = q;
|
|
370
|
-
//calculate the world matrix with the new rotation
|
|
371
|
-
this.transformNode.computeWorldMatrix && this.transformNode.computeWorldMatrix(true);
|
|
372
|
-
return size;
|
|
373
|
-
}
|
|
374
|
-
else {
|
|
375
|
-
return PhysicsBody._DEFAULT_OBJECT_SIZE;
|
|
376
|
-
}
|
|
334
|
+
this._collisionCBEnabled = enabled;
|
|
335
|
+
this._physicsPlugin.setCollisionCallbackEnabled(this, enabled);
|
|
377
336
|
}
|
|
378
|
-
|
|
379
|
-
*
|
|
380
|
-
* @
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
const boundingInfo = tmAbstractMesh.getBoundingInfo();
|
|
387
|
-
this.transformNode.computeWorldMatrix(true);
|
|
388
|
-
tmAbstractMesh.refreshBoundingInfo();
|
|
389
|
-
delta.copyFrom(boundingInfo.boundingBox.centerWorld);
|
|
390
|
-
delta.subtractInPlace(tmAbstractMesh.getAbsolutePosition());
|
|
391
|
-
delta.x /= tmAbstractMesh.scaling.x;
|
|
392
|
-
delta.y /= tmAbstractMesh.scaling.y;
|
|
393
|
-
delta.z /= tmAbstractMesh.scaling.z;
|
|
394
|
-
return delta;
|
|
395
|
-
}
|
|
396
|
-
else {
|
|
397
|
-
return Vector3.Zero();
|
|
398
|
-
}
|
|
337
|
+
/*
|
|
338
|
+
* Get the center of the object in world space.
|
|
339
|
+
* @param instanceIndex - If this body is instanced, the index of the instance to get the center for.
|
|
340
|
+
* @returns geometric center of the associated mesh
|
|
341
|
+
*/
|
|
342
|
+
getObjectCenterWorld(instanceIndex) {
|
|
343
|
+
const ref = new Vector3();
|
|
344
|
+
return this.getObjectCenterWorldToRef(ref, instanceIndex);
|
|
399
345
|
}
|
|
400
|
-
|
|
346
|
+
/*
|
|
347
|
+
* Get the center of the object in world space.
|
|
348
|
+
* @param ref - The vector3 to store the result in.
|
|
349
|
+
* @param instanceIndex - If this body is instanced, the index of the instance to get the center for.
|
|
401
350
|
* @returns geometric center of the associated mesh
|
|
402
351
|
*/
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
352
|
+
getObjectCenterWorldToRef(ref, instanceIndex) {
|
|
353
|
+
var _a;
|
|
354
|
+
if (((_a = this._pluginDataInstances) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
355
|
+
const index = instanceIndex || 0;
|
|
356
|
+
const matrixData = this.transformNode._thinInstanceDataStorage.matrixData;
|
|
357
|
+
if (matrixData) {
|
|
358
|
+
ref.set(matrixData[index * 16 + 12], matrixData[index * 16 + 13], matrixData[index * 16 + 14]);
|
|
359
|
+
}
|
|
407
360
|
}
|
|
408
361
|
else {
|
|
409
|
-
|
|
362
|
+
ref.copyFrom(this.transformNode.position);
|
|
410
363
|
}
|
|
364
|
+
return ref;
|
|
411
365
|
}
|
|
412
366
|
/**
|
|
413
367
|
* Adds a constraint to the physics engine.
|
|
414
368
|
*
|
|
415
369
|
* @param childBody - The body to which the constraint will be applied.
|
|
416
370
|
* @param constraint - The constraint to be applied.
|
|
371
|
+
* @param instanceIndex - If this body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.
|
|
372
|
+
* @param childInstanceIndex - If the child body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.
|
|
417
373
|
*
|
|
418
374
|
*/
|
|
419
|
-
addConstraint(childBody, constraint) {
|
|
420
|
-
this._physicsPlugin.addConstraint(this, childBody, constraint);
|
|
375
|
+
addConstraint(childBody, constraint, instanceIndex, childInstanceIndex) {
|
|
376
|
+
this._physicsPlugin.addConstraint(this, childBody, constraint, instanceIndex, childInstanceIndex);
|
|
421
377
|
}
|
|
422
378
|
/**
|
|
423
379
|
* Sync with a bone
|
|
@@ -460,12 +416,31 @@ export class PhysicsBody {
|
|
|
460
416
|
}
|
|
461
417
|
mesh.setAbsolutePosition(pos);
|
|
462
418
|
}
|
|
419
|
+
/**
|
|
420
|
+
* Executes a callback on the body or all of the instances of a body
|
|
421
|
+
* @param callback the callback to execute
|
|
422
|
+
*/
|
|
423
|
+
iterateOverAllInstances(callback) {
|
|
424
|
+
var _a;
|
|
425
|
+
if (((_a = this._pluginDataInstances) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
426
|
+
for (let i = 0; i < this._pluginDataInstances.length; i++) {
|
|
427
|
+
callback(this, i);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
callback(this, undefined);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
463
434
|
/**
|
|
464
435
|
* Disposes the body from the physics engine.
|
|
465
436
|
*
|
|
466
437
|
* 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.
|
|
467
438
|
*/
|
|
468
439
|
dispose() {
|
|
440
|
+
// Disable collisions CB so it doesn't fire when the body is disposed
|
|
441
|
+
if (this._collisionCBEnabled) {
|
|
442
|
+
this.setCollisionCallbackEnabled(false);
|
|
443
|
+
}
|
|
469
444
|
if (this._nodeDisposeObserver) {
|
|
470
445
|
this.transformNode.onDisposeObservable.remove(this._nodeDisposeObserver);
|
|
471
446
|
this._nodeDisposeObserver = null;
|
|
@@ -477,6 +452,4 @@ export class PhysicsBody {
|
|
|
477
452
|
this._pluginDataInstances.length = 0;
|
|
478
453
|
}
|
|
479
454
|
}
|
|
480
|
-
PhysicsBody._DEFAULT_OBJECT_SIZE = new Vector3(1, 1, 1);
|
|
481
|
-
PhysicsBody._IDENTITY_QUATERNION = Quaternion.Identity();
|
|
482
455
|
//# sourceMappingURL=physicsBody.js.map
|
|
@@ -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;AAS1E,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,CAAC;QACpC,IAAI,aAAa,CAAC,gBAAgB,EAAE,IAAI,C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AAW,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 { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\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"]}
|
|
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;IAsCpB;;;;;;;;;OASG;IACH,YAAY,aAA4B,EAAE,UAA6B,EAAE,YAAqB,EAAE,KAAY;QA/C5G;;WAEG;QACI,gBAAW,GAA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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;CACJ","sourcesContent":["import type { IPhysicsCollisionEvent, IPhysicsEnginePluginV2, PhysicsMassProperties, 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 * If the collision callback is enabled\r\n */\r\n private _collisionCBEnabled: boolean = false;\r\n /**\r\n * The transform node associated with this Physics Body\r\n */\r\n transformNode: TransformNode;\r\n /**\r\n * Disable pre-step that consists in updating Physics Body from Transform Node Translation/Orientation.\r\n * True by default for maximum performance.\r\n */\r\n disablePreStep: boolean = true;\r\n\r\n /**\r\n * Physics engine will try to make this body sleeping and not active\r\n */\r\n public startAsleep: boolean;\r\n\r\n private _nodeDisposeObserver: Nullable<Observer<Node>>;\r\n\r\n /**\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, startsAsleep: boolean, scene: Scene) {\r\n if (!scene) {\r\n return;\r\n }\r\n const physicsEngine = scene.getPhysicsEngine() as PhysicsEngine;\r\n if (!physicsEngine) {\r\n throw new Error(\"No Physics Engine available.\");\r\n }\r\n this._physicsEngine = physicsEngine;\r\n if (physicsEngine.getPluginVersion() != 2) {\r\n throw new Error(\"Plugin version is incorrect. Expected version 2.\");\r\n }\r\n const physicsPlugin = physicsEngine.getPhysicsPlugin();\r\n if (!physicsPlugin) {\r\n throw new Error(\"No Physics Plugin available.\");\r\n }\r\n\r\n this._physicsPlugin = physicsPlugin as IPhysicsEnginePluginV2;\r\n if (!transformNode.rotationQuaternion) {\r\n transformNode.rotationQuaternion = Quaternion.FromEulerAngles(transformNode.rotation.x, transformNode.rotation.y, transformNode.rotation.z);\r\n }\r\n\r\n this.startAsleep = startsAsleep;\r\n\r\n // 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 * Returns the string \"PhysicsBody\".\r\n * @returns \"PhysicsBody\"\r\n */\r\n public getClassName() {\r\n return \"PhysicsBody\";\r\n }\r\n\r\n /**\r\n * Clone the PhysicsBody to a new body and assign it to the transformNode parameter\r\n * @param transformNode transformNode that will be used for the cloned PhysicsBody\r\n * @returns the newly cloned PhysicsBody\r\n */\r\n public clone(transformNode: TransformNode): PhysicsBody {\r\n const clonedBody = new PhysicsBody(transformNode, this.getMotionType(), this.startAsleep, this.transformNode.getScene());\r\n clonedBody.shape = this.shape;\r\n return clonedBody;\r\n }\r\n\r\n /**\r\n * If a physics body is connected to an instanced node, update the number physic instances to match the number of node instances.\r\n */\r\n public updateBodyInstances() {\r\n const m = this.transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.updateBodyInstances(this, m);\r\n }\r\n }\r\n\r\n /**\r\n * This returns the number of internal instances of the physics body\r\n */\r\n public get numInstances(): number {\r\n return this._pluginDataInstances.length;\r\n }\r\n\r\n /**\r\n * Sets the shape of the physics body.\r\n * @param shape - The shape of the physics body.\r\n *\r\n * This method is useful for setting the shape of the physics body, which is necessary for the physics engine to accurately simulate the body's behavior.\r\n * The shape is used to calculate the body's mass, inertia, and other properties.\r\n */\r\n public set shape(shape: Nullable<PhysicsShape>) {\r\n this._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(): Nullable<PhysicsShape> {\r\n return this._physicsPlugin.getShape(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, instanceIndex?: number) {\r\n this._physicsPlugin.setEventMask(this, eventMask, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the event mask of the physics engine.\r\n *\r\n * @returns The event mask of the physics engine.\r\n *\r\n * This method is useful for getting the event mask of the physics engine,\r\n * which is used to determine which events the engine will respond to.\r\n * This is important for ensuring that the engine is responding to the correct events and not\r\n * wasting resources on unnecessary events.\r\n */\r\n public getEventMask(instanceIndex?: number): number {\r\n return this._physicsPlugin.getEventMask(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.\r\n */\r\n public setMotionType(motionType: PhysicsMotionType, instanceIndex?: number) {\r\n this._physicsPlugin.setMotionType(this, motionType, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.\r\n */\r\n public getMotionType(instanceIndex?: number): PhysicsMotionType {\r\n return this._physicsPlugin.getMotionType(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Computes the mass properties of the physics object, based on the set of physics shapes this body uses.\r\n * This method is useful for computing the initial mass properties of a physics object, such as its mass,\r\n * inertia, and center of mass; these values are important for accurately simulating the physics of the\r\n * object in the physics engine, and computing values based on the shape will provide you with reasonable\r\n * intial values, which you can then customize.\r\n */\r\n public computeMassProperties(instanceIndex?: number): PhysicsMassProperties {\r\n return this._physicsPlugin.computeMassProperties(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the mass properties of the physics object.\r\n *\r\n * @param massProps - The mass properties to set.\r\n * @param instanceIndex - The index of the instance to set the mass properties for. If not defined, the mass properties will be set for all instances.\r\n *\r\n * This method is useful for setting the mass properties of a physics object, such as its mass,\r\n * inertia, and center of mass. This is important for accurately simulating the physics of the object in the physics engine.\r\n */\r\n public setMassProperties(massProps: PhysicsMassProperties, instanceIndex?: number): void {\r\n this._physicsPlugin.setMassProperties(this, massProps, instanceIndex);\r\n }\r\n\r\n /**\r\n * Retrieves the mass properties of the object.\r\n *\r\n * @returns The mass properties of the object.\r\n *\r\n * This method is useful for physics simulations, as it allows the user to\r\n * retrieve the mass properties of the object, such as its mass, center of mass,\r\n * and moment of inertia. This information is necessary for accurate physics\r\n * simulations.\r\n */\r\n public getMassProperties(instanceIndex?: number): PhysicsMassProperties {\r\n return this._physicsPlugin.getMassProperties(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the linear damping of the physics body.\r\n *\r\n * @param damping - The linear damping value.\r\n *\r\n * This method is useful for controlling the linear damping of the physics body,\r\n * which is the rate at which the body's velocity decreases over time. This is useful for simulating\r\n * the effects of air resistance or other forms of friction.\r\n */\r\n public setLinearDamping(damping: number, instanceIndex?: number) {\r\n this._physicsPlugin.setLinearDamping(this, damping, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the linear damping of the physics body.\r\n * @returns The linear damping of the physics body.\r\n *\r\n * This method is useful for retrieving the linear damping of the physics body, which is the amount of\r\n * resistance the body has to linear motion. This is useful for simulating realistic physics behavior\r\n * in a game.\r\n */\r\n public getLinearDamping(instanceIndex?: number): number {\r\n return this._physicsPlugin.getLinearDamping(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the angular damping of the physics body.\r\n * @param damping The angular damping of the body.\r\n *\r\n * This method is useful for controlling the angular velocity of a physics body.\r\n * By setting the damping, the body's angular velocity will be reduced over time, simulating the effect of friction.\r\n * This can be used to create realistic physical behavior in a physics engine.\r\n */\r\n public setAngularDamping(damping: number, instanceIndex?: number) {\r\n this._physicsPlugin.setAngularDamping(this, damping, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the angular damping of the physics body.\r\n *\r\n * @returns The angular damping of the physics body.\r\n *\r\n * This method is useful for getting the angular damping of the physics body,\r\n * which is the rate of reduction of the angular velocity over time.\r\n * This is important for simulating realistic physics behavior in a game.\r\n */\r\n public getAngularDamping(instanceIndex?: number): number {\r\n return this._physicsPlugin.getAngularDamping(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the linear velocity of the physics object.\r\n * @param linVel - The linear velocity to set.\r\n *\r\n * This method is useful for setting the linear velocity of a physics object,\r\n * which is necessary for simulating realistic physics in a game engine.\r\n * By setting the linear velocity, the physics object will move in the direction and speed specified by the vector.\r\n * This allows for realistic physics simulations, such as simulating the motion of a ball rolling down a hill.\r\n */\r\n public setLinearVelocity(linVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.setLinearVelocity(this, linVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the linear velocity of the physics body and stores it in the given vector3.\r\n * @param linVel - The vector3 to store the linear velocity in.\r\n *\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, instanceIndex?: number): void {\r\n return this._physicsPlugin.getLinearVelocityToRef(this, linVel, instanceIndex);\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, instanceIndex?: number): void {\r\n this._physicsPlugin.setAngularVelocity(this, angVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the angular velocity of the physics body and stores it in the given vector3.\r\n * @param angVel - The vector3 to store the angular velocity in.\r\n *\r\n * This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's\r\n * rotational speed. This information can be used to create realistic physics simulations.\r\n */\r\n public getAngularVelocityToRef(angVel: Vector3, instanceIndex?: number): void {\r\n return this._physicsPlugin.getAngularVelocityToRef(this, angVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Applies an impulse to the physics object.\r\n *\r\n * @param impulse The impulse vector.\r\n * @param location The location of the impulse.\r\n * @param instanceIndex For a instanced body, the instance to where the impulse should be applied. If not specified, the impulse is applied to all instances.\r\n *\r\n * This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyImpulse(impulse: Vector3, location: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyImpulse(this, impulse, location, instanceIndex);\r\n }\r\n\r\n /**\r\n * Applies a force to the physics object.\r\n *\r\n * @param force The force vector.\r\n * @param location The location of the force.\r\n * @param instanceIndex For a instanced body, the instance to where the force should be applied. If not specified, the force is applied to all instances.\r\n *\r\n * This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyForce(force: Vector3, location: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyForce(this, force, location, instanceIndex);\r\n }\r\n\r\n /**\r\n * Retrieves the geometry of the body from the physics plugin.\r\n *\r\n * @returns The geometry of the body.\r\n *\r\n * This method is useful for retrieving the geometry of the body from the physics plugin, which can be used for various physics calculations.\r\n */\r\n public getGeometry(): {} {\r\n return this._physicsPlugin.getBodyGeometry(this);\r\n }\r\n\r\n /**\r\n * Returns an observable that will be notified for 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 this._collisionCBEnabled = enabled;\r\n this._physicsPlugin.setCollisionCallbackEnabled(this, enabled);\r\n }\r\n\r\n /*\r\n * Get the center of the object in world space.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the center for.\r\n * @returns geometric center of the associated mesh\r\n */\r\n public getObjectCenterWorld(instanceIndex?: number): Vector3 {\r\n const ref = new Vector3();\r\n return this.getObjectCenterWorldToRef(ref, instanceIndex);\r\n }\r\n\r\n /*\r\n * Get the center of the object in world space.\r\n * @param ref - The vector3 to store the result in.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the center for.\r\n * @returns geometric center of the associated mesh\r\n */\r\n public getObjectCenterWorldToRef(ref: Vector3, instanceIndex?: number): Vector3 {\r\n if (this._pluginDataInstances?.length > 0) {\r\n const index = instanceIndex || 0;\r\n const matrixData = (this.transformNode as Mesh)._thinInstanceDataStorage.matrixData;\r\n if (matrixData) {\r\n ref.set(matrixData[index * 16 + 12], matrixData[index * 16 + 13], matrixData[index * 16 + 14]);\r\n }\r\n } else {\r\n ref.copyFrom(this.transformNode.position);\r\n }\r\n return ref;\r\n }\r\n\r\n /**\r\n * Adds a constraint to the physics engine.\r\n *\r\n * @param childBody - The body to which the constraint will be applied.\r\n * @param constraint - The constraint to be applied.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.\r\n * @param childInstanceIndex - If the child body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.\r\n *\r\n */\r\n public addConstraint(childBody: PhysicsBody, constraint: PhysicsConstraint, instanceIndex?: number, childInstanceIndex?: number): void {\r\n this._physicsPlugin.addConstraint(this, childBody, constraint, instanceIndex, childInstanceIndex);\r\n }\r\n\r\n /**\r\n * Sync with a bone\r\n * @param bone The bone that the impostor will be synced to.\r\n * @param boneMesh The mesh that the bone is influencing.\r\n * @param jointPivot The pivot of the joint / bone in local space.\r\n * @param distToJoint Optional distance from the impostor to the joint.\r\n * @param adjustRotation Optional quaternion for adjusting the local rotation of the bone.\r\n * @param boneAxis Optional vector3 axis the bone is aligned with\r\n */\r\n public syncWithBone(bone: Bone, boneMesh: AbstractMesh, jointPivot: Vector3, distToJoint?: number, adjustRotation?: Quaternion, boneAxis?: Vector3) {\r\n const mesh = this.transformNode;\r\n\r\n if (mesh.rotationQuaternion) {\r\n if (adjustRotation) {\r\n const tempQuat = TmpVectors.Quaternion[0];\r\n bone.getRotationQuaternionToRef(Space.WORLD, boneMesh, tempQuat);\r\n tempQuat.multiplyToRef(adjustRotation, mesh.rotationQuaternion);\r\n } else {\r\n bone.getRotationQuaternionToRef(Space.WORLD, boneMesh, mesh.rotationQuaternion);\r\n }\r\n }\r\n\r\n const pos = TmpVectors.Vector3[0];\r\n const boneDir = TmpVectors.Vector3[1];\r\n\r\n if (!boneAxis) {\r\n boneAxis = TmpVectors.Vector3[2];\r\n boneAxis.x = 0;\r\n boneAxis.y = 1;\r\n boneAxis.z = 0;\r\n }\r\n\r\n bone.getDirectionToRef(boneAxis, boneMesh, boneDir);\r\n bone.getAbsolutePositionToRef(boneMesh, pos);\r\n\r\n if ((distToJoint === undefined || distToJoint === null) && jointPivot) {\r\n distToJoint = jointPivot.length();\r\n }\r\n\r\n if (distToJoint !== undefined && distToJoint !== null) {\r\n pos.x += boneDir.x * distToJoint;\r\n pos.y += boneDir.y * distToJoint;\r\n pos.z += boneDir.z * distToJoint;\r\n }\r\n\r\n mesh.setAbsolutePosition(pos);\r\n }\r\n\r\n /**\r\n * Executes a callback on the body or all of the instances of a body\r\n * @param callback the callback to execute\r\n */\r\n public iterateOverAllInstances(callback: (body: PhysicsBody, instanceIndex?: number) => void) {\r\n if (this._pluginDataInstances?.length > 0) {\r\n for (let i = 0; i < this._pluginDataInstances.length; i++) {\r\n callback(this, i);\r\n }\r\n } else {\r\n callback(this, undefined);\r\n }\r\n }\r\n\r\n /**\r\n * 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 // Disable collisions CB so it doesn't fire when the body is disposed\r\n if (this._collisionCBEnabled) {\r\n this.setCollisionCallbackEnabled(false);\r\n }\r\n if (this._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"]}
|