forked from 1b-agent/opencadstudio-upstream
feat(draworder): cross-type draw order + context menu
DRAWORDER now affects rendering immediately (bump geometry epoch so the sort cache rebuilds) and front/back anchor to the block's full effective sort range instead of only existing table entries, so bring-to-front actually lands on top. The render fallback sorts table-absent entities by their own handle. Draw order now applies across entity types, not just within a type. A per-entity draw-order rank (SortEntitiesTable override or own handle, ranked per block) is encoded as a small signed clip-z bias in the wire, hatch, image, and 3DFACE pipelines. The shared LessEqual depth buffer then orders fills, lines, rasters and 2D solids against each other regardless of pass order — without touching model coordinates. 3D meshes keep real geometric depth; wipeouts stay always-on-top. Adds a Draw Order submenu to the viewport context menu (Bring to Front, Send to Back, Bring Above/Send Under Object). The above/under items run an interactive reference-object pick, then reorder the captured selection. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
14a981dc87
commit
09e7e90aae
19 files changed
+469
-36
No files matched your search
@@ -14,8 +14,9 @@ struct Uniforms {
|
||||
var<uniform> u: Uniforms;
|
||||
|
||||
struct VertexIn {
|
||||
@location(0) position: vec3<f32>,
|
||||
@location(1) color: vec4<f32>,
|
||||
@location(0) position: vec3<f32>,
|
||||
@location(1) color: vec4<f32>,
|
||||
@location(2) draw_depth: f32,
|
||||
};
|
||||
|
||||
struct VertexOut {
|
||||
@@ -23,10 +24,15 @@ struct VertexOut {
|
||||
@location(0) color: vec4<f32>,
|
||||
};
|
||||
|
||||
// Draw-order depth bias (see wire.wgsl). Signed draw_depth; 0.0 (3D mesh
|
||||
// faces) leaves real depth untouched; 2D fills / 3DFACE quads order by rank.
|
||||
const DRAW_ORDER_BIAS: f32 = 0.001;
|
||||
|
||||
@vertex
|
||||
fn vs_main(v: VertexIn) -> VertexOut {
|
||||
var out: VertexOut;
|
||||
out.clip_pos = u.view_proj * vec4<f32>(v.position, 1.0);
|
||||
out.clip_pos.z = out.clip_pos.z - v.draw_depth * DRAW_ORDER_BIAS * out.clip_pos.w;
|
||||
out.color = v.color;
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -45,9 +45,14 @@ struct HatchInstance {
|
||||
boundary_count: u32,
|
||||
family_offset: u32,
|
||||
family_count: u32,
|
||||
_pad0: vec2<u32>,
|
||||
draw_depth: f32, // signed (-1,1) draw-order bias; 0 = neutral
|
||||
_pad0: u32,
|
||||
}
|
||||
|
||||
// Draw-order depth bias (see wire.wgsl). Higher draw_depth → smaller z →
|
||||
// drawn on top, ordering this fill against other entity types.
|
||||
const DRAW_ORDER_BIAS: f32 = 0.001;
|
||||
|
||||
struct LineFamily {
|
||||
cos_a: f32,
|
||||
sin_a: f32,
|
||||
@@ -122,6 +127,7 @@ fn corner_xy(c: u32, aabb: vec4<f32>) -> vec2<f32> {
|
||||
local.y + inst.world_origin.y,
|
||||
0.0);
|
||||
o.clip = u.view_proj * vec4<f32>(world, 1.0);
|
||||
o.clip.z = o.clip.z - inst.draw_depth * DRAW_ORDER_BIAS * o.clip.w;
|
||||
o.xz = local;
|
||||
o.instance_index = v.instance_index;
|
||||
return o;
|
||||
|
||||
@@ -19,13 +19,16 @@ struct Uniforms {
|
||||
|
||||
// Per-image params (fade, clip flag, etc.)
|
||||
struct ImageParams {
|
||||
opacity: f32,
|
||||
_pad0: f32,
|
||||
_pad1: f32,
|
||||
_pad2: f32,
|
||||
opacity: f32,
|
||||
draw_depth: f32, // signed (-1,1) draw-order bias; 0 = neutral
|
||||
_pad1: f32,
|
||||
_pad2: f32,
|
||||
};
|
||||
@group(1) @binding(2) var<uniform> img_params: ImageParams;
|
||||
|
||||
// Draw-order depth bias (see wire.wgsl).
|
||||
const DRAW_ORDER_BIAS: f32 = 0.001;
|
||||
|
||||
// ── Vertex stage ──────────────────────────────────────────────────────────────
|
||||
struct VertIn {
|
||||
@location(0) pos: vec3<f32>,
|
||||
@@ -41,6 +44,7 @@ struct VertOut {
|
||||
fn vs_main(in: VertIn) -> VertOut {
|
||||
var out: VertOut;
|
||||
out.clip_pos = u.mvp * vec4<f32>(in.pos, 1.0);
|
||||
out.clip_pos.z = out.clip_pos.z - img_params.draw_depth * DRAW_ORDER_BIAS * out.clip_pos.w;
|
||||
out.uv = in.uv;
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -35,8 +35,15 @@ struct InstanceIn {
|
||||
@location(6) pattern_length: f32,
|
||||
@location(7) pat0: vec4<f32>,
|
||||
@location(8) pat1: vec4<f32>,
|
||||
@location(9) draw_depth: f32,
|
||||
}
|
||||
|
||||
// Draw-order depth bias: shifts clip-space z so 2D entities of different
|
||||
// types order against each other through the shared LessEqual depth test.
|
||||
// draw_depth is signed (-1,1): front → positive → smaller z → drawn on top;
|
||||
// 0.0 = neutral (real depth). Depth32Float gives ample precision.
|
||||
const DRAW_ORDER_BIAS: f32 = 0.001;
|
||||
|
||||
struct VertexOut {
|
||||
@builtin(position) clip_pos: vec4<f32>,
|
||||
@location(0) color: vec4<f32>,
|
||||
@@ -111,6 +118,7 @@ struct VertexOut {
|
||||
|
||||
var out: VertexOut;
|
||||
out.clip_pos = final_clip;
|
||||
out.clip_pos.z = out.clip_pos.z - in.draw_depth * DRAW_ORDER_BIAS * out.clip_pos.w;
|
||||
out.color = in.color;
|
||||
out.distance = mix(in.distance_a, in.distance_b, which_end);
|
||||
out.pattern_length = in.pattern_length;
|
||||
|
||||
Reference in new issue
Block a user