@babylonjs/core 5.45.1 → 5.45.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/Engines/thinEngine.js +2 -2
  2. package/Engines/thinEngine.js.map +1 -1
  3. package/Inputs/scene.inputManager.js +12 -1
  4. package/Inputs/scene.inputManager.js.map +1 -1
  5. package/Materials/Textures/videoTexture.d.ts +1 -0
  6. package/Materials/Textures/videoTexture.js +19 -8
  7. package/Materials/Textures/videoTexture.js.map +1 -1
  8. package/Physics/index.d.ts +1 -0
  9. package/Physics/index.js +1 -0
  10. package/Physics/index.js.map +1 -1
  11. package/Physics/physicsHelper.d.ts +452 -1
  12. package/Physics/physicsHelper.js +877 -2
  13. package/Physics/physicsHelper.js.map +1 -1
  14. package/Physics/v1/index.d.ts +0 -1
  15. package/Physics/v1/index.js +0 -1
  16. package/Physics/v1/index.js.map +1 -1
  17. package/Physics/v2/IPhysicsEnginePlugin.d.ts +2 -1
  18. package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
  19. package/Physics/v2/index.d.ts +1 -0
  20. package/Physics/v2/index.js +1 -0
  21. package/Physics/v2/index.js.map +1 -1
  22. package/Physics/v2/physicsAggregate.d.ts +18 -0
  23. package/Physics/v2/physicsAggregate.js +44 -2
  24. package/Physics/v2/physicsAggregate.js.map +1 -1
  25. package/Physics/v2/physicsBody.d.ts +22 -1
  26. package/Physics/v2/physicsBody.js +54 -1
  27. package/Physics/v2/physicsBody.js.map +1 -1
  28. package/Physics/v2/physicsEngine.d.ts +7 -2
  29. package/Physics/v2/physicsEngine.js +9 -2
  30. package/Physics/v2/physicsEngine.js.map +1 -1
  31. package/Shaders/ShadersInclude/bumpFragmentMainFunctions.js +4 -1
  32. package/Shaders/ShadersInclude/bumpFragmentMainFunctions.js.map +1 -1
  33. package/package.json +1 -1
  34. package/Physics/v1/physicsHelper.d.ts +0 -411
  35. package/Physics/v1/physicsHelper.js +0 -709
  36. package/Physics/v1/physicsHelper.js.map +0 -1
@@ -1,709 +0,0 @@
1
- import { Logger } from "../../Misc/logger.js";
2
- import { Vector3 } from "../../Maths/math.vector.js";
3
- import { CreateSphere } from "../../Meshes/Builders/sphereBuilder.js";
4
- import { CreateCylinder } from "../../Meshes/Builders/cylinderBuilder.js";
5
- import { Ray } from "../../Culling/ray.js";
6
- /**
7
- * A helper for physics simulations
8
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
9
- */
10
- export class PhysicsHelper {
11
- /**
12
- * Initializes the Physics helper
13
- * @param scene Babylon.js scene
14
- */
15
- constructor(scene) {
16
- this._scene = scene;
17
- this._physicsEngine = this._scene.getPhysicsEngine();
18
- if (!this._physicsEngine) {
19
- Logger.Warn("Physics engine not enabled. Please enable the physics before you can use the methods.");
20
- return;
21
- }
22
- }
23
- /**
24
- * Applies a radial explosion impulse
25
- * @param origin the origin of the explosion
26
- * @param radiusOrEventOptions the radius or the options of radial explosion
27
- * @param strength the explosion strength
28
- * @param falloff possible options: Constant & Linear. Defaults to Constant
29
- * @returns A physics radial explosion event, or null
30
- */
31
- applyRadialExplosionImpulse(origin, radiusOrEventOptions, strength, falloff) {
32
- if (!this._physicsEngine) {
33
- Logger.Warn("Physics engine not enabled. Please enable the physics before you call this method.");
34
- return null;
35
- }
36
- const impostors = this._physicsEngine.getImpostors();
37
- if (impostors.length === 0) {
38
- return null;
39
- }
40
- if (typeof radiusOrEventOptions === "number") {
41
- radiusOrEventOptions = new PhysicsRadialExplosionEventOptions();
42
- radiusOrEventOptions.radius = radiusOrEventOptions;
43
- radiusOrEventOptions.strength = strength || radiusOrEventOptions.strength;
44
- radiusOrEventOptions.falloff = falloff || radiusOrEventOptions.falloff;
45
- }
46
- const event = new PhysicsRadialExplosionEvent(this._scene, radiusOrEventOptions);
47
- const affectedImpostorsWithData = Array();
48
- impostors.forEach((impostor) => {
49
- const impostorHitData = event.getImpostorHitData(impostor, origin);
50
- if (!impostorHitData) {
51
- return;
52
- }
53
- impostor.applyImpulse(impostorHitData.force, impostorHitData.contactPoint);
54
- affectedImpostorsWithData.push({
55
- impostor: impostor,
56
- hitData: impostorHitData,
57
- });
58
- });
59
- event.triggerAffectedImpostorsCallback(affectedImpostorsWithData);
60
- event.dispose(false);
61
- return event;
62
- }
63
- /**
64
- * Applies a radial explosion force
65
- * @param origin the origin of the explosion
66
- * @param radiusOrEventOptions the radius or the options of radial explosion
67
- * @param strength the explosion strength
68
- * @param falloff possible options: Constant & Linear. Defaults to Constant
69
- * @returns A physics radial explosion event, or null
70
- */
71
- applyRadialExplosionForce(origin, radiusOrEventOptions, strength, falloff) {
72
- if (!this._physicsEngine) {
73
- Logger.Warn("Physics engine not enabled. Please enable the physics before you call the PhysicsHelper.");
74
- return null;
75
- }
76
- const impostors = this._physicsEngine.getImpostors();
77
- if (impostors.length === 0) {
78
- return null;
79
- }
80
- if (typeof radiusOrEventOptions === "number") {
81
- radiusOrEventOptions = new PhysicsRadialExplosionEventOptions();
82
- radiusOrEventOptions.radius = radiusOrEventOptions;
83
- radiusOrEventOptions.strength = strength || radiusOrEventOptions.strength;
84
- radiusOrEventOptions.falloff = falloff || radiusOrEventOptions.falloff;
85
- }
86
- const event = new PhysicsRadialExplosionEvent(this._scene, radiusOrEventOptions);
87
- const affectedImpostorsWithData = Array();
88
- impostors.forEach((impostor) => {
89
- const impostorHitData = event.getImpostorHitData(impostor, origin);
90
- if (!impostorHitData) {
91
- return;
92
- }
93
- impostor.applyForce(impostorHitData.force, impostorHitData.contactPoint);
94
- affectedImpostorsWithData.push({
95
- impostor: impostor,
96
- hitData: impostorHitData,
97
- });
98
- });
99
- event.triggerAffectedImpostorsCallback(affectedImpostorsWithData);
100
- event.dispose(false);
101
- return event;
102
- }
103
- /**
104
- * Creates a gravitational field
105
- * @param origin the origin of the explosion
106
- * @param radiusOrEventOptions the radius or the options of radial explosion
107
- * @param strength the explosion strength
108
- * @param falloff possible options: Constant & Linear. Defaults to Constant
109
- * @returns A physics gravitational field event, or null
110
- */
111
- gravitationalField(origin, radiusOrEventOptions, strength, falloff) {
112
- if (!this._physicsEngine) {
113
- Logger.Warn("Physics engine not enabled. Please enable the physics before you call the PhysicsHelper.");
114
- return null;
115
- }
116
- const impostors = this._physicsEngine.getImpostors();
117
- if (impostors.length === 0) {
118
- return null;
119
- }
120
- if (typeof radiusOrEventOptions === "number") {
121
- radiusOrEventOptions = new PhysicsRadialExplosionEventOptions();
122
- radiusOrEventOptions.radius = radiusOrEventOptions;
123
- radiusOrEventOptions.strength = strength || radiusOrEventOptions.strength;
124
- radiusOrEventOptions.falloff = falloff || radiusOrEventOptions.falloff;
125
- }
126
- const event = new PhysicsGravitationalFieldEvent(this, this._scene, origin, radiusOrEventOptions);
127
- event.dispose(false);
128
- return event;
129
- }
130
- /**
131
- * Creates a physics updraft event
132
- * @param origin the origin of the updraft
133
- * @param radiusOrEventOptions the radius or the options of the updraft
134
- * @param strength the strength of the updraft
135
- * @param height the height of the updraft
136
- * @param updraftMode possible options: Center & Perpendicular. Defaults to Center
137
- * @returns A physics updraft event, or null
138
- */
139
- updraft(origin, radiusOrEventOptions, strength, height, updraftMode) {
140
- if (!this._physicsEngine) {
141
- Logger.Warn("Physics engine not enabled. Please enable the physics before you call the PhysicsHelper.");
142
- return null;
143
- }
144
- if (this._physicsEngine.getImpostors().length === 0) {
145
- return null;
146
- }
147
- if (typeof radiusOrEventOptions === "number") {
148
- radiusOrEventOptions = new PhysicsUpdraftEventOptions();
149
- radiusOrEventOptions.radius = radiusOrEventOptions;
150
- radiusOrEventOptions.strength = strength || radiusOrEventOptions.strength;
151
- radiusOrEventOptions.height = height || radiusOrEventOptions.height;
152
- radiusOrEventOptions.updraftMode = updraftMode || radiusOrEventOptions.updraftMode;
153
- }
154
- const event = new PhysicsUpdraftEvent(this._scene, origin, radiusOrEventOptions);
155
- event.dispose(false);
156
- return event;
157
- }
158
- /**
159
- * Creates a physics vortex event
160
- * @param origin the of the vortex
161
- * @param radiusOrEventOptions the radius or the options of the vortex
162
- * @param strength the strength of the vortex
163
- * @param height the height of the vortex
164
- * @returns a Physics vortex event, or null
165
- * A physics vortex event or null
166
- */
167
- vortex(origin, radiusOrEventOptions, strength, height) {
168
- if (!this._physicsEngine) {
169
- Logger.Warn("Physics engine not enabled. Please enable the physics before you call the PhysicsHelper.");
170
- return null;
171
- }
172
- if (this._physicsEngine.getImpostors().length === 0) {
173
- return null;
174
- }
175
- if (typeof radiusOrEventOptions === "number") {
176
- radiusOrEventOptions = new PhysicsVortexEventOptions();
177
- radiusOrEventOptions.radius = radiusOrEventOptions;
178
- radiusOrEventOptions.strength = strength || radiusOrEventOptions.strength;
179
- radiusOrEventOptions.height = height || radiusOrEventOptions.height;
180
- }
181
- const event = new PhysicsVortexEvent(this._scene, origin, radiusOrEventOptions);
182
- event.dispose(false);
183
- return event;
184
- }
185
- }
186
- /**
187
- * Represents a physics radial explosion event
188
- */
189
- class PhysicsRadialExplosionEvent {
190
- /**
191
- * Initializes a radial explosion event
192
- * @param _scene BabylonJS scene
193
- * @param _options The options for the vortex event
194
- */
195
- constructor(_scene, _options) {
196
- this._scene = _scene;
197
- this._options = _options;
198
- this._dataFetched = false; // check if the data has been fetched. If not, do cleanup
199
- this._options = { ...new PhysicsRadialExplosionEventOptions(), ...this._options };
200
- }
201
- /**
202
- * Returns the data related to the radial explosion event (sphere).
203
- * @returns The radial explosion event data
204
- */
205
- getData() {
206
- this._dataFetched = true;
207
- return {
208
- sphere: this._sphere,
209
- };
210
- }
211
- /**
212
- * Returns the force and contact point of the impostor or false, if the impostor is not affected by the force/impulse.
213
- * @param impostor A physics imposter
214
- * @param origin the origin of the explosion
215
- * @returns {Nullable<PhysicsHitData>} A physics force and contact point, or null
216
- */
217
- getImpostorHitData(impostor, origin) {
218
- if (impostor.mass === 0) {
219
- return null;
220
- }
221
- if (!this._intersectsWithSphere(impostor, origin, this._options.radius)) {
222
- return null;
223
- }
224
- if (impostor.object.getClassName() !== "Mesh" && impostor.object.getClassName() !== "InstancedMesh") {
225
- return null;
226
- }
227
- const impostorObjectCenter = impostor.getObjectCenter();
228
- const direction = impostorObjectCenter.subtract(origin);
229
- const ray = new Ray(origin, direction, this._options.radius);
230
- const hit = ray.intersectsMesh(impostor.object);
231
- const contactPoint = hit.pickedPoint;
232
- if (!contactPoint) {
233
- return null;
234
- }
235
- const distanceFromOrigin = Vector3.Distance(origin, contactPoint);
236
- if (distanceFromOrigin > this._options.radius) {
237
- return null;
238
- }
239
- const multiplier = this._options.falloff === PhysicsRadialImpulseFalloff.Constant ? this._options.strength : this._options.strength * (1 - distanceFromOrigin / this._options.radius);
240
- const force = direction.multiplyByFloats(multiplier, multiplier, multiplier);
241
- return { force: force, contactPoint: contactPoint, distanceFromOrigin: distanceFromOrigin };
242
- }
243
- /**
244
- * Triggers affected impostors callbacks
245
- * @param affectedImpostorsWithData defines the list of affected impostors (including associated data)
246
- */
247
- triggerAffectedImpostorsCallback(affectedImpostorsWithData) {
248
- if (this._options.affectedImpostorsCallback) {
249
- this._options.affectedImpostorsCallback(affectedImpostorsWithData);
250
- }
251
- }
252
- /**
253
- * Disposes the sphere.
254
- * @param force Specifies if the sphere should be disposed by force
255
- */
256
- dispose(force = true) {
257
- if (force) {
258
- this._sphere.dispose();
259
- }
260
- else {
261
- setTimeout(() => {
262
- if (!this._dataFetched) {
263
- this._sphere.dispose();
264
- }
265
- }, 0);
266
- }
267
- }
268
- /*** Helpers ***/
269
- _prepareSphere() {
270
- if (!this._sphere) {
271
- this._sphere = CreateSphere("radialExplosionEventSphere", this._options.sphere, this._scene);
272
- this._sphere.isVisible = false;
273
- }
274
- }
275
- _intersectsWithSphere(impostor, origin, radius) {
276
- const impostorObject = impostor.object;
277
- this._prepareSphere();
278
- this._sphere.position = origin;
279
- this._sphere.scaling = new Vector3(radius * 2, radius * 2, radius * 2);
280
- this._sphere._updateBoundingInfo();
281
- this._sphere.computeWorldMatrix(true);
282
- return this._sphere.intersectsMesh(impostorObject, true);
283
- }
284
- }
285
- /**
286
- * Represents a gravitational field event
287
- */
288
- class PhysicsGravitationalFieldEvent {
289
- /**
290
- * Initializes the physics gravitational field event
291
- * @param _physicsHelper A physics helper
292
- * @param _scene BabylonJS scene
293
- * @param _origin The origin position of the gravitational field event
294
- * @param _options The options for the vortex event
295
- */
296
- constructor(_physicsHelper, _scene, _origin, _options) {
297
- this._physicsHelper = _physicsHelper;
298
- this._scene = _scene;
299
- this._origin = _origin;
300
- this._options = _options;
301
- this._dataFetched = false; // check if the has been fetched the data. If not, do cleanup
302
- this._options = { ...new PhysicsRadialExplosionEventOptions(), ...this._options };
303
- this._tickCallback = this._tick.bind(this);
304
- this._options.strength = this._options.strength * -1;
305
- }
306
- /**
307
- * Returns the data related to the gravitational field event (sphere).
308
- * @returns A gravitational field event
309
- */
310
- getData() {
311
- this._dataFetched = true;
312
- return {
313
- sphere: this._sphere,
314
- };
315
- }
316
- /**
317
- * Enables the gravitational field.
318
- */
319
- enable() {
320
- this._tickCallback.call(this);
321
- this._scene.registerBeforeRender(this._tickCallback);
322
- }
323
- /**
324
- * Disables the gravitational field.
325
- */
326
- disable() {
327
- this._scene.unregisterBeforeRender(this._tickCallback);
328
- }
329
- /**
330
- * Disposes the sphere.
331
- * @param force The force to dispose from the gravitational field event
332
- */
333
- dispose(force = true) {
334
- if (force) {
335
- this._sphere.dispose();
336
- }
337
- else {
338
- setTimeout(() => {
339
- if (!this._dataFetched) {
340
- this._sphere.dispose();
341
- }
342
- }, 0);
343
- }
344
- }
345
- _tick() {
346
- // Since the params won't change, we fetch the event only once
347
- if (this._sphere) {
348
- this._physicsHelper.applyRadialExplosionForce(this._origin, this._options);
349
- }
350
- else {
351
- const radialExplosionEvent = this._physicsHelper.applyRadialExplosionForce(this._origin, this._options);
352
- if (radialExplosionEvent) {
353
- this._sphere = radialExplosionEvent.getData().sphere.clone("radialExplosionEventSphereClone");
354
- }
355
- }
356
- }
357
- }
358
- /**
359
- * Represents a physics updraft event
360
- */
361
- class PhysicsUpdraftEvent {
362
- /**
363
- * Initializes the physics updraft event
364
- * @param _scene BabylonJS scene
365
- * @param _origin The origin position of the updraft
366
- * @param _options The options for the updraft event
367
- */
368
- constructor(_scene, _origin, _options) {
369
- this._scene = _scene;
370
- this._origin = _origin;
371
- this._options = _options;
372
- this._originTop = Vector3.Zero(); // the most upper part of the cylinder
373
- this._originDirection = Vector3.Zero(); // used if the updraftMode is perpendicular
374
- this._cylinderPosition = Vector3.Zero(); // to keep the cylinders position, because normally the origin is in the center and not on the bottom
375
- this._dataFetched = false; // check if the has been fetched the data. If not, do cleanup
376
- this._physicsEngine = this._scene.getPhysicsEngine();
377
- this._options = { ...new PhysicsUpdraftEventOptions(), ...this._options };
378
- this._origin.addToRef(new Vector3(0, this._options.height / 2, 0), this._cylinderPosition);
379
- this._origin.addToRef(new Vector3(0, this._options.height, 0), this._originTop);
380
- if (this._options.updraftMode === PhysicsUpdraftMode.Perpendicular) {
381
- this._originDirection = this._origin.subtract(this._originTop).normalize();
382
- }
383
- this._tickCallback = this._tick.bind(this);
384
- this._prepareCylinder();
385
- }
386
- /**
387
- * Returns the data related to the updraft event (cylinder).
388
- * @returns A physics updraft event
389
- */
390
- getData() {
391
- this._dataFetched = true;
392
- return {
393
- cylinder: this._cylinder,
394
- };
395
- }
396
- /**
397
- * Enables the updraft.
398
- */
399
- enable() {
400
- this._tickCallback.call(this);
401
- this._scene.registerBeforeRender(this._tickCallback);
402
- }
403
- /**
404
- * Disables the updraft.
405
- */
406
- disable() {
407
- this._scene.unregisterBeforeRender(this._tickCallback);
408
- }
409
- /**
410
- * Disposes the cylinder.
411
- * @param force Specifies if the updraft should be disposed by force
412
- */
413
- dispose(force = true) {
414
- if (!this._cylinder) {
415
- return;
416
- }
417
- if (force) {
418
- this._cylinder.dispose();
419
- }
420
- else {
421
- setTimeout(() => {
422
- if (!this._dataFetched) {
423
- this._cylinder.dispose();
424
- }
425
- }, 0);
426
- }
427
- }
428
- _getImpostorHitData(impostor) {
429
- if (impostor.mass === 0) {
430
- return null;
431
- }
432
- if (!this._intersectsWithCylinder(impostor)) {
433
- return null;
434
- }
435
- const impostorObjectCenter = impostor.getObjectCenter();
436
- let direction;
437
- if (this._options.updraftMode === PhysicsUpdraftMode.Perpendicular) {
438
- direction = this._originDirection;
439
- }
440
- else {
441
- direction = impostorObjectCenter.subtract(this._originTop);
442
- }
443
- const distanceFromOrigin = Vector3.Distance(this._origin, impostorObjectCenter);
444
- const multiplier = this._options.strength * -1;
445
- const force = direction.multiplyByFloats(multiplier, multiplier, multiplier);
446
- return { force: force, contactPoint: impostorObjectCenter, distanceFromOrigin: distanceFromOrigin };
447
- }
448
- _tick() {
449
- this._physicsEngine.getImpostors().forEach((impostor) => {
450
- const impostorHitData = this._getImpostorHitData(impostor);
451
- if (!impostorHitData) {
452
- return;
453
- }
454
- impostor.applyForce(impostorHitData.force, impostorHitData.contactPoint);
455
- });
456
- }
457
- /*** Helpers ***/
458
- _prepareCylinder() {
459
- if (!this._cylinder) {
460
- this._cylinder = CreateCylinder("updraftEventCylinder", {
461
- height: this._options.height,
462
- diameter: this._options.radius * 2,
463
- }, this._scene);
464
- this._cylinder.isVisible = false;
465
- }
466
- }
467
- _intersectsWithCylinder(impostor) {
468
- const impostorObject = impostor.object;
469
- this._cylinder.position = this._cylinderPosition;
470
- return this._cylinder.intersectsMesh(impostorObject, true);
471
- }
472
- }
473
- /**
474
- * Represents a physics vortex event
475
- */
476
- class PhysicsVortexEvent {
477
- /**
478
- * Initializes the physics vortex event
479
- * @param _scene The BabylonJS scene
480
- * @param _origin The origin position of the vortex
481
- * @param _options The options for the vortex event
482
- */
483
- constructor(_scene, _origin, _options) {
484
- this._scene = _scene;
485
- this._origin = _origin;
486
- this._options = _options;
487
- this._originTop = Vector3.Zero(); // the most upper part of the cylinder
488
- this._cylinderPosition = Vector3.Zero(); // to keep the cylinders position, because normally the origin is in the center and not on the bottom
489
- this._dataFetched = false; // check if the has been fetched the data. If not, do cleanup
490
- this._physicsEngine = this._scene.getPhysicsEngine();
491
- this._options = { ...new PhysicsVortexEventOptions(), ...this._options };
492
- this._origin.addToRef(new Vector3(0, this._options.height / 2, 0), this._cylinderPosition);
493
- this._origin.addToRef(new Vector3(0, this._options.height, 0), this._originTop);
494
- this._tickCallback = this._tick.bind(this);
495
- this._prepareCylinder();
496
- }
497
- /**
498
- * Returns the data related to the vortex event (cylinder).
499
- * @returns The physics vortex event data
500
- */
501
- getData() {
502
- this._dataFetched = true;
503
- return {
504
- cylinder: this._cylinder,
505
- };
506
- }
507
- /**
508
- * Enables the vortex.
509
- */
510
- enable() {
511
- this._tickCallback.call(this);
512
- this._scene.registerBeforeRender(this._tickCallback);
513
- }
514
- /**
515
- * Disables the cortex.
516
- */
517
- disable() {
518
- this._scene.unregisterBeforeRender(this._tickCallback);
519
- }
520
- /**
521
- * Disposes the sphere.
522
- * @param force
523
- */
524
- dispose(force = true) {
525
- if (force) {
526
- this._cylinder.dispose();
527
- }
528
- else {
529
- setTimeout(() => {
530
- if (!this._dataFetched) {
531
- this._cylinder.dispose();
532
- }
533
- }, 0);
534
- }
535
- }
536
- _getImpostorHitData(impostor) {
537
- if (impostor.mass === 0) {
538
- return null;
539
- }
540
- if (!this._intersectsWithCylinder(impostor)) {
541
- return null;
542
- }
543
- if (impostor.object.getClassName() !== "Mesh" && impostor.object.getClassName() !== "InstancedMesh") {
544
- return null;
545
- }
546
- const impostorObjectCenter = impostor.getObjectCenter();
547
- const originOnPlane = new Vector3(this._origin.x, impostorObjectCenter.y, this._origin.z); // the distance to the origin as if both objects were on a plane (Y-axis)
548
- const originToImpostorDirection = impostorObjectCenter.subtract(originOnPlane);
549
- const ray = new Ray(originOnPlane, originToImpostorDirection, this._options.radius);
550
- const hit = ray.intersectsMesh(impostor.object);
551
- const contactPoint = hit.pickedPoint;
552
- if (!contactPoint) {
553
- return null;
554
- }
555
- const absoluteDistanceFromOrigin = hit.distance / this._options.radius;
556
- let directionToOrigin = contactPoint.normalize();
557
- if (absoluteDistanceFromOrigin > this._options.centripetalForceThreshold) {
558
- directionToOrigin = directionToOrigin.negate();
559
- }
560
- let forceX;
561
- let forceY;
562
- let forceZ;
563
- if (absoluteDistanceFromOrigin > this._options.centripetalForceThreshold) {
564
- forceX = directionToOrigin.x * this._options.centripetalForceMultiplier;
565
- forceY = directionToOrigin.y * this._options.updraftForceMultiplier;
566
- forceZ = directionToOrigin.z * this._options.centripetalForceMultiplier;
567
- }
568
- else {
569
- const perpendicularDirection = Vector3.Cross(originOnPlane, impostorObjectCenter).normalize();
570
- forceX = (perpendicularDirection.x + directionToOrigin.x) * this._options.centrifugalForceMultiplier;
571
- forceY = this._originTop.y * this._options.updraftForceMultiplier;
572
- forceZ = (perpendicularDirection.z + directionToOrigin.z) * this._options.centrifugalForceMultiplier;
573
- }
574
- let force = new Vector3(forceX, forceY, forceZ);
575
- force = force.multiplyByFloats(this._options.strength, this._options.strength, this._options.strength);
576
- return { force: force, contactPoint: impostorObjectCenter, distanceFromOrigin: absoluteDistanceFromOrigin };
577
- }
578
- _tick() {
579
- this._physicsEngine.getImpostors().forEach((impostor) => {
580
- const impostorHitData = this._getImpostorHitData(impostor);
581
- if (!impostorHitData) {
582
- return;
583
- }
584
- impostor.applyForce(impostorHitData.force, impostorHitData.contactPoint);
585
- });
586
- }
587
- /*** Helpers ***/
588
- _prepareCylinder() {
589
- if (!this._cylinder) {
590
- this._cylinder = CreateCylinder("vortexEventCylinder", {
591
- height: this._options.height,
592
- diameter: this._options.radius * 2,
593
- }, this._scene);
594
- this._cylinder.isVisible = false;
595
- }
596
- }
597
- _intersectsWithCylinder(impostor) {
598
- const impostorObject = impostor.object;
599
- this._cylinder.position = this._cylinderPosition;
600
- return this._cylinder.intersectsMesh(impostorObject, true);
601
- }
602
- }
603
- /**
604
- * Options fot the radial explosion event
605
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
606
- */
607
- export class PhysicsRadialExplosionEventOptions {
608
- constructor() {
609
- /**
610
- * The radius of the sphere for the radial explosion.
611
- */
612
- this.radius = 5;
613
- /**
614
- * The strength of the explosion.
615
- */
616
- this.strength = 10;
617
- /**
618
- * The strength of the force in correspondence to the distance of the affected object
619
- */
620
- this.falloff = PhysicsRadialImpulseFalloff.Constant;
621
- /**
622
- * Sphere options for the radial explosion.
623
- */
624
- this.sphere = { segments: 32, diameter: 1 };
625
- }
626
- }
627
- /**
628
- * Options fot the updraft event
629
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
630
- */
631
- export class PhysicsUpdraftEventOptions {
632
- constructor() {
633
- /**
634
- * The radius of the cylinder for the vortex
635
- */
636
- this.radius = 5;
637
- /**
638
- * The strength of the updraft.
639
- */
640
- this.strength = 10;
641
- /**
642
- * The height of the cylinder for the updraft.
643
- */
644
- this.height = 10;
645
- /**
646
- * The mode for the the updraft.
647
- */
648
- this.updraftMode = PhysicsUpdraftMode.Center;
649
- }
650
- }
651
- /**
652
- * Options fot the vortex event
653
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
654
- */
655
- export class PhysicsVortexEventOptions {
656
- constructor() {
657
- /**
658
- * The radius of the cylinder for the vortex
659
- */
660
- this.radius = 5;
661
- /**
662
- * The strength of the vortex.
663
- */
664
- this.strength = 10;
665
- /**
666
- * The height of the cylinder for the vortex.
667
- */
668
- this.height = 10;
669
- /**
670
- * At which distance, relative to the radius the centripetal forces should kick in? Range: 0-1
671
- */
672
- this.centripetalForceThreshold = 0.7;
673
- /**
674
- * This multiplier determines with how much force the objects will be pushed sideways/around the vortex, when below the threshold.
675
- */
676
- this.centripetalForceMultiplier = 5;
677
- /**
678
- * This multiplier determines with how much force the objects will be pushed sideways/around the vortex, when above the threshold.
679
- */
680
- this.centrifugalForceMultiplier = 0.5;
681
- /**
682
- * This multiplier determines with how much force the objects will be pushed upwards, when in the vortex.
683
- */
684
- this.updraftForceMultiplier = 0.02;
685
- }
686
- }
687
- /**
688
- * The strength of the force in correspondence to the distance of the affected object
689
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
690
- */
691
- export var PhysicsRadialImpulseFalloff;
692
- (function (PhysicsRadialImpulseFalloff) {
693
- /** Defines that impulse is constant in strength across it's whole radius */
694
- PhysicsRadialImpulseFalloff[PhysicsRadialImpulseFalloff["Constant"] = 0] = "Constant";
695
- /** Defines that impulse gets weaker if it's further from the origin */
696
- PhysicsRadialImpulseFalloff[PhysicsRadialImpulseFalloff["Linear"] = 1] = "Linear";
697
- })(PhysicsRadialImpulseFalloff || (PhysicsRadialImpulseFalloff = {}));
698
- /**
699
- * The strength of the force in correspondence to the distance of the affected object
700
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine#further-functionality-of-the-impostor-class
701
- */
702
- export var PhysicsUpdraftMode;
703
- (function (PhysicsUpdraftMode) {
704
- /** Defines that the upstream forces will pull towards the top center of the cylinder */
705
- PhysicsUpdraftMode[PhysicsUpdraftMode["Center"] = 0] = "Center";
706
- /** Defines that once a impostor is inside the cylinder, it will shoot out perpendicular from the ground of the cylinder */
707
- PhysicsUpdraftMode[PhysicsUpdraftMode["Perpendicular"] = 1] = "Perpendicular";
708
- })(PhysicsUpdraftMode || (PhysicsUpdraftMode = {}));
709
- //# sourceMappingURL=physicsHelper.js.map