perf(point_cloud): 1M point support, mat4 coordinate transforms, and metrics HUD#2
perf(point_cloud): 1M point support, mat4 coordinate transforms, and metrics HUD#2
Conversation
…rMaterial transforms Co-authored-by: daohu527 <10419854+daohu527@users.noreply.github.com>
|
以下是详细说明及相应的代码变更(commit 1. 如何支持 100 万点云正常显示关键变更① ② 坐标变换:4 个 float uniform → 单个 // vertex shader
vec4 worldPos = uTransform * vec4(position, 1.0);
vec4 mvPos = modelViewMatrix * worldPos;在 CPU 侧,默认组合 ADC 航向(yaw)和位置;若传感器安装有倾斜角(roll/pitch)或偏置,只需在调用 // 示例:额外的传感器外参(激光雷达相对车体的安装偏置)
const extrinsic = new THREE.Matrix4().makeRotationFromEuler(sensorRotation);
extrinsic.setPosition(sensorOffset);
// 在 point_cloud.update() 内部自动 compose:
// uTransform = adcWorldMatrix * extrinsic③ 2. 指标面板(Points / FPS / Bandwidth)新增了一个半透明 HUD 悬浮在 3D 画布左上角,仅在开启点云显示时可见:
3. 业界通用方案
|
… panel Agent-Logs-Url: https://github.com/wheelos/frontend/sessions/9bd5d430-502c-4911-b410-9d2b915c0d3e Co-authored-by: daohu527 <10419854+daohu527@users.noreply.github.com>
c45800a to
0151843
Compare
Point cloud rendering in Dreamview was bottlenecked by
THREE.Geometry's per-vertex JS object model, per-frame CPU-side transform updates, and a hard cap of 200k points, causing severe FPS degradation at high point counts.Key changes
THREE.Geometry→THREE.BufferGeometry+Float32ArrayEliminates per-vertex JS object allocations. Direct typed-array writes are ~10× faster; GPU receives a single contiguous DMA transfer instead of incremental uploads.
MAX_POINTSraised to 1,000,000Two pre-allocated
Float32Arraybuffers (positions + colors, ~24 MB total) support up to 1M LiDAR returns with a flat GPU upload cost.setDrawRange(0, total)replaces the "hide unused points" loopThe old code ran a second
O(MAX_POINTS)loop every frame to move inactive points to(0,0,-10). Now a single metadata write tells the GPU to skip them entirely.ShaderMaterialwithmat4 uTransformfor full 3D coordinate transformsReplaces four separate float uniforms (X/Y/Z offset + Z-rotation) with a single
mat4uniform. The vertex shader applies the full rigid-body transform on the GPU in one matrix-vector multiply. The host side composes the matrix from the ADC heading and position without allocating each frame. Any sensor-extrinsic correction (roll, pitch, non-zero LiDAR mounting offset) can be pre-multiplied into this matrix at the call site without touching the shader.BufferAttribute.dynamic = trueFlags VBOs as
DYNAMIC_DRAW, reducing GPU driver stalls on repeated per-frame uploads.Pre-computed height→color RGB table
Replaces the per-point
if/else+ object-map lookup with a direct array index into pre-computed[r, g, b]float triplets, eliminating transient allocations inside the hot loop.Real-time metrics HUD panel
A semi-transparent overlay in the top-left of the 3D canvas shows three live metrics (visible only when point cloud display is enabled):
updatePointCloudcallanimate()looponmessage, normalised to KB/s per secondMetrics are stored in a new
PointCloudMetricsMobX store and rendered by a newPointCloudMetricsReact component wired into theScene.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.