dev
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<template>
|
||||
<div v-show="forRendering">
|
||||
<div ref="target"></div>
|
||||
<v-slide-group show-arrows>
|
||||
<v-slide-group-item v-for="(a, i) in animations" :key="i" v-slot="{ isSelected }">
|
||||
<v-btn :color="isSelected ? 'primary' : undefined" class="ma-2"
|
||||
:prepend-icon="'mdi-' + (a.playing ? 'stop' : 'play')" rounded @click="toggleAnimation(a)">
|
||||
{{ a.name }}
|
||||
</v-btn>
|
||||
</v-slide-group-item>
|
||||
</v-slide-group>
|
||||
</div>
|
||||
<v-img v-if="obj && !forRendering && obj.type == 'object2d'" :src="`/asset/default/${obj.asset?.name}`"></v-img>
|
||||
<video v-if="obj && !forRendering && obj.type == 'video'" controls :autoplay="autoplay ? 'autoplay' : ''"
|
||||
:src="`/asset/default/${obj.asset?.name}`"></video>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { GameEngine } from '@/lib/gameEngine.js';
|
||||
let gameEngine = null;
|
||||
|
||||
export default{
|
||||
props:{
|
||||
object: Object,
|
||||
objectId: Number,
|
||||
autoplay: Boolean
|
||||
},
|
||||
data(){
|
||||
return {
|
||||
animations: [],
|
||||
obj: null
|
||||
}
|
||||
},
|
||||
async mounted(){
|
||||
if (this.object) {
|
||||
this.obj = this.object;
|
||||
}else{
|
||||
this.obj = (await this.$api.gameObject.load(this.objectId)).data;
|
||||
}
|
||||
},
|
||||
beforeUnmount() {
|
||||
gameEngine?.stop();
|
||||
},
|
||||
watch:{
|
||||
async obj(){
|
||||
gameEngine = new GameEngine();
|
||||
this.gameEngine = gameEngine;
|
||||
await gameEngine.init(this.$refs.target);
|
||||
await this.loadAsset();
|
||||
}
|
||||
},
|
||||
computed:{
|
||||
forRendering() {
|
||||
return this.$p.objectTypes.find(t=> t.value == this.obj?.type)?.render
|
||||
}
|
||||
},
|
||||
methods:{
|
||||
async loadAsset() {
|
||||
if (this.forRendering) {
|
||||
gameEngine.scene.clear();
|
||||
if (this.obj.type == 'panorama2d') {
|
||||
let t = await gameEngine.loadTexture(`/asset/default/${this.obj.asset.name}`);
|
||||
t.mapping = gameEngine.$.EquirectangularReflectionMapping;
|
||||
gameEngine.scene.background = t;
|
||||
gameEngine.scene.environment = t;
|
||||
gameEngine.scene.add(gameEngine.camera);
|
||||
} else {
|
||||
let gltf = await gameEngine.load(`/asset/default/${this.obj.asset.name}`);
|
||||
console.debug('GLTF', gltf);
|
||||
this.loadedAsset = gltf;
|
||||
this.animations = gltf.animations.map(a => ({
|
||||
name: a.name, id: a.uuid
|
||||
}));
|
||||
let bb = new gameEngine.$.Box3().setFromObject(gltf.scene);
|
||||
gltf.scene.traverse(function (o) {
|
||||
o.frustumCulled = false;
|
||||
});
|
||||
gameEngine.camera.position.set(bb.max.x, bb.max.y, bb.max.z);
|
||||
gameEngine.controls.target.set((bb.max.x + bb.min.x) / 2, (bb.max.y + bb.min.y) / 2, (bb.max.z + bb.min.z) / 2)
|
||||
gameEngine.controls.update();
|
||||
gameEngine.scene.add(gltf.scene);
|
||||
//gameEngine.scene.add(gameEngine.light);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async toggleAnimation(animation){
|
||||
animation.playing = !animation.playing;
|
||||
gameEngine.playAnimation(
|
||||
gameEngine.scene,
|
||||
this.loadedAsset.animations.find(a=>a.uuid == animation.id),
|
||||
animation.playing
|
||||
);
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user