cargo fmt
This commit is contained in:
parent
468cbde5e1
commit
ca07268c7c
204 changed files with 13988 additions and 5516 deletions
|
|
@ -20,7 +20,7 @@ use iced::wgpu::util::DeviceExt;
|
|||
#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
|
||||
pub struct Face3DVertex {
|
||||
pub position: [f32; 3],
|
||||
pub color: [f32; 4],
|
||||
pub color: [f32; 4],
|
||||
}
|
||||
|
||||
impl Face3DVertex {
|
||||
|
|
@ -58,7 +58,11 @@ impl Face3DGpu {
|
|||
/// emits 2 triangles per face.
|
||||
/// - `all_wires`: all entity wires — `fill_tris` holds pre-triangulated
|
||||
/// fill data for PolyfaceMesh / PolygonMesh.
|
||||
pub fn from_wires(device: &wgpu::Device, face3d_wires: &[WireModel], all_wires: &[WireModel]) -> Self {
|
||||
pub fn from_wires(
|
||||
device: &wgpu::Device,
|
||||
face3d_wires: &[WireModel],
|
||||
all_wires: &[WireModel],
|
||||
) -> Self {
|
||||
let mut vertices: Vec<Face3DVertex> = Vec::with_capacity(face3d_wires.len() * 6);
|
||||
|
||||
// Face3D quads (4 key_vertices → 2 triangles).
|
||||
|
|
@ -69,7 +73,10 @@ impl Face3DGpu {
|
|||
let [r, g, b, a] = wire.color;
|
||||
let fill_color = [r * 0.45, g * 0.45, b * 0.45, a];
|
||||
let p = &wire.key_vertices;
|
||||
let v = |i: usize| Face3DVertex { position: p[i], color: fill_color };
|
||||
let v = |i: usize| Face3DVertex {
|
||||
position: p[i],
|
||||
color: fill_color,
|
||||
};
|
||||
vertices.push(v(0));
|
||||
vertices.push(v(1));
|
||||
vertices.push(v(2));
|
||||
|
|
@ -86,7 +93,10 @@ impl Face3DGpu {
|
|||
let [r, g, b, a] = wire.color;
|
||||
let fill_color = [r * 0.45, g * 0.45, b * 0.45, a];
|
||||
for &position in &wire.fill_tris {
|
||||
vertices.push(Face3DVertex { position, color: fill_color });
|
||||
vertices.push(Face3DVertex {
|
||||
position,
|
||||
color: fill_color,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,7 @@
|
|||
// binding 1 — BoundaryData (16384 bytes) boundary polygon vertices
|
||||
// binding 2 — FamilyBatchData (1296 bytes) up to 16 line families + 128 dash values
|
||||
|
||||
use crate::scene::hatch_model::{
|
||||
HatchModel, HatchPattern, PatFamily, MAX_HATCH_BOUNDARY_VERTS,
|
||||
};
|
||||
use crate::scene::hatch_model::{HatchModel, HatchPattern, PatFamily, MAX_HATCH_BOUNDARY_VERTS};
|
||||
use iced::wgpu;
|
||||
use iced::wgpu::util::DeviceExt;
|
||||
|
||||
|
|
|
|||
|
|
@ -114,7 +114,10 @@ impl ImageGpu {
|
|||
});
|
||||
|
||||
// ── Opacity uniform ───────────────────────────────────────────────
|
||||
let params = ImageParams { opacity: model.opacity.clamp(0.0, 1.0), _pad: [0.0; 3] };
|
||||
let params = ImageParams {
|
||||
opacity: model.opacity.clamp(0.0, 1.0),
|
||||
_pad: [0.0; 3],
|
||||
};
|
||||
let _params_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("image.params"),
|
||||
contents: bytemuck::bytes_of(¶ms),
|
||||
|
|
@ -146,12 +149,30 @@ impl ImageGpu {
|
|||
// UV: BL=(0,1), BR=(1,1), TR=(1,0), TL=(0,0)
|
||||
let [p0, p1, p2, p3] = model.corners;
|
||||
let verts = [
|
||||
ImageVertex { pos: p0, uv: [0.0, 1.0] },
|
||||
ImageVertex { pos: p1, uv: [1.0, 1.0] },
|
||||
ImageVertex { pos: p2, uv: [1.0, 0.0] },
|
||||
ImageVertex { pos: p0, uv: [0.0, 1.0] },
|
||||
ImageVertex { pos: p2, uv: [1.0, 0.0] },
|
||||
ImageVertex { pos: p3, uv: [0.0, 0.0] },
|
||||
ImageVertex {
|
||||
pos: p0,
|
||||
uv: [0.0, 1.0],
|
||||
},
|
||||
ImageVertex {
|
||||
pos: p1,
|
||||
uv: [1.0, 1.0],
|
||||
},
|
||||
ImageVertex {
|
||||
pos: p2,
|
||||
uv: [1.0, 0.0],
|
||||
},
|
||||
ImageVertex {
|
||||
pos: p0,
|
||||
uv: [0.0, 1.0],
|
||||
},
|
||||
ImageVertex {
|
||||
pos: p2,
|
||||
uv: [1.0, 0.0],
|
||||
},
|
||||
ImageVertex {
|
||||
pos: p3,
|
||||
uv: [0.0, 0.0],
|
||||
},
|
||||
];
|
||||
let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("image.vbuf"),
|
||||
|
|
|
|||
|
|
@ -609,7 +609,11 @@ impl Pipeline {
|
|||
self.gpu_wires = wires
|
||||
.iter()
|
||||
.filter(|w| {
|
||||
let segs = w.points.len().saturating_sub(1).min(wire_gpu::MAX_SEGS_PER_WIRE);
|
||||
let segs = w
|
||||
.points
|
||||
.len()
|
||||
.saturating_sub(1)
|
||||
.min(wire_gpu::MAX_SEGS_PER_WIRE);
|
||||
if total_segs + segs > MAX_TOTAL_SEGS {
|
||||
skipped += 1;
|
||||
false
|
||||
|
|
@ -641,31 +645,42 @@ impl Pipeline {
|
|||
pub fn compute_wire_scissors(&mut self, view_proj: glam::Mat4, clip_w: u32, clip_h: u32) {
|
||||
let w = clip_w as f32;
|
||||
let h = clip_h as f32;
|
||||
self.wire_pixel_scissors = self.gpu_wires.iter().map(|wire| {
|
||||
let [x0, y0, x1, y1] = wire.vp_scissor?;
|
||||
let corners = [
|
||||
view_proj.project_point3(glam::Vec3::new(x0, y0, 0.0)),
|
||||
view_proj.project_point3(glam::Vec3::new(x1, y0, 0.0)),
|
||||
view_proj.project_point3(glam::Vec3::new(x0, y1, 0.0)),
|
||||
view_proj.project_point3(glam::Vec3::new(x1, y1, 0.0)),
|
||||
];
|
||||
let px: Vec<f32> = corners.iter().map(|c| (c.x + 1.0) * 0.5 * w).collect();
|
||||
let py: Vec<f32> = corners.iter().map(|c| (1.0 - c.y) * 0.5 * h).collect();
|
||||
let sx0 = px.iter().cloned().fold(f32::INFINITY, f32::min).max(0.0) as u32;
|
||||
let sy0 = py.iter().cloned().fold(f32::INFINITY, f32::min).max(0.0) as u32;
|
||||
let sx1 = (px.iter().cloned().fold(f32::NEG_INFINITY, f32::max) as u32).min(clip_w);
|
||||
let sy1 = (py.iter().cloned().fold(f32::NEG_INFINITY, f32::max) as u32).min(clip_h);
|
||||
if sx1 <= sx0 || sy1 <= sy0 { return None; }
|
||||
Some([sx0, sy0, sx1 - sx0, sy1 - sy0])
|
||||
}).collect();
|
||||
self.wire_pixel_scissors = self
|
||||
.gpu_wires
|
||||
.iter()
|
||||
.map(|wire| {
|
||||
let [x0, y0, x1, y1] = wire.vp_scissor?;
|
||||
let corners = [
|
||||
view_proj.project_point3(glam::Vec3::new(x0, y0, 0.0)),
|
||||
view_proj.project_point3(glam::Vec3::new(x1, y0, 0.0)),
|
||||
view_proj.project_point3(glam::Vec3::new(x0, y1, 0.0)),
|
||||
view_proj.project_point3(glam::Vec3::new(x1, y1, 0.0)),
|
||||
];
|
||||
let px: Vec<f32> = corners.iter().map(|c| (c.x + 1.0) * 0.5 * w).collect();
|
||||
let py: Vec<f32> = corners.iter().map(|c| (1.0 - c.y) * 0.5 * h).collect();
|
||||
let sx0 = px.iter().cloned().fold(f32::INFINITY, f32::min).max(0.0) as u32;
|
||||
let sy0 = py.iter().cloned().fold(f32::INFINITY, f32::min).max(0.0) as u32;
|
||||
let sx1 = (px.iter().cloned().fold(f32::NEG_INFINITY, f32::max) as u32).min(clip_w);
|
||||
let sy1 = (py.iter().cloned().fold(f32::NEG_INFINITY, f32::max) as u32).min(clip_h);
|
||||
if sx1 <= sx0 || sy1 <= sy0 {
|
||||
return None;
|
||||
}
|
||||
Some([sx0, sy0, sx1 - sx0, sy1 - sy0])
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
|
||||
/// Upload all 3DFACE entities as two batched GPU objects:
|
||||
/// - `gpu_face3d_fill`: filled triangles (1 buffer, 1 draw call)
|
||||
/// - `gpu_face3d_edges`: merged edge wires (1 buffer, 1 draw call)
|
||||
pub fn upload_face3d(&mut self, device: &wgpu::Device, face3d_wires: &[WireModel], all_wires: &[WireModel]) {
|
||||
let has_fills = !face3d_wires.is_empty()
|
||||
|| all_wires.iter().any(|w| !w.fill_tris.is_empty());
|
||||
pub fn upload_face3d(
|
||||
&mut self,
|
||||
device: &wgpu::Device,
|
||||
face3d_wires: &[WireModel],
|
||||
all_wires: &[WireModel],
|
||||
) {
|
||||
let has_fills =
|
||||
!face3d_wires.is_empty() || all_wires.iter().any(|w| !w.fill_tris.is_empty());
|
||||
if !has_fills {
|
||||
self.gpu_face3d_fill = None;
|
||||
self.gpu_face3d_edges = vec![];
|
||||
|
|
@ -725,7 +740,12 @@ impl Pipeline {
|
|||
let vp = clip_bounds;
|
||||
let msaa = &self.msaa_view;
|
||||
let [r, g, b, a] = bg_color;
|
||||
let clear_color = wgpu::Color { r: r as f64, g: g as f64, b: b as f64, a: a as f64 };
|
||||
let clear_color = wgpu::Color {
|
||||
r: r as f64,
|
||||
g: g as f64,
|
||||
b: b as f64,
|
||||
a: a as f64,
|
||||
};
|
||||
|
||||
// ── Pass 1: hatch fills ────────────────────────────────────────────
|
||||
{
|
||||
|
|
|
|||
|
|
@ -90,18 +90,18 @@ impl CubeRegion {
|
|||
11 => (PI, -FRAC_PI_4), // EDGE_BOT_BACK
|
||||
12 => (FRAC_PI_2, -FRAC_PI_4),
|
||||
13 => (-FRAC_PI_2, -FRAC_PI_4),
|
||||
14 => (FRAC_PI_4, 0.0), // EDGE_FRONT_RIGHT (between 0 and PI/2)
|
||||
15 => (-FRAC_PI_4, 0.0), // EDGE_FRONT_LEFT
|
||||
16 => (PI * 0.75, 0.0), // EDGE_BACK_RIGHT (between PI and PI/2)
|
||||
17 => (-PI * 0.75, 0.0), // EDGE_BACK_LEFT
|
||||
18 => (FRAC_PI_4, iso), // CORNER_TPF_R (FRONT+RIGHT)
|
||||
19 => (-FRAC_PI_4, iso), // CORNER_TPF_L (FRONT+LEFT)
|
||||
20 => (PI * 0.75, iso), // CORNER_TBK_R (BACK+RIGHT)
|
||||
21 => (-PI * 0.75, iso), // CORNER_TBK_L (BACK+LEFT)
|
||||
22 => (FRAC_PI_4, -iso), // CORNER_BTF_R
|
||||
23 => (-FRAC_PI_4, -iso), // CORNER_BTF_L
|
||||
24 => (PI * 0.75, -iso), // CORNER_BBK_R
|
||||
25 => (-PI * 0.75, -iso), // CORNER_BBK_L
|
||||
14 => (FRAC_PI_4, 0.0), // EDGE_FRONT_RIGHT (between 0 and PI/2)
|
||||
15 => (-FRAC_PI_4, 0.0), // EDGE_FRONT_LEFT
|
||||
16 => (PI * 0.75, 0.0), // EDGE_BACK_RIGHT (between PI and PI/2)
|
||||
17 => (-PI * 0.75, 0.0), // EDGE_BACK_LEFT
|
||||
18 => (FRAC_PI_4, iso), // CORNER_TPF_R (FRONT+RIGHT)
|
||||
19 => (-FRAC_PI_4, iso), // CORNER_TPF_L (FRONT+LEFT)
|
||||
20 => (PI * 0.75, iso), // CORNER_TBK_R (BACK+RIGHT)
|
||||
21 => (-PI * 0.75, iso), // CORNER_TBK_L (BACK+LEFT)
|
||||
22 => (FRAC_PI_4, -iso), // CORNER_BTF_R
|
||||
23 => (-FRAC_PI_4, -iso), // CORNER_BTF_L
|
||||
24 => (PI * 0.75, -iso), // CORNER_BBK_R
|
||||
25 => (-PI * 0.75, -iso), // CORNER_BBK_L
|
||||
_ => (0.0, 0.0),
|
||||
}
|
||||
}
|
||||
|
|
@ -909,11 +909,11 @@ pub fn build_geometry() -> (Vec<CubeVertex>, Vec<u32>) {
|
|||
&mut is,
|
||||
);
|
||||
for &([sx, sy, sz], region) in &[
|
||||
([1.0f32, 1.0, 1.0], CORNER_TBK_R), // sy=+1 = BACK yönü
|
||||
([1.0f32, 1.0, 1.0], CORNER_TBK_R), // sy=+1 = BACK yönü
|
||||
([-1.0, 1.0, 1.0], CORNER_TBK_L),
|
||||
([1.0, 1.0, -1.0], CORNER_BBK_R),
|
||||
([-1.0, 1.0, -1.0], CORNER_BBK_L),
|
||||
([1.0, -1.0, 1.0], CORNER_TPF_R), // sy=-1 = FRONT yönü
|
||||
([1.0, -1.0, 1.0], CORNER_TPF_R), // sy=-1 = FRONT yönü
|
||||
([-1.0, -1.0, 1.0], CORNER_TPF_L),
|
||||
([1.0, -1.0, -1.0], CORNER_BTF_R),
|
||||
([-1.0, -1.0, -1.0], CORNER_BTF_L),
|
||||
|
|
@ -934,32 +934,32 @@ pub fn build_geometry() -> (Vec<CubeVertex>, Vec<u32>) {
|
|||
pub fn region_centroids() -> [[f32; 3]; NUM_REGIONS] {
|
||||
let m = (F + E) * 0.5;
|
||||
[
|
||||
[0.0, 0.0, E], // FACE_TOP
|
||||
[0.0, 0.0, -E], // FACE_BOTTOM
|
||||
[0.0, -E, 0.0], // FACE_FRONT (geometry Y=-E)
|
||||
[0.0, E, 0.0], // FACE_BACK (geometry Y=+E)
|
||||
[E, 0.0, 0.0], // FACE_RIGHT
|
||||
[-E, 0.0, 0.0], // FACE_LEFT
|
||||
[0.0, -m, m], // EDGE_TOP_FRONT
|
||||
[0.0, m, m], // EDGE_TOP_BACK
|
||||
[m, 0.0, m], // EDGE_TOP_RIGHT
|
||||
[-m, 0.0, m], // EDGE_TOP_LEFT
|
||||
[0.0, -m, -m], // EDGE_BOT_FRONT
|
||||
[0.0, m, -m], // EDGE_BOT_BACK
|
||||
[m, 0.0, -m], // EDGE_BOT_RIGHT
|
||||
[-m, 0.0, -m], // EDGE_BOT_LEFT
|
||||
[m, -m, 0.0], // EDGE_FRONT_RIGHT
|
||||
[-m, -m, 0.0], // EDGE_FRONT_LEFT
|
||||
[m, m, 0.0], // EDGE_BACK_RIGHT
|
||||
[-m, m, 0.0], // EDGE_BACK_LEFT
|
||||
[m, -m, m], // CORNER_TPF_R (geometry sy=-1 = FRONT)
|
||||
[-m, -m, m], // CORNER_TPF_L
|
||||
[m, m, m], // CORNER_TBK_R (geometry sy=+1 = BACK)
|
||||
[-m, m, m], // CORNER_TBK_L
|
||||
[m, -m, -m], // CORNER_BTF_R (geometry sy=-1 = FRONT)
|
||||
[-m, -m, -m], // CORNER_BTF_L
|
||||
[m, m, -m], // CORNER_BBK_R (geometry sy=+1 = BACK)
|
||||
[-m, m, -m], // CORNER_BBK_L
|
||||
[0.0, 0.0, E], // FACE_TOP
|
||||
[0.0, 0.0, -E], // FACE_BOTTOM
|
||||
[0.0, -E, 0.0], // FACE_FRONT (geometry Y=-E)
|
||||
[0.0, E, 0.0], // FACE_BACK (geometry Y=+E)
|
||||
[E, 0.0, 0.0], // FACE_RIGHT
|
||||
[-E, 0.0, 0.0], // FACE_LEFT
|
||||
[0.0, -m, m], // EDGE_TOP_FRONT
|
||||
[0.0, m, m], // EDGE_TOP_BACK
|
||||
[m, 0.0, m], // EDGE_TOP_RIGHT
|
||||
[-m, 0.0, m], // EDGE_TOP_LEFT
|
||||
[0.0, -m, -m], // EDGE_BOT_FRONT
|
||||
[0.0, m, -m], // EDGE_BOT_BACK
|
||||
[m, 0.0, -m], // EDGE_BOT_RIGHT
|
||||
[-m, 0.0, -m], // EDGE_BOT_LEFT
|
||||
[m, -m, 0.0], // EDGE_FRONT_RIGHT
|
||||
[-m, -m, 0.0], // EDGE_FRONT_LEFT
|
||||
[m, m, 0.0], // EDGE_BACK_RIGHT
|
||||
[-m, m, 0.0], // EDGE_BACK_LEFT
|
||||
[m, -m, m], // CORNER_TPF_R (geometry sy=-1 = FRONT)
|
||||
[-m, -m, m], // CORNER_TPF_L
|
||||
[m, m, m], // CORNER_TBK_R (geometry sy=+1 = BACK)
|
||||
[-m, m, m], // CORNER_TBK_L
|
||||
[m, -m, -m], // CORNER_BTF_R (geometry sy=-1 = FRONT)
|
||||
[-m, -m, -m], // CORNER_BTF_L
|
||||
[m, m, -m], // CORNER_BBK_R (geometry sy=+1 = BACK)
|
||||
[-m, m, -m], // CORNER_BBK_L
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -146,8 +146,18 @@ impl WireGpu {
|
|||
|
||||
for wire in wires {
|
||||
let color = wire.color;
|
||||
let pat0 = [wire.pattern[0], wire.pattern[1], wire.pattern[2], wire.pattern[3]];
|
||||
let pat1 = [wire.pattern[4], wire.pattern[5], wire.pattern[6], wire.pattern[7]];
|
||||
let pat0 = [
|
||||
wire.pattern[0],
|
||||
wire.pattern[1],
|
||||
wire.pattern[2],
|
||||
wire.pattern[3],
|
||||
];
|
||||
let pat1 = [
|
||||
wire.pattern[4],
|
||||
wire.pattern[5],
|
||||
wire.pattern[6],
|
||||
wire.pattern[7],
|
||||
];
|
||||
let half_width = wire.line_weight_px * 0.5;
|
||||
let n = wire.points.len();
|
||||
let raw_segs = n.saturating_sub(1);
|
||||
|
|
@ -183,8 +193,12 @@ impl WireGpu {
|
|||
for i in 0..capped_segs {
|
||||
let a = wire.points[i];
|
||||
let b = wire.points[i + 1];
|
||||
if !a[0].is_finite() || !a[1].is_finite() || !a[2].is_finite()
|
||||
|| !b[0].is_finite() || !b[1].is_finite() || !b[2].is_finite()
|
||||
if !a[0].is_finite()
|
||||
|| !a[1].is_finite()
|
||||
|| !a[2].is_finite()
|
||||
|| !b[0].is_finite()
|
||||
|| !b[1].is_finite()
|
||||
|| !b[2].is_finite()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -193,18 +207,25 @@ impl WireGpu {
|
|||
let make = |which_end: f32, side: f32| -> WireVertex {
|
||||
let dist = if which_end < 0.5 { dist_a } else { dist_b };
|
||||
WireVertex {
|
||||
pos_a: a, pos_b: b, which_end, side, color,
|
||||
distance: dist, half_width,
|
||||
pos_a: a,
|
||||
pos_b: b,
|
||||
which_end,
|
||||
side,
|
||||
color,
|
||||
distance: dist,
|
||||
half_width,
|
||||
pattern_length: wire.pattern_length,
|
||||
_pad: 0.0, pat0, pat1,
|
||||
_pad: 0.0,
|
||||
pat0,
|
||||
pat1,
|
||||
}
|
||||
};
|
||||
vertices.push(make(0.0, -1.0));
|
||||
vertices.push(make(1.0, -1.0));
|
||||
vertices.push(make(1.0, 1.0));
|
||||
vertices.push(make(1.0, 1.0));
|
||||
vertices.push(make(0.0, -1.0));
|
||||
vertices.push(make(1.0, 1.0));
|
||||
vertices.push(make(0.0, 1.0));
|
||||
vertices.push(make(1.0, 1.0));
|
||||
vertices.push(make(0.0, 1.0));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue