This commit is contained in:
2025-11-25 09:20:42 +02:00
parent 63f5e45e68
commit 2f93b11b28
@@ -1,4 +1,4 @@
import { Group, Vector3, Matrix4, Mesh, Quaternion, PlaneGeometry, MeshStandardMaterial, DoubleSide} from 'three';
import { Group, Vector3, Matrix4, Mesh, Quaternion, PlaneGeometry, MeshStandardMaterial, DoubleSide, RepeatWrapping, Vector2} from 'three';
import { InteractiveObject } from '../InteractiveObject';
class MazeObject {
@@ -79,6 +79,9 @@ class MazeObject {
bbox.r = Math.max(g.position.x, bbox.r)
bbox.f = Math.max(g.position.z, bbox.f)
});
//the floor:
addPhysics(def.matrix, [0, -0.2, offsetZ + wallSize/2], {width:wallSize/2, height:0.1, depth: wallSize/2})
}
this.mazeObject = function(def, room, step = 0) {
@@ -102,6 +105,9 @@ class MazeObject {
offsetZ = def.len * tubeSize;
addPhysics(def.matrix, [tubeSize / 2, 0.6, offsetZ/2], offsetZ)
addPhysics(def.matrix, [-tubeSize / 2, 0.6, offsetZ/2], offsetZ)
//the floor:
addPhysics(def.matrix, [0, -0.2, offsetZ/2], {width:tubeSize/2, height:0.1, depth: offsetZ/2})
addRoom(['floor', 'door', def.r ? 'door' : 'wall', def.f ? 'door' : 'wall', def.l ? 'door' : 'wall'], def, offsetZ)
if (def.userData?.qid !== undefined || def.userData?.finish){
@@ -137,25 +143,30 @@ class MazeObject {
};
this.load = async function(){
let mazeAsset = await engine.load('/static/meshes/quiz.gltf', '');
['tunnel', 'wall', 'door', 'floor'].forEach(e => {
let mazeAsset = await engine.load(params.mazeFile, '/static/meshes/quiz/');
['tunnel', 'wall', 'door', 'floor', 'surface'].forEach(e => {
o[e] = mazeAsset.scene.getObjectByName(e);
//o[e].frustumCulled = false;
o[e].scale.set(scale, scale, scale)
});
this.mazeObject(def, room);
let floorSize = { width: (bbox.r - bbox.l + 10*scale)/2, height: 1, depth: (bbox.f + 10*scale)/2 }
const floorGeometry = new PlaneGeometry(floorSize.width*2, floorSize.depth*2);
const floor = new Mesh(floorGeometry,new MeshStandardMaterial({
roughness: 0, metalness:1, color: 0x00ffff, side: DoubleSide
}))
floor.rotation.set(Math.PI/2, 0, 0)
let floorSize = { width: bbox.r - bbox.l + 10*scale, height: 1, depth: bbox.f + 10*scale }
const floor = o.surface.clone();
const mt = floor.material.clone();
['map', 'normalMap'].forEach(m=>{
if (!mt[m]) return;
mt[m] = mt[m].clone();
mt[m].wrapS = mt[m].wrapT = RepeatWrapping;
mt[m].repeat = new Vector2(Math.floor(floorSize.width / wallSize), Math.floor(floorSize.depth / wallSize));
mt[m].needsUpdate = true;
});
floor.position.set((bbox.l + bbox.r)/2, 0, bbox.f/2);
floor.scale.set(floorSize.width, scale, floorSize.depth)
root.add(floor);
let pf = engine.physics.add({position: floor.position}, 'fixed', false, undefined, 'cuboid', floorSize)
//let pf = engine.physics.add({position: floor.position}, 'fixed', false, undefined, 'cuboid', floorSize)
//pf.collider.setRestitution(0);
pf.collider.setTranslationWrtParent({x:0, y: -floorSize.height, z:0})
//pf.collider.setTranslationWrtParent({x:0, y: -floorSize.height, z:0})
}
}
}