modified buildRig.ts
This commit is contained in:
parent
9cfab198d8
commit
2509869723
@ -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);
|
||||
if (appConfig.current.flyMode) {
|
||||
rigAggregate.body.setGravityFactor(.02);
|
||||
} else {
|
||||
rigAggregate.body.setGravityFactor(1);
|
||||
}
|
||||
|
||||
return rigMesh;
|
||||
}
|
||||
|
||||
@ -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:
|
||||
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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user