Skip to content

Commit 4712621

Browse files
committed
ICP pairs: yellow fat-line for visibility
LinesLayer now renders via drei's Line (Line2 + LineMaterial under the hood), which actually honors line width on WebGL — native lineSegments silently caps at 1 px. Adds a `width` field to LineLayer (default 1). ICP page: pair lines bumped from 1 px gray (#e2e8f0, 0.6 opacity) to 2 px amber (#facc15, 0.95 opacity), and the per-frame pair sample count went from 250 to 400. Legend dot follows the new color.
1 parent 26d6f2d commit 4712621

2 files changed

Lines changed: 35 additions & 18 deletions

File tree

web/src/components/PointCloudViewer.tsx

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useMemo, useRef, useState } from "react";
22
import { Canvas, useThree } from "@react-three/fiber";
3-
import { OrbitControls, GizmoHelper, GizmoViewport } from "@react-three/drei";
3+
import { OrbitControls, GizmoHelper, GizmoViewport, Line as FatLine } from "@react-three/drei";
44
import * as THREE from "three";
55
import { CameraSyncStore, nextSyncId } from "../lib/cameraSync";
66
import type { PointCloud } from "../lib/types";
@@ -17,9 +17,14 @@ type Layer = {
1717
};
1818

1919
type LineLayer = {
20+
/** Endpoint stream packed [x0,y0,z0, x1,y1,z1, ...]. Every consecutive
21+
* pair of points is rendered as one segment. */
2022
positions: Float32Array;
2123
color: string;
2224
opacity?: number;
25+
/** Pixel width of the rendered line. Default 1. Implemented via drei's
26+
* fat-line so it actually honors widths above 1 on WebGL. */
27+
width?: number;
2328
};
2429

2530
type Props = {
@@ -385,23 +390,35 @@ function PointsLayer({
385390
}
386391

387392
function LinesLayer({ layer }: { layer: LineLayer }) {
388-
const geom = useMemo(() => {
389-
const g = new THREE.BufferGeometry();
390-
g.setAttribute("position", new THREE.BufferAttribute(layer.positions, 3));
391-
return g;
393+
// The width default of 1 falls back to native WebGL lines (the only width
394+
// they support); anything > 1 needs drei's fat-line shader. We render
395+
// every pair of consecutive endpoints as a separate segment via the
396+
// `segments` flag.
397+
const points = useMemo(() => {
398+
const total = (layer.positions.length / 3) | 0;
399+
const out: [number, number, number][] = new Array(total);
400+
for (let i = 0; i < total; i++) {
401+
out[i] = [
402+
layer.positions[i * 3],
403+
layer.positions[i * 3 + 1],
404+
layer.positions[i * 3 + 2],
405+
];
406+
}
407+
return out;
392408
}, [layer.positions]);
393409

394-
const mat = useMemo(
395-
() =>
396-
new THREE.LineBasicMaterial({
397-
color: new THREE.Color(layer.color),
398-
transparent: (layer.opacity ?? 1) < 1,
399-
opacity: layer.opacity ?? 1,
400-
}),
401-
[layer.color, layer.opacity],
402-
);
410+
if (points.length === 0) return null;
403411

404-
return <lineSegments geometry={geom} material={mat} />;
412+
return (
413+
<FatLine
414+
points={points}
415+
color={layer.color}
416+
lineWidth={layer.width ?? 1}
417+
segments
418+
transparent={(layer.opacity ?? 1) < 1}
419+
opacity={layer.opacity ?? 1}
420+
/>
421+
);
405422
}
406423

407424
function unionBounds(layers: Layer[]) {

web/src/pages/Lec11Icp.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default function Lec11Icp() {
9797
setTransform(result.transform);
9898
setFitness(result.fitness);
9999
setPairs(result.pairs);
100-
setPairCoords(samplePairCoords(result.pairCoords, 250));
100+
setPairCoords(samplePairCoords(result.pairCoords, 400));
101101
setIter((i) => i + 1);
102102
if (result.fitness === 0 || delta < CONVERGE_EPS) {
103103
setConverged(true);
@@ -131,7 +131,7 @@ export default function Lec11Icp() {
131131
<div className="flex items-center gap-3">
132132
<Dot color="#f87171" /> {t.lec11.legendSrc}
133133
<Dot color="#00d4aa" /> {t.lec11.legendTgt}
134-
<Dot color="#e2e8f0" /> pairs
134+
<Dot color="#facc15" /> pairs
135135
</div>
136136
<div className="code-font flex items-center gap-3 text-[var(--dim)]">
137137
<span>iter {iter}</span>
@@ -157,7 +157,7 @@ export default function Lec11Icp() {
157157
]}
158158
lines={
159159
pairCoords.length > 0
160-
? [{ positions: pairCoords, color: "#e2e8f0", opacity: 0.6 }]
160+
? [{ positions: pairCoords, color: "#facc15", opacity: 0.95, width: 2 }]
161161
: undefined
162162
}
163163
framingKey={framingEpoch}

0 commit comments

Comments
 (0)