fixed custom physics and simplified diasounds.ts
This commit is contained in:
parent
23bce14635
commit
26c8fb664f
@ -23,7 +23,6 @@ import {IndexdbPersistenceManager} from "./integration/indexdbPersistenceManager
|
|||||||
export class App {
|
export class App {
|
||||||
//preTasks = [havokModule];
|
//preTasks = [havokModule];
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
||||||
const logger = log.getLogger('App');
|
const logger = log.getLogger('App');
|
||||||
log.setDefaultLevel('warn');
|
log.setDefaultLevel('warn');
|
||||||
const canvas = document.createElement("canvas");
|
const canvas = document.createElement("canvas");
|
||||||
@ -49,6 +48,7 @@ export class App {
|
|||||||
const persistenceManager = new IndexdbPersistenceManager("diagram");
|
const persistenceManager = new IndexdbPersistenceManager("diagram");
|
||||||
const controllers = new Controllers();
|
const controllers = new Controllers();
|
||||||
const toolbox = new Toolbox(scene, controllers);
|
const toolbox = new Toolbox(scene, controllers);
|
||||||
|
|
||||||
const diagramManager = new DiagramManager(scene, controllers, toolbox);
|
const diagramManager = new DiagramManager(scene, controllers, toolbox);
|
||||||
diagramManager.setPersistenceManager(persistenceManager);
|
diagramManager.setPersistenceManager(persistenceManager);
|
||||||
const config = new AppConfig(persistenceManager);
|
const config = new AppConfig(persistenceManager);
|
||||||
@ -60,7 +60,6 @@ export class App {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const camera: ArcRotateCamera = new ArcRotateCamera("Camera", -Math.PI / 2, Math.PI / 2, 4,
|
const camera: ArcRotateCamera = new ArcRotateCamera("Camera", -Math.PI / 2, Math.PI / 2, 4,
|
||||||
new Vector3(0, 1.6, 0), scene);
|
new Vector3(0, 1.6, 0), scene);
|
||||||
|
|
||||||
@ -104,7 +103,6 @@ export class App {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const gamepadManager = new GamepadManager(scene);
|
const gamepadManager = new GamepadManager(scene);
|
||||||
/*
|
/*
|
||||||
const voiceManager = new VoiceManager();
|
const voiceManager = new VoiceManager();
|
||||||
|
|||||||
@ -14,43 +14,38 @@ export class CustomPhysics {
|
|||||||
public async initializeAsync() {
|
public async initializeAsync() {
|
||||||
const havok = await HavokPhysics();
|
const havok = await HavokPhysics();
|
||||||
const havokPlugin = new HavokPlugin(true, havok);
|
const havokPlugin = new HavokPlugin(true, havok);
|
||||||
this.scene.enablePhysics(new Vector3(0, -9.8, 0), havokPlugin);
|
const scene = this.scene;
|
||||||
this.scene.collisionsEnabled = true;
|
scene.enablePhysics(new Vector3(0, -9.8, 0), havokPlugin);
|
||||||
this.scene.onAfterPhysicsObservable.add(() => {
|
scene.collisionsEnabled = true;
|
||||||
this.scene.meshes.forEach((mesh) => {
|
scene.onAfterPhysicsObservable.add(() => {
|
||||||
|
scene.meshes.forEach((mesh) => {
|
||||||
if (mesh?.metadata?.template && mesh.physicsBody) {
|
if (mesh?.metadata?.template && mesh.physicsBody) {
|
||||||
const body = mesh.physicsBody;
|
const body = mesh.physicsBody;
|
||||||
const linearVelocity = new Vector3();
|
const linearVelocity = new Vector3();
|
||||||
body.getLinearVelocityToRef(linearVelocity);
|
body.getLinearVelocityToRef(linearVelocity);
|
||||||
if (linearVelocity.length() < .1) {
|
if (linearVelocity.length() < .1) {
|
||||||
if (true) {
|
|
||||||
body.disablePreStep = false;
|
body.disablePreStep = false;
|
||||||
const pos: Vector3 = body.getObjectCenterWorld();
|
const pos: Vector3 = body.getObjectCenterWorld();
|
||||||
const val: Vector3 = this.config.snapGridVal(pos);
|
const val: Vector3 = this.config.snapGridVal(pos,
|
||||||
|
this.config.current.gridSnap);
|
||||||
body.transformNode.position.set(val.x, val.y, val.z);
|
body.transformNode.position.set(val.x, val.y, val.z);
|
||||||
const rot: Quaternion =
|
const rot: Quaternion =
|
||||||
Quaternion.FromEulerVector(this.config.snapRotateVal(body.transformNode.rotationQuaternion.toEulerAngles()))
|
Quaternion.FromEulerVector(
|
||||||
|
this.config.snapRotateVal(body.transformNode.rotationQuaternion.toEulerAngles(),
|
||||||
|
this.config.current.rotateSnap))
|
||||||
|
|
||||||
body.transformNode.rotationQuaternion.set(
|
body.transformNode.rotationQuaternion.set(
|
||||||
rot.x, rot.y, rot.z, rot.w
|
rot.x, rot.y, rot.z, rot.w
|
||||||
);
|
);
|
||||||
|
scene.onAfterRenderObservable.addOnce(() => {
|
||||||
//mesh.metadata.snapped=true;
|
|
||||||
//(this.scene.getPhysicsEngine().getPhysicsPlugin() as IPhysicsEnginePluginV2).syncTransform(body, body.transformNode);
|
|
||||||
this.scene.onAfterRenderObservable.addOnce(() => {
|
|
||||||
body.disablePreStep = true;
|
body.disablePreStep = true;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//mesh.metadata.snapped = false;
|
|
||||||
}
|
|
||||||
//mesh.position = mesh.physicsImpostor.physicsBody.position;
|
|
||||||
//mesh.rotationQuaternion = mesh.physicsImpostor.physicsBody.quaternion;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -20,36 +20,22 @@ export class DiaSounds {
|
|||||||
|
|
||||||
constructor(scene: Scene) {
|
constructor(scene: Scene) {
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
this._enter = new Sound("enter", "/assets/sounds/sounds.mp3", this.scene, null, {
|
const soundSprite = [
|
||||||
autoplay: false,
|
{obj: "_enter", name: "enter", url: "/assets/sounds/sounds.mp3"},
|
||||||
loop: false,
|
{obj: "_exit", name: "exit", url: "/assets/sounds/sounds.mp3"},
|
||||||
volume: this.volume,
|
{obj: "_high", name: "high", url: "/assets/sounds/sounds.mp3"},
|
||||||
offset: 0,
|
{obj: "_low", name: "low", url: "/assets/sounds/sounds.mp3"},
|
||||||
length: 1.0
|
];
|
||||||
});
|
|
||||||
this._exit = new Sound("exit", "/assets/sounds/sounds.mp3", this.scene, null, {
|
|
||||||
autoplay: false,
|
|
||||||
loop: false,
|
|
||||||
offset: 1,
|
|
||||||
volume: this.volume,
|
|
||||||
length: 1.0
|
|
||||||
});
|
|
||||||
this._high = new Sound("high", "/assets/sounds/sounds.mp3", this.scene, null, {
|
|
||||||
autoplay: false,
|
|
||||||
loop: false,
|
|
||||||
offset: 2,
|
|
||||||
volume: this.volume,
|
|
||||||
length: 1.0
|
|
||||||
});
|
|
||||||
this._low = new Sound("low", "/assets/sounds/sounds.mp3", this.scene, null, {
|
|
||||||
autoplay: false,
|
|
||||||
loop: false,
|
|
||||||
offset: 3,
|
|
||||||
volume: this.volume,
|
|
||||||
length: 1.0
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
soundSprite.forEach((item: { obj: any, name: string, url: string }, idx) => {
|
||||||
|
this[item.obj] = new Sound(item.name, item.url, this.scene, null, {
|
||||||
|
autoplay: false,
|
||||||
|
loop: false,
|
||||||
|
volume: this.volume,
|
||||||
|
offset: idx,
|
||||||
|
length: 1.0
|
||||||
|
});
|
||||||
|
});
|
||||||
this._bounce = new Sound("bounce", "/assets/sounds/drumsprite.mp3", this.scene, null, {
|
this._bounce = new Sound("bounce", "/assets/sounds/drumsprite.mp3", this.scene, null, {
|
||||||
autoplay: false,
|
autoplay: false,
|
||||||
loop: false,
|
loop: false,
|
||||||
@ -61,24 +47,27 @@ export class DiaSounds {
|
|||||||
volume: 1,
|
volume: 1,
|
||||||
loop: true
|
loop: true
|
||||||
});
|
});
|
||||||
this._birds = new Sound("warbler", "/assets/sounds/warbler.mp3", this.scene, null, {
|
const spatialOptions = {
|
||||||
spatialSound: true,
|
spatialSound: true,
|
||||||
autoplay: false,
|
autoplay: false,
|
||||||
volume: .5,
|
volume: .5,
|
||||||
loop: false
|
loop: false
|
||||||
});
|
}
|
||||||
this.birds.switchPanningModelToHRTF();
|
this._birds = this.buildSpatialSound("warbler", "/assets/sounds/warbler.mp3");
|
||||||
this.birds.maxDistance = 40;
|
this._dove = this.buildSpatialSound("dove", "/assets/sounds/dove.mp3");
|
||||||
this._dove = new Sound("dove", "/assets/sounds/dove.mp3", this.scene, null, {
|
}
|
||||||
spatialSound: true,
|
|
||||||
autoplay: false,
|
|
||||||
volume: .5,
|
|
||||||
loop: false
|
|
||||||
});
|
|
||||||
this._dove.switchPanningModelToHRTF();
|
|
||||||
this._dove.maxDistance = 40;
|
|
||||||
|
|
||||||
//this._enter.autoplay = true;
|
private buildSpatialSound(name: string, url: string) {
|
||||||
|
const spatialOptions = {
|
||||||
|
spatialSound: true,
|
||||||
|
autoplay: false,
|
||||||
|
volume: .5,
|
||||||
|
loop: false
|
||||||
|
}
|
||||||
|
const sound = new Sound(name, url, this.scene, null, spatialOptions);
|
||||||
|
sound.switchPanningModelToHRTF();
|
||||||
|
sound.maxDistance = 40;
|
||||||
|
return sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get background(): Sound {
|
public get background(): Sound {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user