This commit is contained in:
2025-11-29 16:42:33 +02:00
parent a8b4053986
commit 83c42aa593
@@ -1,5 +1,6 @@
import { Group, Vector3, Matrix4, Mesh, Quaternion, PlaneGeometry, MeshStandardMaterial, DoubleSide, RepeatWrapping, Vector2} from 'three'; import { Group, Vector3, Matrix4, Mesh, Quaternion, PlaneGeometry, MeshStandardMaterial, DoubleSide, RepeatWrapping, Vector2} from 'three';
import { InteractiveObject } from '../InteractiveObject'; import { InteractiveObject } from '../InteractiveObject';
import { getBoundingBox, getBoundingBoxSize } from '@/lib/MeshUtils';
class MazeObject { class MazeObject {
constructor(engine, def, params){ constructor(engine, def, params){
@@ -103,8 +104,9 @@ class MazeObject {
root.add(t); root.add(t);
} }
offsetZ = def.len * tubeSize; offsetZ = def.len * tubeSize;
addPhysics(def.matrix, [tubeSize / 2, 0.6, offsetZ/2], offsetZ) let sz = { width: Math.max(0.1, (tubeSize-o.tunnel.userData.size.x)/2), height:1, depth:offsetZ/2 }
addPhysics(def.matrix, [-tubeSize / 2, 0.6, offsetZ/2], offsetZ) addPhysics(def.matrix, [tubeSize / 2, 0.6, offsetZ/2], sz)
addPhysics(def.matrix, [-tubeSize / 2, 0.6, offsetZ/2], sz)
//the floor: //the floor:
addPhysics(def.matrix, [0, -0.1, offsetZ/2], {width:tubeSize/2, height:0.1, depth: offsetZ/2}) addPhysics(def.matrix, [0, -0.1, offsetZ/2], {width:tubeSize/2, height:0.1, depth: offsetZ/2})
@@ -146,11 +148,15 @@ class MazeObject {
let mazeAsset = await engine.load(params.mazeFile, '/static/meshes/quiz/'); let mazeAsset = await engine.load(params.mazeFile, '/static/meshes/quiz/');
['tunnel', 'wall', 'door', 'floor', 'surface'].forEach(e => { ['tunnel', 'wall', 'door', 'floor', 'surface'].forEach(e => {
o[e] = mazeAsset.scene.getObjectByName(e); o[e] = mazeAsset.scene.getObjectByName(e);
//o[e].frustumCulled = false; if (o[e]){
o[e].scale.set(scale, scale, scale) o[e].scale.setScalar(scale);
let bb = getBoundingBox(o[e]);
o[e].userData.size = getBoundingBoxSize(bb);
}
}); });
this.mazeObject(def, room); this.mazeObject(def, room);
if (o.surface){
let floorSize = { width: bbox.r - bbox.l + 10*scale, height: 1, depth: bbox.f + 10*scale } let floorSize = { width: bbox.r - bbox.l + 10*scale, height: 1, depth: bbox.f + 10*scale }
const floor = o.surface.clone(); const floor = o.surface.clone();
const mt = floor.material.clone(); const mt = floor.material.clone();
@@ -166,9 +172,7 @@ class MazeObject {
floor.position.set((bbox.l + bbox.r)/2, 0, bbox.f/2); floor.position.set((bbox.l + bbox.r)/2, 0, bbox.f/2);
floor.scale.set(floorSize.width, scale, floorSize.depth) floor.scale.set(floorSize.width, scale, floorSize.depth)
root.add(floor); root.add(floor);
//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})
} }
} }
} }