Stocken behoben: auf macOS keine JSON-Szene/3D-Modell mehr nach jeder Aenderung aufbauen (niemand liest sie); Auswahl-Hervorhebung ueber eigenen kleinen Befehl, unveraendertes Layout nicht neu senden
This commit is contained in:
1 parent
e4c164cb29
commit
dc6ab429f2
5 files changed
+87
-28
No files matched your search
@@ -205,6 +205,8 @@ pub struct ChunkRenderer {
|
||||
uniform: Option<(wgpu::Buffer, wgpu::BindGroup, u64)>,
|
||||
buffers: HashMap<u32, wgpu::Buffer>,
|
||||
layout: Vec<ChunkGeom>,
|
||||
/// Auswahl-Hervorhebung: eine Geometrie zuoberst, unabhaengig vom Layout gesetzt.
|
||||
highlight: Option<ChunkGeom>,
|
||||
msaa: Option<(wgpu::Texture, (u32, u32))>,
|
||||
format: wgpu::TextureFormat,
|
||||
samples: u32,
|
||||
@@ -389,6 +391,7 @@ impl ChunkRenderer {
|
||||
uniform: None,
|
||||
buffers: HashMap::new(),
|
||||
layout: Vec::new(),
|
||||
highlight: None,
|
||||
msaa: None,
|
||||
format,
|
||||
samples,
|
||||
@@ -522,6 +525,10 @@ impl ChunkRenderer {
|
||||
(tmp.into_iter().map(|(_, i)| i).collect(), groups)
|
||||
}
|
||||
|
||||
pub fn set_highlight(&mut self, geom: Option<ChunkGeom>) {
|
||||
self.highlight = geom;
|
||||
}
|
||||
|
||||
pub fn set_layout(&mut self, layout: Vec<ChunkGeom>) {
|
||||
self.layout = layout;
|
||||
}
|
||||
@@ -550,7 +557,7 @@ impl ChunkRenderer {
|
||||
let stride = (std::mem::size_of::<Globals>() as u64).div_ceil(align) * align;
|
||||
let mut blocks: Vec<Globals> = Vec::new();
|
||||
let vp = [vw as f32, vh as f32];
|
||||
for g in &self.layout {
|
||||
for g in self.layout.iter().chain(self.highlight.iter()) {
|
||||
if g.fill_pos.is_none() || g.fill_idx.is_none() {
|
||||
continue;
|
||||
}
|
||||
@@ -560,7 +567,7 @@ impl ChunkRenderer {
|
||||
blocks.push(Globals { view_proj: proj, color: c, viewport_px: vp, stroke_px: 0.0, stroke_scale: 1.0 });
|
||||
}
|
||||
}
|
||||
for g in &self.layout {
|
||||
for g in self.layout.iter().chain(self.highlight.iter()) {
|
||||
if g.line_vtx.is_none() || g.line_idx.is_none() {
|
||||
continue;
|
||||
}
|
||||
@@ -698,7 +705,7 @@ impl ChunkRenderer {
|
||||
});
|
||||
let mut block = 0u32;
|
||||
pass.set_pipeline(&self.fill_pipeline);
|
||||
for g in &self.layout {
|
||||
for g in self.layout.iter().chain(self.highlight.iter()) {
|
||||
let (Some(p), Some(i)) = (g.fill_pos, g.fill_idx) else { continue };
|
||||
let (Some(pb), Some(ib)) = (self.buffers.get(&p), self.buffers.get(&i)) else {
|
||||
block += g.fill_batches.len() as u32;
|
||||
@@ -713,7 +720,7 @@ impl ChunkRenderer {
|
||||
}
|
||||
}
|
||||
pass.set_pipeline(&self.line_pipeline);
|
||||
for g in &self.layout {
|
||||
for g in self.layout.iter().chain(self.highlight.iter()) {
|
||||
let (Some(p), Some(i)) = (g.line_vtx, g.line_idx) else { continue };
|
||||
let (Some(pb), Some(ib)) = (self.buffers.get(&p), self.buffers.get(&i)) else {
|
||||
block += g.line_batches.len() as u32;
|
||||
|
||||
+24
-1
@@ -157,6 +157,21 @@ fn native2d_patch(app: tauri::AppHandle, request: tauri::ipc::Request<'_>) -> Re
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn native2d_highlight(app: tauri::AppHandle, geom: Option<serde_json::Value>, delete: Vec<u32>) -> Result<(), String> {
|
||||
#[cfg(all(feature = "native2d", target_os = "macos"))]
|
||||
{
|
||||
let geom = match geom {
|
||||
Some(v) => Some(serde_json::from_value(v).map_err(|e| e.to_string())?),
|
||||
None => None,
|
||||
};
|
||||
native_embed::set_highlight(&app, geom, delete);
|
||||
}
|
||||
#[cfg(not(all(feature = "native2d", target_os = "macos")))]
|
||||
let _ = (app, geom, delete);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn native2d_layout(app: tauri::AppHandle, layout: serde_json::Value, delete: Vec<u32>) -> Result<(), String> {
|
||||
#[cfg(all(feature = "native2d", target_os = "macos"))]
|
||||
@@ -197,9 +212,15 @@ fn native2d_frame(app: tauri::AppHandle, view: serde_json::Value, paper_scale: f
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///
|
||||
/// macOS: die eingebettete 2D-Fläche (`native_embed`) bekommt ihre Daten über
|
||||
/// Chunk-Uploads, und es gibt dort kein natives 3D-Fenster — dort also `false`,
|
||||
/// sonst würde die Webview nach JEDER Plan-/Projektänderung den ganzen Plan bzw.
|
||||
/// das 3D-Modell als JSON aufbauen, nur damit Rust es verwirft (bei Kataster-
|
||||
/// Importen sekundenlanges Stocken).
|
||||
#[tauri::command]
|
||||
fn native_viewport_enabled() -> bool {
|
||||
cfg!(any(feature = "native2d", feature = "native3d"))
|
||||
cfg!(all(any(feature = "native2d", feature = "native3d"), not(target_os = "macos")))
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
@@ -248,6 +269,7 @@ pub fn run() {
|
||||
native2d_embed_hide,
|
||||
native2d_upload,
|
||||
native2d_patch,
|
||||
native2d_highlight,
|
||||
native2d_layout,
|
||||
native2d_frame,
|
||||
native2d_texts,
|
||||
@@ -264,6 +286,7 @@ pub fn run() {
|
||||
native2d_embed_hide,
|
||||
native2d_upload,
|
||||
native2d_patch,
|
||||
native2d_highlight,
|
||||
native2d_layout,
|
||||
native2d_frame,
|
||||
native2d_texts,
|
||||
|
||||
@@ -240,3 +240,12 @@ pub fn patch(app: &AppHandle, from: u32, to: u32, ranges: &[(u64, u64)], bytes:
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Auswahl-Hervorhebung setzen (eigene Geometrie zuoberst) und neu zeichnen.
|
||||
pub fn set_highlight(app: &AppHandle, geom: Option<ChunkGeom>, delete: Vec<u32>) {
|
||||
if let Some(e) = app.state::<EmbedState>().0.lock().unwrap().as_mut() {
|
||||
e.renderer.delete(&delete);
|
||||
e.renderer.set_highlight(geom);
|
||||
draw(e);
|
||||
}
|
||||
}
|
||||
@@ -162,14 +162,25 @@ export class NativeGl implements BufferGl {
|
||||
for (const id of deleted) this.live.delete(id);
|
||||
}
|
||||
|
||||
/** Geometrien (in Zeichenreihenfolge) → Layout für Rust, plus freizugebende Puffer. */
|
||||
takeLayout(geometries: readonly GpuGeometry[]): { layout: NativeChunkLayout[]; delete: number[] } {
|
||||
const id = (b: WebGLBuffer | null): number | null => (b ? (b as unknown as NativeBuffer).id : null);
|
||||
/** Ausstehende Uploads senden; liefert die freizugebenden Puffer-IDs. */
|
||||
takeUploads(): number[] {
|
||||
const del = this.pendingDelete;
|
||||
this.pendingDelete = [];
|
||||
// Erst die Uploads (in Reihenfolge VOR dem Layout-Aufruf des Aufrufers).
|
||||
this.flushUploads(del);
|
||||
const layout = geometries.map((g) => ({
|
||||
return del;
|
||||
}
|
||||
|
||||
/** Geometrien (in Zeichenreihenfolge) → Layout für Rust, plus freizugebende Puffer. */
|
||||
takeLayout(geometries: readonly GpuGeometry[]): { layout: NativeChunkLayout[]; delete: number[] } {
|
||||
// Erst die Uploads (in Reihenfolge VOR dem Layout-Aufruf des Aufrufers).
|
||||
const del = this.takeUploads();
|
||||
return { layout: geometries.map((g) => this.layoutOf(g)), delete: del };
|
||||
}
|
||||
|
||||
/** Layout-Eintrag einer einzelnen Geometrie. */
|
||||
layoutOf(g: GpuGeometry): NativeChunkLayout {
|
||||
const id = (b: WebGLBuffer | null): number | null => (b ? (b as unknown as NativeBuffer).id : null);
|
||||
return {
|
||||
fill_pos: id(g.fill.positionBuffer),
|
||||
fill_idx: id(g.fill.indexBuffer),
|
||||
fill_batches: g.fill.batches.map((b) => ({ start: b.startIndex, count: b.indexCount, color: b.color })),
|
||||
@@ -184,7 +195,6 @@ export class NativeGl implements BufferGl {
|
||||
})),
|
||||
origin: [g.origin?.x ?? 0, g.origin?.y ?? 0] as [number, number],
|
||||
greyed: !!g.greyed,
|
||||
}));
|
||||
return { layout, delete: del };
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -193,6 +193,7 @@ export function useNativePlanRenderer(
|
||||
if (remove.length) void invoke('native2d_texts', { upsert: [], remove }).catch(() => {});
|
||||
lastPlan.current = null;
|
||||
highlightGeom.current = null;
|
||||
lastSentGeoms.current = null;
|
||||
setGpuTexts(false);
|
||||
const { delete: del } = glRef.current.takeLayout([]);
|
||||
void invoke('native2d_layout', { layout: [], delete: del }).catch(() => {});
|
||||
@@ -205,18 +206,16 @@ export function useNativePlanRenderer(
|
||||
};
|
||||
}, [enabled, canvasRef, syncRect]);
|
||||
|
||||
/** Layout = Plan-Chunks + (optional) Auswahl-Hervorhebung zuoberst. */
|
||||
/** Zuletzt gesendete Geometrie-Liste: unverändert → kein erneuter Layout-Versand. */
|
||||
const lastSentGeoms = useRef<readonly GpuGeometry[] | null>(null);
|
||||
const takeFullLayout = useCallback(() => {
|
||||
const gl = glRef.current!;
|
||||
const geoms = cacheRef.current?.geometries ?? [];
|
||||
const hl = highlightGeom.current;
|
||||
const res = gl.takeLayout(hl ? [...geoms, hl] : geoms);
|
||||
if (hl && res.layout.length) {
|
||||
const dpr = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;
|
||||
const last = res.layout[res.layout.length - 1];
|
||||
last.line_batches = last.line_batches.map((b) => ({ ...b, stroke_mm: 2.5 * dpr, device_px: true }));
|
||||
}
|
||||
return res;
|
||||
const prev = lastSentGeoms.current;
|
||||
const same = !!prev && prev.length === geoms.length && prev.every((g, i) => g === geoms[i]);
|
||||
lastSentGeoms.current = geoms.slice();
|
||||
const res = gl.takeLayout(geoms);
|
||||
return { ...res, unchanged: same && res.delete.length === 0 };
|
||||
}, []);
|
||||
|
||||
/**
|
||||
@@ -248,10 +247,18 @@ export function useNativePlanRenderer(
|
||||
}
|
||||
highlightGeom.current = compilePrimitivesToGpu(gl, lines, lastPxPerMeter.current);
|
||||
}
|
||||
const { layout, delete: del } = takeFullLayout();
|
||||
void invoke('native2d_layout', { layout, delete: del }).catch(() => {});
|
||||
const del = gl.takeUploads();
|
||||
const hl = highlightGeom.current;
|
||||
let geom = null;
|
||||
if (hl) {
|
||||
const dpr = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;
|
||||
const e = gl.layoutOf(hl);
|
||||
e.line_batches = e.line_batches.map((b) => ({ ...b, stroke_mm: 2.5 * dpr, device_px: true }));
|
||||
geom = e;
|
||||
}
|
||||
void invoke('native2d_highlight', { geom, delete: del }).catch(() => {});
|
||||
},
|
||||
[takeFullLayout],
|
||||
[],
|
||||
);
|
||||
|
||||
const updateGeometry = useCallback((plan: Plan, pxPerMeter = 0) => {
|
||||
@@ -272,12 +279,15 @@ export function useNativePlanRenderer(
|
||||
cache.dispose();
|
||||
}
|
||||
lastPxPerMeter.current = pxPerMeter;
|
||||
const { layout, delete: del } = takeFullLayout();
|
||||
const { layout, delete: del, unchanged } = takeFullLayout();
|
||||
lastPlan.current = plan;
|
||||
// Direkt (nicht über sendFrame): Reihenfolge nach den Puffer-Uploads ist wichtig.
|
||||
void invoke('native2d_layout', { layout, delete: del }).catch((e) =>
|
||||
console.debug('native2d_layout fehlgeschlagen', e),
|
||||
);
|
||||
// Unverändertes Layout (kein Chunk neu, nichts freigegeben) nicht erneut senden.
|
||||
if (!unchanged) {
|
||||
void invoke('native2d_layout', { layout, delete: del }).catch((e) =>
|
||||
console.debug('native2d_layout fehlgeschlagen', e),
|
||||
);
|
||||
}
|
||||
pushTexts(plan);
|
||||
}, [pushTexts, takeFullLayout]);
|
||||
|
||||
|
||||
Reference in new issue
Block a user