Added some sounds.

This commit is contained in:
Michael Mainguy 2023-07-29 21:38:52 -05:00
parent 4c52d7b1d7
commit d67fbbedee
8 changed files with 94 additions and 7 deletions

BIN
public/Big Dripper_1.wav Normal file

Binary file not shown.

BIN
public/sounds.mp3 Normal file

Binary file not shown.

View File

@ -27,6 +27,7 @@ import {DualshockEventMapper} from "./util/dualshockEventMapper";
import log from "loglevel"; import log from "loglevel";
import {AppConfig} from "./util/appConfig"; import {AppConfig} from "./util/appConfig";
import {IndexdbPersistenceManager} from "./diagram/indexdbPersistenceManager"; import {IndexdbPersistenceManager} from "./diagram/indexdbPersistenceManager";
import {DiaSounds} from "./util/diaSounds";
export class App { export class App {
//preTasks = [havokModule]; //preTasks = [havokModule];
@ -64,6 +65,8 @@ export class App {
const scene = new Scene(engine); const scene = new Scene(engine);
this.scene = scene; this.scene = scene;
const sounds = new DiaSounds(scene);
sounds.enter.autoplay = true;
const havokInstance = await HavokPhysics(); const havokInstance = await HavokPhysics();
@ -95,8 +98,12 @@ export class App {
} }
}); });
this.xr.baseExperience.onStateChangedObservable.add((state) => { this.xr.baseExperience.onStateChangedObservable.add((state) => {
if (state == WebXRState.IN_XR) { if (state == WebXRState.IN_XR) {
this.scene.audioEnabled = true;
this.xr.baseExperience.camera.position = new Vector3(0, 1.6, 0); this.xr.baseExperience.camera.position = new Vector3(0, 1.6, 0);
window.addEventListener(('pa-button-state-change'), (event: any) => { window.addEventListener(('pa-button-state-change'), (event: any) => {
if (event.detail) { if (event.detail) {

View File

@ -51,8 +51,8 @@ export class Base {
Controllers.controllerObserver.add((event) => { Controllers.controllerObserver.add((event) => {
if (event.type == 'pulse') { if (event.type == 'pulse') {
this.logger.debug(event); this.logger.debug(event);
if (event.gripId == this.controller.grip.id) { if (event.gripId == this?.controller?.grip?.id) {
this.controller.motionController.pulse(.25, 30); this.controller?.motionController?.pulse(.25, 30);
} }
} }
}); });

View File

@ -8,7 +8,6 @@ import {
Observable, Observable,
PlaySoundAction, PlaySoundAction,
Scene, Scene,
Sound,
WebXRExperienceHelper WebXRExperienceHelper
} from "@babylonjs/core"; } from "@babylonjs/core";
import {DiagramEntity, DiagramEvent, DiagramEventType} from "./diagramEntity"; import {DiagramEntity, DiagramEvent, DiagramEventType} from "./diagramEntity";
@ -16,6 +15,7 @@ import {IPersistenceManager} from "./persistenceManager";
import {MeshConverter} from "./meshConverter"; import {MeshConverter} from "./meshConverter";
import log from "loglevel"; import log from "loglevel";
import {Controllers} from "../controllers/controllers"; import {Controllers} from "../controllers/controllers";
import {DiaSounds} from "../util/diaSounds";
export class DiagramManager { export class DiagramManager {
public readonly onDiagramEventObservable: Observable<DiagramEvent> = new Observable(); public readonly onDiagramEventObservable: Observable<DiagramEvent> = new Observable();
@ -24,7 +24,6 @@ export class DiagramManager {
private readonly scene: Scene; private readonly scene: Scene;
private xr: WebXRExperienceHelper; private xr: WebXRExperienceHelper;
private readonly tick: Sound;
public setPersistenceManager(persistenceManager: IPersistenceManager) { public setPersistenceManager(persistenceManager: IPersistenceManager) {
this.persistenceManager = persistenceManager; this.persistenceManager = persistenceManager;
@ -43,11 +42,9 @@ export class DiagramManager {
constructor(scene: Scene, xr: WebXRExperienceHelper) { constructor(scene: Scene, xr: WebXRExperienceHelper) {
this.scene = scene; this.scene = scene;
this.xr = xr; this.xr = xr;
this.tick = new Sound("tick", './tick.mp3', this.scene);
this.tick.setVolume(.3);
this.actionManager = new ActionManager(this.scene); this.actionManager = new ActionManager(this.scene);
this.actionManager.registerAction( this.actionManager.registerAction(
new PlaySoundAction(ActionManager.OnPointerOverTrigger, this.tick)); new PlaySoundAction(ActionManager.OnPointerOverTrigger, DiaSounds.instance.tick));
this.actionManager.registerAction( this.actionManager.registerAction(
new ExecuteCodeAction(ActionManager.OnPointerOverTrigger, (evt) => { new ExecuteCodeAction(ActionManager.OnPointerOverTrigger, (evt) => {
Controllers.controllerObserver.notifyObservers({ Controllers.controllerObserver.notifyObservers({

View File

@ -15,6 +15,7 @@ import log from "loglevel";
export class MeshConverter { export class MeshConverter {
private static logger = log.getLogger('MeshConverter'); private static logger = log.getLogger('MeshConverter');
public static toDiagramEntity(mesh: AbstractMesh): DiagramEntity { public static toDiagramEntity(mesh: AbstractMesh): DiagramEntity {
if (!mesh) { if (!mesh) {
this.logger.error("toDiagramEntity: mesh is null"); this.logger.error("toDiagramEntity: mesh is null");
@ -57,6 +58,7 @@ export class MeshConverter {
log.debug('error: mesh is an instance'); log.debug('error: mesh is an instance');
} else { } else {
mesh = new InstancedMesh(entity.id, (mesh as Mesh)); mesh = new InstancedMesh(entity.id, (mesh as Mesh));
} }
} else { } else {
log.debug('no mesh found for ' + entity.template + "-" + entity.color); log.debug('no mesh found for ' + entity.template + "-" + entity.color);
@ -68,7 +70,10 @@ export class MeshConverter {
mesh.metadata = {template: entity.template}; mesh.metadata = {template: entity.template};
if (entity.position) { if (entity.position) {
mesh.position = entity.position; mesh.position = entity.position;
} }
if (entity.rotation) { if (entity.rotation) {
mesh.rotation = entity.rotation; mesh.rotation = entity.rotation;
@ -88,6 +93,15 @@ export class MeshConverter {
mesh.metadata.text = entity.text; mesh.metadata.text = entity.text;
this.updateTextNode(mesh, entity.text); this.updateTextNode(mesh, entity.text);
} }
/*
const sphereAggregate = new PhysicsAggregate(mesh, PhysicsShapeType.BOX, {
mass: 10,
restitution: 0.1,
startAsleep: false
}, scene);
*/
} else { } else {
this.logger.error("fromDiagramEntity: mesh is null after it should have been created"); this.logger.error("fromDiagramEntity: mesh is null after it should have been created");
} }

View File

@ -4,6 +4,7 @@ import {CameraHelper} from "../util/cameraHelper";
import log from "loglevel"; import log from "loglevel";
import {AppConfig} from "../util/appConfig"; import {AppConfig} from "../util/appConfig";
import {Controllers} from "../controllers/controllers"; import {Controllers} from "../controllers/controllers";
import {DiaSounds} from "../util/diaSounds";
export class ConfigMenu { export class ConfigMenu {
private readonly scene: Scene; private readonly scene: Scene;
@ -22,10 +23,12 @@ export class ConfigMenu {
public toggle() { public toggle() {
if (this.configPlane) { if (this.configPlane) {
DiaSounds.instance.exit.play();
this.configPlane.dispose(); this.configPlane.dispose();
this.configPlane = null; this.configPlane = null;
return; return;
} }
DiaSounds.instance.enter.play();
const width = .25; const width = .25;
const height = .55; const height = .55;
const res = 256; const res = 256;

66
src/util/diaSounds.ts Normal file
View File

@ -0,0 +1,66 @@
import {Scene, Sound} from "@babylonjs/core";
export class DiaSounds {
public static instance: DiaSounds;
private scene: Scene;
constructor(scene: Scene) {
this.scene = scene;
this._enter = new Sound("enter", "./sounds.mp3", this.scene, null, {
autoplay: false,
loop: false,
offset: 0,
length: 1.0
});
this._exit = new Sound("exit", "./sounds.mp3", this.scene, null, {
autoplay: false,
loop: false,
offset: 1,
length: 1.0
});
this._high = new Sound("high", "./sounds.mp3", this.scene, null, {
autoplay: false,
loop: false,
offset: 2,
length: 1.0
});
this._low = new Sound("low", "./sounds.mp3", this.scene, null, {
autoplay: false,
loop: false,
offset: 2,
length: 1.0
});
DiaSounds.instance = this;
}
public get tick() {
return new Sound("tick", './tick.mp3', this.scene);
}
private _enter: Sound;
public get enter() {
return this._enter;
}
private _exit: Sound;
public get exit() {
return this._exit;
}
private _high: Sound;
public get high() {
return this._high;
}
private _low: Sound;
public get low() {
return this._low;
}
}