interactive objects integration

This commit is contained in:
2025-11-04 16:41:42 +02:00
parent 429ab07db5
commit 4236927537
13 changed files with 178 additions and 243 deletions
+13 -10
View File
@@ -31,29 +31,25 @@ class Physics{
let colliderDesc
switch (colliderType) {
case 'cuboid':
{
case 'cuboid':{
const { width, height, depth } = colliderSettings
colliderDesc = RAPIER.ColliderDesc.cuboid(width, height, depth)
}
break
case 'ball':
{
case 'ball':{
const { radius } = colliderSettings
colliderDesc = RAPIER.ColliderDesc.ball(radius)
}
break
case 'capsule':
{
case 'capsule':{
const { halfHeight, radius } = colliderSettings
colliderDesc = RAPIER.ColliderDesc.capsule(halfHeight, radius)
}
break
default:
{
default:{
colliderDesc = RAPIER.ColliderDesc.trimesh(
mesh.geometry.attributes.position.array,
mesh.geometry.index?.array
@@ -74,14 +70,21 @@ class Physics{
// * Responsible for collision detection
const collider = this.world.createCollider(colliderDesc, rigidBody)
const physicsObject = { mesh, collider, rigidBody, fn: postPhysicsFn, autoAnimate }
this.physicsObjects.push(physicsObject)
return physicsObject
}
clear(){
this.physicsObjects.forEach(po=>{
po.characterController && this.world.removeCharacterController(po.characterController)
this.world.removeCollider(po.collider);
this.world.removeRigidBody(po.rigidBody);
})
this.physicsObjects = [];
}
step(){
this.world.step(this.eventQueue)