WebGL2-Plan-Renderer entfernt: 2D nur noch render2d (native Metal oder WASM/WebGPU), SVG als Interaktions-Ebene/Rueckfall
This commit is contained in:
1 parent
20cbad40e1
commit
1ea0fab6ce
9 files changed
+30
-808
No files matched your search
+11
-28
@@ -25,7 +25,6 @@ import { docFromText } from "../text/richText";
|
||||
import { contentFontBaselineFromTop, TEXT_LINE_HEIGHT_MULT } from "../text/fontMetrics";
|
||||
import { textFrameCorners } from "../text/textFrame";
|
||||
import { RichTextEditor } from "../text/RichTextEditor";
|
||||
import { useGlPlanRenderer } from "./useGlPlanRenderer";
|
||||
import { useNativeAvailable, useNativePlanRenderer } from "./useNativePlanRenderer";
|
||||
import { isGpuText } from "./nativeText";
|
||||
import { LiveMeet, LiveValue, createMeetStore, createValueStore } from "./planView/liveMeet";
|
||||
@@ -804,39 +803,23 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
const svgRef = useRef<SVGSVGElement | null>(null);
|
||||
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
||||
|
||||
// Engine-Auswahl. STANDARD-Pfad: WebGL2 (useGlPlanRenderer); der SVG-Renderer
|
||||
// bleibt automatischer Fallback (nur falls WebGL2/Shader nicht verfügbar), `?gl=0`
|
||||
// erzwingt reines SVG. INTEGRATIONS-SPIKE: Mit `?engine=wasm` UND vorhandenem
|
||||
// WebGPU (navigator.gpu) übernimmt statt WebGL2 der native render2d-Renderer als
|
||||
// WASM/WebGPU-Viewport (useWasmPlanRenderer) — dieselbe Szene, dieselbe ViewBox,
|
||||
// dasselbe SVG-Overlay (Text/Griffe/Auswahl) darüber. Fehlt WebGPU trotz Flag:
|
||||
// stiller Fallback auf WebGL2 (+ Warnung).
|
||||
const engineParam =
|
||||
typeof window === "undefined"
|
||||
? null
|
||||
: new URLSearchParams(window.location.search).get("engine");
|
||||
// Engine-Auswahl. Zwei GPU-Pfade, kein WebGL2 mehr:
|
||||
// • NATIVE Metal-Fläche hinter der Webview (macOS-Tauri mit Feature native2d, s.
|
||||
// useNativePlanRenderer.ts): STANDARD, wo verfügbar; `?native=0` schaltet sie ab.
|
||||
// • render2d als WASM/WebGPU (useWasmPlanRenderer): überall sonst (Linux/Electron).
|
||||
// Der SVG-Renderer bleibt die Interaktions-Ebene (Text/Griffe/Auswahl) und der Rückfall,
|
||||
// wenn kein GPU-Pfad läuft (`?gl=0` erzwingt ihn). Solange die Verfügbarkeit des nativen
|
||||
// Pfads noch erfragt wird (null), startet KEINE Engine.
|
||||
const hasWebGpu = typeof navigator !== "undefined" && "gpu" in navigator;
|
||||
const wantWasm = engineParam === "wasm" && hasWebGpu;
|
||||
useEffect(() => {
|
||||
if (engineParam === "wasm" && !hasWebGpu) {
|
||||
console.warn("engine=wasm angefragt, aber navigator.gpu fehlt → WebGL2-Fallback");
|
||||
}
|
||||
}, [engineParam, hasWebGpu]);
|
||||
// NATIVE Metal-Fläche hinter der Webview (macOS-Tauri mit Feature native2d,
|
||||
// s. useNativePlanRenderer.ts): STANDARD, wo verfügbar; `?native=0` schaltet auf
|
||||
// WebGL2 zurück. Solange die Verfügbarkeit noch erfragt wird (null), startet
|
||||
// KEINE Engine — sonst würde kurz ein WebGL-Kontext aufgebaut und wieder verworfen.
|
||||
const nativeAvail = useNativeAvailable();
|
||||
const glParam = typeof window === "undefined" ? null : new URLSearchParams(window.location.search).get("gl");
|
||||
const nativeOptOut = typeof window !== "undefined" && new URLSearchParams(window.location.search).get("native") === "0";
|
||||
const wantNative = nativeAvail === true && !wantWasm && !nativeOptOut && glParam !== "0";
|
||||
// WebGL2 nur, wenn weder der WASM- noch der native Pfad aktiv ist (und `?gl!=0`).
|
||||
const wantGl = !wantWasm && !wantNative && nativeAvail !== null && glParam !== "0";
|
||||
const wantNative = nativeAvail === true && !nativeOptOut && glParam !== "0";
|
||||
const wantWasm = !wantNative && nativeAvail !== null && hasWebGpu && glParam !== "0";
|
||||
// Alle Hooks unbedingt aufrufen (Hook-Regeln); je nach Flag ist genau einer aktiv.
|
||||
const glHook = useGlPlanRenderer(canvasRef, wantGl);
|
||||
const wasmHook = useWasmPlanRenderer(canvasRef, wantWasm);
|
||||
const nativeHook = useNativePlanRenderer(canvasRef, wantNative);
|
||||
const activeEngine = wantWasm ? wasmHook : wantNative ? nativeHook : glHook;
|
||||
const activeEngine = wantWasm ? wasmHook : nativeHook;
|
||||
// Text im Inline-Editor nicht zusätzlich nativ zeichnen.
|
||||
const setNativeExcludedText = nativeHook.setExcludedText;
|
||||
useEffect(() => {
|
||||
@@ -845,7 +828,7 @@ export const PlanView = forwardRef<PlanViewHandle, PlanViewProps>(
|
||||
const { render: renderGl, updateGeometry, ready: glReady } = activeEngine;
|
||||
// „GPU-Canvas montieren?" — beide GPU-Pfade brauchen das Canvas (an der ABSICHT
|
||||
// montiert, nicht am ready, sonst könnte die Engine mangels Canvas nie starten).
|
||||
const wantGpu = wantGl || wantWasm || wantNative;
|
||||
const wantGpu = wantWasm || wantNative;
|
||||
// Georeferenzierte Hintergrund-Rasterbilder (Luftbild) vorhanden? Der GPU-
|
||||
// Canvas löscht das Blatt UNDURCHSICHTIG (clearColor …,1) und würde ein
|
||||
// dahinterliegendes Bild verdecken. Daher bei aktivem Luftbild bewusst den
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// CSS-Custom-Property → RGB (für die GPU-Renderer).
|
||||
|
||||
/** Liest eine CSS-Custom-Property (z. B. "--sheet") als RGB[0..1] oder null. */
|
||||
export function readCssColor(varName: string): [number, number, number] | null {
|
||||
if (typeof window === 'undefined') return null;
|
||||
const raw = getComputedStyle(document.documentElement).getPropertyValue(varName).trim();
|
||||
let h = raw.startsWith('#') ? raw.slice(1) : raw;
|
||||
if (h.length === 3) h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
|
||||
if (h.length < 6) return null;
|
||||
const r = parseInt(h.slice(0, 2), 16);
|
||||
const g = parseInt(h.slice(2, 4), 16);
|
||||
const b = parseInt(h.slice(4, 6), 16);
|
||||
if (isNaN(r) || isNaN(g) || isNaN(b)) return null;
|
||||
return [r / 255, g / 255, b / 255];
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { compilePrimitivesToGpu, triangulate } from './glPlanCompile';
|
||||
import { computeOrthoMatrix } from './glPlanRender';
|
||||
import type { Vec2 } from '../../model/types';
|
||||
import type { Primitive } from '../generatePlan';
|
||||
|
||||
@@ -154,35 +153,6 @@ describe('triangulate', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('computeOrthoMatrix', () => {
|
||||
it('liefert eine 4×4-Matrix', () => {
|
||||
const m = computeOrthoMatrix({ x: 0, y: 0, w: 100, h: 100 }, 100, 100);
|
||||
expect(m).toBeInstanceOf(Float32Array);
|
||||
expect(m.length).toBe(16);
|
||||
});
|
||||
|
||||
it('bildet die viewBox-Ecken bei passendem Aspekt auf Clip [-1,1] ab', () => {
|
||||
// Quadratischer viewBox + quadratisches Canvas → keine Aspekt-Dehnung.
|
||||
const m = computeOrthoMatrix({ x: 0, y: 0, w: 100, h: 100 }, 100, 100);
|
||||
// Bildschirm-Punkt (0,0) = obere-linke Ecke → Clip (-1, +1).
|
||||
const clip = (x: number, y: number) => ({
|
||||
x: m[0] * x + m[4] * y + m[12],
|
||||
y: m[1] * x + m[5] * y + m[13],
|
||||
});
|
||||
const tl = clip(0, 0);
|
||||
expect(tl.x).toBeCloseTo(-1, 5);
|
||||
expect(tl.y).toBeCloseTo(1, 5);
|
||||
const br = clip(100, 100);
|
||||
expect(br.x).toBeCloseTo(1, 5);
|
||||
expect(br.y).toBeCloseTo(-1, 5);
|
||||
});
|
||||
|
||||
it('verschiedene viewBoxes → verschiedene Matrizen', () => {
|
||||
const a = computeOrthoMatrix({ x: 0, y: 0, w: 100, h: 100 }, 100, 100);
|
||||
const b = computeOrthoMatrix({ x: 50, y: 50, w: 200, h: 200 }, 100, 100);
|
||||
expect([...a].every((v, i) => v === b[i])).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('compilePrimitivesToGpu: kompaktes Linien-Vertex-Format (nativ)', () => {
|
||||
it('liefert 3 Wörter je Vertex statt 6 Floats', () => {
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
// Genauigkeit bei Landeskoordinaten: float32 kann bei ~2,4·10⁸ (2,7 Mio. m ×
|
||||
// 90 px/m) nur noch ~16 Einheiten auflösen. Die Geometrie wird deshalb relativ
|
||||
// zu einem lokalen Ursprung abgelegt; der Renderer zieht ihn in doppelter
|
||||
// Genauigkeit von der Ansicht ab.
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import type { Primitive } from "../generatePlan";
|
||||
import { compilePrimitivesToGpu } from "./glPlanCompile";
|
||||
import { PlanGpuRenderer, orthoBounds } from "./glPlanRender";
|
||||
import type { GpuGeometry, ShaderProgram } from "./glPlanTypes";
|
||||
|
||||
const X0 = 2_665_000.123; // Landeskoordinate (m)
|
||||
const Y0 = 1_211_000.456;
|
||||
|
||||
const seg = (ax: number, ay: number, bx: number, by: number): Primitive => ({
|
||||
kind: "line",
|
||||
a: { x: ax, y: ay },
|
||||
b: { x: bx, y: by },
|
||||
cls: "draw2d",
|
||||
weightMm: 0.18,
|
||||
color: "#000000",
|
||||
drawingId: "d",
|
||||
});
|
||||
|
||||
function captureGl() {
|
||||
const vertexData: Float32Array[] = [];
|
||||
const gl = {
|
||||
createBuffer: () => ({}),
|
||||
bindBuffer: () => {},
|
||||
bufferData: (_t: number, data: Float32Array | Uint32Array) => {
|
||||
if (data instanceof Float32Array) vertexData.push(data.slice());
|
||||
},
|
||||
ARRAY_BUFFER: 1,
|
||||
ELEMENT_ARRAY_BUFFER: 2,
|
||||
STATIC_DRAW: 3,
|
||||
} as unknown as WebGL2RenderingContext;
|
||||
return { gl, vertexData };
|
||||
}
|
||||
|
||||
describe("lokaler Ursprung je Geometrie", () => {
|
||||
it("legt Vertices bei Landeskoordinaten klein (relativ) ab", () => {
|
||||
const { gl, vertexData } = captureGl();
|
||||
const geo = compilePrimitivesToGpu(gl, [seg(X0, Y0, X0 + 10, Y0), seg(X0 + 10, Y0, X0 + 10, Y0 + 5)], 90);
|
||||
// Ursprung = erster Punkt in Bildschirm-Einheiten.
|
||||
expect(geo.origin!.x).toBeCloseTo(X0 * 90, 3);
|
||||
expect(geo.origin!.y).toBeCloseTo(-Y0 * 90, 3);
|
||||
// Linien-Vertexpuffer: [x,y, nx,ny, side, miter] — x,y nur wenige hundert Einheiten.
|
||||
const verts = vertexData[0];
|
||||
for (let i = 0; i < verts.length; i += 6) {
|
||||
expect(Math.abs(verts[i])).toBeLessThan(2000);
|
||||
expect(Math.abs(verts[i + 1])).toBeLessThan(2000);
|
||||
}
|
||||
});
|
||||
|
||||
it("Renderer: lokale Position + Ursprungs-Projektion == absolute Projektion (doppelte Genauigkeit)", () => {
|
||||
const uniforms: Float32Array[] = [];
|
||||
const gl = {
|
||||
clearColor() {}, disable() {}, enable() {}, blendFunc() {}, viewport() {}, clear() {},
|
||||
useProgram() {}, bindBuffer() {}, enableVertexAttribArray() {}, disableVertexAttribArray() {},
|
||||
vertexAttribPointer() {}, uniform1f() {}, uniform2f() {}, uniform4fv() {}, drawElements() {},
|
||||
uniformMatrix4fv: (_loc: unknown, _t: boolean, m: Float32Array) => uniforms.push(m.slice()),
|
||||
DEPTH_TEST: 1, BLEND: 2, SRC_ALPHA: 3, ONE_MINUS_SRC_ALPHA: 4, COLOR_BUFFER_BIT: 5,
|
||||
ARRAY_BUFFER: 6, ELEMENT_ARRAY_BUFFER: 7, FLOAT: 8, TRIANGLES: 9, UNSIGNED_INT: 10,
|
||||
} as unknown as WebGL2RenderingContext;
|
||||
const prog = (): ShaderProgram =>
|
||||
({ program: {}, uniforms: { viewProj: 1, color: 2, strokePx: 3, strokeScale: 4, viewportPx: 5 }, attribs: { position: 0, normal: 1, side: 2, miter: 3 } }) as unknown as ShaderProgram;
|
||||
const renderer = new PlanGpuRenderer(gl, prog(), prog());
|
||||
|
||||
const origin = { x: X0 * 90, y: -Y0 * 90 };
|
||||
const geometry = {
|
||||
fill: { positionBuffer: {}, indexBuffer: {}, batches: [{ startIndex: 0, indexCount: 3, color: [0, 0, 0, 1] }] },
|
||||
line: { positionBuffer: null, vertexBuffer: {}, indexBuffer: {}, batches: [] },
|
||||
bounds: { minX: 0, minY: 0, maxX: 1, maxY: 1 },
|
||||
origin,
|
||||
} as unknown as GpuGeometry;
|
||||
|
||||
// Ansicht 30 Einheiten breit, weit draussen bei den Landeskoordinaten.
|
||||
const vb = { x: origin.x + 100, y: origin.y + 50, w: 30, h: 20 };
|
||||
renderer.render(geometry, vb, { width: 600, height: 400 });
|
||||
const m = uniforms[uniforms.length - 1];
|
||||
|
||||
// Ein Punkt in der Mitte der Ansicht, lokal ausgedrückt.
|
||||
const local = { x: 100 + 15, y: 50 + 10 };
|
||||
const ndcX = m[0] * local.x + m[12];
|
||||
const ndcY = m[5] * local.y + m[13];
|
||||
expect(ndcX).toBeCloseTo(0, 5);
|
||||
expect(ndcY).toBeCloseTo(0, 5);
|
||||
// Der linke Rand der Ansicht liegt bei NDC -1.
|
||||
expect(m[0] * 100 + m[12]).toBeCloseTo(-1, 5);
|
||||
|
||||
// Gegenprobe: dieselbe Rechnung in doppelter Genauigkeit mit absoluten Koordinaten.
|
||||
const b = orthoBounds(vb, 600, 400);
|
||||
const absX = origin.x + local.x;
|
||||
expect((2 * (absX - b.left)) / (b.right - b.left) - 1).toBeCloseTo(0, 9);
|
||||
});
|
||||
});
|
||||
@@ -1,316 +0,0 @@
|
||||
/**
|
||||
* WebGL2-Render-Loop des GPU-Grundrisses.
|
||||
*
|
||||
* Zeichnet zwischengespeicherte GPU-Geometrie (aus glPlanCompile) und aktualisiert
|
||||
* beim Pan/Zoom NUR die Projektionsmatrix (kein Re-Tessellieren). Getrieben vom
|
||||
* Aufrufer (PlanView-Pan/Zoom-Handler), nicht per requestAnimationFrame.
|
||||
*/
|
||||
|
||||
import type { GpuGeometry, ShaderProgram, ViewBox } from './glPlanTypes';
|
||||
import { GREY_RGB } from './glPlanCompile';
|
||||
|
||||
/** viewBox-Einheiten je Meter (identisch zu PlanView/toScreen). */
|
||||
const PX_PER_M = 90;
|
||||
|
||||
/** 4×4-Einheitsmatrix (Spalten-Major, WebGL-Konvention). */
|
||||
function mat4Identity(): Float32Array {
|
||||
const m = new Float32Array(16);
|
||||
m[0] = 1;
|
||||
m[5] = 1;
|
||||
m[10] = 1;
|
||||
m[15] = 1;
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Orthografische Projektion [left,right]×[bottom,top] → Clip [-1,1].
|
||||
* Spalten-Major.
|
||||
*/
|
||||
function mat4Ortho(
|
||||
left: number,
|
||||
right: number,
|
||||
bottom: number,
|
||||
top: number,
|
||||
): Float32Array {
|
||||
const m = mat4Identity();
|
||||
const w = right - left;
|
||||
const h = top - bottom;
|
||||
m[0] = 2 / w;
|
||||
m[5] = 2 / h;
|
||||
m[10] = -1;
|
||||
m[12] = -(right + left) / w;
|
||||
m[13] = -(top + bottom) / h;
|
||||
return m;
|
||||
}
|
||||
|
||||
/** viewBox-Gleichheit (Cache-Invalidierung). */
|
||||
function viewBoxEqual(a: ViewBox, b: ViewBox): boolean {
|
||||
return a.x === b.x && a.y === b.y && a.w === b.w && a.h === b.h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Projektionsmatrix für einen viewBox, aspekt-korrigiert wie SVG
|
||||
* `preserveAspectRatio="xMidYMid meet"`: der viewBox wird auf das
|
||||
* Canvas-Seitenverhältnis GEDEHNT (zentriert), damit die Skalierung in X und Y
|
||||
* gleich ist (keine Verzerrung, Perpendikel bleiben senkrecht).
|
||||
*
|
||||
* Eingabe-Positionen sind bereits im BILDSCHIRM-Raum (toScreen), daher keine
|
||||
* zusätzliche Meter-Skalierung. Bildschirm-Y zeigt nach unten → top=vb.y,
|
||||
* bottom=vb.y+vb.h (kleineres Y oben → Clip +1).
|
||||
*/
|
||||
/** Auf das Canvas-Seitenverhältnis erweiterter Ausschnitt (doppelte Genauigkeit). */
|
||||
export function orthoBounds(
|
||||
viewBox: ViewBox,
|
||||
canvasW: number,
|
||||
canvasH: number,
|
||||
): { left: number; right: number; bottom: number; top: number } {
|
||||
let { x, y, w, h } = viewBox;
|
||||
if (canvasW > 0 && canvasH > 0 && w > 0 && h > 0) {
|
||||
const cAspect = canvasW / canvasH;
|
||||
const vAspect = w / h;
|
||||
if (cAspect > vAspect) {
|
||||
// Canvas breiter → viewBox in der Breite dehnen, X zentrieren.
|
||||
const nw = h * cAspect;
|
||||
x -= (nw - w) / 2;
|
||||
w = nw;
|
||||
} else {
|
||||
// Canvas höher → viewBox in der Höhe dehnen, Y zentrieren.
|
||||
const nh = w / cAspect;
|
||||
y -= (nh - h) / 2;
|
||||
h = nh;
|
||||
}
|
||||
}
|
||||
// top = y (Bildschirm-Y oben, kleiner), bottom = y + h.
|
||||
return { left: x, right: x + w, bottom: y + h, top: y };
|
||||
}
|
||||
|
||||
export function computeOrthoMatrix(
|
||||
viewBox: ViewBox,
|
||||
canvasW: number,
|
||||
canvasH: number,
|
||||
): Float32Array {
|
||||
const b = orthoBounds(viewBox, canvasW, canvasH);
|
||||
return mat4Ortho(b.left, b.right, b.bottom, b.top);
|
||||
}
|
||||
|
||||
/** Wiederverwendeter Farbpuffer fürs Dimmen (kein Array je Batch und Frame). */
|
||||
const tintScratch = new Float32Array(4);
|
||||
function tint(r: number, g: number, b: number, a: number): Float32Array {
|
||||
tintScratch[0] = r;
|
||||
tintScratch[1] = g;
|
||||
tintScratch[2] = b;
|
||||
tintScratch[3] = a;
|
||||
return tintScratch;
|
||||
}
|
||||
|
||||
/**
|
||||
* WebGL2-GPU-Renderer. Verwaltet Shader-Programme + Projektionsmatrix, zeichnet
|
||||
* Füll- und Linien-Batches effizient über Matrix-Uniforms.
|
||||
*/
|
||||
export class PlanGpuRenderer {
|
||||
private gl: WebGL2RenderingContext;
|
||||
private fillProgram: ShaderProgram;
|
||||
private lineProgram: ShaderProgram;
|
||||
private lastViewBox: ViewBox | null = null;
|
||||
private lastCanvas: { w: number; h: number } = { w: 0, h: 0 };
|
||||
private projMatrix: Float32Array;
|
||||
private projBounds = { left: 0, right: 1, bottom: 1, top: 0 };
|
||||
private readonly projScratch = new Float32Array(16);
|
||||
|
||||
constructor(
|
||||
gl: WebGL2RenderingContext,
|
||||
fillProg: ShaderProgram,
|
||||
lineProg: ShaderProgram,
|
||||
) {
|
||||
this.gl = gl;
|
||||
this.fillProgram = fillProg;
|
||||
this.lineProgram = lineProg;
|
||||
this.projMatrix = mat4Identity();
|
||||
|
||||
// Zeichenblatt-Hintergrund (hell, Default #f0f0f0 = --sheet), keine Tiefe;
|
||||
// Alpha-Blending für weiche Kanten/transluzente Räume.
|
||||
gl.clearColor(0.941, 0.941, 0.941, 1);
|
||||
gl.disable(gl.DEPTH_TEST);
|
||||
gl.enable(gl.BLEND);
|
||||
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
/** Löschfarbe (Zeichenblatt) setzen — theme-sicher aus --sheet. */
|
||||
setClearColor(r: number, g: number, b: number): void {
|
||||
this.gl.clearColor(r, g, b, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Projektion relativ zum lokalen Ursprung einer Geometrie. Der Ursprung wird in
|
||||
* DOPPELTER Genauigkeit von den Ausschnittsgrenzen abgezogen, erst das kleine
|
||||
* Ergebnis geht als float32 an die GPU (s. `GpuGeometry.origin`).
|
||||
*/
|
||||
private projectionFor(origin: { x: number; y: number } | undefined): Float32Array {
|
||||
if (!origin || (origin.x === 0 && origin.y === 0)) return this.projMatrix;
|
||||
const b = this.projBounds;
|
||||
const m = this.projScratch;
|
||||
m.set(this.projMatrix);
|
||||
m[12] = -((b.right - origin.x) + (b.left - origin.x)) / (b.right - b.left);
|
||||
m[13] = -((b.top - origin.y) + (b.bottom - origin.y)) / (b.top - b.bottom);
|
||||
return m;
|
||||
}
|
||||
|
||||
/** Projektionsmatrix nur bei viewBox-/Canvas-Änderung neu berechnen. */
|
||||
private updateProjection(viewBox: ViewBox, canvasW: number, canvasH: number): void {
|
||||
if (
|
||||
!this.lastViewBox ||
|
||||
!viewBoxEqual(viewBox, this.lastViewBox) ||
|
||||
this.lastCanvas.w !== canvasW ||
|
||||
this.lastCanvas.h !== canvasH
|
||||
) {
|
||||
this.projBounds = orthoBounds(viewBox, canvasW, canvasH);
|
||||
this.projMatrix = mat4Ortho(this.projBounds.left, this.projBounds.right, this.projBounds.bottom, this.projBounds.top);
|
||||
this.lastViewBox = { ...viewBox };
|
||||
this.lastCanvas = { w: canvasW, h: canvasH };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeichnet einen Frame.
|
||||
* @param geometry GPU-Geometrie (Fill + Line) bzw. eine Liste davon (Chunks, in
|
||||
* Zeichenreihenfolge: erst alle Füllungen, dann alle Linien); null → nur löschen.
|
||||
* @param viewBox Aktueller Ausschnitt (Bildschirm-Einheiten).
|
||||
* @param viewport Zeichenpuffer-Größe in Geräte-Pixeln.
|
||||
* @param paperScaleN Papier-Massstab-Nenner (1:N) für echte mm-Strichbreiten.
|
||||
*/
|
||||
render(
|
||||
geometry: GpuGeometry | readonly GpuGeometry[] | null,
|
||||
viewBox: ViewBox,
|
||||
viewport: { width: number; height: number },
|
||||
paperScaleN = 100,
|
||||
): void {
|
||||
const gl = this.gl;
|
||||
gl.viewport(0, 0, viewport.width, viewport.height);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
if (!geometry) return;
|
||||
|
||||
this.updateProjection(viewBox, viewport.width, viewport.height);
|
||||
|
||||
// Umrechnung Papier-mm → Geräte-px, EXAKT wie der SVG-printStrokeVb-Pfad:
|
||||
// Breite_vb = mm·N/1000·PX_PER_M (viewBox-Einheiten, skaliert mit Zoom)
|
||||
// Breite_px = Breite_vb · meetSkala (Geräte-px je viewBox-Einheit)
|
||||
// → mm·(N/1000·PX_PER_M·meet). meet nutzt die Geräte-px-Viewport-Größe, enthält
|
||||
// damit dpr. So gilt: 0.35 mm bei 1:100 = echte 0.35 mm Papier (== SVG).
|
||||
const meet = Math.min(viewport.width / viewBox.w, viewport.height / viewBox.h);
|
||||
const mmToDevicePx = (paperScaleN / 1000) * PX_PER_M * meet;
|
||||
|
||||
const list: readonly GpuGeometry[] = Array.isArray(geometry)
|
||||
? (geometry as readonly GpuGeometry[])
|
||||
: [geometry as GpuGeometry];
|
||||
for (const g of list) this.drawFills(g);
|
||||
for (const g of list) this.drawLines(g, viewport, mmToDevicePx, meet);
|
||||
}
|
||||
|
||||
/** Gefüllte Polygone (Poché). */
|
||||
private drawFills(geometry: GpuGeometry): void {
|
||||
const gl = this.gl;
|
||||
const { positionBuffer, indexBuffer, batches } = geometry.fill;
|
||||
if (!positionBuffer || !indexBuffer || !batches.length) return;
|
||||
const prog = this.fillProgram;
|
||||
if (!prog?.program) return;
|
||||
|
||||
gl.useProgram(prog.program);
|
||||
if (prog.uniforms.viewProj) {
|
||||
gl.uniformMatrix4fv(prog.uniforms.viewProj, false, this.projectionFor(geometry.origin));
|
||||
}
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
|
||||
const pos = prog.attribs.position;
|
||||
if (pos !== undefined && pos >= 0) {
|
||||
gl.enableVertexAttribArray(pos);
|
||||
gl.vertexAttribPointer(pos, 2, gl.FLOAT, false, 8, 0);
|
||||
}
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
|
||||
|
||||
for (const b of batches) {
|
||||
if (prog.uniforms.color) gl.uniform4fv(prog.uniforms.color, geometry.greyed ? tint(1, 1, 1, b.color[3]) : b.color);
|
||||
gl.drawElements(gl.TRIANGLES, b.indexCount, gl.UNSIGNED_INT, b.startIndex * 4);
|
||||
}
|
||||
if (pos !== undefined && pos >= 0) gl.disableVertexAttribArray(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Striche. Zwei Skalierungs-Regime pro Batch (siehe `LineBatch.screenPx`):
|
||||
* • Papier-mm (Standard) — Wand-/Objekt-Umrisse UND Schraffur-Musterlinien
|
||||
* (letztere seit dem Haarlinien-Fix ein gewöhnlicher 0.02-mm-Stift wie
|
||||
* die Wand-Schichtfugen): massstabs- + zoomrichtig über `mmToDevicePx`.
|
||||
* • Bildschirm-px (`screenPx`) — für etwaige künftige rein bildschirm-
|
||||
* gekoppelte Linien: NUR mit `meet` (Zoom) skaliert, unabhängig vom
|
||||
* Papier-Massstab N. Aktuell von keinem Batch mehr genutzt, Infrastruktur
|
||||
* bleibt erhalten.
|
||||
*/
|
||||
private drawLines(
|
||||
geometry: GpuGeometry,
|
||||
viewport: { width: number; height: number },
|
||||
mmToDevicePx: number,
|
||||
meet: number,
|
||||
): void {
|
||||
const gl = this.gl;
|
||||
const { vertexBuffer, indexBuffer, batches } = geometry.line;
|
||||
if (!vertexBuffer || !indexBuffer || !batches.length) return;
|
||||
const prog = this.lineProgram;
|
||||
if (!prog?.program) return;
|
||||
|
||||
gl.useProgram(prog.program);
|
||||
if (prog.uniforms.viewProj) {
|
||||
gl.uniformMatrix4fv(prog.uniforms.viewProj, false, this.projectionFor(geometry.origin));
|
||||
}
|
||||
if (prog.uniforms.viewportPx) {
|
||||
gl.uniform2f(prog.uniforms.viewportPx, viewport.width, viewport.height);
|
||||
}
|
||||
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
|
||||
const stride = 6 * 4; // [x,y, nx,ny, side, miter]
|
||||
const pos = prog.attribs.position;
|
||||
const nrm = prog.attribs.normal;
|
||||
const side = prog.attribs.side;
|
||||
const miter = prog.attribs.miter;
|
||||
if (pos !== undefined && pos >= 0) {
|
||||
gl.enableVertexAttribArray(pos);
|
||||
gl.vertexAttribPointer(pos, 2, gl.FLOAT, false, stride, 0);
|
||||
}
|
||||
if (nrm !== undefined && nrm >= 0) {
|
||||
gl.enableVertexAttribArray(nrm);
|
||||
gl.vertexAttribPointer(nrm, 2, gl.FLOAT, false, stride, 2 * 4);
|
||||
}
|
||||
if (side !== undefined && side >= 0) {
|
||||
gl.enableVertexAttribArray(side);
|
||||
gl.vertexAttribPointer(side, 1, gl.FLOAT, false, stride, 4 * 4);
|
||||
}
|
||||
if (miter !== undefined && miter >= 0) {
|
||||
gl.enableVertexAttribArray(miter);
|
||||
gl.vertexAttribPointer(miter, 1, gl.FLOAT, false, stride, 5 * 4);
|
||||
}
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
|
||||
|
||||
// strokePx-Uniform trägt die Breite (Papier-mm ODER Bildschirm-px, je nach
|
||||
// `screenPx`); strokeScale wählt PRO BATCH den passenden Massstabsfaktor.
|
||||
// Der Shader multipliziert beides und klemmt bei ~0.6 px (Haarlinie
|
||||
// sichtbar, MSAA via antialias:true), damit sehr feine Gewichte beim
|
||||
// Rauszoomen nicht verschwinden.
|
||||
for (const b of batches) {
|
||||
if (prog.uniforms.color) {
|
||||
gl.uniform4fv(prog.uniforms.color, geometry.greyed ? tint(GREY_RGB, GREY_RGB, GREY_RGB, b.color[3]) : b.color);
|
||||
}
|
||||
if (prog.uniforms.strokePx) gl.uniform1f(prog.uniforms.strokePx, b.strokeMm);
|
||||
if (prog.uniforms.strokeScale) {
|
||||
gl.uniform1f(prog.uniforms.strokeScale, b.screenPx ? meet : mmToDevicePx);
|
||||
}
|
||||
gl.drawElements(gl.TRIANGLES, b.indexCount, gl.UNSIGNED_INT, b.startIndex * 4);
|
||||
}
|
||||
if (pos !== undefined && pos >= 0) gl.disableVertexAttribArray(pos);
|
||||
if (nrm !== undefined && nrm >= 0) gl.disableVertexAttribArray(nrm);
|
||||
if (side !== undefined && side >= 0) gl.disableVertexAttribArray(side);
|
||||
if (miter !== undefined && miter >= 0) gl.disableVertexAttribArray(miter);
|
||||
}
|
||||
|
||||
/** Cache invalidieren (z. B. nach Größenänderung). */
|
||||
invalidateViewBox(): void {
|
||||
this.lastViewBox = null;
|
||||
}
|
||||
}
|
||||
@@ -1,185 +0,0 @@
|
||||
/**
|
||||
* WebGL2-Shader-Programme für den GPU-Grundriss-Renderer.
|
||||
* Kompilierung + Fehlerbehandlung (Warnung + null, keine Exceptions).
|
||||
*/
|
||||
|
||||
import type { ShaderProgram } from './glPlanTypes';
|
||||
|
||||
/**
|
||||
* Füll-Vertex-Shader: bildet Bildschirm-Raum-Positionen über die viewProj-Matrix
|
||||
* in den Clip-Raum ab. Für gefüllte Polygone (Wand-Poché, Räume, Decken).
|
||||
*/
|
||||
export const FILL_VERT = `#version 300 es
|
||||
precision highp float;
|
||||
|
||||
uniform mat4 viewProj;
|
||||
|
||||
in vec2 position;
|
||||
|
||||
void main() {
|
||||
gl_Position = viewProj * vec4(position, 0.0, 1.0);
|
||||
}
|
||||
`;
|
||||
|
||||
/** Füll-Fragment-Shader: einheitliche Farbe (MVP, noch keine Schraffur). */
|
||||
export const FILL_FRAG = `#version 300 es
|
||||
precision mediump float;
|
||||
|
||||
uniform vec4 color;
|
||||
|
||||
out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
outColor = color;
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* Linien-Vertex-Shader mit BILDSCHIRMKONSTANTER Breite.
|
||||
*
|
||||
* Idee: sowohl der Endpunkt als auch (Endpunkt + Normale) werden durch viewProj
|
||||
* transformiert; ihre Differenz im Clip-Raum (in Pixel skaliert) ergibt die
|
||||
* Perpendikel-Richtung. Diese wird auf `strokePx/2` Pixel normiert und — je nach
|
||||
* `side` — auf die passende Seite versetzt, dann px→Clip zurückgerechnet. So ist
|
||||
* die Strichbreite unabhängig vom Zoom (keine Re-Tessellierung nötig).
|
||||
*/
|
||||
export const LINE_VERT = `#version 300 es
|
||||
precision highp float;
|
||||
|
||||
uniform mat4 viewProj;
|
||||
uniform float strokePx; // Basis-Breite in Geräte-px (bei strokeScale=1)
|
||||
uniform float strokeScale; // Zoom-Skalierung: >1 = reingezoomt → dicker (Papier)
|
||||
uniform vec2 viewportPx; // Zeichenpuffer-Größe [w,h] in Geräte-px
|
||||
|
||||
in vec2 position; // Bildschirm-Raum-Stützpunkt
|
||||
in vec2 normal; // Bildschirm-Raum-Einheits-Miter-Bisektor (Richtung des Versatzes)
|
||||
in float side; // +1.0 oder -1.0
|
||||
in float miter; // Miter-Längenfaktor 1/cos(θ/2) (1.0 = gerade, keine Ecke)
|
||||
|
||||
void main() {
|
||||
vec4 clipP = viewProj * vec4(position, 0.0, 1.0);
|
||||
vec4 clipN = viewProj * vec4(position + normal, 0.0, 1.0);
|
||||
|
||||
// Bisektor-Richtung im Pixel-Raum (Clip-Differenz → px).
|
||||
vec2 dirPx = (clipN.xy - clipP.xy) * viewportPx * 0.5;
|
||||
float len = length(dirPx);
|
||||
vec2 unitPx = len > 1e-6 ? dirPx / len : vec2(0.0);
|
||||
|
||||
// Echte Papierbreite in Geräte-px = mm(strokePx) · (mm→px)(strokeScale); mind.
|
||||
// 0.6 px. Der Miter-Faktor verlängert den Versatz an Ecken, sodass benachbarte
|
||||
// Segmente bündig verschmelzen (gehrte Ecke statt Butt-Cap-Stufe).
|
||||
float widthPx = max(1.0, strokePx * strokeScale) * miter;
|
||||
vec2 offsetPx = unitPx * (widthPx * 0.5) * side;
|
||||
clipP.xy += offsetPx / (viewportPx * 0.5);
|
||||
|
||||
gl_Position = clipP;
|
||||
}
|
||||
`;
|
||||
|
||||
/** Linien-Fragment-Shader: einheitliche Farbe. */
|
||||
export const LINE_FRAG = `#version 300 es
|
||||
precision mediump float;
|
||||
|
||||
uniform vec4 color;
|
||||
|
||||
out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
outColor = color;
|
||||
}
|
||||
`;
|
||||
|
||||
/** Kompiliert einen einzelnen Shader; null + Warnung bei Fehler. */
|
||||
function compileShader(
|
||||
gl: WebGL2RenderingContext,
|
||||
type: number,
|
||||
source: string,
|
||||
): WebGLShader | null {
|
||||
const shader = gl.createShader(type);
|
||||
if (!shader) {
|
||||
console.warn('WebGL: Shader-Objekt konnte nicht erstellt werden');
|
||||
return null;
|
||||
}
|
||||
gl.shaderSource(shader, source);
|
||||
gl.compileShader(shader);
|
||||
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
||||
console.warn(`WebGL: Shader-Kompilierung fehlgeschlagen:\n${gl.getShaderInfoLog(shader)}`);
|
||||
gl.deleteShader(shader);
|
||||
return null;
|
||||
}
|
||||
return shader;
|
||||
}
|
||||
|
||||
/** Verlinkt Vertex + Fragment zu einem Programm; null + Warnung bei Fehler. */
|
||||
function linkProgram(
|
||||
gl: WebGL2RenderingContext,
|
||||
vert: WebGLShader,
|
||||
frag: WebGLShader,
|
||||
): WebGLProgram | null {
|
||||
const program = gl.createProgram();
|
||||
if (!program) {
|
||||
console.warn('WebGL: Programm konnte nicht erstellt werden');
|
||||
return null;
|
||||
}
|
||||
gl.attachShader(program, vert);
|
||||
gl.attachShader(program, frag);
|
||||
gl.linkProgram(program);
|
||||
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
||||
console.warn(`WebGL: Programm-Verlinkung fehlgeschlagen:\n${gl.getProgramInfoLog(program)}`);
|
||||
gl.deleteProgram(program);
|
||||
return null;
|
||||
}
|
||||
return program;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kompiliert + verlinkt ein vollständiges Shader-Programm und ermittelt alle
|
||||
* Attribut-/Uniform-Orte. Gibt null zurück (mit Warnung) statt zu werfen.
|
||||
*/
|
||||
export function compileShaderProgram(
|
||||
gl: WebGL2RenderingContext,
|
||||
vertSrc: string,
|
||||
fragSrc: string,
|
||||
): ShaderProgram | null {
|
||||
const vert = compileShader(gl, gl.VERTEX_SHADER, vertSrc);
|
||||
if (!vert) return null;
|
||||
const frag = compileShader(gl, gl.FRAGMENT_SHADER, fragSrc);
|
||||
if (!frag) {
|
||||
gl.deleteShader(vert);
|
||||
return null;
|
||||
}
|
||||
const program = linkProgram(gl, vert, frag);
|
||||
gl.deleteShader(vert);
|
||||
gl.deleteShader(frag);
|
||||
if (!program) return null;
|
||||
|
||||
const loc = (name: string): GLint => gl.getAttribLocation(program, name);
|
||||
const uni = (name: string) => gl.getUniformLocation(program, name);
|
||||
|
||||
return {
|
||||
program,
|
||||
attribs: {
|
||||
position: loc('position'),
|
||||
normal: loc('normal'),
|
||||
side: loc('side'),
|
||||
miter: loc('miter'),
|
||||
},
|
||||
uniforms: {
|
||||
viewProj: uni('viewProj'),
|
||||
color: uni('color'),
|
||||
strokePx: uni('strokePx'),
|
||||
strokeScale: uni('strokeScale'),
|
||||
viewportPx: uni('viewportPx'),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** Füll-Programm (gefüllte Polygone). */
|
||||
export function createFillProgram(gl: WebGL2RenderingContext): ShaderProgram | null {
|
||||
return compileShaderProgram(gl, FILL_VERT, FILL_FRAG);
|
||||
}
|
||||
|
||||
/** Linien-Programm (bildschirmkonstante Striche). */
|
||||
export function createLineProgram(gl: WebGL2RenderingContext): ShaderProgram | null {
|
||||
return compileShaderProgram(gl, LINE_VERT, LINE_FRAG);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
/**
|
||||
* WebGL2-GPU-Plan-Renderer — öffentliche API.
|
||||
*/
|
||||
|
||||
export * from './glPlanTypes';
|
||||
export {
|
||||
compileShaderProgram,
|
||||
createFillProgram,
|
||||
createLineProgram,
|
||||
} from './glPlanShaders';
|
||||
export { compilePrimitivesToGpu, triangulate } from './glPlanCompile';
|
||||
export { GpuChunkCache } from './glPlanChunks';
|
||||
export { PlanGpuRenderer, computeOrthoMatrix } from './glPlanRender';
|
||||
@@ -1,138 +0,0 @@
|
||||
/**
|
||||
* React-Hook für den WebGL2-GPU-Plan-Renderer.
|
||||
* Verwaltet GL-Kontext, Shader, Geometrie-Cache und Render-Aufrufe.
|
||||
*
|
||||
* Fällt bei fehlendem WebGL2/Shader-Fehler still auf null zurück; der Aufrufer
|
||||
* (PlanView) behält dann den SVG-Pfad (Parität-Fallback).
|
||||
*/
|
||||
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import type { Plan } from './generatePlan';
|
||||
import {
|
||||
GpuChunkCache,
|
||||
createFillProgram,
|
||||
createLineProgram,
|
||||
PlanGpuRenderer,
|
||||
type ViewBox,
|
||||
} from './glPlan';
|
||||
|
||||
/** Liest eine CSS-Custom-Property (z. B. "--sheet") als RGB[0..1] oder null. */
|
||||
export function readCssColor(varName: string): [number, number, number] | null {
|
||||
if (typeof window === 'undefined') return null;
|
||||
const raw = getComputedStyle(document.documentElement).getPropertyValue(varName).trim();
|
||||
let h = raw.startsWith('#') ? raw.slice(1) : raw;
|
||||
if (h.length === 3) h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
|
||||
if (h.length < 6) return null;
|
||||
const r = parseInt(h.slice(0, 2), 16);
|
||||
const g = parseInt(h.slice(2, 4), 16);
|
||||
const b = parseInt(h.slice(4, 6), 16);
|
||||
if (isNaN(r) || isNaN(g) || isNaN(b)) return null;
|
||||
return [r / 255, g / 255, b / 255];
|
||||
}
|
||||
|
||||
export function useGlPlanRenderer(
|
||||
canvasRef: React.RefObject<HTMLCanvasElement | null>,
|
||||
enabled: boolean,
|
||||
) {
|
||||
const glRef = useRef<WebGL2RenderingContext | null>(null);
|
||||
const rendererRef = useRef<PlanGpuRenderer | null>(null);
|
||||
const cacheRef = useRef<GpuChunkCache | null>(null);
|
||||
// GL WIRKLICH aktiv (Kontext + Shader ok)? Steuert den SVG-Fallback: bei false
|
||||
// rendert der Aufrufer den vollen SVG-Pfad, bei true übernimmt die GL-Ebene.
|
||||
const [ready, setReady] = useState(false);
|
||||
|
||||
// GL-Kontext + Shader einmal aufsetzen.
|
||||
useEffect(() => {
|
||||
if (!enabled || !canvasRef.current) {
|
||||
setReady(false);
|
||||
return;
|
||||
}
|
||||
let disposed = false;
|
||||
try {
|
||||
const gl = canvasRef.current.getContext('webgl2', {
|
||||
antialias: true,
|
||||
alpha: false,
|
||||
premultipliedAlpha: false,
|
||||
});
|
||||
if (!gl) {
|
||||
console.warn('WebGL2 nicht verfügbar → SVG-Fallback');
|
||||
return;
|
||||
}
|
||||
const fillProg = createFillProgram(gl);
|
||||
const lineProg = createLineProgram(gl);
|
||||
if (!fillProg || !lineProg) {
|
||||
console.warn('Shader-Kompilierung fehlgeschlagen → SVG-Fallback');
|
||||
return;
|
||||
}
|
||||
if (disposed) return;
|
||||
glRef.current = gl;
|
||||
cacheRef.current = new GpuChunkCache(gl);
|
||||
const renderer = new PlanGpuRenderer(gl, fillProg, lineProg);
|
||||
// Löschfarbe theme-sicher aus --sheet (Zeichenblatt ist immer „Papier").
|
||||
const sheet = readCssColor('--sheet');
|
||||
if (sheet) renderer.setClearColor(sheet[0], sheet[1], sheet[2]);
|
||||
rendererRef.current = renderer;
|
||||
setReady(true);
|
||||
} catch (e) {
|
||||
console.warn('WebGL2-Init fehlgeschlagen:', e);
|
||||
glRef.current = null;
|
||||
rendererRef.current = null;
|
||||
setReady(false);
|
||||
}
|
||||
return () => {
|
||||
disposed = true;
|
||||
cacheRef.current?.dispose();
|
||||
cacheRef.current = null;
|
||||
setReady(false);
|
||||
};
|
||||
}, [enabled, canvasRef]);
|
||||
|
||||
/**
|
||||
* Geometrie (neu) tessellieren und cachen. Läuft beim Plan-Wechsel UND bei
|
||||
* jedem LOD-Bucket-Wechsel des Zooms (PlanView triggert beides). `pxPerMeter`
|
||||
* = aktueller Bildschirm-Massstab (Geräte-px je Modell-Meter); steuert die
|
||||
* adaptive Bogen-Tessellierung (mehr Segmente beim Hineinzoomen). 0 → fixer
|
||||
* zoom-unabhängiger Rückfall.
|
||||
*/
|
||||
const updateGeometry = useCallback((plan: Plan, pxPerMeter = 0) => {
|
||||
const cache = cacheRef.current;
|
||||
if (!cache || !plan) return;
|
||||
try {
|
||||
// LOD-Bucket wie in PlanView (log2 des Massstabs): nur Chunks mit Bögen/
|
||||
// Kreisen hängen davon ab und werden bei einem Wechsel neu kompiliert.
|
||||
cache.update(
|
||||
plan.primitives,
|
||||
pxPerMeter,
|
||||
pxPerMeter > 0 ? Math.round(Math.log2(pxPerMeter)) : -Infinity,
|
||||
plan.greyedRanges,
|
||||
plan.underlay,
|
||||
);
|
||||
} catch (e) {
|
||||
console.warn('Tessellierung fehlgeschlagen:', e);
|
||||
cache.dispose();
|
||||
}
|
||||
}, []);
|
||||
|
||||
/** Einen Frame zeichnen (Canvas-Größe + dpr hier abgleichen). */
|
||||
const render = useCallback(
|
||||
(viewBox: ViewBox, paperScaleN = 100) => {
|
||||
const gl = glRef.current;
|
||||
const renderer = rendererRef.current;
|
||||
const canvas = canvasRef.current;
|
||||
if (!gl || !renderer || !canvas) return;
|
||||
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
const w = Math.max(1, Math.round(rect.width * dpr));
|
||||
const h = Math.max(1, Math.round(rect.height * dpr));
|
||||
if (canvas.width !== w || canvas.height !== h) {
|
||||
canvas.width = w;
|
||||
canvas.height = h;
|
||||
}
|
||||
renderer.render(cacheRef.current?.geometries ?? null, viewBox, { width: w, height: h }, paperScaleN);
|
||||
},
|
||||
[canvasRef],
|
||||
);
|
||||
|
||||
return { render, updateGeometry, ready };
|
||||
}
|
||||
@@ -10,10 +10,12 @@
|
||||
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import type { Plan } from './generatePlan';
|
||||
import { GpuChunkCache, compilePrimitivesToGpu, type GpuGeometry, type ViewBox } from './glPlan';
|
||||
import { GpuChunkCache } from './glPlan/glPlanChunks';
|
||||
import { compilePrimitivesToGpu } from './glPlan/glPlanCompile';
|
||||
import type { GpuGeometry, ViewBox } from './glPlan/glPlanTypes';
|
||||
import type { Primitive } from './generatePlan';
|
||||
import { NativeGl, type NativeInvoke } from './glPlan/nativeGl';
|
||||
import { readCssColor } from './useGlPlanRenderer';
|
||||
import { readCssColor } from './cssColor';
|
||||
import { NativeTextSync } from './nativeText';
|
||||
|
||||
/** Läuft die App in einer Tauri-Webview? */
|
||||
|
||||
Reference in new issue
Block a user