Added background noise. Refactor customEnvironment.ts
This commit is contained in:
parent
01874b9e9e
commit
bbe54dc3e3
BIN
public/assets/sounds/noise.mp3
Normal file
BIN
public/assets/sounds/noise.mp3
Normal file
Binary file not shown.
@ -1,5 +1,5 @@
|
|||||||
importScripts('https://storage.googleapis.com/workbox-cdn/releases/7.1.0/workbox-sw.js');
|
importScripts('https://storage.googleapis.com/workbox-cdn/releases/7.1.0/workbox-sw.js');
|
||||||
const VERSION = '5';
|
const VERSION = '6';
|
||||||
const CACHE = "deepdiagram";
|
const CACHE = "deepdiagram";
|
||||||
const IMAGEDELIVERY_CACHE = "deepdiagram-images";
|
const IMAGEDELIVERY_CACHE = "deepdiagram-images";
|
||||||
|
|
||||||
|
|||||||
@ -32,19 +32,11 @@ export class DiagramManager {
|
|||||||
this._diagramMenuManager = new DiagramMenuManager(this.onDiagramEventObservable, this._controllers, this._config);
|
this._diagramMenuManager = new DiagramMenuManager(this.onDiagramEventObservable, this._controllers, this._config);
|
||||||
this._diagramEntityActionManager = buildEntityActionManager(this._controllers);
|
this._diagramEntityActionManager = buildEntityActionManager(this._controllers);
|
||||||
this.onDiagramEventObservable.add(this.onDiagramEvent, DiagramEventObserverMask.FROM_DB, true, this);
|
this.onDiagramEventObservable.add(this.onDiagramEvent, DiagramEventObserverMask.FROM_DB, true, this);
|
||||||
this.logger.debug("DiagramManager constructed");
|
|
||||||
this._scene.onMeshRemovedObservable.add((mesh) => {
|
this._scene.onMeshRemovedObservable.add((mesh) => {
|
||||||
cleanupOrphanConnections(mesh, this.onDiagramEventObservable);
|
cleanupOrphanConnections(mesh, this.onDiagramEventObservable);
|
||||||
});
|
});
|
||||||
document.addEventListener('uploadImage', (event: CustomEvent) => {
|
document.addEventListener('uploadImage', (event: CustomEvent) => {
|
||||||
let position = {x: 0, y: 1.6, z: 0};
|
|
||||||
if (event.detail.position) {
|
|
||||||
position = {
|
|
||||||
x: event.detail.position.x,
|
|
||||||
y: event.detail.position.y,
|
|
||||||
z: event.detail.position.z
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const diagramEntity: DiagramEntity = {
|
const diagramEntity: DiagramEntity = {
|
||||||
template: '#image-template',
|
template: '#image-template',
|
||||||
image: event.detail.data,
|
image: event.detail.data,
|
||||||
@ -60,7 +52,8 @@ export class DiagramManager {
|
|||||||
entity: diagramEntity
|
entity: diagramEntity
|
||||||
}, DiagramEventObserverMask.ALL);
|
}, DiagramEventObserverMask.ALL);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
this.logger.debug("DiagramManager constructed");
|
||||||
}
|
}
|
||||||
|
|
||||||
public get diagramMenuManager(): DiagramMenuManager {
|
public get diagramMenuManager(): DiagramMenuManager {
|
||||||
@ -71,6 +64,7 @@ export class DiagramManager {
|
|||||||
return this._controllers;
|
return this._controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public createCopy(mesh: AbstractMesh, copy: boolean = false): AbstractMesh {
|
public createCopy(mesh: AbstractMesh, copy: boolean = false): AbstractMesh {
|
||||||
const newMesh = newInstanceFromMeshOrInstance(mesh);
|
const newMesh = newInstanceFromMeshOrInstance(mesh);
|
||||||
newMesh.id = 'id' + uuidv4();
|
newMesh.id = 'id' + uuidv4();
|
||||||
@ -109,9 +103,9 @@ function newInstanceFromMeshOrInstance(mesh: AbstractMesh): AbstractMesh {
|
|||||||
return new InstancedMesh('id' + uuidv4(), (mesh as InstancedMesh).sourceMesh);
|
return new InstancedMesh('id' + uuidv4(), (mesh as InstancedMesh).sourceMesh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanupOrphanConnections(mesh: AbstractMesh, diagramEventObservable: Observable<DiagramEvent>) {
|
function cleanupOrphanConnections(mesh: AbstractMesh, diagramEventObservable: Observable<DiagramEvent>) {
|
||||||
if (isDiagramEntity(mesh)) {
|
if (isDiagramEntity(mesh) && mesh.metadata.template != '#connection-template') {
|
||||||
if (mesh.metadata.template != '#connection-template') {
|
|
||||||
mesh.getScene().meshes.forEach((m) => {
|
mesh.getScene().meshes.forEach((m) => {
|
||||||
if (m?.metadata?.to == mesh.id || m?.metadata?.from == mesh.id) {
|
if (m?.metadata?.to == mesh.id || m?.metadata?.from == mesh.id) {
|
||||||
diagramEventObservable.notifyObservers({type: DiagramEventType.REMOVE, entity: toDiagramEntity(m)});
|
diagramEventObservable.notifyObservers({type: DiagramEventType.REMOVE, entity: toDiagramEntity(m)});
|
||||||
@ -119,4 +113,3 @@ function cleanupOrphanConnections(mesh: AbstractMesh, diagramEventObservable: Ob
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@ -10,6 +10,7 @@ import {
|
|||||||
PhysicsShapeType,
|
PhysicsShapeType,
|
||||||
PointsCloudSystem,
|
PointsCloudSystem,
|
||||||
Scene,
|
Scene,
|
||||||
|
Sound,
|
||||||
Texture,
|
Texture,
|
||||||
TransformNode,
|
TransformNode,
|
||||||
Vector3
|
Vector3
|
||||||
@ -32,58 +33,36 @@ export class CustomEnvironment {
|
|||||||
if (loading) {
|
if (loading) {
|
||||||
loading.remove();
|
loading.remove();
|
||||||
}
|
}
|
||||||
|
this.scene.ambientColor = new Color3(.2, .2, .2);
|
||||||
const light = new HemisphericLight("light1", new Vector3(1, 2, 1), this.scene);
|
const light = new HemisphericLight("light1", new Vector3(1, 2, 1), this.scene);
|
||||||
light.groundColor = new Color3(.1, .1, .1)
|
light.groundColor = new Color3(.1, .1, .1)
|
||||||
light.diffuse = new Color3(1, 1, 1);
|
light.diffuse = new Color3(1, 1, 1);
|
||||||
light.intensity = .8;
|
light.setDirectionToTarget(new Vector3(.4, .5, .5).normalize());
|
||||||
|
light.intensity = .5;
|
||||||
|
|
||||||
const physics = new CustomPhysics(this.scene, config);
|
const physics = new CustomPhysics(this.scene, config);
|
||||||
physics
|
physics
|
||||||
.initializeAsync()
|
.initializeAsync()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const ground = this.createGround();
|
const ground = this.createGround();
|
||||||
|
new PhysicsAggregate(ground, PhysicsShapeType.BOX, {mass: 0}, this.scene);
|
||||||
|
createPoints(20, 20);
|
||||||
|
this.createBackgroundAudio();
|
||||||
this._groundMeshObservable.notifyObservers(ground);
|
this._groundMeshObservable.notifyObservers(ground);
|
||||||
|
this.createWalls();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private initSounds() {
|
|
||||||
/* try {
|
|
||||||
const sounds = new DiaSounds(this.scene);
|
|
||||||
window.setTimeout((sound) => {
|
|
||||||
sound.play()
|
|
||||||
}, 2000, sounds.background);
|
|
||||||
const effects: Array<Sound> = sounds.backgroundEffects;
|
|
||||||
|
|
||||||
window.setInterval((sounds: Array<Sound>) => {
|
|
||||||
if (Math.random() < .5) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const MAX_DISTANCE = 40;
|
|
||||||
const sound = Math.floor(Math.random() * sounds.length);
|
|
||||||
const x = (Math.random() * MAX_DISTANCE) - (MAX_DISTANCE / 2);
|
|
||||||
const y = Math.random() * (MAX_DISTANCE / 2);
|
|
||||||
const z = (Math.random() * MAX_DISTANCE) - (MAX_DISTANCE / 2);
|
|
||||||
|
|
||||||
const position = new Vector3(x, y, z);
|
|
||||||
if (sounds[sound].isPlaying) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
sounds[sound].setPosition(position);
|
|
||||||
sounds[sound].setVolume(Math.random() * .3);
|
|
||||||
sounds[sound].play();
|
|
||||||
}
|
|
||||||
|
|
||||||
}, 2000, effects);
|
|
||||||
} catch (error) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
public get groundMeshObservable() {
|
public get groundMeshObservable() {
|
||||||
return this._groundMeshObservable;
|
return this._groundMeshObservable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private createBackgroundAudio() {
|
||||||
|
const noise = new Sound("backgroundNoise", "/assets/sounds/noise.mp3", this.scene, null, {
|
||||||
|
loop: true,
|
||||||
|
volume: .2,
|
||||||
|
autoplay: true
|
||||||
|
});
|
||||||
|
}
|
||||||
private createGround() {
|
private createGround() {
|
||||||
const scene = this.scene;
|
const scene = this.scene;
|
||||||
|
|
||||||
@ -92,24 +71,23 @@ export class CustomEnvironment {
|
|||||||
height: 20,
|
height: 20,
|
||||||
subdivisions: 1
|
subdivisions: 1
|
||||||
}, scene);
|
}, scene);
|
||||||
createPoints(20, 20);
|
|
||||||
ground.material = createGridMaterial(Color3.FromHexString("#aaffaa"), Color3.FromHexString("#111511"));
|
ground.material = createGridMaterial(Color3.FromHexString("#aaffaa"), Color3.FromHexString("#111511"));
|
||||||
|
|
||||||
|
//buildAvatar(scene);
|
||||||
|
return ground;
|
||||||
|
}
|
||||||
|
|
||||||
|
private createWalls() {
|
||||||
const color1 = Color3.FromHexString("#ff9999");
|
const color1 = Color3.FromHexString("#ff9999");
|
||||||
const color2 = Color3.FromHexString("#221111");
|
const color2 = Color3.FromHexString("#221111");
|
||||||
const color3 = Color3.FromHexString("#9999ff");
|
const color3 = Color3.FromHexString("#9999ff");
|
||||||
const color4 = Color3.FromHexString("#111115");
|
const color4 = Color3.FromHexString("#111115");
|
||||||
|
|
||||||
|
|
||||||
this.createWall(new Vector3(0, 10, 10), new Vector3(0, 0, 0), color3, color4);
|
this.createWall(new Vector3(0, 10, 10), new Vector3(0, 0, 0), color3, color4);
|
||||||
this.createWall(new Vector3(0, 10, -10), new Vector3(0, Math.PI, 0), color3, color4);
|
this.createWall(new Vector3(0, 10, -10), new Vector3(0, Math.PI, 0), color3, color4);
|
||||||
this.createWall(new Vector3(10, 10, 0), new Vector3(0, Math.PI / 2, 0), color1, color2);
|
this.createWall(new Vector3(10, 10, 0), new Vector3(0, Math.PI / 2, 0), color1, color2);
|
||||||
this.createWall(new Vector3(-10, 10, 0), new Vector3(0, -Math.PI / 2, 0), color1, color2);
|
this.createWall(new Vector3(-10, 10, 0), new Vector3(0, -Math.PI / 2, 0), color1, color2);
|
||||||
|
|
||||||
new PhysicsAggregate(ground, PhysicsShapeType.BOX, {mass: 0}, scene);
|
|
||||||
//buildAvatar(scene);
|
|
||||||
return ground;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private createWall(position: Vector3, rotation: Vector3, color1: Color3, color2: Color3) {
|
private createWall(position: Vector3, rotation: Vector3, color1: Color3, color2: Color3) {
|
||||||
const scene = this.scene;
|
const scene = this.scene;
|
||||||
const wall = MeshBuilder.CreatePlane("wall", {width: 20, height: 20}, scene);
|
const wall = MeshBuilder.CreatePlane("wall", {width: 20, height: 20}, scene);
|
||||||
@ -122,6 +100,7 @@ export class CustomEnvironment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function createPoints(divisions: number = 10, scale: number = 80) {
|
async function createPoints(divisions: number = 10, scale: number = 80) {
|
||||||
const scene = DefaultScene.Scene;
|
const scene = DefaultScene.Scene;
|
||||||
const half = .5;
|
const half = .5;
|
||||||
|
|||||||
45
src/vrApp.ts
45
src/vrApp.ts
@ -29,28 +29,6 @@ export class VrApp {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async initialize(scene: Scene) {
|
|
||||||
setMainCamera(scene);
|
|
||||||
const spinner = new Spinner();
|
|
||||||
spinner.show();
|
|
||||||
const diagramManager = new DiagramManager();
|
|
||||||
await initDb(diagramManager);
|
|
||||||
initEnvironment(diagramManager, spinner);
|
|
||||||
const gamepadManager = new GamepadManager(scene);
|
|
||||||
addSceneInspector();
|
|
||||||
const el = document.querySelector('#download');
|
|
||||||
if (el) {
|
|
||||||
el.addEventListener('click', () => {
|
|
||||||
exportGltf();
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if (!localStorage.getItem('tutorialCompleted')) {
|
|
||||||
this.logger.info('Starting tutorial');
|
|
||||||
const intro = new Introduction();
|
|
||||||
}
|
|
||||||
this.logger.info('Render loop started');
|
|
||||||
}
|
|
||||||
|
|
||||||
private async initializeEngine() {
|
private async initializeEngine() {
|
||||||
let engine: WebGPUEngine | Engine = null;
|
let engine: WebGPUEngine | Engine = null;
|
||||||
if (webGpu) {
|
if (webGpu) {
|
||||||
@ -73,6 +51,29 @@ export class VrApp {
|
|||||||
scene.render();
|
scene.render();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
public async initialize(scene: Scene) {
|
||||||
|
setMainCamera(scene);
|
||||||
|
const spinner = new Spinner();
|
||||||
|
spinner.show();
|
||||||
|
const diagramManager = new DiagramManager();
|
||||||
|
await initDb(diagramManager);
|
||||||
|
initEnvironment(diagramManager, spinner);
|
||||||
|
const gamepadManager = new GamepadManager(scene);
|
||||||
|
addSceneInspector();
|
||||||
|
const el = document.querySelector('#download');
|
||||||
|
if (el) {
|
||||||
|
el.addEventListener('click', () => {
|
||||||
|
exportGltf();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (!localStorage.getItem('tutorialCompleted')) {
|
||||||
|
this.logger.info('Starting tutorial');
|
||||||
|
const intro = new Introduction();
|
||||||
|
}
|
||||||
|
this.logger.info('Render loop started');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
const vrApp = new VrApp();
|
const vrApp = new VrApp();
|
||||||
buildQuestLink();
|
buildQuestLink();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user