@onerjs/core 8.49.9 → 8.50.1
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.
|
@@ -352,6 +352,10 @@ export class HavokPlugin {
|
|
|
352
352
|
* Name of the plugin
|
|
353
353
|
*/
|
|
354
354
|
this.name = "HavokPlugin";
|
|
355
|
+
/**
|
|
356
|
+
* Indicates whether the plugin has been disposed
|
|
357
|
+
*/
|
|
358
|
+
this._isDisposed = false;
|
|
355
359
|
this._multiQueryCollector = undefined;
|
|
356
360
|
this._fixedTimeStep = 1 / 60;
|
|
357
361
|
this._maxQueryCollectorHits = 1;
|
|
@@ -427,6 +431,9 @@ export class HavokPlugin {
|
|
|
427
431
|
* This is useful for planetary scenarios where gravity direction varies by location.
|
|
428
432
|
*/
|
|
429
433
|
setGravity(gravity, worldPosition) {
|
|
434
|
+
if (this._isDisposed) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
430
437
|
const gravityArray = this._bVecToV3(gravity);
|
|
431
438
|
if (worldPosition) {
|
|
432
439
|
// Set gravity for a specific region based on world position
|
|
@@ -451,6 +458,9 @@ export class HavokPlugin {
|
|
|
451
458
|
* @returns The gravity vector.
|
|
452
459
|
*/
|
|
453
460
|
getGravity(worldPosition) {
|
|
461
|
+
if (this._isDisposed) {
|
|
462
|
+
return Vector3.Zero();
|
|
463
|
+
}
|
|
454
464
|
if (worldPosition) {
|
|
455
465
|
const region = this._getOrCreateWorldRegion(worldPosition);
|
|
456
466
|
return new Vector3(region.gravity[0], region.gravity[1], region.gravity[2]);
|
|
@@ -464,6 +474,9 @@ export class HavokPlugin {
|
|
|
464
474
|
*
|
|
465
475
|
*/
|
|
466
476
|
setTimeStep(timeStep) {
|
|
477
|
+
if (this._isDisposed) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
467
480
|
this._fixedTimeStep = timeStep;
|
|
468
481
|
}
|
|
469
482
|
/**
|
|
@@ -473,6 +486,9 @@ export class HavokPlugin {
|
|
|
473
486
|
*
|
|
474
487
|
*/
|
|
475
488
|
getTimeStep() {
|
|
489
|
+
if (this._isDisposed) {
|
|
490
|
+
return 1 / 60;
|
|
491
|
+
}
|
|
476
492
|
return this._fixedTimeStep;
|
|
477
493
|
}
|
|
478
494
|
/**
|
|
@@ -481,6 +497,9 @@ export class HavokPlugin {
|
|
|
481
497
|
* @param maxQueryCollectorHits - The maximum number of raycast hits to process.
|
|
482
498
|
*/
|
|
483
499
|
setMaxQueryCollectorHits(maxQueryCollectorHits) {
|
|
500
|
+
if (this._isDisposed) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
484
503
|
if (maxQueryCollectorHits === this._maxQueryCollectorHits) {
|
|
485
504
|
return;
|
|
486
505
|
}
|
|
@@ -498,6 +517,9 @@ export class HavokPlugin {
|
|
|
498
517
|
* @returns The maximum number of raycast hits to process.
|
|
499
518
|
*/
|
|
500
519
|
getMaxQueryCollectorHits() {
|
|
520
|
+
if (this._isDisposed) {
|
|
521
|
+
return 1;
|
|
522
|
+
}
|
|
501
523
|
return this._maxQueryCollectorHits;
|
|
502
524
|
}
|
|
503
525
|
/**
|
|
@@ -511,6 +533,9 @@ export class HavokPlugin {
|
|
|
511
533
|
* to accurately simulate the physics bodies in the world.
|
|
512
534
|
*/
|
|
513
535
|
executeStep(delta, physicsBodies) {
|
|
536
|
+
if (this._isDisposed) {
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
514
539
|
// Re-region bodies that have moved outside their current world region
|
|
515
540
|
// BEFORE pre-step and stepping, so the body participates in the correct
|
|
516
541
|
// world's step and its body buffer transform is valid when sync reads it.
|
|
@@ -595,6 +620,9 @@ export class HavokPlugin {
|
|
|
595
620
|
* and orientation to a transform and sets the body's transform to the given values.
|
|
596
621
|
*/
|
|
597
622
|
initBody(body, motionType, position, orientation) {
|
|
623
|
+
if (this._isDisposed) {
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
598
626
|
body._pluginData = new BodyPluginData(this._hknp.HP_Body_Create()[1]);
|
|
599
627
|
this._internalSetMotionType(body._pluginData, motionType);
|
|
600
628
|
// Get the world region for this body's position
|
|
@@ -612,6 +640,9 @@ export class HavokPlugin {
|
|
|
612
640
|
* @param body - The body to remove.
|
|
613
641
|
*/
|
|
614
642
|
removeBody(body) {
|
|
643
|
+
if (this._isDisposed) {
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
615
646
|
if (body._pluginDataInstances && body._pluginDataInstances.length > 0) {
|
|
616
647
|
for (const instance of body._pluginDataInstances) {
|
|
617
648
|
this._bodyCollisionObservable.delete(instance.hpBodyId[0]);
|
|
@@ -639,6 +670,9 @@ export class HavokPlugin {
|
|
|
639
670
|
* world.
|
|
640
671
|
*/
|
|
641
672
|
initBodyInstances(body, motionType, mesh) {
|
|
673
|
+
if (this._isDisposed) {
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
642
676
|
const instancesCount = mesh._thinInstanceDataStorage?.instancesCount ?? 0;
|
|
643
677
|
const matrixData = mesh._thinInstanceDataStorage.matrixData;
|
|
644
678
|
if (!matrixData) {
|
|
@@ -651,6 +685,9 @@ export class HavokPlugin {
|
|
|
651
685
|
}
|
|
652
686
|
}
|
|
653
687
|
_createOrUpdateBodyInstances(body, motionType, matrixData, startIndex, endIndex, update) {
|
|
688
|
+
if (this._isDisposed) {
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
654
691
|
const rotation = TmpVectors.Quaternion[0];
|
|
655
692
|
const rotationMatrix = Matrix.Identity();
|
|
656
693
|
const worldPos = TmpVectors.Vector3[0];
|
|
@@ -699,6 +736,9 @@ export class HavokPlugin {
|
|
|
699
736
|
* @param mesh the mesh with reference instances
|
|
700
737
|
*/
|
|
701
738
|
updateBodyInstances(body, mesh) {
|
|
739
|
+
if (this._isDisposed) {
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
702
742
|
const instancesCount = mesh._thinInstanceDataStorage?.instancesCount ?? 0;
|
|
703
743
|
const matrixData = mesh._thinInstanceDataStorage.matrixData;
|
|
704
744
|
if (!matrixData) {
|
|
@@ -739,6 +779,9 @@ export class HavokPlugin {
|
|
|
739
779
|
* This is important for ensuring that the physics body is accurately represented in the physics engine.
|
|
740
780
|
*/
|
|
741
781
|
sync(body) {
|
|
782
|
+
if (this._isDisposed) {
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
742
785
|
this.syncTransform(body, body.transformNode);
|
|
743
786
|
}
|
|
744
787
|
/**
|
|
@@ -756,6 +799,9 @@ export class HavokPlugin {
|
|
|
756
799
|
* physical behavior of the body.
|
|
757
800
|
*/
|
|
758
801
|
syncTransform(body, transformNode) {
|
|
802
|
+
if (this._isDisposed) {
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
759
805
|
// Get the floating origin offset - this was subtracted when positions were sent to Havok
|
|
760
806
|
// We need to add it back to get the correct world position
|
|
761
807
|
if (body._pluginDataInstances.length) {
|
|
@@ -849,6 +895,9 @@ export class HavokPlugin {
|
|
|
849
895
|
* will set the shape for each instance of the mesh.
|
|
850
896
|
*/
|
|
851
897
|
setShape(body, shape) {
|
|
898
|
+
if (this._isDisposed) {
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
852
901
|
const shapeHandle = shape && shape._pluginData ? shape._pluginData : BigInt(0);
|
|
853
902
|
if (!(body.transformNode instanceof Mesh) || !body.transformNode._thinInstanceDataStorage?.matrixData) {
|
|
854
903
|
if (body._pluginData) {
|
|
@@ -883,6 +932,9 @@ export class HavokPlugin {
|
|
|
883
932
|
*
|
|
884
933
|
*/
|
|
885
934
|
getShape(body) {
|
|
935
|
+
if (this._isDisposed) {
|
|
936
|
+
return null;
|
|
937
|
+
}
|
|
886
938
|
const pluginRef = this._getPluginReference(body);
|
|
887
939
|
const shapePluginData = this._hknp.HP_Body_GetShape(pluginRef.hpBodyId)[1];
|
|
888
940
|
if (shapePluginData != 0) {
|
|
@@ -898,6 +950,9 @@ export class HavokPlugin {
|
|
|
898
950
|
*
|
|
899
951
|
*/
|
|
900
952
|
getShapeType(shape) {
|
|
953
|
+
if (this._isDisposed) {
|
|
954
|
+
return 0 /* PhysicsShapeType.SPHERE */;
|
|
955
|
+
}
|
|
901
956
|
if (shape.type) {
|
|
902
957
|
return shape.type;
|
|
903
958
|
}
|
|
@@ -915,6 +970,9 @@ export class HavokPlugin {
|
|
|
915
970
|
* This function is useful for setting the event mask of a physics body, which is used to determine which events the body will respond to. This is important for ensuring that the physics engine is able to accurately simulate the behavior of the body in the game world.
|
|
916
971
|
*/
|
|
917
972
|
setEventMask(body, eventMask, instanceIndex) {
|
|
973
|
+
if (this._isDisposed) {
|
|
974
|
+
return;
|
|
975
|
+
}
|
|
918
976
|
this._applyToBodyOrInstances(body, (bodyPluginData) => {
|
|
919
977
|
this._hknp.HP_Body_SetEventMask(bodyPluginData.hpBodyId, eventMask);
|
|
920
978
|
}, instanceIndex);
|
|
@@ -940,6 +998,9 @@ export class HavokPlugin {
|
|
|
940
998
|
};
|
|
941
999
|
}
|
|
942
1000
|
_internalUpdateMassProperties(pluginData) {
|
|
1001
|
+
if (this._isDisposed) {
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
943
1004
|
// Recompute the mass based on the shape
|
|
944
1005
|
const newProps = this._internalComputeMassProperties(pluginData);
|
|
945
1006
|
const massProps = pluginData.userMassProps;
|
|
@@ -959,6 +1020,9 @@ export class HavokPlugin {
|
|
|
959
1020
|
this._hknp.HP_Body_SetMassProperties(pluginData.hpBodyId, newProps);
|
|
960
1021
|
}
|
|
961
1022
|
_internalSetMotionType(pluginData, motionType) {
|
|
1023
|
+
if (this._isDisposed) {
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
962
1026
|
switch (motionType) {
|
|
963
1027
|
case 0 /* PhysicsMotionType.STATIC */:
|
|
964
1028
|
this._hknp.HP_Body_SetMotionType(pluginData.hpBodyId, this._hknp.MotionType.STATIC);
|
|
@@ -978,6 +1042,9 @@ export class HavokPlugin {
|
|
|
978
1042
|
* @param instanceIndex - The index of the instance to set the motion type for. If undefined, the motion type of all the bodies will be set.
|
|
979
1043
|
*/
|
|
980
1044
|
setMotionType(body, motionType, instanceIndex) {
|
|
1045
|
+
if (this._isDisposed) {
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
981
1048
|
this._applyToBodyOrInstances(body, (pluginData) => {
|
|
982
1049
|
this._internalSetMotionType(pluginData, motionType);
|
|
983
1050
|
}, instanceIndex);
|
|
@@ -1007,6 +1074,9 @@ export class HavokPlugin {
|
|
|
1007
1074
|
* @param controlMode - The activation control mode.
|
|
1008
1075
|
*/
|
|
1009
1076
|
setActivationControl(body, controlMode) {
|
|
1077
|
+
if (this._isDisposed) {
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1010
1080
|
switch (controlMode) {
|
|
1011
1081
|
case 1 /* PhysicsActivationControl.ALWAYS_ACTIVE */:
|
|
1012
1082
|
this._hknp.HP_Body_SetActivationControl(body._pluginData.hpBodyId, this._hknp.ActivationControl.ALWAYS_ACTIVE);
|
|
@@ -1054,6 +1124,9 @@ export class HavokPlugin {
|
|
|
1054
1124
|
*
|
|
1055
1125
|
*/
|
|
1056
1126
|
setMassProperties(body, massProps, instanceIndex) {
|
|
1127
|
+
if (this._isDisposed) {
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1057
1130
|
this._applyToBodyOrInstances(body, (pluginData) => {
|
|
1058
1131
|
pluginData.userMassProps = massProps;
|
|
1059
1132
|
this._internalUpdateMassProperties(pluginData);
|
|
@@ -1066,6 +1139,9 @@ export class HavokPlugin {
|
|
|
1066
1139
|
* @returns The mass properties of the physics body.
|
|
1067
1140
|
*/
|
|
1068
1141
|
getMassProperties(body, instanceIndex) {
|
|
1142
|
+
if (this._isDisposed) {
|
|
1143
|
+
return { mass: 1, inertia: Vector3.Zero(), centerOfMass: Vector3.Zero() };
|
|
1144
|
+
}
|
|
1069
1145
|
const pluginRef = this._getPluginReference(body, instanceIndex);
|
|
1070
1146
|
const massPropsTuple = this._hknp.HP_Body_GetMassProperties(pluginRef.hpBodyId)[1];
|
|
1071
1147
|
return this._fromMassPropertiesTuple(massPropsTuple);
|
|
@@ -1081,6 +1157,9 @@ export class HavokPlugin {
|
|
|
1081
1157
|
* This method allows the user to set the linear damping of a body, which can be used to control the motion of the body.
|
|
1082
1158
|
*/
|
|
1083
1159
|
setLinearDamping(body, damping, instanceIndex) {
|
|
1160
|
+
if (this._isDisposed) {
|
|
1161
|
+
return;
|
|
1162
|
+
}
|
|
1084
1163
|
this._applyToBodyOrInstances(body, (pluginData) => {
|
|
1085
1164
|
this._hknp.HP_Body_SetLinearDamping(pluginData.hpBodyId, damping);
|
|
1086
1165
|
}, instanceIndex);
|
|
@@ -1109,6 +1188,9 @@ export class HavokPlugin {
|
|
|
1109
1188
|
* By setting the angular damping, the body's angular velocity will be reduced over time, allowing for more realistic physics simulations.
|
|
1110
1189
|
*/
|
|
1111
1190
|
setAngularDamping(body, damping, instanceIndex) {
|
|
1191
|
+
if (this._isDisposed) {
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1112
1194
|
this._applyToBodyOrInstances(body, (pluginData) => {
|
|
1113
1195
|
this._hknp.HP_Body_SetAngularDamping(pluginData.hpBodyId, damping);
|
|
1114
1196
|
}, instanceIndex);
|
|
@@ -1136,6 +1218,9 @@ export class HavokPlugin {
|
|
|
1136
1218
|
* motion in a physics engine. The linear velocity is the speed and direction of the body's movement.
|
|
1137
1219
|
*/
|
|
1138
1220
|
setLinearVelocity(body, linVel, instanceIndex) {
|
|
1221
|
+
if (this._isDisposed) {
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1139
1224
|
this._applyToBodyOrInstances(body, (pluginData) => {
|
|
1140
1225
|
this._hknp.HP_Body_SetLinearVelocity(pluginData.hpBodyId, this._bVecToV3(linVel));
|
|
1141
1226
|
}, instanceIndex);
|
|
@@ -1151,6 +1236,9 @@ export class HavokPlugin {
|
|
|
1151
1236
|
* information can be used to simulate realistic physics behavior in a game.
|
|
1152
1237
|
*/
|
|
1153
1238
|
getLinearVelocityToRef(body, linVel, instanceIndex) {
|
|
1239
|
+
if (this._isDisposed) {
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1154
1242
|
const pluginRef = this._getPluginReference(body, instanceIndex);
|
|
1155
1243
|
const lv = this._hknp.HP_Body_GetLinearVelocity(pluginRef.hpBodyId)[1];
|
|
1156
1244
|
this._v3ToBvecRef(lv, linVel);
|
|
@@ -1159,6 +1247,9 @@ export class HavokPlugin {
|
|
|
1159
1247
|
* Apply an operation either to all instances of a body, if instanceIndex is not specified, or to a specific instance.
|
|
1160
1248
|
*/
|
|
1161
1249
|
_applyToBodyOrInstances(body, fnToApply, instanceIndex) {
|
|
1250
|
+
if (this._isDisposed) {
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1162
1253
|
if (body._pluginDataInstances?.length > 0 && instanceIndex === undefined) {
|
|
1163
1254
|
for (let i = 0; i < body._pluginDataInstances.length; i++) {
|
|
1164
1255
|
fnToApply(body._pluginDataInstances[i]);
|
|
@@ -1179,6 +1270,9 @@ export class HavokPlugin {
|
|
|
1179
1270
|
* This can be used to simulate physical forces such as explosions, collisions, and gravity.
|
|
1180
1271
|
*/
|
|
1181
1272
|
applyImpulse(body, impulse, location, instanceIndex) {
|
|
1273
|
+
if (this._isDisposed) {
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1182
1276
|
this._applyToBodyOrInstances(body, (pluginRef) => {
|
|
1183
1277
|
const offset = pluginRef.worldRegion.floatingOrigin;
|
|
1184
1278
|
this._hknp.HP_Body_ApplyImpulse(pluginRef.hpBodyId, this._bVecToV3WithOffset(location, offset), this._bVecToV3(impulse));
|
|
@@ -1191,6 +1285,9 @@ export class HavokPlugin {
|
|
|
1191
1285
|
* @param instanceIndex - The index of the instance to apply the impulse to. If not specified, the impulse will be applied to all instances.
|
|
1192
1286
|
*/
|
|
1193
1287
|
applyAngularImpulse(body, angularImpulse, instanceIndex) {
|
|
1288
|
+
if (this._isDisposed) {
|
|
1289
|
+
return;
|
|
1290
|
+
}
|
|
1194
1291
|
this._applyToBodyOrInstances(body, (pluginRef) => {
|
|
1195
1292
|
this._hknp.HP_Body_ApplyAngularImpulse(pluginRef.hpBodyId, this._bVecToV3(angularImpulse));
|
|
1196
1293
|
}, instanceIndex);
|
|
@@ -1206,6 +1303,9 @@ export class HavokPlugin {
|
|
|
1206
1303
|
* This can be used to simulate physical forces such as explosions, collisions, and gravity.
|
|
1207
1304
|
*/
|
|
1208
1305
|
applyForce(body, force, location, instanceIndex) {
|
|
1306
|
+
if (this._isDisposed) {
|
|
1307
|
+
return;
|
|
1308
|
+
}
|
|
1209
1309
|
force.scaleToRef(this.getTimeStep(), this._tmpVec3[0]);
|
|
1210
1310
|
this.applyImpulse(body, this._tmpVec3[0], location, instanceIndex);
|
|
1211
1311
|
}
|
|
@@ -1219,6 +1319,9 @@ export class HavokPlugin {
|
|
|
1219
1319
|
* This can be used to simulate rotational forces such as motors, angular momentum, and rotational dynamics.
|
|
1220
1320
|
*/
|
|
1221
1321
|
applyTorque(body, torque, instanceIndex) {
|
|
1322
|
+
if (this._isDisposed) {
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1222
1325
|
torque.scaleToRef(this.getTimeStep(), this._tmpVec3[0]);
|
|
1223
1326
|
this.applyAngularImpulse(body, this._tmpVec3[0], instanceIndex);
|
|
1224
1327
|
}
|
|
@@ -1233,6 +1336,9 @@ export class HavokPlugin {
|
|
|
1233
1336
|
* This allows for more realistic simulations of physical objects, as they can be given a rotational velocity.
|
|
1234
1337
|
*/
|
|
1235
1338
|
setAngularVelocity(body, angVel, instanceIndex) {
|
|
1339
|
+
if (this._isDisposed) {
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1236
1342
|
this._applyToBodyOrInstances(body, (pluginRef) => {
|
|
1237
1343
|
this._hknp.HP_Body_SetAngularVelocity(pluginRef.hpBodyId, this._bVecToV3(angVel));
|
|
1238
1344
|
}, instanceIndex);
|
|
@@ -1249,6 +1355,9 @@ export class HavokPlugin {
|
|
|
1249
1355
|
* calculate the motion of the body in the physics engine.
|
|
1250
1356
|
*/
|
|
1251
1357
|
getAngularVelocityToRef(body, angVel, instanceIndex) {
|
|
1358
|
+
if (this._isDisposed) {
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
1252
1361
|
const pluginRef = this._getPluginReference(body, instanceIndex);
|
|
1253
1362
|
const av = this._hknp.HP_Body_GetAngularVelocity(pluginRef.hpBodyId)[1];
|
|
1254
1363
|
this._v3ToBvecRef(av, angVel);
|
|
@@ -1266,6 +1375,9 @@ export class HavokPlugin {
|
|
|
1266
1375
|
* same transformation.
|
|
1267
1376
|
*/
|
|
1268
1377
|
setPhysicsBodyTransformation(body, node) {
|
|
1378
|
+
if (this._isDisposed) {
|
|
1379
|
+
return;
|
|
1380
|
+
}
|
|
1269
1381
|
if (body.getPrestepType() == PhysicsPrestepType.TELEPORT) {
|
|
1270
1382
|
const transformNode = body.transformNode;
|
|
1271
1383
|
if (body.numInstances > 0) {
|
|
@@ -1338,6 +1450,9 @@ export class HavokPlugin {
|
|
|
1338
1450
|
* @param instanceIndex The index of the instance in an instanced body
|
|
1339
1451
|
*/
|
|
1340
1452
|
setTargetTransform(body, position, rotation, instanceIndex) {
|
|
1453
|
+
if (this._isDisposed) {
|
|
1454
|
+
return;
|
|
1455
|
+
}
|
|
1341
1456
|
this._applyToBodyOrInstances(body, (pluginRef) => {
|
|
1342
1457
|
const offset = pluginRef.worldRegion.floatingOrigin;
|
|
1343
1458
|
this._hknp.HP_Body_SetTargetQTransform(pluginRef.hpBodyId, [this._bVecToV3WithOffset(position, offset), this._bQuatToV4(rotation)]);
|
|
@@ -1350,6 +1465,9 @@ export class HavokPlugin {
|
|
|
1350
1465
|
* @param instanceIndex the index of the instance in an instanced body
|
|
1351
1466
|
*/
|
|
1352
1467
|
setGravityFactor(body, factor, instanceIndex) {
|
|
1468
|
+
if (this._isDisposed) {
|
|
1469
|
+
return;
|
|
1470
|
+
}
|
|
1353
1471
|
this._applyToBodyOrInstances(body, (pluginRef) => {
|
|
1354
1472
|
this._hknp.HP_Body_SetGravityFactor(pluginRef.hpBodyId, factor);
|
|
1355
1473
|
}, instanceIndex);
|
|
@@ -1361,6 +1479,9 @@ export class HavokPlugin {
|
|
|
1361
1479
|
* @returns the gravity factor
|
|
1362
1480
|
*/
|
|
1363
1481
|
getGravityFactor(body, instanceIndex) {
|
|
1482
|
+
if (this._isDisposed) {
|
|
1483
|
+
return 1;
|
|
1484
|
+
}
|
|
1364
1485
|
const pluginRef = this._getPluginReference(body, instanceIndex);
|
|
1365
1486
|
return this._hknp.HP_Body_GetGravityFactor(pluginRef.hpBodyId)[1];
|
|
1366
1487
|
}
|
|
@@ -1373,6 +1494,9 @@ export class HavokPlugin {
|
|
|
1373
1494
|
* This is important for avoiding memory leaks in the physics engine.
|
|
1374
1495
|
*/
|
|
1375
1496
|
disposeBody(body) {
|
|
1497
|
+
if (this._isDisposed) {
|
|
1498
|
+
return;
|
|
1499
|
+
}
|
|
1376
1500
|
if (body._pluginDataInstances && body._pluginDataInstances.length > 0) {
|
|
1377
1501
|
for (const instance of body._pluginDataInstances) {
|
|
1378
1502
|
this._hknp.HP_Body_Release(instance.hpBodyId);
|
|
@@ -1385,6 +1509,9 @@ export class HavokPlugin {
|
|
|
1385
1509
|
}
|
|
1386
1510
|
}
|
|
1387
1511
|
_createOptionsFromGroundMesh(options) {
|
|
1512
|
+
if (this._isDisposed) {
|
|
1513
|
+
return;
|
|
1514
|
+
}
|
|
1388
1515
|
const mesh = options.groundMesh;
|
|
1389
1516
|
if (!mesh) {
|
|
1390
1517
|
return;
|
|
@@ -1435,6 +1562,9 @@ export class HavokPlugin {
|
|
|
1435
1562
|
* For example, a sphere requires a radius, while a box requires extents and a rotation.
|
|
1436
1563
|
*/
|
|
1437
1564
|
initShape(shape, type, options) {
|
|
1565
|
+
if (this._isDisposed) {
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1438
1568
|
switch (type) {
|
|
1439
1569
|
case 0 /* PhysicsShapeType.SPHERE */:
|
|
1440
1570
|
{
|
|
@@ -1539,6 +1669,9 @@ export class HavokPlugin {
|
|
|
1539
1669
|
* @param membershipMask - The shape filter membership mask to set.
|
|
1540
1670
|
*/
|
|
1541
1671
|
setShapeFilterMembershipMask(shape, membershipMask) {
|
|
1672
|
+
if (this._isDisposed) {
|
|
1673
|
+
return;
|
|
1674
|
+
}
|
|
1542
1675
|
const collideWith = this._hknp.HP_Shape_GetFilterInfo(shape._pluginData)[1][1];
|
|
1543
1676
|
this._hknp.HP_Shape_SetFilterInfo(shape._pluginData, [membershipMask, collideWith]);
|
|
1544
1677
|
}
|
|
@@ -1548,6 +1681,9 @@ export class HavokPlugin {
|
|
|
1548
1681
|
* @returns The shape filter membership mask of the given body.
|
|
1549
1682
|
*/
|
|
1550
1683
|
getShapeFilterMembershipMask(shape) {
|
|
1684
|
+
if (this._isDisposed) {
|
|
1685
|
+
return 0;
|
|
1686
|
+
}
|
|
1551
1687
|
return this._hknp.HP_Shape_GetFilterInfo(shape._pluginData)[1][0];
|
|
1552
1688
|
}
|
|
1553
1689
|
/**
|
|
@@ -1556,6 +1692,9 @@ export class HavokPlugin {
|
|
|
1556
1692
|
* @param collideMask - The shape filter collide mask to set.
|
|
1557
1693
|
*/
|
|
1558
1694
|
setShapeFilterCollideMask(shape, collideMask) {
|
|
1695
|
+
if (this._isDisposed) {
|
|
1696
|
+
return;
|
|
1697
|
+
}
|
|
1559
1698
|
const membership = this._hknp.HP_Shape_GetFilterInfo(shape._pluginData)[1][0];
|
|
1560
1699
|
this._hknp.HP_Shape_SetFilterInfo(shape._pluginData, [membership, collideMask]);
|
|
1561
1700
|
}
|
|
@@ -1565,6 +1704,9 @@ export class HavokPlugin {
|
|
|
1565
1704
|
* @returns The shape filter collide mask of the given body.
|
|
1566
1705
|
*/
|
|
1567
1706
|
getShapeFilterCollideMask(shape) {
|
|
1707
|
+
if (this._isDisposed) {
|
|
1708
|
+
return 0;
|
|
1709
|
+
}
|
|
1568
1710
|
return this._hknp.HP_Shape_GetFilterInfo(shape._pluginData)[1][1];
|
|
1569
1711
|
}
|
|
1570
1712
|
/**
|
|
@@ -1574,6 +1716,9 @@ export class HavokPlugin {
|
|
|
1574
1716
|
*
|
|
1575
1717
|
*/
|
|
1576
1718
|
setMaterial(shape, material) {
|
|
1719
|
+
if (this._isDisposed) {
|
|
1720
|
+
return;
|
|
1721
|
+
}
|
|
1577
1722
|
const dynamicFriction = material.friction ?? 0.5;
|
|
1578
1723
|
const staticFriction = material.staticFriction ?? dynamicFriction;
|
|
1579
1724
|
const restitution = material.restitution ?? 0.0;
|
|
@@ -1604,6 +1749,9 @@ export class HavokPlugin {
|
|
|
1604
1749
|
*
|
|
1605
1750
|
*/
|
|
1606
1751
|
setDensity(shape, density) {
|
|
1752
|
+
if (this._isDisposed) {
|
|
1753
|
+
return;
|
|
1754
|
+
}
|
|
1607
1755
|
this._hknp.HP_Shape_SetDensity(shape._pluginData, density);
|
|
1608
1756
|
}
|
|
1609
1757
|
/**
|
|
@@ -1651,6 +1799,9 @@ export class HavokPlugin {
|
|
|
1651
1799
|
*
|
|
1652
1800
|
*/
|
|
1653
1801
|
addChild(shape, newChild, translation, rotation, scale) {
|
|
1802
|
+
if (this._isDisposed) {
|
|
1803
|
+
return;
|
|
1804
|
+
}
|
|
1654
1805
|
const transformNative = [
|
|
1655
1806
|
translation ? this._bVecToV3(translation) : [0, 0, 0],
|
|
1656
1807
|
rotation ? this._bQuatToV4(rotation) : [0, 0, 0, 1],
|
|
@@ -1665,6 +1816,9 @@ export class HavokPlugin {
|
|
|
1665
1816
|
*
|
|
1666
1817
|
*/
|
|
1667
1818
|
removeChild(shape, childIndex) {
|
|
1819
|
+
if (this._isDisposed) {
|
|
1820
|
+
return;
|
|
1821
|
+
}
|
|
1668
1822
|
this._hknp.HP_Shape_RemoveChild(shape._pluginData, childIndex);
|
|
1669
1823
|
}
|
|
1670
1824
|
/**
|
|
@@ -1683,6 +1837,9 @@ export class HavokPlugin {
|
|
|
1683
1837
|
* @param isTrigger if the shape is a trigger
|
|
1684
1838
|
*/
|
|
1685
1839
|
setTrigger(shape, isTrigger) {
|
|
1840
|
+
if (this._isDisposed) {
|
|
1841
|
+
return;
|
|
1842
|
+
}
|
|
1686
1843
|
this._hknp.HP_Shape_SetTrigger(shape._pluginData, isTrigger);
|
|
1687
1844
|
}
|
|
1688
1845
|
/**
|
|
@@ -1753,6 +1910,9 @@ export class HavokPlugin {
|
|
|
1753
1910
|
* This method is useful for releasing a physics shape from the physics engine, freeing up resources and preventing memory leaks.
|
|
1754
1911
|
*/
|
|
1755
1912
|
disposeShape(shape) {
|
|
1913
|
+
if (this._isDisposed) {
|
|
1914
|
+
return;
|
|
1915
|
+
}
|
|
1756
1916
|
this._shapes.delete(shape._pluginData[0]);
|
|
1757
1917
|
this._hknp.HP_Shape_Release(shape._pluginData);
|
|
1758
1918
|
shape._pluginData = undefined;
|
|
@@ -1770,6 +1930,9 @@ export class HavokPlugin {
|
|
|
1770
1930
|
* This function is useful for setting up a physics constraint in a physics engine.
|
|
1771
1931
|
*/
|
|
1772
1932
|
initConstraint(constraint, body, childBody, instanceIndex, childInstanceIndex) {
|
|
1933
|
+
if (this._isDisposed) {
|
|
1934
|
+
return;
|
|
1935
|
+
}
|
|
1773
1936
|
const type = constraint.type;
|
|
1774
1937
|
const options = constraint.options;
|
|
1775
1938
|
if (!type || !options) {
|
|
@@ -1933,6 +2096,9 @@ export class HavokPlugin {
|
|
|
1933
2096
|
*
|
|
1934
2097
|
*/
|
|
1935
2098
|
setEnabled(constraint, isEnabled) {
|
|
2099
|
+
if (this._isDisposed) {
|
|
2100
|
+
return;
|
|
2101
|
+
}
|
|
1936
2102
|
for (const jointId of constraint._pluginData) {
|
|
1937
2103
|
this._hknp.HP_Constraint_SetEnabled(jointId, isEnabled);
|
|
1938
2104
|
}
|
|
@@ -1957,6 +2123,9 @@ export class HavokPlugin {
|
|
|
1957
2123
|
*
|
|
1958
2124
|
*/
|
|
1959
2125
|
setCollisionsEnabled(constraint, isEnabled) {
|
|
2126
|
+
if (this._isDisposed) {
|
|
2127
|
+
return;
|
|
2128
|
+
}
|
|
1960
2129
|
for (const jointId of constraint._pluginData) {
|
|
1961
2130
|
this._hknp.HP_Constraint_SetCollisionsEnabled(jointId, isEnabled);
|
|
1962
2131
|
}
|
|
@@ -1983,6 +2152,9 @@ export class HavokPlugin {
|
|
|
1983
2152
|
*
|
|
1984
2153
|
*/
|
|
1985
2154
|
setAxisFriction(constraint, axis, friction) {
|
|
2155
|
+
if (this._isDisposed) {
|
|
2156
|
+
return;
|
|
2157
|
+
}
|
|
1986
2158
|
for (const jointId of constraint._pluginData) {
|
|
1987
2159
|
this._hknp.HP_Constraint_SetAxisFriction(jointId, this._constraintAxisToNative(axis), friction);
|
|
1988
2160
|
}
|
|
@@ -2009,6 +2181,9 @@ export class HavokPlugin {
|
|
|
2009
2181
|
* @param limitMode - The limit mode to set.
|
|
2010
2182
|
*/
|
|
2011
2183
|
setAxisMode(constraint, axis, limitMode) {
|
|
2184
|
+
if (this._isDisposed) {
|
|
2185
|
+
return;
|
|
2186
|
+
}
|
|
2012
2187
|
for (const jointId of constraint._pluginData) {
|
|
2013
2188
|
this._hknp.HP_Constraint_SetAxisMode(jointId, this._constraintAxisToNative(axis), this._limitModeToNative(limitMode));
|
|
2014
2189
|
}
|
|
@@ -2037,6 +2212,9 @@ export class HavokPlugin {
|
|
|
2037
2212
|
*
|
|
2038
2213
|
*/
|
|
2039
2214
|
setAxisMinLimit(constraint, axis, limit) {
|
|
2215
|
+
if (this._isDisposed) {
|
|
2216
|
+
return;
|
|
2217
|
+
}
|
|
2040
2218
|
for (const jointId of constraint._pluginData) {
|
|
2041
2219
|
this._hknp.HP_Constraint_SetAxisMinLimit(jointId, this._constraintAxisToNative(axis), limit);
|
|
2042
2220
|
}
|
|
@@ -2063,6 +2241,9 @@ export class HavokPlugin {
|
|
|
2063
2241
|
*
|
|
2064
2242
|
*/
|
|
2065
2243
|
setAxisMaxLimit(constraint, axis, limit) {
|
|
2244
|
+
if (this._isDisposed) {
|
|
2245
|
+
return;
|
|
2246
|
+
}
|
|
2066
2247
|
for (const jointId of constraint._pluginData) {
|
|
2067
2248
|
this._hknp.HP_Constraint_SetAxisMaxLimit(jointId, this._constraintAxisToNative(axis), limit);
|
|
2068
2249
|
}
|
|
@@ -2090,6 +2271,9 @@ export class HavokPlugin {
|
|
|
2090
2271
|
*
|
|
2091
2272
|
*/
|
|
2092
2273
|
setAxisMotorType(constraint, axis, motorType) {
|
|
2274
|
+
if (this._isDisposed) {
|
|
2275
|
+
return;
|
|
2276
|
+
}
|
|
2093
2277
|
for (const jointId of constraint._pluginData) {
|
|
2094
2278
|
this._hknp.HP_Constraint_SetAxisMotorType(jointId, this._constraintAxisToNative(axis), this._constraintMotorTypeToNative(motorType));
|
|
2095
2279
|
}
|
|
@@ -2117,6 +2301,9 @@ export class HavokPlugin {
|
|
|
2117
2301
|
*
|
|
2118
2302
|
*/
|
|
2119
2303
|
setAxisMotorTarget(constraint, axis, target) {
|
|
2304
|
+
if (this._isDisposed) {
|
|
2305
|
+
return;
|
|
2306
|
+
}
|
|
2120
2307
|
for (const jointId of constraint._pluginData) {
|
|
2121
2308
|
this._hknp.HP_Constraint_SetAxisMotorTarget(jointId, this._constraintAxisToNative(axis), target);
|
|
2122
2309
|
}
|
|
@@ -2144,6 +2331,9 @@ export class HavokPlugin {
|
|
|
2144
2331
|
*
|
|
2145
2332
|
*/
|
|
2146
2333
|
setAxisMotorMaxForce(constraint, axis, maxForce) {
|
|
2334
|
+
if (this._isDisposed) {
|
|
2335
|
+
return;
|
|
2336
|
+
}
|
|
2147
2337
|
for (const jointId of constraint._pluginData) {
|
|
2148
2338
|
this._hknp.HP_Constraint_SetAxisMotorMaxForce(jointId, this._constraintAxisToNative(axis), maxForce);
|
|
2149
2339
|
}
|
|
@@ -2172,6 +2362,9 @@ export class HavokPlugin {
|
|
|
2172
2362
|
* the Havok constraint, when it is no longer needed. This is important for avoiding memory leaks.
|
|
2173
2363
|
*/
|
|
2174
2364
|
disposeConstraint(constraint) {
|
|
2365
|
+
if (this._isDisposed) {
|
|
2366
|
+
return;
|
|
2367
|
+
}
|
|
2175
2368
|
if (constraint._pluginData) {
|
|
2176
2369
|
for (const jointId of constraint._pluginData) {
|
|
2177
2370
|
if (this._constraintToBodyIdPair.has(jointId)) {
|
|
@@ -2185,6 +2378,9 @@ export class HavokPlugin {
|
|
|
2185
2378
|
constraint._initOptions = void 0;
|
|
2186
2379
|
}
|
|
2187
2380
|
_populateHitData(hitData, result) {
|
|
2381
|
+
if (this._isDisposed) {
|
|
2382
|
+
return;
|
|
2383
|
+
}
|
|
2188
2384
|
const hitBody = this._bodies.get(hitData[0][0]);
|
|
2189
2385
|
result.body = hitBody?.body;
|
|
2190
2386
|
result.bodyIndex = hitBody?.index;
|
|
@@ -2212,6 +2408,9 @@ export class HavokPlugin {
|
|
|
2212
2408
|
* If result is a populated array, it will only fill the PhysicsRaycastResults present in the array.
|
|
2213
2409
|
*/
|
|
2214
2410
|
raycast(from, to, result, query) {
|
|
2411
|
+
if (this._isDisposed) {
|
|
2412
|
+
return;
|
|
2413
|
+
}
|
|
2215
2414
|
const queryMembership = query?.membership ?? ~0;
|
|
2216
2415
|
const queryCollideWith = query?.collideWith ?? ~0;
|
|
2217
2416
|
const shouldHitTriggers = query?.shouldHitTriggers ?? false;
|
|
@@ -2268,6 +2467,9 @@ export class HavokPlugin {
|
|
|
2268
2467
|
* @param result contact point on the hit shape, in world space
|
|
2269
2468
|
*/
|
|
2270
2469
|
pointProximity(query, result) {
|
|
2470
|
+
if (this._isDisposed) {
|
|
2471
|
+
return;
|
|
2472
|
+
}
|
|
2271
2473
|
const queryMembership = query?.collisionFilter?.membership ?? ~0;
|
|
2272
2474
|
const queryCollideWith = query?.collisionFilter?.collideWith ?? ~0;
|
|
2273
2475
|
result.reset();
|
|
@@ -2291,6 +2493,9 @@ export class HavokPlugin {
|
|
|
2291
2493
|
* @param hitShapeResult contact point on hit shape, in world space
|
|
2292
2494
|
*/
|
|
2293
2495
|
shapeProximity(query, inputShapeResult, hitShapeResult) {
|
|
2496
|
+
if (this._isDisposed) {
|
|
2497
|
+
return;
|
|
2498
|
+
}
|
|
2294
2499
|
inputShapeResult.reset();
|
|
2295
2500
|
hitShapeResult.reset();
|
|
2296
2501
|
const shapeId = query.shape._pluginData;
|
|
@@ -2316,6 +2521,9 @@ export class HavokPlugin {
|
|
|
2316
2521
|
* @param hitShapeResult contact point on hit shape, in world space
|
|
2317
2522
|
*/
|
|
2318
2523
|
shapeCast(query, inputShapeResult, hitShapeResult) {
|
|
2524
|
+
if (this._isDisposed) {
|
|
2525
|
+
return;
|
|
2526
|
+
}
|
|
2319
2527
|
inputShapeResult.reset();
|
|
2320
2528
|
hitShapeResult.reset();
|
|
2321
2529
|
const shapeId = query.shape._pluginData;
|
|
@@ -2379,6 +2587,9 @@ export class HavokPlugin {
|
|
|
2379
2587
|
* @param enabled whether to enable or disable collision events
|
|
2380
2588
|
*/
|
|
2381
2589
|
setCollisionCallbackEnabled(body, enabled) {
|
|
2590
|
+
if (this._isDisposed) {
|
|
2591
|
+
return;
|
|
2592
|
+
}
|
|
2382
2593
|
// Register for collide events by default
|
|
2383
2594
|
const collideEvents = this._hknp.EventType.COLLISION_STARTED.value | this._hknp.EventType.COLLISION_CONTINUED.value | this._hknp.EventType.COLLISION_FINISHED.value;
|
|
2384
2595
|
if (body._pluginDataInstances && body._pluginDataInstances.length) {
|
|
@@ -2397,6 +2608,9 @@ export class HavokPlugin {
|
|
|
2397
2608
|
* @param enabled whether to enable or disable collision ended events
|
|
2398
2609
|
*/
|
|
2399
2610
|
setCollisionEndedCallbackEnabled(body, enabled) {
|
|
2611
|
+
if (this._isDisposed) {
|
|
2612
|
+
return;
|
|
2613
|
+
}
|
|
2400
2614
|
// Register to collide ended events
|
|
2401
2615
|
const pluginRef = this._getPluginReference(body);
|
|
2402
2616
|
let currentCollideEvents = this._hknp.HP_Body_GetEventMask(pluginRef.hpBodyId)[1];
|
|
@@ -2415,6 +2629,9 @@ export class HavokPlugin {
|
|
|
2415
2629
|
}
|
|
2416
2630
|
}
|
|
2417
2631
|
_notifyTriggers(world) {
|
|
2632
|
+
if (this._isDisposed) {
|
|
2633
|
+
return;
|
|
2634
|
+
}
|
|
2418
2635
|
const targetWorld = world ?? this.world;
|
|
2419
2636
|
let eventAddress = this._hknp.HP_World_GetTriggerEvents(targetWorld)[1];
|
|
2420
2637
|
const event = new TriggerEvent();
|
|
@@ -2441,6 +2658,9 @@ export class HavokPlugin {
|
|
|
2441
2658
|
* @param world optional world to check collisions for (defaults to main world)
|
|
2442
2659
|
*/
|
|
2443
2660
|
_notifyCollisions(world) {
|
|
2661
|
+
if (this._isDisposed) {
|
|
2662
|
+
return;
|
|
2663
|
+
}
|
|
2444
2664
|
const targetWorld = world ?? this.world;
|
|
2445
2665
|
let eventAddress = this._hknp.HP_World_GetCollisionEvents(targetWorld)[1];
|
|
2446
2666
|
const event = new CollisionEvent();
|
|
@@ -2538,6 +2758,10 @@ export class HavokPlugin {
|
|
|
2538
2758
|
* Dispose the world and free resources
|
|
2539
2759
|
*/
|
|
2540
2760
|
dispose() {
|
|
2761
|
+
if (this._isDisposed) {
|
|
2762
|
+
return;
|
|
2763
|
+
}
|
|
2764
|
+
this._isDisposed = true;
|
|
2541
2765
|
if (this._queryCollector) {
|
|
2542
2766
|
this._hknp.HP_QueryCollector_Release(this._queryCollector);
|
|
2543
2767
|
this._queryCollector = undefined;
|