refactoring

This commit is contained in:
2025-11-04 07:51:22 +02:00
parent b1e27301b4
commit 96012fda27
6 changed files with 56 additions and 116 deletions
@@ -0,0 +1,10 @@
<template>
</template>
<script>
export default {
//for now this will be dummy
}
</script>
@@ -1,7 +1,4 @@
//import { Hint } from "./Hint";
import { Group, AnimationMixer, LoopPingPong, Vector3 } from "three";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
import { assignMaterial, assignParams } from "@/lib/MeshUtils";
import { Group } from "three";
import { PuzzleGame1 } from "./PuzzleGame1";
import { PuzzleGame2 } from "./PuzzleGame2";
// import { Game3 } from "./games/Game3";
@@ -19,8 +16,8 @@ class InteractiveObject {
this.name = obj.name;
this.ready = new Promise((resolve, reject) => {
let mesh;
switch (obj.id) {
case 'group':
switch (obj.type || 'GenericObject') {
case 'Group':
mesh = new Group();
obj.group.forEach(g => {
let go = new InteractiveObject(g, context);
@@ -30,51 +27,18 @@ class InteractiveObject {
});
resolve(mesh);
break;
case 'text':
case 'Text':
let text = new TextObject(obj, context);
resolve(text.object);
break;
case 'mesh':
mesh = obj.value;
resolve(mesh);
break;
case 'image':
case 'Image':
let imo = new ImageObject(obj, context);
mesh = imo.object;
resolve(mesh);
break;
case 'hint':
let hint = new Hint(obj, context);
mesh = hint.object;
resolve(mesh);
break;
case 'gltf':
//console.log('loadingg', obj.value)
new GLTFLoader().load(obj.value, (gltf) => {
let gltfObj = gltf.scene;
gltf.scene.traverse(function (object) {
object.frustumCulled = false;
if (obj.name && obj.name == object.name) {
gltfObj = object;
}
// object.castShadow = true;
// object.receiveShadow = true;
});
assignMaterial(gltfObj, obj, context);
if (gltf.animations && gltf.animations.length) {
let mixer = new AnimationMixer(gltfObj);
context.mixers.push(mixer);
let action = mixer.clipAction(gltf.animations[0]);
action.setLoop(LoopPingPong);
action.play();
}
resolve(gltfObj);
});
break;
case 'asset':
mesh = context.assets[obj.value].clone();
assignMaterial(mesh, obj, context);
resolve(mesh);
case 'GenericObject':
let promise = context.load(`/asset/default/${obj.$go.asset.name}`);
promise.then(resolve);
break;
case 'PuzzleGame1':
case 'PuzzleGame2':
@@ -94,41 +58,6 @@ class InteractiveObject {
}
});
this.ready.then((mesh) => {
mesh.go = {};
// let restriction;
// if (!context.disableRestrictions && obj.restriction) {
// restriction = {
// type: 'deny',
// a: [obj.room.localToWorld(new Vector3().fromArray(obj.restriction[0])), obj.room.localToWorld(new Vector3().fromArray(obj.restriction[1]))]
// };
// context.areas.push(restriction);
// }
mesh.go.finish = () => {
if (obj.finish) {
var f;
if (obj.finish.nextAction) {
var next = obj.finish.nextAction;
delete obj.finish.nextAction;
f = () => {
if (next.activate) {
context.activate(next.activate);
}
};
}
var me = obj.finish._ || {};
delete obj.finish._;
context.motionEngine.add({ o: mesh, a: obj.finish, t: me.t || 1, f: me.f || f, d: me.d || 0 });
}
if (restriction) context.areas.splice(context.areas.indexOf(restriction), 1);
};
if (mesh.object) mesh.object.onfinish = mesh.go.finish;
assignParams(mesh, obj);
obj.animation && context.motionEngine.add({
o: mesh,
a: obj.animation.motion,
r: obj.animation.repeat,
t: obj.animation.duration || 1
});
this.object = mesh;
});
}
@@ -30,7 +30,7 @@ class VideoPlayer {
vi.pause();
}
});
resolve(plane);
resolve(this);
})
vi.addEventListener('play', ()=>{
if (context.dashboard?.active){
@@ -48,7 +48,7 @@ class VideoPlayer {
scale: plane.scale.clone()
}
}
console.log(data.location)
//console.log(data.location)
context.dashboard.group.attach(plane);
//plane.applyMatrix4(m.invert())
@@ -1,15 +1,15 @@
<template>
<asset-selector @select="assignVideoObject" :type="['Descriptive']">
<template v-slot:activator="props">
<v-btn v-bind="props" prepend-icon="mdi-video-box" color="deep-orange-darken-4" block>Choose video object</v-btn>
</template>
</asset-selector>
<v-card v-if="modelValue.go">
<v-card-item>
<v-img :src="`/asset/thumb/${modelValue.go}.webp`" />
<div class="text-caption text-center">{{ modelValue.title }}</div>
</v-card-item>
</v-card>
<asset-selector @select="assignVideoObject" :type="['Descriptive']">
<template v-slot:activator="props">
<v-btn v-bind="props" prepend-icon="mdi-video-box" color="deep-orange-darken-4" block>Choose video object</v-btn>
</template>
</asset-selector>
</template>
<script>
+10 -6
View File
@@ -23,8 +23,8 @@
</v-form>
</v-card>
<v-container v-if="selected && modelValue.io">
<component :is="modelValue.io.id" v-model="modelValue.io"></component>
<v-container v-if="selected && modelValue.type">
<component :is="modelValue.type" v-model="mv"></component>
</v-container>
</template>
@@ -35,10 +35,11 @@ import Utils from '@/lib/Utils';
import VideoPlayer from '../InteractiveObjects/VideoPlayer.vue';
import PuzzleGame1 from '../InteractiveObjects/PuzzleGame1.vue';
import MazeQuizGame from '../InteractiveObjects/MazeQuizGame/MazeQuizGame.vue';
import GenericObject from '../InteractiveObjects/GenericObject.vue';
export default {
emits:['target', 'preview'],
components: { SvgIcon, VideoPlayer, PuzzleGame1, MazeQuizGame },
components: { SvgIcon, VideoPlayer, PuzzleGame1, MazeQuizGame, GenericObject },
data(){
return {
active: false
@@ -60,6 +61,9 @@ export default {
showInView(){
this.vd.__showInView = this.visible && this.parent.visible;
return this.vd.__showInView;
},
mv(){
return this.modelValue
}
},
steps: [['x1', 'y1']],
@@ -76,9 +80,9 @@ export default {
delete this.modelValue.io;
}
if (e.type == 'InteractiveObject'){
this.modelValue.io = {
id: e.id
};
this.modelValue.type = e.id;
}else{
this.modelValue.type = 'Object3D'
}
}
}
+21 -24
View File
@@ -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){