Every line was drawn 1px regardless of its CAD lineweight. Two causes: the dwg-wasm parseResult never carried the field (acadrust reads EntityCommon::line_weight but it was dropped in serialization), and the renderer merged all segments into one LineSegments whose LineBasicMaterial.linewidth WebGL ignores. Resolve ByLayer/ByBlock/Default per entity and bucket segments by dash|lineweight. Weighted buckets get their own LineSegments2 + LineMaterial with worldUnits:false, so width stays constant in pixels while zooming - AutoCAD LWDISPLAY semantics - at 8 px/mm (0.25mm = 2px). Anything at or below the 0.25mm default stays in the hairline batch so drawings that never assigned a weight render exactly as before. Fat batches are instanced, so layer masking compacts the instance buffer and lowers instanceCount instead of rewriting an index; slotOf tracks where each segment moved so the selection highlight still finds its vertices. Per-entity color spans (meta.spans) let the highlight repaint across the hairline batch and every bucket it touched. Buckets past 400k segments fall back to hairline to bound GPU/heap cost. Display follows the drawing's LWDISPLAY and can be forced from the toolbar; the property panel now shows the entity lineweight. Verified headless at a fixed camera on the 65k-entity road drawing: cyan road edge 2px -> 5px, layer hide/restore returns the exact baseline pixel counts, and a 0.35mm LWPOLYLINE selects and highlights. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
38 lines
1.9 KiB
TypeScript
38 lines
1.9 KiB
TypeScript
// Types for the ported JS 2D engine (Viewer2D.js). Colocated so tsc resolves
|
|
// `./Viewer2D.js` imports without allowJs. Only the methods the app uses are typed.
|
|
import type { CadSpace } from './cadSpaces';
|
|
|
|
export class Viewer2D {
|
|
constructor(container: HTMLElement);
|
|
/** Render a DWG/DXF parseResult. `keepView` preserves pan/zoom on re-render. */
|
|
load(result: unknown, opts?: { keepView?: boolean; keepTheme?: boolean; spaceHandle?: string | number | null }): void;
|
|
/** Zoom-extents to the loaded drawing. */
|
|
fit(): void;
|
|
/** Resync renderer/camera to the container size (call after un-hiding). */
|
|
resize(): void;
|
|
onSelect(cb: (entity: unknown) => void): void;
|
|
getSelectedEntity(): unknown;
|
|
zoomToSelection(): void;
|
|
setAccent(hex: string): void;
|
|
setTheme(dark: boolean): void;
|
|
setGrid(visible: boolean): void;
|
|
/** Lineweight display (AutoCAD LWDISPLAY); null follows the drawing's own flag. */
|
|
setLineweightEnabled(on: boolean | null): void;
|
|
getLineweightEnabled(): boolean;
|
|
getLayerInfo(): { name: string; colorHex: string; count: number; visible: boolean }[];
|
|
setHiddenLayers(nameSet: Set<string>): void;
|
|
/** Model / Paper (Layout) spaces for the loaded drawing. */
|
|
getSpaces(): CadSpace[];
|
|
getActiveSpace(): string | null;
|
|
/** Switch Model ↔ Layout; re-renders (fit unless keepView). */
|
|
setSpace(spaceHandle: string | number | null, opts?: { keepView?: boolean }): void;
|
|
getZoomPercent(): number;
|
|
onViewChange(cb: () => void): void;
|
|
/** Screen client coords → drawing world (Z=0 plane). */
|
|
screenToWorld(clientX: number, clientY: number): { x: number; y: number; z: number } | null;
|
|
/** Live CAD coords under the cursor; null when pointer leaves the canvas. */
|
|
onPointerWorld(cb: ((p: { x: number; y: number; z: number } | null) => void) | null): void;
|
|
startMeasure(cb: (r: { phase: string; ax: number; ay: number; az: number; bx: number; by: number; bz: number; d: number }) => void): void;
|
|
stopMeasure(): void;
|
|
}
|