refactoring
This commit is contained in:
@@ -129,24 +129,21 @@ export default {
|
||||
gameEngine.activeObjects.add(env.scene);
|
||||
}
|
||||
for (let i of this.scene.data.items || []) {
|
||||
if (i.data.io){
|
||||
i.data.$io = new InteractiveObject(i.data.io, gameEngine)
|
||||
i.data.$io.ready.then(o=>{
|
||||
this.setObjectAttributes(l, i.data, { scene: o }, 1);
|
||||
gameEngine.activeObjects.add(o);
|
||||
})
|
||||
}else{
|
||||
let gltf = await gameEngine.load(`/asset/default/${i.data.$go.asset.name}`);
|
||||
this.setObjectAttributes(l, i.data, gltf, 1);
|
||||
gameEngine.activeObjects.add(gltf.scene);
|
||||
if (this.env == 'GamePlaying'){
|
||||
if (i.data.$go.type == 'player3d'){
|
||||
let hero = new Hero(gltf, i.data.$go);
|
||||
hero.init(gameEngine);
|
||||
}else{
|
||||
if (gltf.animations?.length){
|
||||
gameEngine.playAnimation(gameEngine.scene, gltf.animations[0]);
|
||||
}
|
||||
let io = new InteractiveObject(i.data, gameEngine)
|
||||
await io.ready;
|
||||
|
||||
//let gltf = await gameEngine.load(`/asset/default/${i.data.$go.asset.name}`);
|
||||
let objKey = (i.data.type == 'GenericObject' || !i.data.type) ? 'scene' : 'object'
|
||||
console.log(i.data, io.object)
|
||||
this.setObjectAttributes(l, i.data, io.object, 1, objKey);
|
||||
gameEngine.activeObjects.add(io.object[objKey]);
|
||||
if (this.env == 'GamePlaying'){
|
||||
if (i.data.$go.type == 'player3d'){
|
||||
let hero = new Hero(io.object, i.data.$go);
|
||||
hero.init(gameEngine);
|
||||
}else{
|
||||
if (io.object.animations?.length){
|
||||
gameEngine.playAnimation(gameEngine.scene, io.object.animations[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -184,22 +181,22 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
setObjectAttributes(l, data, o, autoScaleFactor = 1){
|
||||
setObjectAttributes(l, data, o, autoScaleFactor = 1, objectKey = 'scene'){
|
||||
if (l[data.id]){
|
||||
['position', 'scale', 'rotation'].forEach(p=>{
|
||||
o.scene[p].copy(l[data.id][p])
|
||||
o[objectKey][p].copy(l[data.id][p])
|
||||
})
|
||||
}else{
|
||||
gameEngine.autoScale(o.scene, autoScaleFactor);
|
||||
gameEngine.autoScale(o[objectKey], autoScaleFactor);
|
||||
}
|
||||
l[data.id] = l[data.id] || {};
|
||||
['position', 'scale', 'rotation', 'visible'].forEach(p=>{
|
||||
l[data.id][p] = o.scene[p];
|
||||
l[data.id][p] = o[objectKey][p];
|
||||
})
|
||||
l[data.id].__o = o.scene;
|
||||
l[data.id].__o = o[objectKey];
|
||||
l[data.id].__g = o;
|
||||
l[data.id].__title = data.title;
|
||||
o.scene.__pn_id = data.id;
|
||||
o[objectKey].__pn_id = data.id;
|
||||
},
|
||||
|
||||
async toggleAnimation(animation){
|
||||
|
||||
Reference in New Issue
Block a user