new physics engine - rapier instead of cannon
This commit is contained in:
+32
-22
@@ -13,7 +13,7 @@ import { TransformControls } from 'three/addons/controls/TransformControls.js';
|
||||
import { ARButton } from 'three/addons/webxr/ARButton.js';
|
||||
import { XRButton } from 'three/addons/webxr/XRButton.js';
|
||||
import { XRControllerModelFactory } from 'three/addons/webxr/XRControllerModelFactory.js';
|
||||
import * as CANNON from 'cannon-es';
|
||||
import * as RAPIER from '@dimforge/rapier3d'
|
||||
import { Clickable } from './Clickable.js';
|
||||
|
||||
class GameEngine {
|
||||
@@ -247,28 +247,38 @@ class GameEngine {
|
||||
}
|
||||
|
||||
initPhysics() {
|
||||
const world = new CANNON.World()
|
||||
world.gravity.set(0, -9.82, 0)
|
||||
const groundMaterial = new CANNON.Material('groundMaterial')
|
||||
const slipperyMaterial = new CANNON.Material('slipperyMaterial')
|
||||
const slippery_ground_cm = new CANNON.ContactMaterial(
|
||||
groundMaterial,
|
||||
slipperyMaterial,
|
||||
{
|
||||
friction: 0,
|
||||
restitution: 0.3,
|
||||
contactEquationStiffness: 1e10,
|
||||
contactEquationRelaxation: 30,
|
||||
}
|
||||
)
|
||||
world.addContactMaterial(slippery_ground_cm)
|
||||
const planeShape = new CANNON.Plane()
|
||||
const planeBody = new CANNON.Body({ mass: 0, material: groundMaterial })
|
||||
planeBody.addShape(planeShape)
|
||||
planeBody.quaternion.setFromAxisAngle(new CANNON.Vec3(1, 0, 0), -Math.PI / 2)
|
||||
world.addBody(planeBody)
|
||||
//const world = new CANNON.World()
|
||||
//world.gravity.set(0, -9.82, 0)
|
||||
let gravity = { x: 0.0, y: -9.81, z: 0.0 };
|
||||
let world = new RAPIER.World(gravity);
|
||||
|
||||
// Create Ground.
|
||||
let bodyDesc = RAPIER.RigidBodyDesc.fixed();
|
||||
let body = world.createRigidBody(bodyDesc);
|
||||
let colliderDesc = RAPIER.ColliderDesc.cuboid(100.0, 0.1, 100.0);
|
||||
world.createCollider(colliderDesc, body.handle);
|
||||
|
||||
// const groundMaterial = new CANNON.Material('groundMaterial')
|
||||
// const slipperyMaterial = new CANNON.Material('slipperyMaterial')
|
||||
// const slippery_ground_cm = new CANNON.ContactMaterial(
|
||||
// groundMaterial,
|
||||
// slipperyMaterial,
|
||||
// {
|
||||
// friction: 0,
|
||||
// restitution: 0.3,
|
||||
// contactEquationStiffness: 1e10,
|
||||
// contactEquationRelaxation: 30,
|
||||
// }
|
||||
// )
|
||||
// world.addContactMaterial(slippery_ground_cm)
|
||||
// const planeShape = new CANNON.Plane()
|
||||
// const planeBody = new CANNON.Body({ mass: 0, material: groundMaterial })
|
||||
// planeBody.addShape(planeShape)
|
||||
// planeBody.quaternion.setFromAxisAngle(new CANNON.Vec3(1, 0, 0), -Math.PI / 2)
|
||||
// world.addBody(planeBody)
|
||||
this.phy = {
|
||||
world, slipperyMaterial
|
||||
world,
|
||||
//slipperyMaterial
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user