resolves #25
This commit is contained in:
@@ -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';
|
import { InteractiveObject } from '../InteractiveObject';
|
||||||
|
|
||||||
class MazeObject {
|
class MazeObject {
|
||||||
@@ -79,6 +79,9 @@ class MazeObject {
|
|||||||
bbox.r = Math.max(g.position.x, bbox.r)
|
bbox.r = Math.max(g.position.x, bbox.r)
|
||||||
bbox.f = Math.max(g.position.z, bbox.f)
|
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) {
|
this.mazeObject = function(def, room, step = 0) {
|
||||||
@@ -102,6 +105,9 @@ class MazeObject {
|
|||||||
offsetZ = def.len * tubeSize;
|
offsetZ = def.len * tubeSize;
|
||||||
addPhysics(def.matrix, [tubeSize / 2, 0.6, offsetZ/2], offsetZ)
|
addPhysics(def.matrix, [tubeSize / 2, 0.6, offsetZ/2], offsetZ)
|
||||||
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)
|
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){
|
if (def.userData?.qid !== undefined || def.userData?.finish){
|
||||||
@@ -137,25 +143,30 @@ class MazeObject {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.load = async function(){
|
this.load = async function(){
|
||||||
let mazeAsset = await engine.load('/static/meshes/quiz.gltf', '');
|
let mazeAsset = await engine.load(params.mazeFile, '/static/meshes/quiz/');
|
||||||
['tunnel', 'wall', 'door', 'floor'].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;
|
//o[e].frustumCulled = false;
|
||||||
o[e].scale.set(scale, scale, scale)
|
o[e].scale.set(scale, scale, scale)
|
||||||
});
|
});
|
||||||
this.mazeObject(def, room);
|
this.mazeObject(def, room);
|
||||||
|
|
||||||
let floorSize = { width: (bbox.r - bbox.l + 10*scale)/2, height: 1, depth: (bbox.f + 10*scale)/2 }
|
let floorSize = { width: bbox.r - bbox.l + 10*scale, height: 1, depth: bbox.f + 10*scale }
|
||||||
const floorGeometry = new PlaneGeometry(floorSize.width*2, floorSize.depth*2);
|
const floor = o.surface.clone();
|
||||||
const floor = new Mesh(floorGeometry,new MeshStandardMaterial({
|
const mt = floor.material.clone();
|
||||||
roughness: 0, metalness:1, color: 0x00ffff, side: DoubleSide
|
['map', 'normalMap'].forEach(m=>{
|
||||||
}))
|
if (!mt[m]) return;
|
||||||
floor.rotation.set(Math.PI/2, 0, 0)
|
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.position.set((bbox.l + bbox.r)/2, 0, bbox.f/2);
|
||||||
|
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)
|
//let pf = engine.physics.add({position: floor.position}, 'fixed', false, undefined, 'cuboid', floorSize)
|
||||||
//pf.collider.setRestitution(0);
|
//pf.collider.setRestitution(0);
|
||||||
pf.collider.setTranslationWrtParent({x:0, y: -floorSize.height, z:0})
|
//pf.collider.setTranslationWrtParent({x:0, y: -floorSize.height, z:0})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user