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,29 +148,31 @@ 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);
let floorSize = { width: bbox.r - bbox.l + 10*scale, height: 1, depth: bbox.f + 10*scale } if (o.surface){
const floor = o.surface.clone(); let floorSize = { width: bbox.r - bbox.l + 10*scale, height: 1, depth: bbox.f + 10*scale }
const mt = floor.material.clone(); const floor = o.surface.clone();
['map', 'normalMap'].forEach(m=>{ const mt = floor.material.clone();
if (!mt[m]) return //console.log('missing', m); ['map', 'normalMap'].forEach(m=>{
mt[m] = mt[m].clone(); if (!mt[m]) return //console.log('missing', m);
mt[m].wrapS = mt[m].wrapT = RepeatWrapping; mt[m] = mt[m].clone();
mt[m].repeat = new Vector2(Math.floor(floorSize.width/wallSize), Math.floor(floorSize.depth/wallSize)); mt[m].wrapS = mt[m].wrapT = RepeatWrapping;
mt[m].needsUpdate = true; mt[m].repeat = new Vector2(Math.floor(floorSize.width/wallSize), Math.floor(floorSize.depth/wallSize));
}); mt[m].needsUpdate = true;
mt.needsUpdate = true; });
floor.material = mt; mt.needsUpdate = true;
floor.position.set((bbox.l + bbox.r)/2, 0, bbox.f/2); floor.material = mt;
floor.scale.set(floorSize.width, scale, floorSize.depth) floor.position.set((bbox.l + bbox.r)/2, 0, bbox.f/2);
root.add(floor); floor.scale.set(floorSize.width, scale, floorSize.depth)
//let pf = engine.physics.add({position: floor.position}, 'fixed', false, undefined, 'cuboid', floorSize) root.add(floor);
//pf.collider.setRestitution(0); }
//pf.collider.setTranslationWrtParent({x:0, y: -floorSize.height, z:0})
} }
} }
} }