This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Group, Vector3, Matrix4, Mesh, Quaternion, PlaneGeometry, MeshStandardMaterial, DoubleSide, RepeatWrapping, Vector2} from 'three';
|
||||
import { InteractiveObject } from '../InteractiveObject';
|
||||
import { getBoundingBox, getBoundingBoxSize } from '@/lib/MeshUtils';
|
||||
|
||||
class MazeObject {
|
||||
constructor(engine, def, params){
|
||||
@@ -103,8 +104,9 @@ class MazeObject {
|
||||
root.add(t);
|
||||
}
|
||||
offsetZ = def.len * tubeSize;
|
||||
addPhysics(def.matrix, [tubeSize / 2, 0.6, offsetZ/2], offsetZ)
|
||||
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], sz)
|
||||
addPhysics(def.matrix, [-tubeSize / 2, 0.6, offsetZ/2], sz)
|
||||
//the floor:
|
||||
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/');
|
||||
['tunnel', 'wall', 'door', 'floor', 'surface'].forEach(e => {
|
||||
o[e] = mazeAsset.scene.getObjectByName(e);
|
||||
//o[e].frustumCulled = false;
|
||||
o[e].scale.set(scale, scale, scale)
|
||||
if (o[e]){
|
||||
o[e].scale.setScalar(scale);
|
||||
let bb = getBoundingBox(o[e]);
|
||||
o[e].userData.size = getBoundingBoxSize(bb);
|
||||
}
|
||||
});
|
||||
this.mazeObject(def, room);
|
||||
|
||||
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 //console.log('missing', m);
|
||||
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;
|
||||
});
|
||||
mt.needsUpdate = true;
|
||||
floor.material = mt;
|
||||
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)
|
||||
//pf.collider.setRestitution(0);
|
||||
//pf.collider.setTranslationWrtParent({x:0, y: -floorSize.height, z:0})
|
||||
if (o.surface){
|
||||
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 //console.log('missing', m);
|
||||
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;
|
||||
});
|
||||
mt.needsUpdate = true;
|
||||
floor.material = mt;
|
||||
floor.position.set((bbox.l + bbox.r)/2, 0, bbox.f/2);
|
||||
floor.scale.set(floorSize.width, scale, floorSize.depth)
|
||||
root.add(floor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user