upload
This commit is contained in:
147
test/www/test_robot_marker.js
Normal file
147
test/www/test_robot_marker.js
Normal file
@@ -0,0 +1,147 @@
|
||||
// Hai hinh robot (uoc luong + ground truth) va cao do cua chung.
|
||||
//
|
||||
// ================== VI SAO CAN BAI KIEM NAY ==================
|
||||
// Nguoi van hanh bao "robot co mot nhan ban o canh" trong khi sai so uoc luong
|
||||
// do duoc chi 9 mm. Nguyen nhan la CAU TRUC:
|
||||
//
|
||||
// robotGroup = new Group() <- y = 0
|
||||
// └ v3dBuildRobot() <- y = wheel_radius (phep nang than)
|
||||
// gtGroup = v3dBuildRobot() <- y = wheel_radius, KHONG co lop boc
|
||||
//
|
||||
// `v3dSetPose()` viet `position.set(p.x, 0, -p.y)`, xoa y cua nhom NGOAI. Voi
|
||||
// robotGroup phep nang nam o tang trong nen song sot; voi gtGroup no nam dung
|
||||
// tang bi xoa. Hinh ground truth tut xuong 0.075 m, va o goc camera nghieng
|
||||
// chenh lech do chieu ra thanh khoang cach NGANG nhin thay duoc.
|
||||
//
|
||||
// Khong mot chi so nao doi. Ca hai hinh van duoc ve, van cap nhat, van dung
|
||||
// mau. Chi la chung o hai cao do.
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const vm = require('vm');
|
||||
|
||||
class V3 {
|
||||
constructor(x, y, z) { this.x = x; this.y = y; this.z = z; }
|
||||
copy(o) { this.x = o.x; this.y = o.y; this.z = o.z; return this; }
|
||||
set(x, y, z) { this.x = x; this.y = y; this.z = z; return this; }
|
||||
}
|
||||
const node = () => ({ position: new V3(0, 0, 0), rotation: { x: 0, y: 0, z: 0 },
|
||||
userData: {} });
|
||||
class Grp {
|
||||
constructor() { Object.assign(this, node()); this.children = []; }
|
||||
add(c) { this.children.push(c); }
|
||||
remove(c) { this.children = this.children.filter((x) => x !== c); }
|
||||
traverse(f) { f(this); this.children.forEach((c) => (c.traverse ? c.traverse(f) : f(c))); }
|
||||
}
|
||||
const leaf = (extra) => class {
|
||||
constructor(g, m) { Object.assign(this, node()); this.geometry = g; this.material = m;
|
||||
Object.assign(this, extra || {}); }
|
||||
};
|
||||
const mat = () => class {
|
||||
constructor(o) { Object.assign(this, o); this.color = { set() {} }; }
|
||||
clone() { const c = Object.create(Object.getPrototypeOf(this));
|
||||
Object.assign(c, this); c.color = { set() {} }; return c; }
|
||||
dispose() {}
|
||||
};
|
||||
global.THREE = {
|
||||
Group: Grp, Mesh: leaf(), Line: leaf(), LineLoop: leaf(), LineSegments: leaf(),
|
||||
Points: leaf(), Vector3: V3,
|
||||
MeshLambertMaterial: mat(), MeshStandardMaterial: mat(), LineBasicMaterial: mat(),
|
||||
PointsMaterial: mat(),
|
||||
CylinderGeometry: class {}, ConeGeometry: class {}, BoxGeometry: class { dispose() {} },
|
||||
PlaneGeometry: class { dispose() {} }, GridHelper: class { constructor() { Object.assign(this, node()); } },
|
||||
BufferGeometry: class {
|
||||
constructor() { this.attributes = {}; }
|
||||
setAttribute(n, a) { this.attributes[n] = a; }
|
||||
setFromPoints() { return this; }
|
||||
computeVertexNormals() {} dispose() {}
|
||||
},
|
||||
BufferAttribute: class { constructor(a, n) { this.array = a; this.itemSize = n; } },
|
||||
InstancedMesh: class { constructor() { Object.assign(this, node()); this.instanceMatrix = {}; }
|
||||
setMatrixAt() {} dispose() {} },
|
||||
Matrix4: class { compose() {} }, Quaternion: class { setFromAxisAngle() {} },
|
||||
Color: class { constructor() { this.set = () => {}; } },
|
||||
};
|
||||
|
||||
const www = '/home/quangtrung/projects/vslam_cpp/libs/vslam_web/www';
|
||||
const sb = { THREE: global.THREE, console, window: {}, document: {} };
|
||||
vm.createContext(sb);
|
||||
vm.runInContext(fs.readFileSync(path.join(www, 'app3d.js'), 'utf8') +
|
||||
'\n;this.__V3D = V3D; this.__shape = v3dSetShape; this.__pose = v3dSetPose;' +
|
||||
'\n;this.__scan = v3dSetScan;', sb);
|
||||
|
||||
const V3D = sb.__V3D;
|
||||
V3D.ready = true;
|
||||
V3D.root = new Grp();
|
||||
|
||||
const r = { radius: 0.17, wheel_radius: 0.075, wheel_sep: 0.30,
|
||||
laser_x: 0.24, laser_y: 0.0, laser_z: 0.125, cam_x: 0.10 };
|
||||
sb.__shape(r);
|
||||
|
||||
// Sai so thuc do duoc giua uoc luong va ground truth: 9 mm.
|
||||
const pose = { x: 5.000, y: 2.000, yaw: 0.0 };
|
||||
const gt = { x: 5.009, y: 2.000, yaw: 0.0 };
|
||||
sb.__pose(V3D.robotGroup, pose);
|
||||
sb.__pose(V3D.gtGroup, gt);
|
||||
|
||||
// Cao do TUYET DOI cua mot nut: cong y qua tung tang.
|
||||
function absY(root, pred) {
|
||||
let found = null;
|
||||
(function walk(n, acc) {
|
||||
const y = acc + (n.position ? n.position.y : 0);
|
||||
if (found === null && pred(n)) found = y;
|
||||
(n.children || []).forEach((c) => walk(c, y));
|
||||
})(root, 0);
|
||||
return found;
|
||||
}
|
||||
const isLidar = (n) => n.material && n.material.color !== undefined &&
|
||||
n.geometry instanceof THREE.CylinderGeometry &&
|
||||
n.position && Math.abs(n.position.x - r.laser_x) < 1e-9;
|
||||
|
||||
const bad = [];
|
||||
const say = (label, got, want, tol) => {
|
||||
// Diem quet luu trong Float32Array -- 0.125 + 0.075 khong tron duoc.
|
||||
const ok = Math.abs(got - want) <= (tol === undefined ? 1e-6 : tol);
|
||||
console.log(` ${label.padEnd(36)} ${got.toFixed(4)}${ok ? '' : ' != ' + want.toFixed(4)}`);
|
||||
if (!ok) bad.push(label);
|
||||
};
|
||||
|
||||
// 1. Khoang cach ve phai DUNG BANG khoang cach du lieu -- khong them gi.
|
||||
const A = V3D.robotGroup.position, B = V3D.gtGroup.position;
|
||||
say('khoang cach ve (m)', Math.hypot(A.x - B.x, A.y - B.y, A.z - B.z), 0.009, 1e-6);
|
||||
|
||||
// 2. Hai hinh phai o CUNG cao do. Day la thu bi hong.
|
||||
const yRobot = absY(V3D.robotGroup, (n) => n !== V3D.robotGroup && n.children &&
|
||||
n.children.length > 0);
|
||||
const yGt = absY(V3D.gtGroup, (n) => n !== V3D.gtGroup && n.children &&
|
||||
n.children.length > 0);
|
||||
say('cao do than robot (m)', yRobot, r.wheel_radius);
|
||||
say('cao do than ground truth (m)', yGt, r.wheel_radius);
|
||||
|
||||
// 3. ⚠️ Phep kiem MANH nhat: tru LiDAR tren robot va diem quet phai CUNG cao
|
||||
// do. Hai duong code doc lap -- v3dBuildRobot() va v3dSetScan() -- nen
|
||||
// chung chi khop khi ca hai deu dung.
|
||||
sb.__scan(new Float32Array([2.0, 0.0]), pose, r);
|
||||
const scanY = V3D.scanPts.geometry.attributes.position.array[1];
|
||||
const lidarY = absY(V3D.robotGroup, isLidar);
|
||||
say('cao do diem quet (m)', scanY, r.laser_z + r.wheel_radius);
|
||||
if (lidarY === null) {
|
||||
console.log(' khong tim thay tru LiDAR tren hinh robot');
|
||||
bad.push('tru LiDAR');
|
||||
} else {
|
||||
say('cao do tru LiDAR tren robot (m)', lidarY, scanY);
|
||||
}
|
||||
|
||||
// 4. Hop dong cua v3dSetPose(): no dat VI TRI TREN MAT PHANG, khong dung
|
||||
// toi cao do. Mot nhom mang san phep nang phai giu duoc phep nang do.
|
||||
//
|
||||
// Khong co rang buoc nay thi `position.set(p.x, 0, -p.y)` quay lai luc nao
|
||||
// cung duoc, va lan sau ai them mot lop boc co nang se lai mat no am tham.
|
||||
const lifted = new Grp();
|
||||
lifted.position.y = 0.5;
|
||||
sb.__pose(lifted, { x: 1.0, y: 2.0, yaw: 0.3 });
|
||||
say('v3dSetPose giu cao do san co (m)', lifted.position.y, 0.5);
|
||||
say('v3dSetPose dat x', lifted.position.x, 1.0);
|
||||
say('v3dSetPose dat z (= -y ROS)', lifted.position.z, -2.0);
|
||||
|
||||
console.log(bad.length ? '\n => HONG: ' + bad.join(', ') : '\n => DAT');
|
||||
process.exit(bad.length ? 1 : 0);
|
||||
125
test/www/test_scan_frame.js
Normal file
125
test/www/test_scan_frame.js
Normal file
@@ -0,0 +1,125 @@
|
||||
// Scan co duoc dat DUNG CHO trong khong gian khong?
|
||||
//
|
||||
// ================== VI SAO CAN BAI KIEM NAY ==================
|
||||
// Scan di qua day tren dinh dang POLAR trong frame LASER. Trinh duyet doi sang
|
||||
// Descartes roi ap pose cua BASE. Bo qua khoang gan LiDAR (0.24 m ve truoc)
|
||||
// lam ca vanh quet lui 24 cm -- cac tia khong con nam tren tuong.
|
||||
//
|
||||
// Loi nay KHONG lam gi hong theo nghia van hanh: dung so tia, dung nhip, dung
|
||||
// tam nhin, khong mot ngoai le nao. No chi khien nguoi van hanh thay robot
|
||||
// "troi" va di tim loi trong odometry/SLAM -- cho khong co loi.
|
||||
//
|
||||
// Nen bai kiem do THU DUNG: dung phep bien doi CUA CHINH app3d.js tren mot
|
||||
// canh dung san, roi kiem diem quet co roi trung tuong khong.
|
||||
//
|
||||
// node test_scan_frame.js
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const vm = require('vm');
|
||||
|
||||
// --- THREE gia ---
|
||||
class V3 { constructor(x, y, z) { this.x = x; this.y = y; this.z = z; } }
|
||||
class BufAttr { constructor(a, n) { this.array = a; this.itemSize = n; } }
|
||||
class BufGeom {
|
||||
constructor() { this.attributes = {}; }
|
||||
setAttribute(n, a) { this.attributes[n] = a; }
|
||||
computeVertexNormals() {}
|
||||
dispose() {}
|
||||
}
|
||||
class Grp {
|
||||
constructor() { this.children = []; }
|
||||
add(c) { this.children.push(c); }
|
||||
remove(c) { this.children = this.children.filter((x) => x !== c); }
|
||||
traverse(f) { this.children.forEach(f); }
|
||||
}
|
||||
global.THREE = {
|
||||
Vector3: V3, Color: class { constructor(r, g, b) { Object.assign(this, { r, g, b }); } },
|
||||
Quaternion: class { setFromAxisAngle() {} }, Matrix4: class { compose() {} },
|
||||
BufferAttribute: BufAttr, BufferGeometry: BufGeom, Group: Grp,
|
||||
Points: class { constructor(g, m) { this.geometry = g; this.material = m; } },
|
||||
PointsMaterial: class { constructor(o) { Object.assign(this, o); } },
|
||||
MeshStandardMaterial: class { constructor(o) { Object.assign(this, o); } dispose() {} },
|
||||
InstancedMesh: class { constructor(g, m, n) { this.geometry = g; this.count = n;
|
||||
this.userData = {}; this.instanceMatrix = {}; } setMatrixAt() {} dispose() {} },
|
||||
Mesh: class { constructor(g, m) { this.geometry = g; this.material = m;
|
||||
this.position = { set: () => {} }; this.rotation = { x: 0 }; } },
|
||||
PlaneGeometry: class { dispose() {} }, GridHelper: class {},
|
||||
BoxGeometry: class { dispose() {} },
|
||||
};
|
||||
|
||||
const wwwDir = path.resolve(__dirname, '../../libs/vslam_web/www');
|
||||
const sandbox = { THREE: global.THREE, console, window: {}, document: {} };
|
||||
vm.createContext(sandbox);
|
||||
vm.runInContext(
|
||||
fs.readFileSync(path.join(wwwDir, 'app3d.js'), 'utf8') +
|
||||
'\n;this.__V3D = V3D; this.__setScan = v3dSetScan;',
|
||||
sandbox);
|
||||
const V3D = sandbox.__V3D;
|
||||
V3D.ready = true;
|
||||
V3D.root = new Grp();
|
||||
|
||||
// --- Canh dung san: hanh lang rong 4 m, robot o giua, quay 0 rad ---
|
||||
//
|
||||
// Tuong o y = +2 va y = -2, keo dai theo x. LiDAR o 0.24 m truoc base.
|
||||
const LASER_X = 0.24, WALL = 2.0;
|
||||
const robot = { laser_x: LASER_X, laser_y: 0, laser_z: 0.125, wheel_radius: 0.075 };
|
||||
const pose = { x: 5.0, y: 1.0, yaw: 0.0 };
|
||||
|
||||
// Tia trong frame LASER, moi tia cham dung mot buc tuong.
|
||||
// LiDAR o world y = pose.y = 1.0 (vi laser_y = 0 va yaw = 0).
|
||||
// Tuong tren cach 1.0 m, tuong duoi cach 3.0 m.
|
||||
const rays = [];
|
||||
for (const [ang, dist] of [[Math.PI / 2, 1.0], [-Math.PI / 2, 3.0]]) {
|
||||
rays.push(dist * Math.cos(ang), dist * Math.sin(ang));
|
||||
}
|
||||
// Them mot tia cheo 45 do len tuong tren: cham o khoang cach 1.0/sin(45).
|
||||
rays.push(Math.SQRT2 * Math.cos(Math.PI / 4), Math.SQRT2 * Math.sin(Math.PI / 4));
|
||||
|
||||
sandbox.__setScan(new Float32Array(rays), pose, robot);
|
||||
const pos = V3D.scanPts.geometry.attributes.position.array;
|
||||
|
||||
let bad = 0;
|
||||
const rows = [];
|
||||
for (let i = 0; i < pos.length / 3; ++i) {
|
||||
const wx = pos[i * 3];
|
||||
const wy = -pos[i * 3 + 2]; // three z = -ROS y
|
||||
const wz = pos[i * 3 + 1];
|
||||
// Moi diem phai nam tren mot trong hai buc tuong.
|
||||
const onWall = Math.abs(Math.abs(wy - pose.y) - 0) < 1e6; // tinh o duoi
|
||||
const dTop = Math.abs(wy - (pose.y + 1.0));
|
||||
const dBot = Math.abs(wy - (pose.y - 3.0));
|
||||
const hit = Math.min(dTop, dBot) < 1e-3;
|
||||
if (!hit) bad++;
|
||||
rows.push(` tia ${i}: world (${wx.toFixed(3)}, ${wy.toFixed(3)}, ${wz.toFixed(3)})` +
|
||||
` ${hit ? 'tren tuong' : 'TRUOT ' + Math.min(dTop, dBot).toFixed(3) + ' m'}`);
|
||||
}
|
||||
rows.forEach((r) => console.log(r));
|
||||
|
||||
// ⚠️ Phep kiem THAT: diem quet phai dich len truoc DUNG bang laser_x.
|
||||
//
|
||||
// Tia thang ben (+-90 do) khong doi y khi bu laser_x, nen chung mot minh
|
||||
// KHONG phan biet duoc co bu hay khong. Tia CHEO thi co.
|
||||
const cheo = { x: pos[6], y: -pos[8] };
|
||||
const mongDoi = {
|
||||
x: pose.x + LASER_X + 1.0, // 0.24 tu laser_x + 1.0 tu tia cheo
|
||||
y: pose.y + 1.0,
|
||||
};
|
||||
console.log(`\n tia cheo: duoc (${cheo.x.toFixed(3)}, ${cheo.y.toFixed(3)})`);
|
||||
console.log(` mong (${mongDoi.x.toFixed(3)}, ${mongDoi.y.toFixed(3)})`);
|
||||
const dx = Math.abs(cheo.x - mongDoi.x);
|
||||
if (dx > 1e-3) {
|
||||
bad++;
|
||||
console.log(` LECH ${dx.toFixed(3)} m theo x` +
|
||||
(Math.abs(dx - LASER_X) < 1e-3 ? ' == dung bang laser_x!' : ''));
|
||||
}
|
||||
|
||||
// Do cao: scan phai o do cao LiDAR, khong phai o san.
|
||||
const zMongDoi = robot.laser_z + robot.wheel_radius;
|
||||
if (Math.abs(pos[1] - zMongDoi) > 1e-6) {
|
||||
bad++;
|
||||
console.log(` do cao scan ${pos[1]} != ${zMongDoi}`);
|
||||
}
|
||||
|
||||
console.log(bad ? '\n => HONG' : '\n => DAT');
|
||||
process.exit(bad ? 1 : 0);
|
||||
163
test/www/test_world_mesh.js
Normal file
163
test/www/test_world_mesh.js
Normal file
@@ -0,0 +1,163 @@
|
||||
// Bo giai ma `world.bin` cua trinh duyet, chay bang CHINH khoi do C++ sinh ra.
|
||||
//
|
||||
// ================== VI SAO CAN BAI KIEM NAY ==================
|
||||
// Bo ma hoa o C++ va bo giai ma o JavaScript la hai ban cai dat cua MOT dinh
|
||||
// dang. Chung lech nhau mot byte thi khung 3D ra rac hoac rong -- va mot khung
|
||||
// 3D rong co dung moi chi so van hanh voi mot khung dung: HTTP 200, dung so
|
||||
// byte, khong ngoai le nao.
|
||||
//
|
||||
// Nen bai kiem nay DEM NOI DUNG: bao nhieu hinh hoc, bao nhieu the hien, bao
|
||||
// nhieu tam giac, va do dac nam o dau trong khong gian.
|
||||
//
|
||||
// Khong can bo model AWS 3 GB: khoi duoc sinh tu test/data/world/mini.world.
|
||||
//
|
||||
// node test_world_mesh.js <vslam_world_export> <thu_muc_data> <file_tam>
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { execFileSync } = require('child_process');
|
||||
|
||||
const [exporter, dataDir, tmpBin] = process.argv.slice(2);
|
||||
const wwwDir = path.resolve(__dirname, '../../libs/vslam_web/www');
|
||||
|
||||
// --- THREE gia: chi du de dung hinh, khong ve gi ---
|
||||
class Vector3 { constructor(x, y, z) { this.x = x; this.y = y; this.z = z; } }
|
||||
class Color { constructor(r, g, b) { this.r = r; this.g = g; this.b = b; } }
|
||||
class Quaternion { setFromAxisAngle(a, ang) { this.ang = ang; } }
|
||||
class Matrix4 { compose(p, q, s) { this.p = p; this.q = q; } }
|
||||
class BufferAttribute { constructor(a, n) { this.array = a; this.itemSize = n; } }
|
||||
class BufferGeometry {
|
||||
constructor() { this.attributes = {}; }
|
||||
setAttribute(n, a) { this.attributes[n] = a; }
|
||||
computeVertexNormals() { this.normals = true; }
|
||||
dispose() { this.disposed = true; }
|
||||
}
|
||||
class Group {
|
||||
constructor() { this.children = []; }
|
||||
add(c) { this.children.push(c); }
|
||||
traverse(f) { this.children.forEach(f); }
|
||||
remove(c) { this.children = this.children.filter((x) => x !== c); }
|
||||
}
|
||||
class MeshStandardMaterial { constructor(o) { Object.assign(this, o); } dispose() {} }
|
||||
class InstancedMesh {
|
||||
constructor(g, m, n) {
|
||||
this.geometry = g; this.material = m; this.count = n;
|
||||
this.mats = []; this.userData = {}; this.instanceMatrix = {};
|
||||
}
|
||||
setMatrixAt(i, m) { this.mats[i] = { p: m.p, q: m.q }; }
|
||||
dispose() {}
|
||||
}
|
||||
class Mesh {
|
||||
constructor(g, m) {
|
||||
this.geometry = g; this.material = m;
|
||||
this.position = { set: (x, y, z) => { this.pos = [x, y, z]; } };
|
||||
this.rotation = { x: 0, y: 0, z: 0 };
|
||||
}
|
||||
}
|
||||
global.THREE = {
|
||||
Vector3, Color, Quaternion, Matrix4, BufferAttribute, BufferGeometry, Group,
|
||||
MeshStandardMaterial, InstancedMesh, Mesh,
|
||||
PlaneGeometry: class { constructor(w, h) { this.w = w; this.h = h; } dispose() {} },
|
||||
GridHelper: class { constructor(s) { this.size = s; } },
|
||||
BoxGeometry: class { dispose() {} },
|
||||
};
|
||||
|
||||
// --- nap app3d.js trong pham vi rieng ---
|
||||
const vm = require('vm');
|
||||
const sandbox = { THREE: global.THREE, console, window: {}, document: {} };
|
||||
vm.createContext(sandbox);
|
||||
vm.runInContext(
|
||||
fs.readFileSync(path.join(wwwDir, 'app3d.js'), 'utf8') +
|
||||
'\n;this.__V3D = V3D; this.__setMeshes = v3dSetWorldMeshes;' +
|
||||
'\n;this.__setWorld = v3dSetWorld;',
|
||||
sandbox);
|
||||
|
||||
const V3D = sandbox.__V3D;
|
||||
V3D.ready = true;
|
||||
V3D.root = new Group();
|
||||
V3D.scene = { fog: { near: 0, far: 0 } };
|
||||
|
||||
// --- sinh khoi tu mini.world bang chinh bo ma hoa C++ ---
|
||||
execFileSync(exporter, [
|
||||
'--world', path.join(dataDir, 'world/mini.world'),
|
||||
'--models', path.join(dataDir, 'world/models'),
|
||||
'--meshes', tmpBin, '--meshes-visual',
|
||||
], { stdio: ['ignore', 'ignore', 'inherit'] });
|
||||
|
||||
const raw = fs.readFileSync(tmpBin);
|
||||
const ab = raw.buffer.slice(raw.byteOffset, raw.byteOffset + raw.byteLength);
|
||||
|
||||
const bad = [];
|
||||
const check = (name, got, want) => {
|
||||
const ok = JSON.stringify(got) === JSON.stringify(want);
|
||||
console.log(` ${name.padEnd(28)} ${JSON.stringify(got)}${ok ? '' : ' != ' + JSON.stringify(want)}`);
|
||||
if (!ok) bad.push(name);
|
||||
};
|
||||
|
||||
if (!sandbox.__setMeshes(ab)) {
|
||||
console.log(' => HONG: khong giai ma duoc khoi');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const g = V3D.meshWorld;
|
||||
let nInst = 0, nMat = 0, nTri = 0;
|
||||
const centers = [];
|
||||
for (const im of g.children) {
|
||||
nInst += im.count;
|
||||
nMat += im.mats.length;
|
||||
nTri += im.geometry.attributes.position.array.length / 9;
|
||||
for (const m of im.mats) centers.push(m.p);
|
||||
}
|
||||
|
||||
// mini.world: 4 model khac nhau, 5 the hien (the thu sau co pose hong, bi bo).
|
||||
check('hinh hoc', g.children.length, 4);
|
||||
check('the hien', nInst, 5);
|
||||
check('ma tran da dat', nMat, 5);
|
||||
// Moi hop 8 tam giac; box_m dung cho 2 the hien nen van chi 1 ban hinh hoc.
|
||||
check('tam giac (duy nhat)', nTri, 32);
|
||||
|
||||
// Tam cac the hien, trong he three (x, y, z) = ROS (x, z, -y).
|
||||
const xs = centers.map((p) => +p.x.toFixed(2)).sort((a, b) => a - b);
|
||||
const zs = centers.map((p) => +p.z.toFixed(2)).sort((a, b) => a - b);
|
||||
check('tam theo x', xs, [0, 0, 5, 10, 15]);
|
||||
check('tam theo z (= -y ROS)', zs, [-6, 0, 0, 0, 0]);
|
||||
|
||||
// Hop dau tien khong quay: dinh phai o +-1.0 theo x, +-0.5 theo z.
|
||||
const first = g.children[0].geometry.attributes.position.array;
|
||||
let xmin = 1e9, xmax = -1e9, ymin = 1e9, ymax = -1e9, zmin = 1e9, zmax = -1e9;
|
||||
for (let i = 0; i < first.length; i += 3) {
|
||||
xmin = Math.min(xmin, first[i]); xmax = Math.max(xmax, first[i]);
|
||||
ymin = Math.min(ymin, first[i + 1]); ymax = Math.max(ymax, first[i + 1]);
|
||||
zmin = Math.min(zmin, first[i + 2]); zmax = Math.max(zmax, first[i + 2]);
|
||||
}
|
||||
check('hop 1: rong x', +(xmax - xmin).toFixed(2), 2);
|
||||
check('hop 1: cao y', +(ymax - ymin).toFixed(2), 0.5);
|
||||
check('hop 1: sau z', +(zmax - zmin).toFixed(2), 1);
|
||||
|
||||
// ⚠️ MOI hop phai cao 0.5 m, khong rieng hop dau.
|
||||
//
|
||||
// `..._walls_visual` khai Y_UP nhung du lieu da o Z-up: ap `<up_axis>` len no
|
||||
// lam buc tuong 3 m thanh mot thanh DUNG DUNG cao 56 m. Mat bang van dung, nen
|
||||
// chi do chieu cao moi thay.
|
||||
let tallest = 0;
|
||||
for (const im of g.children) {
|
||||
const a = im.geometry.attributes.position.array;
|
||||
let lo = 1e9, hi = -1e9;
|
||||
for (let i = 1; i < a.length; i += 3) { lo = Math.min(lo, a[i]); hi = Math.max(hi, a[i]); }
|
||||
tallest = Math.max(tallest, hi - lo);
|
||||
}
|
||||
check('hop cao nhat', +tallest.toFixed(2), 0.5);
|
||||
|
||||
// ⚠️ HOI QUY: san nam trong v3dSetWorld(), ma ham do THOAT SOM khi da co mesh
|
||||
// that. Mot lan da lam ca toa nha lo lung tren nen den ma khong loi nao.
|
||||
const grid = { w: 400, h: 400, res: 0.05, ox: -10, oy: -10,
|
||||
cells: new Int8Array(400 * 400) };
|
||||
sandbox.__setWorld(grid, 2.0);
|
||||
check('san sau khi co mesh', !!V3D.floorMesh, true);
|
||||
check('luoi san', !!V3D.gridHelper, true);
|
||||
check('khoi hop da bo', V3D.worldMesh, null);
|
||||
// Suong mu phai phu het bao, khong thi toa nha tan vao nen.
|
||||
check('suong mu >= bao', V3D.scene.fog.far >= 400 * 0.05, true);
|
||||
|
||||
console.log(bad.length ? '\n => HONG: ' + bad.join(', ') : '\n => DAT');
|
||||
process.exit(bad.length ? 1 : 0);
|
||||
Reference in New Issue
Block a user