reloc,web: dinh vi lai TREN DOC (slope.enabled) -- loc gia thuyet bang do nghieng IMU vs do doc ban do, chan mu doc truc (ShiftScoreRatio), vong DUNG YEN khong xoay (ty le nho nhat >= 3 vong / hai cho cung pose), tu chay bo thang tren doc; camera VPR+PnP tren doc (>= 2 anh trung, khop nghieng, LiDAR khong phan doi, pose = trung binh camera) -- sim 10 cho chot dung 1.4-2.9 cm, 0 chot sai; web 3D: ban do uon theo san (FLH1), scan/quy dao theo z, het nen lung, sua ro GPU; CMake: TensorRT tren CMake < 3.17

This commit is contained in:
trung09122002
2026-10-06 10:17:17 +07:00
parent b1ab04c51e
commit f0c5ddb6b8
19 changed files with 1947 additions and 68 deletions

View File

@@ -80,12 +80,31 @@ void EncodeScan(const LaserScan& scan, UnixTime stamp, std::string* out);
void EncodeCloud(const PointCloudXYZ& cloud, UnixTime stamp, uint32_t max_points,
float quant_m, const Pose2D& delta, std::string* out);
// Do cao SAN cua ban do (slam.yaml slope.enabled): luoi THO, mm, kFloorUnknown
// = chua biet. Web uon mat phang ban do 2D theo luoi nay -- khong co no thi
// mat doc va san tang tren duoc ve o z = 0, nam DUOI tuong voxel (o z that)
// va trong nhu san bi thung.
constexpr int16_t kFloorUnknown = -32768;
struct MapFloorGrid {
float resolution = 0.2f;
uint32_t width = 0;
uint32_t height = 0;
float origin_x = 0.0f;
float origin_y = 0.0f;
std::vector<int16_t> mm; // hang chinh, hang 0 = y nho nhat (nhu OccupancyGrid)
};
// RLE hang-chinh. Xem rle.h.
// `type` cho phep dung chung bo ma hoa cho ban do SLAM (kMapFull) va ban do
// THE GIOI cua bo mo phong (kWorldMap): khung giong het nhau, chi khac y
// nghia. Mot bo ma hoa thu hai se la hai cho de lech dinh dang.
//
// `floor_grid` (tuy chon): khoi do cao san NOI SAU phan RLE -- magic "FLH1", f32
// res, i32 w, i32 h, f32 ox, f32 oy, roi w*h int16 (mm). Khong co thi khung y
// het cu.
void EncodeMapFull(const OccupancyGrid& map, UnixTime stamp, std::string* out,
BinaryType type = BinaryType::kMapFull);
BinaryType type = BinaryType::kMapFull,
const MapFloorGrid* floor_grid = nullptr);
// (kMapPatch = 4 da bi BO. No noi duoc vao dau: cong per-session chi la mot
// atomic `acked_map_version_`, khong dien ta noi "session nay dang giu luoi
@@ -149,7 +168,9 @@ struct BinaryHeader {
bool DecodeHeader(const std::string& buf, size_t offset, BinaryHeader* out);
bool DecodeScan(const std::string& buf, LaserScan* out);
bool DecodeMapFull(const std::string& buf, OccupancyGrid* out);
// `floor_grid` (tuy chon) nhan khoi do cao san neu khung co; khong co thi width = 0.
bool DecodeMapFull(const std::string& buf, OccupancyGrid* out,
MapFloorGrid* floor_grid = nullptr);
// Giai mot manh. `out` duoc NOI THEM, khong xoa -- rap nhieu manh bang cach
// goi lien tiep. `total`/`chunk_index`/`chunk_count`/`epoch` tra qua con tro

View File

@@ -13,6 +13,7 @@
#include <string>
#include <vector>
#include "vslam/binary_codec.h"
#include "vslam/stats.h"
#include "vslam/vslam_common.h"
@@ -181,6 +182,8 @@ struct WebSnapshot {
Pose2D cloud_delta;
bool have_cloud_delta = false;
OccupancyGridPtr map; // ban do SLAM dung
// Do cao SAN cua ban do (che do doc), gui kem khung map. Null = phang.
std::shared_ptr<const MapFloorGrid> map_floor;
// Ban do THE GIOI cua bo mo phong (khung nhin "Gazebo"). Null khi chay
// that -- luc do khong co su that nao de doi chieu.
OccupancyGridPtr world_map;

View File

@@ -147,7 +147,7 @@ void EncodeCloud(const PointCloudXYZ& cloud, UnixTime stamp, uint32_t max_points
}
void EncodeMapFull(const OccupancyGrid& map, UnixTime stamp, std::string* out,
BinaryType type) {
BinaryType type, const MapFloorGrid* floor_grid) {
PutHeader(out, type, stamp);
PutF32(out, map.resolution);
PutI32(out, static_cast<int32_t>(map.width));
@@ -169,6 +169,19 @@ void EncodeMapFull(const OccupancyGrid& map, UnixTime stamp, std::string* out,
(*out)[run_count_off + static_cast<size_t>(i)] =
static_cast<char>((r32 >> (8 * i)) & 0xFF);
}
// Khoi do cao san (che do doc), NOI SAU phan RLE -- xem binary_codec.h.
const MapFloorGrid* fg = floor_grid;
if (fg != nullptr && fg->width > 0 && fg->height > 0 &&
fg->mm.size() == static_cast<size_t>(fg->width) * fg->height) {
out->append("FLH1", 4);
PutF32(out, fg->resolution);
PutI32(out, static_cast<int32_t>(fg->width));
PutI32(out, static_cast<int32_t>(fg->height));
PutF32(out, fg->origin_x);
PutF32(out, fg->origin_y);
for (int16_t v : fg->mm) PutI16(out, v);
}
}
// --- Ban do voxel 3D -------------------------------------------------------
@@ -333,9 +346,10 @@ bool DecodeScan(const std::string& buf, LaserScan* out) {
return true;
}
bool DecodeMapFull(const std::string& buf, OccupancyGrid* out) {
bool DecodeMapFull(const std::string& buf, OccupancyGrid* out, MapFloorGrid* floor_grid) {
BinaryHeader h;
if (!DecodeHeader(buf, 0, &h) || h.type != BinaryType::kMapFull) return false;
if (floor_grid != nullptr) *floor_grid = MapFloorGrid{};
size_t o = kBinaryHeaderSize;
if (buf.size() < o + 28) return false;
@@ -351,6 +365,25 @@ bool DecodeMapFull(const std::string& buf, OccupancyGrid* out) {
const size_t expected = static_cast<size_t>(out->width) * out->height;
if (!RleDecode(buf, o, runs, expected, &out->data)) return false;
// Khoi do cao san tuy chon, ngay sau RLE (3 byte moi run).
o += static_cast<size_t>(runs) * 3;
if (floor_grid != nullptr && buf.size() >= o + 24 && buf.compare(o, 4, "FLH1") == 0) {
MapFloorGrid f;
f.resolution = GetF32(buf, o + 4);
f.width = static_cast<uint32_t>(GetI32(buf, o + 8));
f.height = static_cast<uint32_t>(GetI32(buf, o + 12));
f.origin_x = GetF32(buf, o + 16);
f.origin_y = GetF32(buf, o + 20);
const size_t n = static_cast<size_t>(f.width) * f.height;
if (buf.size() >= o + 24 + 2 * n) {
f.mm.resize(n);
for (size_t i = 0; i < n; ++i) {
f.mm[i] = static_cast<int16_t>(GetU16(buf, o + 24 + 2 * i));
}
*floor_grid = std::move(f);
}
}
out->header.stamp = UnixTime::fromNSec(static_cast<int64_t>(h.stamp_ns));
return true;
}

View File

@@ -830,7 +830,8 @@ void WebServer::Publish(const WebSnapshot& snap) {
if (s->acked_map_version() == snap.slam.map_version) continue;
if (!buf) {
buf = std::make_shared<std::string>();
EncodeMapFull(*snap.map, snap.stamp, buf.get());
EncodeMapFull(*snap.map, snap.stamp, buf.get(), BinaryType::kMapFull,
snap.map_floor.get());
}
s->Send(buf, true, /*is_map=*/true);
s->set_acked_map_version(snap.slam.map_version);

View File

@@ -12,7 +12,7 @@ const MAGIC = 0x314C5356; // 'VSL1' little-endian
// Phien ban ma nguon giao dien. TANG khi doi app.js / app3d.js / style.css.
// Hien ngay tren thanh tren cung de phan biet "chua sua" voi "trinh duyet con
// cache ban cu".
const UI_VERSION = '2026-09-30a';
const UI_VERSION = '2026-10-05c';
// ⚠️ HAI bang mau, mot cho moi khung. Chung KHONG duoc giong nhau.
//
@@ -68,6 +68,8 @@ const T_SCAN = 1, T_CLOUD = 2, T_MAP_FULL = 3, T_PATH = 5;
const T_WORLD_MAP = 6;
// Ban do voxel 3D: tap day du (chia manh) va phan them/bot.
const T_VOXEL_FULL = 7, T_VOXEL_DELTA = 8;
// Khoi do cao SAN noi sau RLE cua khung ban do (che do doc, binary_codec.h).
const FLOOR_MAGIC = 0x31484C46; // 'FLH1' little-endian
// Ba ngu nghia cua mot tia. Lan lon chung la lam sai ca man hinh.
const R_NAN = 0xFFFF; // khong do duoc (duoi range_min)
@@ -229,7 +231,21 @@ function onBinary(dv) {
cells.fill(val, p, p + len);
p += len;
}
const grid = { res, w, h, ox, oy, cells };
// Do cao san (mm, -32768 = chua biet) ngay sau RLE. Khong co thi ban do
// phang nhu cu.
let floor = null;
const fo = off + 28 + runs * 3;
if (type === T_MAP_FULL && dv.byteLength >= fo + 24 &&
dv.getUint32(fo, true) === FLOOR_MAGIC) {
const fw = dv.getInt32(fo + 8, true), fh = dv.getInt32(fo + 12, true);
if (fw > 0 && fh > 0 && dv.byteLength >= fo + 24 + fw * fh * 2) {
const mm = new Int16Array(fw * fh);
for (let i = 0; i < fw * fh; i++) mm[i] = dv.getInt16(fo + 24 + i * 2, true);
floor = { res: dv.getFloat32(fo + 4, true), w: fw, h: fh,
ox: dv.getFloat32(fo + 16, true), oy: dv.getFloat32(fo + 20, true), mm };
}
}
const grid = { res, w, h, ox, oy, cells, floor };
if (type === T_WORLD_MAP) {
// Ban do THE GIOI: su that, de lai cho chuan. KHONG lan vao state.map.
state.worldMap = grid;
@@ -620,6 +636,11 @@ function anchorPose(robotPose, anchoredAt) {
x: robotPose.x + c * lx - s * ly,
y: robotPose.y + s * lx + c * ly,
yaw: robotPose.yaw + (anchoredAt.yaw - state.pose.yaw),
// Cao do san duoi robot va do nghieng than (che do doc): khung 3D nang
// scan/cloud len theo z, va xoay scan tho theo roll/pitch.
z: robotPose.z,
roll: robotPose.roll,
pitch: robotPose.pitch,
};
}
@@ -1314,7 +1335,7 @@ function draw3d() {
v3dSetMap({ ...state.map, data: state.map.cells, version: state.mapVersion });
}
if (V3D.mapMesh) V3D.mapMesh.visible = on('lyMap') && !!state.map;
if (on('lyPath')) v3dSetPath(state.path);
if (on('lyPath')) v3dSetPath(state.path, state.map && state.map.floor);
else if (V3D.pathLine) V3D.pathLine.visible = false;
v3dRender(cv3d, on('lyFollow'), split3d);

View File

@@ -456,8 +456,16 @@ function v3dSetScan(arr, pose, r) {
const n = arr.length / 2;
const pos = new Float32Array(n * 3);
// Scan nam o do cao cua LiDAR, khong phai o san. Ve o san se lam nguoi xem
// tuong LiDAR thay duoc vat thap -- no KHONG thay.
const z = r.laser_z + r.wheel_radius;
// tuong LiDAR thay duoc vat thap -- no KHONG thay. Cong cao do san duoi
// robot (che do doc), khong thi o tang tren scan ve chui duoi san.
const z0 = pose.z || 0;
const zl = r.laser_z + r.wheel_radius; // goc LiDAR tren san, he footprint
// Web nhan scan THO: tia nam trong mat phang LiDAR, NGHIENG theo than robot.
// Tren doc 15 do ve phang thi diem cach 3 m lech ~0.8 m (chui vao mat doc)
// -> xoay theo roll/pitch quanh footprint, nhu v3dSetPose xoay hinh robot.
// ROS R = Rz(yaw) Ry(pitch) Rx(roll); khong co tilt thi y het cu.
const cr = Math.cos(pose.roll || 0), sr = Math.sin(pose.roll || 0);
const cp = Math.cos(pose.pitch || 0), sp = Math.sin(pose.pitch || 0);
// ⚠️ Scan den trong frame LASER, khong phai frame BASE.
//
// `laser_link` cach `base_link` 0.24 m ve phia truoc (robot.yaml). Dat thang
@@ -469,9 +477,12 @@ function v3dSetScan(arr, pose, r) {
const lx = r.laser_x || 0, ly = r.laser_y || 0;
for (let i = 0; i < n; ++i) {
const x = arr[i * 2] + lx, y = arr[i * 2 + 1] + ly;
pos[i * 3] = pose.x + c * x - s * y;
pos[i * 3 + 1] = z;
pos[i * 3 + 2] = -(pose.y + s * x + c * y);
// Rx(roll) roi Ry(pitch), trong he footprint (truoc khi quay yaw).
const y1 = y * cr - zl * sr, z1 = y * sr + zl * cr;
const x2 = x * cp + z1 * sp, z2 = -x * sp + z1 * cp;
pos[i * 3] = pose.x + c * x2 - s * y1;
pos[i * 3 + 1] = z0 + z2;
pos[i * 3 + 2] = -(pose.y + s * x2 + c * y1);
}
V3D.scanPts.geometry.dispose();
V3D.scanPts.geometry = new THREE.BufferGeometry();
@@ -493,10 +504,11 @@ function v3dSetCloud(arr, pose) {
const c = Math.cos(pose.yaw), s = Math.sin(pose.yaw);
const n = arr.length / 3;
const pos = new Float32Array(n * 3), col = new Float32Array(n * 3);
const z0 = pose.z || 0; // cao do san duoi robot (che do doc)
for (let i = 0; i < n; ++i) {
const x = arr[i * 3], y = arr[i * 3 + 1], z = arr[i * 3 + 2];
pos[i * 3] = pose.x + c * x - s * y;
pos[i * 3 + 1] = z;
pos[i * 3 + 1] = z0 + z;
pos[i * 3 + 2] = -(pose.y + s * x + c * y);
// To mau theo do cao, cung bang mau voi khung 2D.
const t = Math.max(0, Math.min(1, z / 1.2));
@@ -618,12 +630,22 @@ function v3dSetMapCloud(v, visible) {
// San dat o TOA DO THE GIOI chu khong theo robot. Dat theo robot la dung cai
// bay "sàn troi theo robot": robot dung yen giua man hinh con ca the gioi
// truot qua, trong y het loi dinh vi.
//
// ⚠️ Chi dung lai khi BAO the gioi doi. Chay tu `.world`, v3dSetWorld() goi
// ham nay MOI khung hinh (nhanh mesh that thoat som truoc khoa worldKey), va
// ban cu dung lai mat san + GridHelper moi khung ma khong giai phong cai cu.
// Do tren slope_test.world: geometry tren GPU tang ~1 moi khung (20 -> 203
// sau 183 khung), tuc ~3600/phut o 60 fps -- trinh duyet cham dan.
function v3dSetGround(grid) {
if (!V3D.ready || !grid) return;
const key = grid.w + 'x' + grid.h + '@' + grid.res + ':' + grid.ox + ',' + grid.oy;
if (V3D.groundKey === key && V3D.floorMesh) return;
V3D.groundKey = key;
const r = grid.res;
if (V3D.floorMesh) {
V3D.root.remove(V3D.floorMesh);
V3D.floorMesh.geometry.dispose();
V3D.floorMesh.material.dispose();
}
const fw = grid.w * r, fh = grid.h * r;
V3D.floorMesh = new THREE.Mesh(
@@ -640,7 +662,11 @@ function v3dSetGround(grid) {
const span = Math.max(fw, fh);
V3D.scene.fog.near = span * 0.35;
V3D.scene.fog.far = span * 1.4;
if (V3D.gridHelper) V3D.root.remove(V3D.gridHelper);
if (V3D.gridHelper) {
V3D.root.remove(V3D.gridHelper);
V3D.gridHelper.geometry.dispose();
V3D.gridHelper.material.dispose();
}
V3D.gridHelper = new THREE.GridHelper(Math.ceil(span), Math.ceil(span),
0x93a2b0, 0xa6b3c0);
V3D.root.add(V3D.gridHelper);
@@ -844,11 +870,69 @@ function v3dSetWorld(grid, wallHeight) {
v3dSetGround(grid);
}
// Ban do occupancy -> mot mat phang co texture, dat o san.
// --- Do cao SAN cua ban do (che do doc) ---
//
// Luoi tho (0.2 m, mm, -32768 = chua biet) di kem khung ban do SLAM. O chua
// biet (xa moi node > 4 m: tuong LiDAR thay tu xa) lay gia tri o DA BIET gan
// nhat -- de 0 thi mat phang tu tang tren cam xuong z = 0 thanh mot tam xien.
const FLOOR_UNKNOWN = -32768;
// Mat ban do uon dat CAO hon san uoc luong 4 cm. Trong khung gop, mesh san
// THAT cua world (doc, san) la mat duc trung cho voi no: thap hon du chi 2 mm
// la bi che, ngang nhau la nhap nhay rang cua -- chinh la "nen bi lung". Da do
// (sim, map 645 node): sai uoc - that p1 -2.3 cm, p50 +3.3 cm; nang 3 cm con
// 0.3% o chim, 4 cm con 0%. Robot that khong co mesh world: chi noi 4 cm.
const FLOOR_LIFT = 0.04;
function v3dFloorFill(fl) {
const n = fl.w * fl.h;
const out = new Int16Array(fl.mm);
const q = new Int32Array(n);
let head = 0, tail = 0;
for (let i = 0; i < n; ++i) if (out[i] !== FLOOR_UNKNOWN) q[tail++] = i;
if (tail === 0) return null;
while (head < tail) {
const i = q[head++], c = i % fl.w, r = (i - c) / fl.w;
const nb = [c > 0 ? i - 1 : -1, c + 1 < fl.w ? i + 1 : -1,
r > 0 ? i - fl.w : -1, r + 1 < fl.h ? i + fl.w : -1];
for (const j of nb) {
if (j >= 0 && out[j] === FLOOR_UNKNOWN) { out[j] = out[i]; q[tail++] = j; }
}
}
return { ...fl, mm: out };
}
// Do cao san (m) tai (x, y) ROS: noi suy song tuyen giua TAM 4 o quanh diem
// (dinh mat phang nam dung GOC o -- lay o gan nhat thi tren doc 15 do lech
// ~3 cm theo phia lam tron). null neu ngoai luoi / chua biet.
function v3dFloorAt(fl, x, y) {
if (!fl) return null;
const gx = (x - fl.ox) / fl.res - 0.5, gy = (y - fl.oy) / fl.res - 0.5;
const c0 = Math.floor(gx), r0 = Math.floor(gy);
const fx = gx - c0, fy = gy - r0;
let sw = 0, sz = 0;
for (let k = 0; k < 4; ++k) {
const c = c0 + (k & 1), r = r0 + (k >> 1);
if (c < 0 || r < 0 || c >= fl.w || r >= fl.h) continue;
const v = fl.mm[r * fl.w + c];
if (v === FLOOR_UNKNOWN) continue;
const wgt = ((k & 1) ? fx : 1 - fx) * ((k >> 1) ? fy : 1 - fy);
sw += wgt;
sz += wgt * v;
}
return sw > 1e-6 ? (sz / sw) * 0.001 : null;
}
// Ban do occupancy -> mot mat phang co texture, dat o san -- UON theo do cao
// san khi ban do co (che do doc): mat doc va san tang tren o dung cao do,
// khong nam bep o z = 0 duoi tuong voxel.
function v3dSetMap(map) {
if (!V3D.ready || !map || !map.w || !map.h) return;
if (V3D.mapKey === map.version) return;
V3D.mapKey = map.version;
// Khoa theo MANG O, khong theo so phien ban: khung JSON mang phien ban moi
// toi TRUOC khung ban do, nen khoa theo phien ban co the chot luoi CU voi
// phien ban MOI roi khong bao gio ve lai -- ma o che do dinh vi phien ban
// chi doi khi co lien ket moi.
if (V3D.mapData === map.data) return;
V3D.mapData = map.data;
const cv = document.createElement('canvas');
cv.width = map.w; cv.height = map.h;
@@ -880,23 +964,57 @@ function v3dSetMap(map) {
tex.magFilter = THREE.NearestFilter;
tex.minFilter = THREE.LinearMipmapLinearFilter;
if (V3D.mapMesh) { V3D.root.remove(V3D.mapMesh); V3D.mapMesh.geometry.dispose(); }
if (V3D.mapMesh) {
V3D.root.remove(V3D.mapMesh);
V3D.mapMesh.geometry.dispose();
if (V3D.mapMesh.material.map) V3D.mapMesh.material.map.dispose();
V3D.mapMesh.material.dispose();
}
const wM = map.w * map.res, hM = map.h * map.res;
const fl = map.floor ? v3dFloorFill(map.floor) : null;
let geom;
if (fl) {
// Mot dinh moi o luoi san, tran 256 doan moi chieu (ban do 100 m van
// chi ~66k dinh).
const sx = Math.max(1, Math.min(256, Math.round(wM / fl.res)));
const sy = Math.max(1, Math.min(256, Math.round(hM / fl.res)));
geom = new THREE.PlaneGeometry(wM, hM, sx, sy);
// Dinh cuc bo (x, y, z) -> sau rotation.x = -PI/2 la ROS (x, y, z) quanh
// tam mat phang: cuc bo +y = ROS +y, cuc bo +z = LEN.
const p = geom.attributes.position;
for (let i = 0; i < p.count; ++i) {
const z = v3dFloorAt(fl, map.ox + wM / 2 + p.getX(i), map.oy + hM / 2 + p.getY(i));
p.setZ(i, z === null ? 0 : z);
}
p.needsUpdate = true;
} else {
geom = new THREE.PlaneGeometry(wM, hM);
}
V3D.mapMesh = new THREE.Mesh(
new THREE.PlaneGeometry(wM, hM),
geom,
new THREE.MeshBasicMaterial({ map: tex, transparent: true, depthWrite: false }));
V3D.mapMesh.rotation.x = -Math.PI / 2;
// Hoi thap hon san mot chut de khong z-fight voi luoi va vanh cliff.
V3D.mapMesh.position.set(map.ox + wM / 2, -0.002, -(map.oy + hM / 2));
// Phang: hoi thap hon san mot chut de khong z-fight voi luoi va vanh cliff.
// Uon: nang FLOOR_LIFT len tren mesh san that cua world (xem tren).
V3D.mapMesh.position.set(map.ox + wM / 2, fl ? FLOOR_LIFT : -0.002, -(map.oy + hM / 2));
V3D.mapHasFloor = !!fl;
V3D.root.add(V3D.mapMesh);
}
function v3dSetPath(pts) {
// `floor` (tuy chon): luoi do cao san cua ban do -- quy dao di theo mat doc /
// tang tren thay vi chui duoi san.
function v3dSetPath(pts, floor) {
if (!V3D.ready) return;
if (V3D.pathLine) { V3D.root.remove(V3D.pathLine); V3D.pathLine.geometry.dispose(); }
if (!pts || pts.length < 4) return;
// Quy dao luon nam sat node nen khong can lap o chua biet nhu v3dSetMap.
// Ve TREN mat ban do uon (nang FLOOR_LIFT), khong thi lop trong suot phu len
// lam quy dao mo di.
const v = [];
for (let i = 0; i + 1 < pts.length; i += 2) v.push(toScene(pts[i], pts[i + 1], 0.01));
for (let i = 0; i + 1 < pts.length; i += 2) {
const z = v3dFloorAt(floor, pts[i], pts[i + 1]);
v.push(toScene(pts[i], pts[i + 1], z === null ? 0.01 : z + FLOOR_LIFT + 0.01));
}
V3D.pathLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(v),
new THREE.LineBasicMaterial({ color: 0xffb300 }));
@@ -912,6 +1030,10 @@ function v3dSetPath(pts) {
function v3dSetWorldVisible(on) {
if (V3D.meshWorld) V3D.meshWorld.visible = on;
if (V3D.worldMesh) V3D.worldMesh.visible = on;
// Mat san the gioi (z = 0) o lai lam moc khi tat the gioi -- tru khi ban do
// co do cao san: luc do no nam duoi tang tren nhu mot san sai cho (xem nua
// SLAM trong v3dRender).
if (V3D.floorMesh) V3D.floorMesh.visible = on || !V3D.mapHasFloor;
}
// Dat khung nhin ve mot goc chuan.
@@ -989,17 +1111,21 @@ function v3dRender(canvas, follow, splitSlam) {
}
// Tam quay: bam theo robot neu bat, khong thi theo diem pan cua nguoi dung.
let cx = V3D.orbit.tx, cz = V3D.orbit.ty;
// Bam ca CAO DO (che do doc): o tang tren 1.5 m ma tam quay van o san duoi
// thi camera xoay quanh mot diem chui duoi chan robot. Pose 2D (khong z)
// thi robotGroup o y = 0, y het cu.
let cx = V3D.orbit.tx, cz = V3D.orbit.ty, cy = 0;
if (follow && V3D.robotGroup) {
cx = V3D.robotGroup.position.x + V3D.orbit.tx;
cz = V3D.robotGroup.position.z + V3D.orbit.ty;
cy = V3D.robotGroup.position.y;
}
const o = V3D.orbit;
V3D.camera.position.set(
cx + o.dist * Math.cos(o.el) * Math.cos(o.az),
o.dist * Math.sin(o.el),
cy + o.dist * Math.sin(o.el),
cz + o.dist * Math.cos(o.el) * Math.sin(o.az));
V3D.camera.lookAt(cx, 0.2, cz);
V3D.camera.lookAt(cx, cy + 0.2, cz);
const r = V3D.renderer;
if (!splitSlam) {
@@ -1038,7 +1164,10 @@ function v3dRender(canvas, follow, splitSlam) {
show(hid);
// --- Nua PHAI: chi SLAM, khong co the gioi ---
hid = hide([V3D.meshWorld, V3D.worldMesh]);
// Ban do co do cao san (che do doc) thi an ca mat san THE GIOI (z = 0, tu
// v3dSetGround): duoi tang tren 1.5 m no hien qua lop ban do trong suot
// nhu mot "san" sai cho -- SLAM da tu mang mat san cua no.
hid = hide([V3D.meshWorld, V3D.worldMesh, V3D.mapHasFloor ? V3D.floorMesh : null]);
r.setViewport(half, 0, w - half, h);
r.setScissor(half, 0, w - half, h);
r.render(V3D.scene, V3D.camera);