Moved grabbing to base controller class.

This commit is contained in:
Michael Mainguy 2023-07-19 16:43:22 -05:00
parent 745aed33af
commit 160138b3f4
4 changed files with 23 additions and 25 deletions

View File

@ -1,4 +1,4 @@
import {AbstractMesh, Scene, Vector3, WebXRInputSource} from "@babylonjs/core"; import {AbstractMesh, Scene, Vector3, WebXRControllerComponent, WebXRInputSource} from "@babylonjs/core";
export class Base { export class Base {
static stickVector = Vector3.Zero(); static stickVector = Vector3.Zero();
@ -23,9 +23,22 @@ export class Base {
} }
}); });
} }
this.initGrip(init.components['xr-standard-squeeze']);
}); });
} }
public mesh() {
return this.controller.grip; private initGrip(grip: WebXRControllerComponent) {
grip.onButtonStateChangedObservable.add((value) => {
if (value.value > .5) {
if (this.currentMesh) {
this.currentMesh.setParent(this.controller.pointer);
}
} else {
if (this.currentMesh) {
this.currentMesh.setParent(null);
}
}
});
} }
} }

View File

@ -21,7 +21,7 @@ export class Right extends Base {
this.initBButton(init.components['b-button']); this.initBButton(init.components['b-button']);
this.initAButton(init.components['a-button']); this.initAButton(init.components['a-button']);
this.initThumbstick(init.components['xr-standard-thumbstick']); this.initThumbstick(init.components['xr-standard-thumbstick']);
this.initGrip(init.components['xr-standard-squeeze']);
}); });
} }
@ -115,20 +115,7 @@ export class Right extends Base {
} }
private initGrip(grip: WebXRControllerComponent) {
grip.onButtonStateChangedObservable.add((value) => {
if (value.value > .5) {
if (this.currentMesh) {
this.currentMesh.setParent(this.controller.pointer);
}
} else {
if (this.currentMesh) {
this.currentMesh.setParent(null);
}
}
});
}
public setBMenu(menu: Bmenu) { public setBMenu(menu: Bmenu) {
this.bmenu = menu; this.bmenu = menu;
this.bmenu.setController(this.controller); this.bmenu.setController(this.controller);

View File

@ -2,5 +2,6 @@ export enum BmenuState {
NONE, NONE,
ADDING, // Adding a new entity ADDING, // Adding a new entity
DROPPING, // Dropping an entity DROPPING, // Dropping an entity
REMOVING, // Removing an entity
} }

View File

@ -1,10 +1,4 @@
import { import {AbstractMesh, Scene, Vector3, WebXRExperienceHelper, WebXRInputSource} from "@babylonjs/core";
AbstractMesh,
Scene,
Vector3,
WebXRExperienceHelper,
WebXRInputSource
} from "@babylonjs/core";
import {GUI3DManager, NearMenu, TouchHolographicButton} from "@babylonjs/gui"; import {GUI3DManager, NearMenu, TouchHolographicButton} from "@babylonjs/gui";
import {DiagramManager} from "../diagram/diagramManager"; import {DiagramManager} from "../diagram/diagramManager";
import {BmenuState} from "./MenuState"; import {BmenuState} from "./MenuState";
@ -79,6 +73,7 @@ export class Bmenu {
panel.addButton(this.makeButton("Add Sphere", "addSphere")); panel.addButton(this.makeButton("Add Sphere", "addSphere"));
panel.addButton(this.makeButton("Add Cylinder", "addCylinder")); panel.addButton(this.makeButton("Add Cylinder", "addCylinder"));
panel.addButton(this.makeButton("Add Text", "addText")); panel.addButton(this.makeButton("Add Text", "addText"));
panel.addButton(this.makeButton("Remove", "remove"));
panel.addButton(this.makeButton("Done Adding", "doneAdding")); panel.addButton(this.makeButton("Done Adding", "doneAdding"));
this.manager.controlScaling = .5; this.manager.controlScaling = .5;
@ -119,7 +114,9 @@ export class Bmenu {
break; break;
case "doneAdding": case "doneAdding":
this.state = BmenuState.NONE; this.state = BmenuState.NONE;
break;
case "remove":
this.state = BmenuState.REMOVING;
break; break;
default: default:
console.log("Unknown button"); console.log("Unknown button");