From 2509869723f2337af518ea1b003fa0f446672923 Mon Sep 17 00:00:00 2001 From: Michael Mainguy Date: Sun, 17 Sep 2023 09:15:57 -0500 Subject: [PATCH] modified buildRig.ts --- src/controllers/functions/buildRig.ts | 32 +++++++++++++++++++++++---- src/controllers/rigplatform.ts | 26 +++++++++++++++++++--- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/controllers/functions/buildRig.ts b/src/controllers/functions/buildRig.ts index dbe9d76..04faf88 100644 --- a/src/controllers/functions/buildRig.ts +++ b/src/controllers/functions/buildRig.ts @@ -9,9 +9,10 @@ import { StandardMaterial, Vector3 } from "@babylonjs/core"; +import {AppConfig} from "../../util/appConfig"; -export function buildRig(scene: Scene): Mesh { - const rigMesh = MeshBuilder.CreateBox("platform", {width: 2, height: .02, depth: 2}, scene); +export function buildRig(scene: Scene, appConfig: AppConfig): Mesh { + const rigMesh = MeshBuilder.CreateBox("platform", {width: 2, height: .1, depth: 2}, scene); for (const cam of scene.cameras) { cam.parent = rigMesh; } @@ -24,10 +25,33 @@ export function buildRig(scene: Scene): Mesh { new PhysicsAggregate( rigMesh, PhysicsShapeType.CYLINDER, - {friction: 0, center: Vector3.Zero(), radius: .5, mass: 10, restitution: .01}, + {friction: 0, center: Vector3.Zero(), mass: 50, restitution: .1}, scene); + /*const rightFoot = MeshBuilder.CreateBox("rightFoot", {width: .1, height: .1, depth: .2}, scene); + const rightFootAggregate = + new PhysicsAggregate( + rightFoot, + PhysicsShapeType.BOX, + { friction: 0, center: Vector3.Zero(), radius: .2, pointA: new Vector3(0, 0, 0), + pointB: new Vector3(0, 1.5, 0), mass: 50, restitution: .1}, + scene); + rightFootAggregate.body.setMotionType(PhysicsMotionType.ANIMATED); + rightFoot.parent= rigAggregate.transformNode; + rightFoot.material = rigMaterial; + rightFoot.position.y=.05; + rightFoot.position.x=.2; + rightFoot.position.z= 2; + + */ + + rigAggregate.body.setMotionType(PhysicsMotionType.DYNAMIC); - rigAggregate.body.setGravityFactor(.02); + if (appConfig.current.flyMode) { + rigAggregate.body.setGravityFactor(.02); + } else { + rigAggregate.body.setGravityFactor(1); + } + return rigMesh; } diff --git a/src/controllers/rigplatform.ts b/src/controllers/rigplatform.ts index 76f7e7c..cfa7a3f 100644 --- a/src/controllers/rigplatform.ts +++ b/src/controllers/rigplatform.ts @@ -1,4 +1,4 @@ -import {Angle, Mesh, Quaternion, Scene, Vector3, WebXRDefaultExperience} from "@babylonjs/core"; +import {Angle, Color3, Mesh, MeshBuilder, Quaternion, Scene, Vector3, WebXRDefaultExperience} from "@babylonjs/core"; import {Right} from "./right"; import {Left} from "./left"; import {EditMenu} from "../menus/editMenu"; @@ -36,7 +36,7 @@ export class Rigplatform { this.controllers = controllers; this.xr = xr; this.bMenu = new EditMenu(scene, xr, this.diagramManager, controllers); - this.rigMesh = buildRig(scene); + this.rigMesh = buildRig(scene, this.diagramManager.config); this.fixRotation(); this.initializeControllers(); scene.onActiveCameraChanged.add((s) => { @@ -78,6 +78,9 @@ export class Rigplatform { private registerVelocityObserver() { this.scene.onBeforeRenderObservable.add(() => { const vel = this.velocity.applyRotationQuaternion(this.scene.activeCamera.absoluteRotation); + if (!this.diagramManager.config.current.flyMode) { + vel.y = 0; + } if (vel.length() > 0) { this.logger.debug('Velocity', this.velocity, vel, this.scene.activeCamera.absoluteRotation); } @@ -114,16 +117,33 @@ export class Rigplatform { this.leftright(event.value); break; case ControllerEventType.UP_DOWN: - this.updown(event.value); + if (this.diagramManager.config.current.flyMode) { + this.updown(event.value); + } break; case ControllerEventType.MENU: this.bMenu.toggle(); break; + case ControllerEventType.MOTION: + console.log(JSON.stringify(event)); + this.buildKickLine(event.startPosition, event.endPosition); + break; } }); } } + private buildKickLine(start: Vector3, end: Vector3) { + if (end.y < start.y) { + const line = MeshBuilder.CreateLines("kickLine", {points: [start, end]}, this.scene); + line.color = new Color3(1, 0, 0); + line.isPickable = false; + setTimeout(() => { + line.dispose(); + }, 2000); + } + } + private initializeControllers() { this.xr.input.onControllerAddedObservable.add((source) => { this.registerObserver();