@onerjs/core 8.49.2 → 8.49.4
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/Meshes/transformNode.d.ts +0 -1
- package/Meshes/transformNode.js +24 -24
- package/Meshes/transformNode.js.map +1 -1
- package/Physics/v2/characterController.d.ts +0 -32
- package/Physics/v2/characterController.js +2 -126
- package/Physics/v2/characterController.js.map +1 -1
- package/package.json +1 -1
|
@@ -151,34 +151,6 @@ export class PhysicsCharacterController {
|
|
|
151
151
|
* default 0.5
|
|
152
152
|
*/
|
|
153
153
|
this.stepHeight = 0.5;
|
|
154
|
-
/**
|
|
155
|
-
* The normal threshold for ground detection during step up.
|
|
156
|
-
* Used to determine if a contact surface is ground-like (facing upward).
|
|
157
|
-
* Value is the cosine of the maximum angle from vertical.
|
|
158
|
-
* For example, 0.5 means surfaces with angle less than 60 degrees from vertical are considered ground.
|
|
159
|
-
* default 0.5
|
|
160
|
-
*/
|
|
161
|
-
this.stepGroundNormalThreshold = 0.5;
|
|
162
|
-
/**
|
|
163
|
-
* The ratio of stepHeight used for checking height during step up.
|
|
164
|
-
* Determines at what fraction of the step height to perform the obstruction check.
|
|
165
|
-
* For example, 0.5 means check at half the step height.
|
|
166
|
-
* default 0.5
|
|
167
|
-
*/
|
|
168
|
-
this.stepUpCheckHeightRatio = 0.5;
|
|
169
|
-
/**
|
|
170
|
-
* The minimum distance to check for step up obstruction.
|
|
171
|
-
* This prevents the character from trying to step up when the obstruction is too close.
|
|
172
|
-
* default 0.1
|
|
173
|
-
*/
|
|
174
|
-
this.stepUpCheckDistance = 0.1;
|
|
175
|
-
/**
|
|
176
|
-
* The ratio of horizontal displacement to check after stepping up.
|
|
177
|
-
* Determines how far forward to check for clearance after stepping up.
|
|
178
|
-
* For example, 0.5 means check half the step check distance forward.
|
|
179
|
-
* default 0.5
|
|
180
|
-
*/
|
|
181
|
-
this.stepUpCheckHorizontalRatio = 0.5;
|
|
182
154
|
/**
|
|
183
155
|
* Observable for trigger entered and trigger exited events
|
|
184
156
|
*/
|
|
@@ -210,8 +182,6 @@ export class PhysicsCharacterController {
|
|
|
210
182
|
const hknp = hk._hknp;
|
|
211
183
|
this._startCollector = hknp.HP_QueryCollector_Create(16)[1];
|
|
212
184
|
this._castCollector = hknp.HP_QueryCollector_Create(16)[1];
|
|
213
|
-
this._stepCollector = hknp.HP_QueryCollector_Create(16)[1];
|
|
214
|
-
this._stepUpCollector = hknp.HP_QueryCollector_Create(16)[1];
|
|
215
185
|
}
|
|
216
186
|
/**
|
|
217
187
|
* Dispose the character controller
|
|
@@ -226,8 +196,6 @@ export class PhysicsCharacterController {
|
|
|
226
196
|
const hknp = hk._hknp;
|
|
227
197
|
hknp.HP_QueryCollector_Release(this._startCollector);
|
|
228
198
|
hknp.HP_QueryCollector_Release(this._castCollector);
|
|
229
|
-
hknp.HP_QueryCollector_Release(this._stepCollector);
|
|
230
|
-
hknp.HP_QueryCollector_Release(this._stepUpCollector);
|
|
231
199
|
}
|
|
232
200
|
/**
|
|
233
201
|
* Get shape used for collision
|
|
@@ -1212,85 +1180,6 @@ export class PhysicsCharacterController {
|
|
|
1212
1180
|
_getInvMass(body) {
|
|
1213
1181
|
return 1 / body.body.getMassProperties(body.index).mass;
|
|
1214
1182
|
}
|
|
1215
|
-
_hasGroundContact() {
|
|
1216
|
-
if (this._manifold.length === 0) {
|
|
1217
|
-
return false;
|
|
1218
|
-
}
|
|
1219
|
-
for (let i = 0; i < this._manifold.length; i++) {
|
|
1220
|
-
const contact = this._manifold[i];
|
|
1221
|
-
if (contact.normal.dot(this.up) > this.stepGroundNormalThreshold) {
|
|
1222
|
-
return true;
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
return false;
|
|
1226
|
-
}
|
|
1227
|
-
_tryStepUp(deltaTime, displacement, stepOffset) {
|
|
1228
|
-
if (stepOffset <= 0 || displacement.lengthSquared() < 1e-6) {
|
|
1229
|
-
return false;
|
|
1230
|
-
}
|
|
1231
|
-
const horizontalDisp = this._tmpVecs[30];
|
|
1232
|
-
horizontalDisp.copyFrom(displacement);
|
|
1233
|
-
horizontalDisp.y = 0;
|
|
1234
|
-
if (horizontalDisp.lengthSquared() < 1e-6) {
|
|
1235
|
-
return false;
|
|
1236
|
-
}
|
|
1237
|
-
horizontalDisp.normalizeToRef(horizontalDisp);
|
|
1238
|
-
const hk = this._scene.getPhysicsEngine().getPhysicsPlugin();
|
|
1239
|
-
const hknp = hk._hknp;
|
|
1240
|
-
const stepUpHeight = stepOffset * this.stepUpCheckHeightRatio;
|
|
1241
|
-
const checkPos = this._tmpVecs[31];
|
|
1242
|
-
checkPos.copyFrom(this._position);
|
|
1243
|
-
const scaledVec = this._tmpVecs[26];
|
|
1244
|
-
this.up.scaleToRef(stepUpHeight, scaledVec);
|
|
1245
|
-
checkPos.addInPlace(scaledVec);
|
|
1246
|
-
const stepCheckDist = Math.max(this.stepUpCheckDistance, stepOffset);
|
|
1247
|
-
const checkNative = [checkPos.x, checkPos.y, checkPos.z];
|
|
1248
|
-
const orientation = [this._orientation.x, this._orientation.y, this._orientation.z, this._orientation.w];
|
|
1249
|
-
const castPath = this._tmpVecs[29];
|
|
1250
|
-
horizontalDisp.scaleToRef(stepCheckDist, castPath);
|
|
1251
|
-
const endNative = [checkPos.x + castPath.x, checkPos.y + castPath.y, checkPos.z + castPath.z];
|
|
1252
|
-
const query = [this._shape._pluginData, orientation, checkNative, endNative, false, [this._body._pluginData.hpBodyId[0]]];
|
|
1253
|
-
hknp.HP_World_ShapeCastWithCollector(hk.world, this._stepCollector, query);
|
|
1254
|
-
const numHits = hknp.HP_QueryCollector_GetNumHits(this._stepCollector)[1];
|
|
1255
|
-
if (numHits > 0) {
|
|
1256
|
-
for (let i = 0; i < numHits; i++) {
|
|
1257
|
-
const [fraction, , hitWorld] = hknp.HP_QueryCollector_GetShapeCastResult(this._stepCollector, i)[1];
|
|
1258
|
-
if (fraction >= 1.0) {
|
|
1259
|
-
continue;
|
|
1260
|
-
}
|
|
1261
|
-
const normal = this._tmpVecs[28];
|
|
1262
|
-
normal.set(hitWorld[4][0], hitWorld[4][1], hitWorld[4][2]);
|
|
1263
|
-
const verticalComponent = normal.dot(this.up);
|
|
1264
|
-
if (verticalComponent < this.stepGroundNormalThreshold) {
|
|
1265
|
-
continue;
|
|
1266
|
-
}
|
|
1267
|
-
const stepUpPos = this._tmpVecs[27];
|
|
1268
|
-
stepUpPos.copyFrom(this._position);
|
|
1269
|
-
this.up.scaleToRef(stepOffset, scaledVec);
|
|
1270
|
-
stepUpPos.addInPlace(scaledVec);
|
|
1271
|
-
const stepUpCheck = [
|
|
1272
|
-
this._shape._pluginData,
|
|
1273
|
-
orientation,
|
|
1274
|
-
[stepUpPos.x, stepUpPos.y, stepUpPos.z],
|
|
1275
|
-
[
|
|
1276
|
-
stepUpPos.x + castPath.x * this.stepUpCheckHorizontalRatio,
|
|
1277
|
-
stepUpPos.y + castPath.y * this.stepUpCheckHorizontalRatio,
|
|
1278
|
-
stepUpPos.z + castPath.z * this.stepUpCheckHorizontalRatio,
|
|
1279
|
-
],
|
|
1280
|
-
false,
|
|
1281
|
-
[this._body._pluginData.hpBodyId[0]],
|
|
1282
|
-
];
|
|
1283
|
-
hknp.HP_World_ShapeCastWithCollector(hk.world, this._stepUpCollector, stepUpCheck);
|
|
1284
|
-
const numStepUpHits = hknp.HP_QueryCollector_GetNumHits(this._stepUpCollector)[1];
|
|
1285
|
-
if (numStepUpHits === 0) {
|
|
1286
|
-
this.up.scaleToRef(stepOffset, scaledVec);
|
|
1287
|
-
this._position.addInPlace(scaledVec);
|
|
1288
|
-
return true;
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
return false;
|
|
1293
|
-
}
|
|
1294
1183
|
_integrateManifolds(deltaTime, gravity) {
|
|
1295
1184
|
const hk = this._scene.getPhysicsEngine().getPhysicsPlugin();
|
|
1296
1185
|
const epsSqrd = 1e-8;
|
|
@@ -1312,19 +1201,6 @@ export class PhysicsCharacterController {
|
|
|
1312
1201
|
const solverDeltaTime = solveResults.deltaTime;
|
|
1313
1202
|
newVelocity = solveResults.velocity;
|
|
1314
1203
|
this._resolveContacts(deltaTime, gravity);
|
|
1315
|
-
const displacement = this._tmpVecs[25];
|
|
1316
|
-
if (this._hasGroundContact() && newDisplacement.lengthSquared() > epsSqrd && this.stepHeight > 0) {
|
|
1317
|
-
const horizontalVel = this._tmpVecs[26];
|
|
1318
|
-
horizontalVel.copyFrom(this._velocity);
|
|
1319
|
-
horizontalVel.y = 0;
|
|
1320
|
-
if (horizontalVel.lengthSquared() > epsSqrd) {
|
|
1321
|
-
if (this._tryStepUp(deltaTime, this._lastDisplacement, this.stepHeight)) {
|
|
1322
|
-
remainingTime -= solverDeltaTime;
|
|
1323
|
-
this._lastDisplacement.copyFrom(newDisplacement);
|
|
1324
|
-
continue;
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
1204
|
let newContactIndex = -1;
|
|
1329
1205
|
// todo if (updateResult == hit multiple bodies) ... cast again
|
|
1330
1206
|
// If castCollector had hits on different bodies (so we're not sure if some non-closest body could be in our way) OR
|
|
@@ -1359,8 +1235,8 @@ export class PhysicsCharacterController {
|
|
|
1359
1235
|
const distance = newContact.fraction;
|
|
1360
1236
|
let fraction = distance - keepDistanceAlongMovement * displacementLengthInv;
|
|
1361
1237
|
fraction = Math.min(Math.max(fraction, 0.0), 1.0);
|
|
1362
|
-
newDisplacement.scaleToRef(fraction,
|
|
1363
|
-
this._position.addInPlace(
|
|
1238
|
+
newDisplacement.scaleToRef(fraction, this._tmpVecs[31]);
|
|
1239
|
+
this._position.addInPlace(this._tmpVecs[31]);
|
|
1364
1240
|
remainingTime -= solverDeltaTime * fraction;
|
|
1365
1241
|
}
|
|
1366
1242
|
else {
|