loading progress added
This commit is contained in:
@@ -3,6 +3,7 @@ import { VideoPlayer } from '@/components/InteractiveObjects/VideoPlayer';
|
||||
import { GameEngine } from '@/lib/GameEngine';
|
||||
import { Hero } from '@/lib/Hero';
|
||||
import { autoScale, getBoundingBox, getBoundingBoxCenterPoint, getBoundingBoxSize } from '@/lib/MeshUtils';
|
||||
import Utils from '@/lib/Utils';
|
||||
let gameEngine = null;
|
||||
|
||||
export default {
|
||||
@@ -117,7 +118,13 @@ export default {
|
||||
async loadEnvironment(scene, target){
|
||||
//await gameEngine.loadPanorama(`/asset/default/43.webp`);
|
||||
gameEngine.clearScene();
|
||||
gameEngine.activeObjects.visible = false;
|
||||
gameEngine.dashboard?.loading(0);
|
||||
await this.expandScenarioData(scene);
|
||||
gameEngine.dashboard?.loading(0.1);
|
||||
|
||||
//this is needed cause when mounted canvas has different size
|
||||
this.resize();
|
||||
target.objects = target.objects || {};
|
||||
let l = target.objects;
|
||||
if (this.scene.data.$environment){
|
||||
@@ -136,49 +143,61 @@ export default {
|
||||
}
|
||||
gameEngine.activeObjects.add(env.scene);
|
||||
}
|
||||
if (this.scene.data.items){
|
||||
let loaded = 0;
|
||||
for (let i of this.scene.data.items) {
|
||||
let io = await new InteractiveObject(gameEngine, i.data)
|
||||
|
||||
//let gltf = await gameEngine.load(`/asset/default/${i.data.$go.asset.name}`);
|
||||
//console.log(i.data, io.object)
|
||||
this.setObjectAttributes(l, i.data, io.object, io.source, 1);
|
||||
gameEngine.activeObjects.add(io.object);
|
||||
if (this.env == 'GamePlaying'){
|
||||
if (i.data.$go?.type == 'player3d'){
|
||||
let hero = new Hero(io.source, i.data.$go);
|
||||
hero.init(gameEngine);
|
||||
}else{
|
||||
if (io.source?.animations?.length){
|
||||
gameEngine.playAnimation(gameEngine.scene, io.source.animations[0]);
|
||||
}
|
||||
|
||||
if (!i.data.noPhysics){
|
||||
let bb = getBoundingBox(io.object);
|
||||
let bbs = getBoundingBoxSize(bb);
|
||||
gameEngine.physics.add(io.object, 'fixed', false, undefined, 'capsule', {
|
||||
radius: Math.max(bbs.x, bbs.z)/2, halfHeight: bbs.y/2
|
||||
})
|
||||
}
|
||||
}
|
||||
io.onfinish=()=>{
|
||||
gameEngine.dashboard?.addPoints(i.data.points)
|
||||
i.data.points = 0;
|
||||
}
|
||||
}
|
||||
loaded += 1/this.scene.data.items.length
|
||||
gameEngine.dashboard?.loading(0.1 + 0.89*loaded);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.scene.data.$intro && this.env == 'GamePlaying'){
|
||||
let intro = await new VideoPlayer(gameEngine, this.scene.data.$intro.asset.name, gameEngine.assetPath);
|
||||
let intro = await new VideoPlayer(gameEngine, {$go: this.scene.data.$intro, skipTransition: true, playInHud: true});
|
||||
gameEngine.activeObjects.add(intro.object);
|
||||
intro.video.addEventListener('pause',()=>{
|
||||
intro.object.removeFromParent();
|
||||
gameEngine.activeObjects.visible = true;
|
||||
});
|
||||
intro.video.play();
|
||||
}else{
|
||||
gameEngine.activeObjects.visible = true;
|
||||
}
|
||||
for (let i of this.scene.data.items || []) {
|
||||
let io = await new InteractiveObject(gameEngine, i.data)
|
||||
|
||||
//let gltf = await gameEngine.load(`/asset/default/${i.data.$go.asset.name}`);
|
||||
//console.log(i.data, io.object)
|
||||
this.setObjectAttributes(l, i.data, io.object, io.source, 1);
|
||||
gameEngine.activeObjects.add(io.object);
|
||||
if (this.env == 'GamePlaying'){
|
||||
if (i.data.$go?.type == 'player3d'){
|
||||
let hero = new Hero(io.source, i.data.$go);
|
||||
hero.init(gameEngine);
|
||||
}else{
|
||||
if (io.source?.animations?.length){
|
||||
gameEngine.playAnimation(gameEngine.scene, io.source.animations[0]);
|
||||
}
|
||||
|
||||
if (!i.data.noPhysics){
|
||||
let bb = getBoundingBox(io.object);
|
||||
let bbs = getBoundingBoxSize(bb);
|
||||
gameEngine.physics.add(io.object, 'fixed', false, undefined, 'capsule', {
|
||||
radius: Math.max(bbs.x, bbs.z)/2, halfHeight: bbs.y/2
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
gameEngine.dashboard?.loading(1)
|
||||
// let camera = new gameEngine.$.PerspectiveCamera();
|
||||
// let cameraHelper = new gameEngine.$.CameraHelper(camera);
|
||||
// gameEngine.activeObjects.add(cameraHelper);
|
||||
// gameEngine.activeObjects.add(camera);
|
||||
// this.setObjectAttributes(l, { id: 'camera', 'title': 'Main camera' }, { scene: camera })
|
||||
// cameraHelper.update();
|
||||
|
||||
//this is needed cause when mounted canvas has different size
|
||||
this.resize();
|
||||
},
|
||||
|
||||
targetPointerDown(){
|
||||
|
||||
Reference in New Issue
Block a user