physics test2

This commit is contained in:
2025-10-16 09:53:52 +03:00
parent a60d94fe66
commit 49e0486277
12 changed files with 283 additions and 169 deletions
@@ -5,12 +5,15 @@ import { TextObject } from '../TextObject';
class MazeObject {
constructor(engine, def, params = {}){
let room = new Group();
let scene = room;
let root = room;
this.object = room;
let context = {};
context.wallSize = params.wallSize || .65;
context.tubeSize = params.tubeSize || .8;
context.wallDepth = params.wallDepth || .1;
const scale = 5;
context.wallSize = params.wallSize || .65*scale;
context.tubeSize = params.tubeSize || .8*scale;
context.wallDepth = params.wallDepth || .1*scale;
context.fontPath = params.fontPath || '/static/fonts/ZapfChanceryC.otf';
const cameraNear = .2;
@@ -33,22 +36,21 @@ class MazeObject {
};
let o = {};
let mazeGeometries = [], areas = [];
let areas = [], mazeMeshes = [];
this.mazeObject = function(def, room, step = 0) {
let offsetZ = 0, e;
def.len = def.len || 0;
if (step == 0) {
e = o.door.geometry.clone();
e = o.door.clone();
e.rotateY(_tf.rotation.f);
mazeGeometries.push(e);
mazeMeshes.push(e);
}
for (let i = 0; i < def.len; i++) {
let t = o.tunnel.geometry.clone();
t.translate(0, 0, i * context.tubeSize + context.wallDepth / 2);
let t = o.tunnel.clone();
t.position.set(0, 0, i * context.tubeSize + context.wallDepth / 2);
def.matrix && t.applyMatrix4(def.matrix);
mazeGeometries.push(t);
mazeMeshes.push(t);
}
offsetZ = context.wallDepth + def.len * context.tubeSize - context.tubeSize / 2;
if (!def.len) offsetZ = -.275;
@@ -58,6 +60,14 @@ class MazeObject {
room.localToWorld(new Vector3(context.tubeSize / 2 - cameraNear, 0, offsetZ + cameraNear))
]
});
engine.phy.add(
{position: room.localToWorld(new Vector3(context.tubeSize / 2 - cameraNear, 0, offsetZ + cameraNear))},
'fixed', false, undefined, 'cuboid',{
width:offsetZ*10, height:10, depth:10
}
)
if (def.type == 'area') {
def.area.forEach(ar => {
areas.push({
@@ -75,23 +85,23 @@ class MazeObject {
// def.matrix && e.applyMatrix4(def.matrix);
// mazeGeometries.push(e);
} else {
e = [o.floor.geometry.clone(), o.door.geometry.clone(), o[def.r ? 'door' : 'wall'].geometry.clone(),
o[def.f ? 'door' : 'wall'].geometry.clone(), o[def.l ? 'door' : 'wall'].geometry.clone()];
e[0].translate(0, 0, offsetZ + context.wallSize);
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);
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].translate(0, 0, offsetZ + 0);
e[2].translate(-context.wallSize, 0, offsetZ + context.wallSize);
e[3].translate(0, 0, offsetZ + context.wallSize * 2);
e[4].translate(context.wallSize, 0, offsetZ + context.wallSize);
e[1].position.set(0, 0, offsetZ + 0);
e[2].position.set(-context.wallSize, 0, offsetZ + context.wallSize);
e[3].position.set(0, 0, offsetZ + context.wallSize * 2);
e[4].position.set(context.wallSize, 0, offsetZ + context.wallSize);
e.forEach(g => {
def.matrix && g.applyMatrix4(def.matrix);
mazeGeometries.push(g);
mazeMeshes.push(g);
});
areas.push({
a: [
@@ -119,7 +129,7 @@ class MazeObject {
mtx.makeRotationY(_tf.rotation[d]);
mtx.setPosition(_tf.pNext[d][0], 0, _tf.pNext[d][1] + offsetZ);
let rr = new Group();
scene.add(rr);
root.add(rr);
def[d].matrix = mtx.premultiply(def.matrix || new Matrix4());
rr.applyMatrix4(def[d].matrix);
rr.updateMatrixWorld();
@@ -132,14 +142,18 @@ class MazeObject {
['tunnel', 'wall', 'door', 'floor'].forEach(e => {
o[e] = mazeAsset.scene.getObjectByName(e);
o[e].frustumCulled = false;
o[e].scale.set(scale, scale, scale)
});
o.tunnel.material.depthWrite = false
this.mazeObject(def, room);
mazeGeometries.forEach(mg=>{
scene.add(new Mesh(mg, o.tunnel.material));
mazeMeshes.forEach(mesh=>{
//let mesh = new Mesh(mg, o.tunnel.material)
root.add(mesh);
engine.phy.add(mesh, 'dynamic')
})
console.log(o.tunnel)
//scene.add(new Mesh(BufferGeometryUtils.mergeGeometries(mazeGeometries, false), o.tunnel.material));
console.log(room);
//console.log(room);
}
}
}