interactive objects integration

This commit is contained in:
2025-11-04 16:41:42 +02:00
parent 429ab07db5
commit 4236927537
13 changed files with 178 additions and 243 deletions
@@ -8,37 +8,58 @@ import { PuzzleGame4 } from "./PuzzleGame4";
import { TextObject } from "./TextObject";
import { ImageObject } from "./ImageObject";
import { VideoPlayer } from "./VideoPlayer";
import { MazeQuizGame } from "./MazeQuizGame/MazeQuizGame";
import { assignMaterial, assignParams } from "@/lib/MeshUtils";
const games = {PuzzleGame1, PuzzleGame2, PuzzleGame4};
class InteractiveObject {
constructor(obj, context) {
constructor(obj, gameEngine, params) {
this.name = obj.name;
this.ready = new Promise((resolve, reject) => {
let mesh;
this.ready = new Promise(async (resolve, reject) => {
switch (obj.type || 'GenericObject') {
case 'Group':
mesh = new Group();
obj.group.forEach(g => {
let go = new InteractiveObject(g, context);
go.ready.then((gameMesh) => {
mesh.add(gameMesh);
});
});
resolve(mesh);
this.object = new Group();
for (let g of obj.group){
let go = new InteractiveObject(g, gameEngine);
let gameMesh = await go.ready;
this.object.add(gameMesh.object);
}
break;
case 'Text':
let text = new TextObject(obj, context);
resolve(text.object);
this.source = new TextObject(obj, gameEngine, params);
this.object = this.source.object;
break;
case 'Image':
let imo = new ImageObject(obj, context);
mesh = imo.object;
resolve(mesh);
this.source = new ImageObject(obj, gameEngine, params);
this.object = this.source.object;
break;
case 'Gltf':
let gltf = await gameEngine.load(obj.value);
let gltfObj = gltf.scene;
gltfObj.traverse(function (object) {
object.frustumCulled = false;
if (obj.name && obj.name == object.name) {
gltfObj = object;
}
// object.castShadow = true;
// object.receiveShadow = true;
});
assignMaterial(gltfObj, obj, params);
if (gltf.animations && gltf.animations.length) {
let mixer = new AnimationMixer(gltfObj);
gameEngine.mixers.push(mixer);
let action = mixer.clipAction(gltf.animations[0]);
action.setLoop(LoopPingPong);
action.play();
}
this.object = gltfObj;
this.source = gltf;
break;
case 'GenericObject':
let promise = context.load(`/asset/default/${obj.$go.asset.name}`);
promise.then(resolve);
this.source = await gameEngine.load(`/asset/default/${obj.$go.asset.name}`);
this.object = this.source.scene;
break;
case 'PuzzleGame1':
case 'PuzzleGame2':
@@ -46,19 +67,23 @@ class InteractiveObject {
case 'PuzzleGame4':
case 'PuzzleGame5':
case 'PuzzleGame6':
let game = new games[obj.type](context, obj.args[0], obj.args[1], obj.args[2]);
mesh = game.object;
mesh.game = game;
resolve(mesh);
let game = new games[obj.type](gameEngine, obj.args[0], obj.args[1], obj.args[2]);
this.object = game.object;
this.object.game = game;
break;
case 'VideoPlayer':
let vp = new VideoPlayer(context, `/asset/default/${obj.$go.asset.name}`);
vp.ready.then(resolve);
let vp = new VideoPlayer(gameEngine, `/asset/default/${obj.$go.asset.name}`);
this.source = await vp.ready;
this.object = vp.object;
break;
case 'MazeQuizGame':
this.source = new MazeQuizGame(gameEngine, obj);
await this.source.load();
this.object = this.source.object;
break;
}
});
this.ready.then((mesh) => {
this.object = mesh;
assignParams(this.object, obj);
resolve(this);
});
}
}