102 lines
4.1 KiB
JavaScript
102 lines
4.1 KiB
JavaScript
import { Group } from "three";
|
|
import { PuzzleGame1 } from "./PuzzleGame1";
|
|
import { PuzzleGame2 } from "./PuzzleGame2";
|
|
// import { Game3 } from "./games/Game3";
|
|
import { PuzzleGame4 } from "./PuzzleGame4";
|
|
// import { Game5 } from "./games/Game5";
|
|
// import { Game6 } from "./games/Game6";
|
|
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, MazeQuizGame};
|
|
|
|
class InteractiveObject {
|
|
constructor(obj, gameEngine, params) {
|
|
this.name = obj.name;
|
|
this.ready = new Promise(async (resolve, reject) => {
|
|
switch (obj.type || 'GenericObject') {
|
|
case 'Group':
|
|
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':
|
|
this.source = new TextObject(obj, gameEngine, params);
|
|
this.object = this.source.object;
|
|
break;
|
|
case 'Image':
|
|
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':
|
|
this.source = await gameEngine.load(obj.$go.asset.name);
|
|
this.object = this.source.scene;
|
|
break;
|
|
case 'PuzzleGame3':
|
|
case 'PuzzleGame4':
|
|
case 'PuzzleGame5':
|
|
case 'PuzzleGame6':
|
|
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(gameEngine, gameEngine.assetPath + obj.$go.asset.name);
|
|
this.source = await vp.ready;
|
|
this.object = vp.object;
|
|
break;
|
|
case 'PuzzleGame1':
|
|
case 'PuzzleGame2':
|
|
case 'MazeQuizGame':
|
|
this.source = await new games[obj.type](gameEngine, obj);
|
|
this.object = this.source.object;
|
|
break;
|
|
}
|
|
assignParams(this.object, obj);
|
|
resolve(this);
|
|
});
|
|
}
|
|
}
|
|
|
|
const InteractiveObjectTypes = [
|
|
{
|
|
id: 'PuzzleGame1', name: 'Puzzle Game 1'
|
|
},{
|
|
id: 'PuzzleGame2', name: 'Puzzle Game 2'
|
|
},{
|
|
id: 'MazeQuizGame', name: 'Maze Quiz Game'
|
|
},{
|
|
id: 'VideoPlayer', name: 'Video Player'
|
|
}
|
|
];
|
|
|
|
export { InteractiveObject, InteractiveObjectTypes } |