This commit is contained in:
2025-10-21 18:50:52 +03:00
parent 3ff60a1cf4
commit 8f817eee14
13 changed files with 157 additions and 100 deletions
@@ -42,17 +42,65 @@ class MazeObject {
po.rigidBody.setRotation(quat, true)
}
function addRoom(elements, def, offsetZ){
// e = [
// o.floor.clone(),
// o.door.clone(),
// o[def.r ? 'door' : 'wall'].clone(),
// o[def.f ? 'door' : 'wall'].clone(),
// o[def.l ? 'door' : 'wall'].clone()
// ];
let e = elements.map(e=>o[e].clone())
e[0].position.set(0, 0, offsetZ + context.wallSize/2);
e[1].rotateY(_tf.rotation.b);
e[2].rotateY(_tf.rotation.r);
e[3].rotateY(_tf.rotation.f);
e[4].rotateY(_tf.rotation.l);
e[1].position.set(0, 0, offsetZ + 0);
e[2].position.set(-context.wallSize/2, 0, offsetZ + context.wallSize/2);
e[3].position.set(0, 0, offsetZ + context.wallSize);
e[4].position.set(context.wallSize/2, 0, offsetZ + context.wallSize/2);
if (elements[1] == 'wall'){
addPhysics(def.matrix, [0, 0, offsetZ], context.wallSize, 'front')
}
if (elements[2] == 'wall'){
addPhysics(def.matrix, [-context.wallSize/2, 0, offsetZ + context.wallSize/2], context.wallSize)
}
if (elements[3] == 'wall'){
addPhysics(def.matrix, [0, 0, offsetZ + context.wallSize], context.wallSize, 'front')
}
if (elements[4] == 'wall'){
addPhysics(def.matrix, [context.wallSize/2, 0, offsetZ + context.wallSize/2], context.wallSize)
}
e.forEach(g => {
g.applyMatrix4(def.matrix);
root.add(g);
});
}
this.mazeObject = function(def, room, step = 0) {
if (!def.matrix){
def.matrix = new Matrix4();
}
let offsetZ = 0, e;
def.len = def.len || 0;
// if (step == 0) {
// e = o.door.clone();
// e.rotateY(_tf.rotation.f);
// mazeMeshes.push(e);
// }
if (step == 0) {
// e = o.door.clone();
// e.rotateY(_tf.rotation.f);
// mazeMeshes.push(e);
addRoom(['floor', 'wall', 'wall', 'door', 'wall'], def, -context.wallSize)
}
for (let i = 0; i < def.len; i++) {
let t = o.tunnel.clone();
t.position.set(0, 0, i * context.tubeSize);
@@ -72,44 +120,7 @@ class MazeObject {
addPhysics(def.matrix, [context.tubeSize / 2, 0.6, offsetZ/2], offsetZ)
addPhysics(def.matrix, [-context.tubeSize / 2, 0.6, offsetZ/2], offsetZ)
e = [
o.floor.clone(),
o.door.clone(),
o[def.r ? 'door' : 'wall'].clone(),
o[def.f ? 'door' : 'wall'].clone(),
o[def.l ? 'door' : 'wall'].clone()
];
e[0].position.set(0, 0, offsetZ + context.wallSize/2);
e[1].rotateY(_tf.rotation.b);
e[2].rotateY(_tf.rotation.r);
e[3].rotateY(_tf.rotation.f);
e[4].rotateY(_tf.rotation.l);
e[1].position.set(0, 0, offsetZ + 0);
e[2].position.set(-context.wallSize/2, 0, offsetZ + context.wallSize/2);
e[3].position.set(0, 0, offsetZ + context.wallSize);
e[4].position.set(context.wallSize/2, 0, offsetZ + context.wallSize/2);
if (!def.r){
addPhysics(def.matrix, [-context.wallSize/2, 0, offsetZ + context.wallSize/2], context.wallSize)
}
if (!def.f){
addPhysics(def.matrix, [0, 0, offsetZ + context.wallSize], context.wallSize, 'front')
}
if (!def.l){
addPhysics(def.matrix, [context.wallSize/2, 0, offsetZ + context.wallSize/2], context.wallSize)
}
e.forEach(g => {
g.applyMatrix4(def.matrix);
root.add(g);
});
addRoom(['floor', 'door', def.r ? 'door' : 'wall', def.f ? 'door' : 'wall', def.l ? 'door' : 'wall'], def, offsetZ)
def.objects && def.objects.forEach(async obj => {
obj.room = room;