forked from 1b-agent/opencadstudio-upstream
fix(xref): blocks respect their internal draw order
Xref merge now inserts entities in the source block's chain order and carries SortEntitiesTable objects across (remapped to merged handles). draw_depth_map values become [depth, half] so exploded block/xref fills and wide-polyline band wires both compose child depth as insert_depth + in-block rank x half, recursing into nested inserts with the same divisor - bands and fills from one block interleave by the block's internal order instead of stacking at the insert's single depth. Band batches split per rank via WireModel.depth_override; thin wires stay merged. The wire arena falls back to a full rebuild when a slab carries mixed depths so refreshes don't flatten band overrides. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1546c1dc30
commit
e177f92ff5
48 files changed
+337
-50
No files matched your search
@@ -114,15 +114,10 @@ impl Face3DGpu {
|
||||
face3d_wires: &[WireModel],
|
||||
all_wires: &[WireModel],
|
||||
keep_3d_mesh_fills: bool,
|
||||
depth_map: &rustc_hash::FxHashMap<u64, f32>,
|
||||
depth_map: &rustc_hash::FxHashMap<u64, [f32; 2]>,
|
||||
) -> Self {
|
||||
let depth_of = |w: &WireModel| -> f32 {
|
||||
w.name
|
||||
.parse::<u64>()
|
||||
.ok()
|
||||
.and_then(|h| depth_map.get(&h).copied())
|
||||
.unwrap_or(0.0)
|
||||
};
|
||||
let depth_of =
|
||||
|w: &WireModel| -> f32 { super::wire_gpu::wire_draw_depth(w, depth_map) };
|
||||
let mut verts_3d: Vec<Face3DVertex> = Vec::with_capacity(face3d_wires.len() * 6);
|
||||
let mut verts_2d: Vec<Face3DVertex> = Vec::new();
|
||||
|
||||
|
||||
@@ -1477,7 +1477,7 @@ impl Pipeline {
|
||||
&self,
|
||||
device: &wgpu::Device,
|
||||
wires: &[WireModel],
|
||||
depth_map: &rustc_hash::FxHashMap<u64, f32>,
|
||||
depth_map: &rustc_hash::FxHashMap<u64, [f32; 2]>,
|
||||
) -> (
|
||||
std::sync::Arc<Vec<WireGpu>>,
|
||||
std::sync::Arc<rustc_hash::FxHashMap<u64, Vec<u32>>>,
|
||||
@@ -1543,7 +1543,7 @@ impl Pipeline {
|
||||
wires: &[WireModel],
|
||||
selected: &rustc_hash::FxHashSet<acadrust::Handle>,
|
||||
hover: Option<acadrust::Handle>,
|
||||
depth_map: &rustc_hash::FxHashMap<u64, f32>,
|
||||
depth_map: &rustc_hash::FxHashMap<u64, [f32; 2]>,
|
||||
) {
|
||||
let hover = hover.filter(|h| !selected.contains(h));
|
||||
if selected.is_empty() && hover.is_none() {
|
||||
@@ -1627,7 +1627,7 @@ impl Pipeline {
|
||||
&mut self,
|
||||
device: &wgpu::Device,
|
||||
wires: &[WireModel],
|
||||
depth_map: &rustc_hash::FxHashMap<u64, f32>,
|
||||
depth_map: &rustc_hash::FxHashMap<u64, [f32; 2]>,
|
||||
) {
|
||||
self.gpu_preview_wires = if wires.is_empty() {
|
||||
vec![]
|
||||
@@ -1912,7 +1912,7 @@ impl Pipeline {
|
||||
face3d_wires: &[WireModel],
|
||||
all_wires: &[WireModel],
|
||||
wireframe_only: bool,
|
||||
depth_map: &rustc_hash::FxHashMap<u64, f32>,
|
||||
depth_map: &rustc_hash::FxHashMap<u64, [f32; 2]>,
|
||||
) {
|
||||
// Edge buffer is always built from `face3d_wires`, so 3DFACE
|
||||
// outlines stay on the screen regardless of mode.
|
||||
|
||||
@@ -105,7 +105,7 @@ pub fn is_mesh_edge(w: &WireModel, mesh_names: &rustc_hash::FxHashSet<u64>) -> b
|
||||
/// Surface) are excluded from `draw_depth_map`, so their fallback edge wires
|
||||
/// get draw_depth 0.0. Two coincident opaque such wires share a z-bias and
|
||||
/// resolve by submission order, which a tail relocation would flip.
|
||||
fn append_unsafe(wires: &[&WireModel], depth_map: &FxHashMap<u64, f32>) -> bool {
|
||||
fn append_unsafe(wires: &[&WireModel], depth_map: &FxHashMap<u64, [f32; 2]>) -> bool {
|
||||
wires.iter().any(|w| {
|
||||
w.color[3] < 0.999
|
||||
|| handle_of(w).map_or(true, |h| !depth_map.contains_key(&h.value()))
|
||||
@@ -202,7 +202,7 @@ impl WireArena {
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
wires: &[&WireModel],
|
||||
depth_map: &FxHashMap<u64, f32>,
|
||||
depth_map: &FxHashMap<u64, [f32; 2]>,
|
||||
const_bgl: &wgpu::BindGroupLayout,
|
||||
mesh_edge: bool,
|
||||
) -> Option<Self> {
|
||||
@@ -288,7 +288,7 @@ impl WireArena {
|
||||
queue: &wgpu::Queue,
|
||||
changes: &[(Handle, ChangeKind)],
|
||||
wires: &[&WireModel],
|
||||
depth_map: &FxHashMap<u64, f32>,
|
||||
depth_map: &FxHashMap<u64, [f32; 2]>,
|
||||
) -> bool {
|
||||
let Some(ranges) = handle_ranges(wires) else {
|
||||
return false;
|
||||
@@ -405,13 +405,27 @@ impl WireArena {
|
||||
// entity's z-bias. Refresh each live slab's draw_depth from the new
|
||||
// depth map and re-upload the whole (small) const buffer; the instance
|
||||
// buffer is untouched.
|
||||
// A slab whose consts carry DIFFERENT depths holds block-band wires
|
||||
// with composed per-child offsets (`depth_override`); a flat refresh
|
||||
// to the entity's base depth would erase them. Fall back to a full
|
||||
// rebuild, which recomputes each wire's composed depth.
|
||||
if !self.mesh_edge {
|
||||
for slab in self.slabs.values() {
|
||||
let first = self.consts_cpu[slab.const_off as usize].draw_depth;
|
||||
for k in 1..slab.const_len {
|
||||
if self.consts_cpu[(slab.const_off + k) as usize].draw_depth != first {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (h, slab) in &self.slabs {
|
||||
// Mesh-edge wires keep depth 0 (no draw-order bias); regular wires
|
||||
// take the re-normalised map value.
|
||||
let dd = if self.mesh_edge {
|
||||
0.0
|
||||
} else {
|
||||
depth_map.get(&h.value()).copied().unwrap_or(0.0)
|
||||
depth_map.get(&h.value()).map_or(0.0, |d| d[0])
|
||||
};
|
||||
for k in 0..slab.const_len {
|
||||
self.consts_cpu[(slab.const_off + k) as usize].draw_depth = dd;
|
||||
|
||||
@@ -488,17 +488,23 @@ pub(crate) fn emit_wire_native(
|
||||
|
||||
/// Looks up a wire's draw-order depth from the per-entity map using the
|
||||
/// handle encoded in its `name`. Falls back to 0.0 (transient / preview
|
||||
/// wires that carry no document handle).
|
||||
/// wires that carry no document handle). A wire carrying a block-local
|
||||
/// `depth_override` (a wide-polyline band inside a block) composes it into
|
||||
/// the insert's own sub-range so the band orders against its block siblings.
|
||||
pub(crate) fn wire_draw_depth(
|
||||
wire: &WireModel,
|
||||
depth_map: &rustc_hash::FxHashMap<u64, f32>,
|
||||
depth_map: &rustc_hash::FxHashMap<u64, [f32; 2]>,
|
||||
) -> f32 {
|
||||
wire
|
||||
let base = wire
|
||||
.name
|
||||
.parse::<u64>()
|
||||
.ok()
|
||||
.and_then(|h| depth_map.get(&h).copied())
|
||||
.unwrap_or(0.0)
|
||||
.and_then(|h| depth_map.get(&h).copied());
|
||||
match (base, wire.depth_override) {
|
||||
(Some([d, half]), Some(local)) => d + local * half,
|
||||
(Some([d, _]), None) => d,
|
||||
(None, _) => 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Build the shared per-wire `WireConst` storage buffer and its bind group
|
||||
@@ -546,7 +552,7 @@ impl WireGpu {
|
||||
pub fn from_run(
|
||||
device: &wgpu::Device,
|
||||
wires: &[WireModel],
|
||||
depth_map: &rustc_hash::FxHashMap<u64, f32>,
|
||||
depth_map: &rustc_hash::FxHashMap<u64, [f32; 2]>,
|
||||
mesh_edge: bool,
|
||||
const_bgl: Option<&wgpu::BindGroupLayout>,
|
||||
) -> Vec<Self> {
|
||||
@@ -632,7 +638,7 @@ impl WireGpu {
|
||||
pub fn from_batch(
|
||||
device: &wgpu::Device,
|
||||
wires: &[WireModel],
|
||||
depth_map: &rustc_hash::FxHashMap<u64, f32>,
|
||||
depth_map: &rustc_hash::FxHashMap<u64, [f32; 2]>,
|
||||
const_bgl: Option<&wgpu::BindGroupLayout>,
|
||||
) -> Vec<Self> {
|
||||
let total_segs: usize = wires.iter().map(|w| w.points.len().saturating_sub(1)).sum();
|
||||
|
||||
Reference in new issue
Block a user