From df1c273107dff7ea8cbedfc1d7a929c1b0aeb0df Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 26 Nov 2023 12:03:36 +0100 Subject: [PATCH] Added RigidBody.expandAABB() --- src/physics/Collider.ts | 6 ++++++ src/physics/RigidBody.ts | 6 ++++-- src/physics/solver/XPBDSolver.ts | 4 +--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/physics/Collider.ts b/src/physics/Collider.ts index 8e600ce..3ef6ff8 100644 --- a/src/physics/Collider.ts +++ b/src/physics/Collider.ts @@ -26,6 +26,12 @@ export class Collider { expanded_aabb = new Box3(); aabbHelper = new Box3Helper(this.expanded_aabb); + public expandAABB(scalar: number): void { + this.expanded_aabb + .copy(this.aabb) + .expandByScalar(scalar); + } + public updateGlobalPose(pose: Pose): void { // console.log('updateRotation not implemented') } diff --git a/src/physics/RigidBody.ts b/src/physics/RigidBody.ts index 3ba5ff2..a197b3f 100644 --- a/src/physics/RigidBody.ts +++ b/src/physics/RigidBody.ts @@ -168,8 +168,6 @@ export class RigidBody { this.prevPose.copy(this.pose); // Just in case pose was changed directly after setting static - this.collider.expanded_aabb.copy(this.collider.aabb); - this.updateGeometry(); this.updateCollider(); @@ -383,6 +381,10 @@ export class RigidBody { } public updateCollider() { + if (!this.isDynamic) { + this.collider.expandAABB(1.0); + } + this.collider.updateGlobalPose(this.pose); } diff --git a/src/physics/solver/XPBDSolver.ts b/src/physics/solver/XPBDSolver.ts index 5197aff..23f6b73 100644 --- a/src/physics/solver/XPBDSolver.ts +++ b/src/physics/solver/XPBDSolver.ts @@ -86,9 +86,7 @@ export class XPBDSolver extends BaseSolver { continue; /* (3.5) k * dt * vbody */ - body.collider.expanded_aabb - .copy(body.collider.aabb) - .expandByScalar(2.0 * dt * body.vel.length()); + body.collider.expandAABB(2.0 * dt * body.vel.length()); body.force.set(0, 0, 0); body.torque.set(0, 0, 0);