physics test2

This commit is contained in:
2025-10-16 09:53:52 +03:00
parent a60d94fe66
commit 49e0486277
12 changed files with 283 additions and 169 deletions
+13 -14
View File
@@ -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 RAPIER from '@dimforge/rapier3d'
import { Physics } from './Physics.js';
import { Clickable } from './Clickable.js';
class GameEngine {
@@ -161,7 +161,7 @@ class GameEngine {
gameEngine.camera.updateProjectionMatrix();
})
this.initPhysics();
await this.initPhysics();
if (opts.ar) {
renderer.xr.enabled = true;
@@ -246,17 +246,17 @@ class GameEngine {
this.cameraYaw = yaw;
}
initPhysics() {
async initPhysics() {
//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);
// 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);
// // 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')
@@ -276,10 +276,9 @@ class GameEngine {
// planeBody.addShape(planeShape)
// planeBody.quaternion.setFromAxisAngle(new CANNON.Vec3(1, 0, 0), -Math.PI / 2)
// world.addBody(planeBody)
this.phy = {
world,
//slipperyMaterial
}
this.phy = new Physics();
await this.phy.init();
}
handleXrAction(gameEngine, delta) {