Repository navigation
Description
Package: @thatopen/components-front 3.6.0 (unchanged on main @ ad540db), LengthMeasurement, DimensionLine, GraphicVertexPicker
We hit these while building a measuring tool on top of LengthMeasurement in an app that uses RendererMode.MANUAL. Each one is shown below with the published 3.6.0 bundle (bun, happy-dom, a stub world and a stub caster, see the end). They are related but independent; happy to split them if you prefer.
1. DimensionLine.color recolours every line, and the label text stays white
Every line of a measurement is built with the same material object, this.linesMaterial (Measurement/index.ts L735-L739). The per-line setter DimensionLine.color sets the label and endpoints of its own line, then writes the colour into that shared material. Setting it on one line therefore:
- recolours the 3D line of every other measurement, while their labels keep the old colour;
- gives the next line its colour too, because the constructor reads the label and endpoint colour from the shared material (L237-L242).
The label text is always white (dimension-mark.ts L4), and the setter only changes the background. On a light colour such as #ffd700 that is a contrast of about 1.4:1.
same material object: true
two lines, default colour A: line #0000ff label bg #0000ff text white | B: line #0000ff label bg #0000ff
after lineA.color = #ffd700 A: line #ffd700 label bg #ffd700 text white | B: line #ffd700 label bg #0000ff
new line C line #ffd700 label bg #ffd700
2. Edge mode: a click can commit a zero-length line at the origin
_lastEdgeKey lets updatePreviewLine skip an edge it already shows (L187-L196). It is reset only after a run of missed picks while the preview is visible. cancelCreation (Escape) disposes the preview but keeps the key (L241-L247). When the next click rebuilds the preview from a pick without an edge, buildPreview sets _temp.line to (0,0,0)-(0,0,0) (L136-L141). Moving back onto the same edge then hits the short-circuit: the preview is made visible but never moved to the edge, and the next click commits the zero-length line.
Steps: edge mode, hover an edge, press Escape, hover a face, click, hover the same edge again, click.
enabled, edge mode, cursor over nothing preview hidden _temp.line (0, 0, 0) -> (0, 0, 0) lastEdgeKey null
hover edge E preview visible _temp.line (2, 0, 0) -> (2, 3, 0) lastEdgeKey 2000,0,0|2000,3000,0
Escape preview none _temp.line (2, 0, 0) -> (2, 3, 0) lastEdgeKey 2000,0,0|2000,3000,0
hover a face (no edge) preview none _temp.line (2, 0, 0) -> (2, 3, 0) lastEdgeKey 2000,0,0|2000,3000,0
click: create() rebuilds the preview preview hidden _temp.line (0, 0, 0) -> (0, 0, 0) lastEdgeKey 2000,0,0|2000,3000,0
hover edge E again preview visible _temp.line (0, 0, 0) -> (0, 0, 0) lastEdgeKey 2000,0,0|2000,3000,0
click: committed (0, 0, 0) -> (0, 0, 0) length 0
3. A click right after a camera drag uses the pick from before the drag
Picks are skipped between controlstart and controlend (L326-L332, L232), which makes sense. But lastPick keeps the result from before the drag, and nothing picks again when the drag ends. buildPreview prefers lastPick (LengthMeasurement L110-L112), so releasing the orbit and clicking without moving the mouse starts the measurement at the point that was under the cursor when the drag began.
hover point A: lastPick (1, 0, 0)
orbit drag (3 moves), release: lastPick (1, 0, 0), castRay calls during the drag: 0
click without moving: create() measurement starts at (1, 0, 0), cursor is over (9, 9, 9)
4. MANUAL mode: the snap marker and preview are not repainted
After a pick, Measurement and GraphicVertexPicker repaint by calling world.renderer.update() (Measurement L255, also L218, L312 and graphic-vertex-picker.ts L274). In MANUAL mode update() returns early unless needsUpdate is set (simple-renderer.ts L317-L320), so the marker and the preview line stay where they were last painted until something else requests a frame. In L255 the preview is also updated after that call (onPointerMove fires after it), so even with needsUpdate set there the frame would show the previous preview position.
Run with the real SimpleRenderer.prototype.update, followed by one tick of the frame loop:
AUTO pointer move with a snap: marker at (1, 2, 3), frames rendered by the measurement: 1, after the next loop tick: 2
MANUAL pointer move with a snap: marker at (1, 2, 3), frames rendered by the measurement: 0, after the next loop tick: 0
5. A rejected pick becomes an unhandled rejection
scheduleMarkerUpdate treats a failed pick as "no pick" ("a transient world / fragments race shouldn't bubble", L233-L241). Three other paths start a pick that nobody can await:
GraphicVertexPicker.enabled = truecallsthis.get()without handling its promise (L71-L77);- the
modesetter and theonEnabledChangehandler callinitPreview()the same way (L46-L51, L80-L85).
In our app (on 3.4.3) a pick on a model that had just been unloaded rejected this way. With a caster whose castRay rejects:
measurer.enabled = true (free mode) unhandled rejections: 1 pick failed
pointer move (marker pick) unhandled rejections: 0
measurer.mode = 'edge' unhandled rejections: 1 pick failed
measurer.enabled = false; = true (edge mode) unhandled rejections: 2 pick failed | pick failed
await measurer.create() (free mode) unhandled rejections: 0 (caller caught: pick failed)
Expected
- Setting
coloron one dimension changes only that dimension, and its label text stays readable. - A click in edge mode commits the edge under the cursor or nothing.
- A click after a camera drag measures what is under the cursor after the drag.
- In MANUAL mode the marker and preview are painted after each pick.
- A failed pick is treated as "no pick" on every path.
Suggested fix
DimensionLineclones the shared material the first timecoloris set on it, owns that clone, disposes it indispose()and when thematerialsetter replaces it (re-applying the colour to the new material). The setter also picks a readable text colour, e.g.label.style.color = luminance(color) > 0.179 ? "#000" : "#fff"withluminance = 0.2126 r + 0.7152 g + 0.0722 b. The default blue keeps white text.- In
buildPreview's edge branch, keep the cache in step with the preview it builds:this._lastEdgeKey = p1 && p2 ? edgeKey(p1, p2) : null; this._edgeMissStreak = 0; - Set
this.lastPick = nullin thecontrolstarthandler and callthis.scheduleMarkerUpdate()in thecontrolendhandler. A click before that pick resolves then falls through to the fresh pick inbuildPreview; in edge mode it commits nothing until the pick lands. The wheel handler would get the same treatment. - Replace those
renderer.update()calls withrenderer.needsUpdate = true. The frame loop paints the flagged frame on its next tick in both AUTO and MANUAL mode, after the preview has been updated as well. this.get().catch(() => null)in theGraphicVertexPicker.enabledsetter, and.catch(() => null)on the fresh pick inbuildPreview.
We applied 1, 2, the controlstart/controlend part of 3, 4 at L255 and graphic-vertex-picker L274, and 5 to a copy of the published bundle and re-ran the same scripts. The wheel handler and the update() calls at L218 and L312 were changed only in the suggestion, not tested.
after lineA.color = #ffd700 A: line #ffd700 label bg #ffd700 text #000000 | B: line #0000ff label bg #0000ff
new line C line #0000ff label bg #0000ff
lineType = Fat A #ffd700 (LineMaterial) B #0000ff (LineMaterial) disposed: A's material
lineType = Basic A #ffd700 (LineBasicMaterial) B #0000ff (LineBasicMaterial) disposed: A's material
click: committed (2, 0, 0) -> (2, 3, 0) length 3
orbit drag (3 moves), release: lastPick null, castRay calls during the drag: 0
click without moving: create() measurement starts at (9, 9, 9), cursor is over (9, 9, 9)
AUTO pointer move with a snap: marker at (1, 2, 3), frames rendered by the measurement: 0, after the next loop tick: 1
MANUAL pointer move with a snap: marker at (1, 2, 3), frames rendered by the measurement: 0, after the next loop tick: 1
measurer.enabled = true (free mode) unhandled rejections: 0
measurer.mode = 'edge' unhandled rejections: 0
measurer.enabled = false; = true (edge mode) unhandled rejections: 0
await measurer.create() (free mode) unhandled rejections: 0
With fix 5, create() resolves without starting a measurement when its pick fails, instead of rejecting.
Reproduction
The outputs above come from scripts run with bun against the published packages, not in a browser. The DOM is happy-dom, the world is a stub whose renderer update() is the real OBC.SimpleRenderer.prototype.update, and the caster registered in Raycasters returns whatever the script sets as the next pick. The edge-mode script, for example:
const { measurer, caster, container } = setup(); // stub world + LengthMeasurement
const move = async (pick) => {
caster.next = pick;
container.dispatchEvent(new Event("pointermove"));
await new Promise((r) => setTimeout(r, 30)); // let the rAF pick run
};
measurer.enabled = true;
measurer.mode = "edge";
const E = { point: v(2, 0, 0), snappedEdgeP1: v(2, 0, 0), snappedEdgeP2: v(2, 3, 0) };
await move(E);
window.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape" }));
await move({ point: v(5, 5, 5) });
await measurer.create();
await move(E);
await measurer.create();
console.log([...measurer.list]); // one line, (0,0,0) -> (0,0,0)The full harness and the five scripts are about 250 lines; I can post them or put them in a repo if that helps.
Environment
- @thatopen/components-front 3.6.0, @thatopen/components 3.6.0, @thatopen/fragments 3.6.0, three 0.184.0
- Scripts: bun 1.4.4 with happy-dom 15.11.7
- Package manager: bun
Activity