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
@@ -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;
});
}