This commit is contained in:
@@ -75,26 +75,18 @@ export default{
|
|||||||
engine.ambientLight.intensity = 25;
|
engine.ambientLight.intensity = 25;
|
||||||
if (this.obj.type == 'panorama2d') {
|
if (this.obj.type == 'panorama2d') {
|
||||||
await engine.loadPanorama(this.obj.asset.name);
|
await engine.loadPanorama(this.obj.asset.name);
|
||||||
// let t = await engine.loadTexture(`/asset/default/${this.obj.asset.name}`);
|
|
||||||
// t.mapping = engine.$.EquirectangularReflectionMapping;
|
|
||||||
// engine.scene.background = t;
|
|
||||||
// engine.scene.environment = t;
|
|
||||||
// engine.scene.add(engine.camera);
|
|
||||||
} else {
|
} else {
|
||||||
let gltf = await engine.load(this.obj.asset.name);
|
let gltf = await engine.load(this.obj.asset.name);
|
||||||
//console.debug('GLTF', gltf);
|
|
||||||
this.loadedAsset = gltf;
|
this.loadedAsset = gltf;
|
||||||
this.animations = gltf.animations.map(a => ({
|
this.animations = gltf.animations.map(a => ({
|
||||||
name: a.name, id: a.uuid
|
name: a.name, id: a.uuid
|
||||||
}));
|
}));
|
||||||
autoScale(gltf.scene);
|
autoScale(gltf.scene);
|
||||||
let bb = new engine.$.Box3().setFromObject(gltf.scene);
|
let bb = new engine.$.Box3().setFromObject(gltf.scene);
|
||||||
//console.log(bb)
|
|
||||||
engine.camera.position.set(bb.max.x, bb.max.y, bb.max.z*3);
|
engine.camera.position.set(bb.max.x, bb.max.y, bb.max.z*3);
|
||||||
engine.orbitControls.target.set((bb.max.x + bb.min.x) / 2, (bb.max.y + bb.min.y) / 2, (bb.max.z + bb.min.z) / 2)
|
engine.orbitControls.target.set((bb.max.x + bb.min.x) / 2, (bb.max.y + bb.min.y) / 2, (bb.max.z + bb.min.z) / 2)
|
||||||
engine.orbitControls.update();
|
engine.orbitControls.update();
|
||||||
engine.activeObjects.add(gltf.scene);
|
engine.activeObjects.add(gltf.scene);
|
||||||
//engine.scene.add(engine.light);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ class MazeQuizGame extends EventManager {
|
|||||||
super();
|
super();
|
||||||
this.data = data;
|
this.data = data;
|
||||||
data.noPhysics = true;
|
data.noPhysics = true;
|
||||||
params.mazeFile = data.style || 'quiz-s2.gltf';
|
|
||||||
params.io = this;
|
this.params = { ...params, mazeFile: data.style || 'quiz-s2.gltf', io: this }
|
||||||
|
|
||||||
this.maxPoints = (data.points || 0) + (data.questionPoints||0) * data.questions.length;
|
this.maxPoints = (data.points || 0) + (data.questionPoints||0) * data.questions.length;
|
||||||
this.minPoints = this.maxPoints - (data.questionPenalty||0) * data.questions.length;
|
this.minPoints = this.maxPoints - (data.questionPenalty||0) * data.questions.length;
|
||||||
@@ -52,7 +52,7 @@ class MazeQuizGame extends EventManager {
|
|||||||
return new Promise(async (resolve, reject)=>{
|
return new Promise(async (resolve, reject)=>{
|
||||||
let questions = data.shuffle ? Utils.shuffleArray(data.questions) : data.questions;
|
let questions = data.shuffle ? Utils.shuffleArray(data.questions) : data.questions;
|
||||||
let def = this.generate(questions);
|
let def = this.generate(questions);
|
||||||
this.mazeObject = new MazeObject(engine, def, params)
|
this.mazeObject = new MazeObject(engine, def, this.params)
|
||||||
engine.addEventListener('collision', async e=>{
|
engine.addEventListener('collision', async e=>{
|
||||||
let ud1 = engine.physics.world.getCollider(e.handle1)?.parent()?.userData,
|
let ud1 = engine.physics.world.getCollider(e.handle1)?.parent()?.userData,
|
||||||
ud2 = engine.physics.world.getCollider(e.handle2)?.parent()?.userData;
|
ud2 = engine.physics.world.getCollider(e.handle2)?.parent()?.userData;
|
||||||
@@ -124,7 +124,7 @@ class MazeQuizGame extends EventManager {
|
|||||||
{
|
{
|
||||||
type: 'SceneSwitcher', switchScene: this.data.switchScene, switchType: this.data.switchType,
|
type: 'SceneSwitcher', switchScene: this.data.switchScene, switchType: this.data.switchType,
|
||||||
position:[0,.22,len + .52], scale: [0.33, 0.33, 0.33],
|
position:[0,.22,len + .52], scale: [0.33, 0.33, 0.33],
|
||||||
distance: params.wallSize*4
|
distance: this.params.wallSize*4
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -68,12 +68,12 @@ class GameEngine extends EventManager{
|
|||||||
dirLight.castShadow = true;
|
dirLight.castShadow = true;
|
||||||
dirLight.shadow.mapSize.width = 1024;
|
dirLight.shadow.mapSize.width = 1024;
|
||||||
dirLight.shadow.mapSize.height = 1024;
|
dirLight.shadow.mapSize.height = 1024;
|
||||||
const d = 10;
|
const d = 50;
|
||||||
dirLight.shadow.camera.left = - d;
|
dirLight.shadow.camera.left = - d;
|
||||||
dirLight.shadow.camera.right = d;
|
dirLight.shadow.camera.right = d;
|
||||||
dirLight.shadow.camera.top = d;
|
dirLight.shadow.camera.top = d;
|
||||||
dirLight.shadow.camera.bottom = - d;
|
dirLight.shadow.camera.bottom = - d;
|
||||||
dirLight.shadow.camera.far = 1000;
|
dirLight.shadow.camera.far = 100;
|
||||||
dirLight.shadow.bias = - 0.001;
|
dirLight.shadow.bias = - 0.001;
|
||||||
|
|
||||||
// const spotLight = new THREE.SpotLight(0xffffff);
|
// const spotLight = new THREE.SpotLight(0xffffff);
|
||||||
@@ -162,7 +162,7 @@ class GameEngine extends EventManager{
|
|||||||
renderer.toneMapping = THREE.CineonToneMapping;
|
renderer.toneMapping = THREE.CineonToneMapping;
|
||||||
renderer.toneMappingExposure = 1.0;
|
renderer.toneMappingExposure = 1.0;
|
||||||
renderer.shadowMap.enabled = true;
|
renderer.shadowMap.enabled = true;
|
||||||
renderer.shadowMap.type = THREE.PCFShadowMap; // default THREE.PCFShadowMap
|
renderer.shadowMap.type = THREE.VSMShadowMap; // default THREE.PCFShadowMap
|
||||||
// renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
// renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
||||||
// renderer.toneMappingExposure = 1;
|
// renderer.toneMappingExposure = 1;
|
||||||
// renderer.shadowMap.enabled = true;
|
// renderer.shadowMap.enabled = true;
|
||||||
@@ -674,18 +674,15 @@ class GameEngine extends EventManager{
|
|||||||
this.ambientSound.stop();
|
this.ambientSound.stop();
|
||||||
this.loadedObjects.forEach(o=>clearObject(o.scene))
|
this.loadedObjects.forEach(o=>clearObject(o.scene))
|
||||||
GameEngine.loadedTextures.forEach(t=>{
|
GameEngine.loadedTextures.forEach(t=>{
|
||||||
//console.log('Disposing', t.name, this.renderer.info.memory.textures );
|
|
||||||
t.dispose();
|
t.dispose();
|
||||||
//console.log('Disposed', t.name, this.renderer.info.memory.textures );
|
|
||||||
});
|
});
|
||||||
|
GameEngine.loadedTextures.splice(0, GameEngine.loadedTextures.length);
|
||||||
this.scene.background?.dispose?.();
|
this.scene.background?.dispose?.();
|
||||||
this.scene.environment?.dispose?.();
|
this.scene.environment?.dispose?.();
|
||||||
clearObject(this.scene);
|
clearObject(this.scene);
|
||||||
this.scene = null;
|
this.scene = null;
|
||||||
this.tm?.setScene(null);
|
this.tm?.setScene(null);
|
||||||
this.removeAllListenersOfType('beforeRender');
|
this.removeAllListenersOfType('beforeRender');
|
||||||
this.renderer.renderLists.dispose();
|
|
||||||
this.renderer.properties.dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async resetScene(){
|
async resetScene(){
|
||||||
@@ -703,6 +700,8 @@ class GameEngine extends EventManager{
|
|||||||
this.arBtn?.remove();
|
this.arBtn?.remove();
|
||||||
this.xrBtn?.remove();
|
this.xrBtn?.remove();
|
||||||
this.stats?.dom?.remove();
|
this.stats?.dom?.remove();
|
||||||
|
this.renderer.renderLists.dispose();
|
||||||
|
this.renderer.properties.dispose();
|
||||||
this.renderer.domElement.removeEventListener('wheel', this._wheelEvent)
|
this.renderer.domElement.removeEventListener('wheel', this._wheelEvent)
|
||||||
this.renderer.domElement.remove();
|
this.renderer.domElement.remove();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|||||||
@@ -93,12 +93,14 @@ function clearObject(o){
|
|||||||
disposables.push(object);
|
disposables.push(object);
|
||||||
}
|
}
|
||||||
if (object.isLight){
|
if (object.isLight){
|
||||||
object.shadow?.map?.dispose();
|
//console.log('Disposeing light', object)
|
||||||
object.shadow?.dispose();
|
|
||||||
object.dispose();
|
object.dispose();
|
||||||
|
object.shadow?.dispose();
|
||||||
|
object.shadow?.map?.dispose();
|
||||||
}
|
}
|
||||||
if (object.userData?._io){
|
if (object.userData?._io){
|
||||||
object.userData._io.dispose?.();
|
object.userData._io.dispose?.();
|
||||||
|
delete object.userData._io;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
disposables.forEach(object=>{
|
disposables.forEach(object=>{
|
||||||
@@ -110,6 +112,7 @@ function clearObject(o){
|
|||||||
for (const material of object.material) clearMaterial(material)
|
for (const material of object.material) clearMaterial(material)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
o.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearMaterial(material) {
|
function clearMaterial(material) {
|
||||||
|
|||||||
Reference in New Issue
Block a user