forked from 1b-agent/opencadstudio-upstream
Merge pull request #857 from ramox81/codex/align-point-behavior
Align point command, properties, and display behavior
This commit is contained in:
74 files changed
+998
-191
No files matched your search
Vendored
+141
-7
@@ -20,9 +20,10 @@ use std::sync::Arc;
|
||||
|
||||
use acadrust::types::{Color as AcadColor, LineWeight, Transform, Vector3};
|
||||
use acadrust::{CadDocument, EntityType, Handle};
|
||||
use cadkernel::space::{Plane as KernelPlane, Vec3 as KernelVec3};
|
||||
|
||||
use crate::scene::convert::tessellate;
|
||||
use crate::scene::model::wire_model::{SnapHint, TangentGeom, WireModel};
|
||||
use crate::scene::model::wire_model::{PointMarker, SnapHint, TangentGeom, WireModel};
|
||||
|
||||
const MAX_NESTING_DEPTH: usize = 32;
|
||||
/// Skip wires whose world-AABB projects to fewer than this many pixels in
|
||||
@@ -38,6 +39,7 @@ pub struct LocalWire {
|
||||
/// Low-bit residual paired with `points` so block-instance wires keep
|
||||
/// sub-f32 precision once the renderer translates them to world space.
|
||||
pub points_low: Vec<[f32; 3]>,
|
||||
pub point_marker: Option<PointMarker>,
|
||||
/// SDF glyph quads for block-internal text, in block-local coordinates.
|
||||
/// Non-empty only when SDF text is on and this sub is a TEXT/MTEXT. The
|
||||
/// expand-time transform (`emit_wire`) maps each vertex to world exactly
|
||||
@@ -132,6 +134,7 @@ pub enum LocalSub {
|
||||
pub struct BlockDefn {
|
||||
pub subs: Vec<LocalSub>,
|
||||
pub base_point: Vector3,
|
||||
pub has_point_marker: bool,
|
||||
/// Union of every sub's local AABB (including nested-INSERT contributions
|
||||
/// resolved at expand time via their own defn's `aabb_local`). XY only —
|
||||
/// the wire renderer is 2D-dominant. Expressed in this defn's *offset*
|
||||
@@ -312,23 +315,49 @@ impl BlockCache {
|
||||
// many parents is re-walked per parent — real work on block-heavy
|
||||
// drawings — and the per-name walks are independent, so they fan out.
|
||||
let this: &Self = self;
|
||||
let resolved: Vec<(&String, [f32; 4])> = names
|
||||
let resolved: Vec<(&String, [f32; 4], bool)> = names
|
||||
.par_iter()
|
||||
.map(|name| {
|
||||
let mut visited: Vec<String> = Vec::new();
|
||||
(name, this.defn_aabb_recursive(name, &mut visited))
|
||||
let aabb = this.defn_aabb_recursive(name, &mut visited);
|
||||
visited.clear();
|
||||
let has_marker = this.defn_has_point_marker_recursive(name, &mut visited);
|
||||
(name, aabb, has_marker)
|
||||
})
|
||||
.collect();
|
||||
// Phase 2 (serial): store the AABB back into each defn.
|
||||
for (name, aabb) in resolved {
|
||||
for (name, aabb, has_marker) in resolved {
|
||||
if let Some(defn_arc) = self.defns.get_mut(name) {
|
||||
let mut defn = (**defn_arc).clone();
|
||||
defn.aabb_local = aabb;
|
||||
defn.has_point_marker = has_marker;
|
||||
*defn_arc = Arc::new(defn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn defn_has_point_marker_recursive(
|
||||
&self,
|
||||
block_name: &str,
|
||||
visited: &mut Vec<String>,
|
||||
) -> bool {
|
||||
if visited.iter().any(|name| name == block_name) {
|
||||
return false;
|
||||
}
|
||||
let Some(defn) = self.defns.get(block_name) else {
|
||||
return false;
|
||||
};
|
||||
visited.push(block_name.to_string());
|
||||
let found = defn.subs.iter().any(|sub| match sub {
|
||||
LocalSub::Wire(wire) => wire.point_marker.is_some(),
|
||||
LocalSub::Nested(insert) => {
|
||||
self.defn_has_point_marker_recursive(&insert.block_name, visited)
|
||||
}
|
||||
});
|
||||
visited.pop();
|
||||
found
|
||||
}
|
||||
|
||||
/// Returns the union AABB for `block_name`'s defn, expressed in **that
|
||||
/// defn's offset frame** (so its caller can store it in
|
||||
/// `BlockDefn.aabb_local` without a coordinate-frame mismatch).
|
||||
@@ -619,6 +648,7 @@ fn build_defn(
|
||||
BlockDefn {
|
||||
subs,
|
||||
base_point: crate::scene::render_graph::block_base_point(doc, block_name),
|
||||
has_point_marker: false,
|
||||
aabb_local: [0.0; 4],
|
||||
child_count: br.entity_handles.len(),
|
||||
}
|
||||
@@ -816,6 +846,7 @@ fn tessellate_sub_local(
|
||||
result.push(LocalWire {
|
||||
points: wire.points,
|
||||
points_low: wire.points_low,
|
||||
point_marker: wire.point_marker,
|
||||
text_verts: wire.text_verts,
|
||||
key_vertices: wire.key_vertices,
|
||||
snap_pts: wire.snap_pts,
|
||||
@@ -1069,7 +1100,7 @@ pub fn expand_insert(
|
||||
// Whole-Insert pixel-size LOD: if the entire Insert footprint projects
|
||||
// to sub-pixel size, skip it entirely.
|
||||
if let Some(wpp) = world_per_pixel {
|
||||
if aabb_pixel_size(insert_local, wpp) < MIN_PIXEL_SIZE {
|
||||
if !defn.has_point_marker && aabb_pixel_size(insert_local, wpp) < MIN_PIXEL_SIZE {
|
||||
return Some(vec![]);
|
||||
}
|
||||
}
|
||||
@@ -1244,6 +1275,9 @@ fn translated_prototype_wire(
|
||||
translate_double_single(&mut wire.points, &mut wire.points_low, delta);
|
||||
translate_double_single(&mut wire.fill_tris, &mut wire.fill_tris_low, delta);
|
||||
translate_double_single(&mut wire.pick_tris, &mut wire.pick_tris_low, delta);
|
||||
if let Some(marker) = &mut wire.point_marker {
|
||||
marker.origin += glam::DVec3::from_array(delta);
|
||||
}
|
||||
for (point, _) in &mut wire.snap_pts {
|
||||
point.x += delta[0];
|
||||
point.y += delta[1];
|
||||
@@ -1403,6 +1437,7 @@ struct StyleKey {
|
||||
/// bands vs thin wires of the same colour/style — in separate batches so the
|
||||
/// finalized WireModel carries one correct `world_width`.
|
||||
world_width: u32,
|
||||
point_marker: Option<PointMarkerKey>,
|
||||
aci: u8,
|
||||
plinegen: bool,
|
||||
/// Marks batches that emit only `fill_tris` with no wire `points`. The
|
||||
@@ -1422,6 +1457,15 @@ struct StyleKey {
|
||||
depth_bits: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
struct PointMarkerKey {
|
||||
origin: [u64; 3],
|
||||
normal: [u64; 3],
|
||||
axis_x: [u64; 3],
|
||||
axis_y: [u64; 3],
|
||||
viewport_percent: u32,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
struct BatchEntry {
|
||||
color: [f32; 4],
|
||||
@@ -1432,6 +1476,7 @@ struct BatchEntry {
|
||||
pattern: [f32; 8],
|
||||
line_weight_px: f32,
|
||||
world_width: f32,
|
||||
point_marker: Option<PointMarker>,
|
||||
aci: u8,
|
||||
plinegen: bool,
|
||||
/// Composed block-local draw-order offset for a band batch (see
|
||||
@@ -1511,6 +1556,7 @@ impl BatchEntry {
|
||||
pat: [f32; 8],
|
||||
lw_px: f32,
|
||||
world_width: f32,
|
||||
point_marker: Option<PointMarker>,
|
||||
aci: u8,
|
||||
plinegen: bool,
|
||||
_is_fill_only: bool,
|
||||
@@ -1533,6 +1579,7 @@ impl BatchEntry {
|
||||
pattern: pat,
|
||||
line_weight_px: lw_px,
|
||||
world_width,
|
||||
point_marker,
|
||||
aci,
|
||||
plinegen,
|
||||
fill_is_2d_solid,
|
||||
@@ -1582,6 +1629,7 @@ impl Batches {
|
||||
}
|
||||
}
|
||||
WireModel {
|
||||
point_marker: b.point_marker,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: b.world_width,
|
||||
depth_override: b.local_depth,
|
||||
@@ -1634,6 +1682,7 @@ fn style_key(
|
||||
pat: [f32; 8],
|
||||
lw_px: f32,
|
||||
world_width: f32,
|
||||
point_marker: Option<PointMarker>,
|
||||
aci: u8,
|
||||
plinegen: bool,
|
||||
is_fill_only: bool,
|
||||
@@ -1666,6 +1715,13 @@ fn style_key(
|
||||
],
|
||||
line_weight_px: lw_px.to_bits(),
|
||||
world_width: world_width.to_bits(),
|
||||
point_marker: point_marker.map(|marker| PointMarkerKey {
|
||||
origin: marker.origin.to_array().map(f64::to_bits),
|
||||
normal: marker.normal.to_array().map(f64::to_bits),
|
||||
axis_x: marker.axis_x.to_array().map(f64::to_bits),
|
||||
axis_y: marker.axis_y.to_array().map(f64::to_bits),
|
||||
viewport_percent: marker.viewport_percent.to_bits(),
|
||||
}),
|
||||
aci,
|
||||
plinegen,
|
||||
is_fill_only,
|
||||
@@ -2004,6 +2060,69 @@ fn transformed_wire_length_scale(lw: &LocalWire, xform: &Transform) -> f32 {
|
||||
}
|
||||
}
|
||||
|
||||
fn transformed_point_marker(marker: PointMarker, xform: &Transform) -> (PointMarker, f64) {
|
||||
let origin = xform.apply(Vector3::new(marker.origin.x, marker.origin.y, marker.origin.z));
|
||||
let map_direction = |direction: glam::DVec3| {
|
||||
let mapped = xform.matrix.transform_direction(Vector3::new(
|
||||
direction.x,
|
||||
direction.y,
|
||||
direction.z,
|
||||
));
|
||||
KernelVec3::new(mapped.x, mapped.y, mapped.z)
|
||||
};
|
||||
let mapped_normal = map_direction(marker.normal);
|
||||
let normal_scale = mapped_normal.length().max(f64::MIN_POSITIVE);
|
||||
let normal = mapped_normal.normalize().unwrap_or(KernelVec3::Z);
|
||||
let mapped_x = map_direction(marker.axis_x);
|
||||
let axis_x = (mapped_x - normal * mapped_x.dot(normal))
|
||||
.normalize()
|
||||
.unwrap_or(KernelVec3::X);
|
||||
let mapped_y = map_direction(marker.axis_y);
|
||||
let axis_y = (mapped_y - normal * mapped_y.dot(normal) - axis_x * mapped_y.dot(axis_x))
|
||||
.normalize()
|
||||
.or_else(|| normal.cross(axis_x).normalize())
|
||||
.unwrap_or(KernelVec3::Y);
|
||||
(
|
||||
PointMarker {
|
||||
origin: glam::DVec3::new(origin.x, origin.y, origin.z),
|
||||
normal: glam::DVec3::from_array(normal.to_array()),
|
||||
axis_x: glam::DVec3::from_array(axis_x.to_array()),
|
||||
axis_y: glam::DVec3::from_array(axis_y.to_array()),
|
||||
viewport_percent: marker.viewport_percent,
|
||||
},
|
||||
normal_scale,
|
||||
)
|
||||
}
|
||||
|
||||
fn transformed_marker_point(
|
||||
point: KernelVec3,
|
||||
source: PointMarker,
|
||||
target: PointMarker,
|
||||
axial_scale: f64,
|
||||
) -> KernelVec3 {
|
||||
let source_origin = KernelVec3::from(source.origin.to_array());
|
||||
let source_normal = KernelVec3::from(source.normal.to_array())
|
||||
.normalize()
|
||||
.unwrap_or(KernelVec3::Z);
|
||||
let delta = point - source_origin;
|
||||
let axial = delta.dot(source_normal);
|
||||
let source_plane = KernelPlane::from_axes(
|
||||
source.origin.to_array(),
|
||||
source.axis_x.to_array(),
|
||||
source.axis_y.to_array(),
|
||||
);
|
||||
let uv = source_plane
|
||||
.project_vector((delta - source_normal * axial).to_array())
|
||||
.unwrap_or([0.0; 2]);
|
||||
let target_plane = KernelPlane::from_axes(
|
||||
target.origin.to_array(),
|
||||
target.axis_x.to_array(),
|
||||
target.axis_y.to_array(),
|
||||
);
|
||||
KernelVec3::from(target_plane.point_at(uv))
|
||||
+ KernelVec3::from(target.normal.to_array()) * axial * axial_scale
|
||||
}
|
||||
|
||||
fn emit_wire(
|
||||
lw: &LocalWire,
|
||||
accum_xform: &Transform,
|
||||
@@ -2069,6 +2188,10 @@ fn emit_wire(
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
let marker_transform = lw
|
||||
.point_marker
|
||||
.map(|marker| transformed_point_marker(marker, accum_xform));
|
||||
let point_marker = marker_transform.map(|(marker, _)| marker);
|
||||
|
||||
// Only band wires take a per-child composed depth: their solid area is
|
||||
// what covers siblings, and their width already splits them into their own
|
||||
@@ -2089,6 +2212,7 @@ fn emit_wire(
|
||||
final_pat,
|
||||
final_lw_px,
|
||||
final_world_width,
|
||||
point_marker,
|
||||
final_aci,
|
||||
lw.plinegen,
|
||||
lw.is_fill_only,
|
||||
@@ -2118,6 +2242,7 @@ fn emit_wire(
|
||||
final_pat,
|
||||
final_lw_px,
|
||||
final_world_width,
|
||||
point_marker,
|
||||
final_aci,
|
||||
lw.plinegen,
|
||||
lw.is_fill_only,
|
||||
@@ -2151,11 +2276,20 @@ fn emit_wire(
|
||||
let pl = lw.points_low.get(idx).copied().unwrap_or([0.0; 3]);
|
||||
// Reconstruct the f64 source from (high, low) before applying the
|
||||
// insert transform — otherwise the low half is silently dropped.
|
||||
let v = accum_xform.apply(Vector3::new(
|
||||
let source = KernelVec3::new(
|
||||
p[0] as f64 + pl[0] as f64,
|
||||
p[1] as f64 + pl[1] as f64,
|
||||
p[2] as f64 + pl[2] as f64,
|
||||
));
|
||||
);
|
||||
let mapped = if let (Some(source_marker), Some((target_marker, axial_scale))) =
|
||||
(lw.point_marker, marker_transform)
|
||||
{
|
||||
transformed_marker_point(source, source_marker, target_marker, axial_scale)
|
||||
} else {
|
||||
let point = accum_xform.apply(Vector3::new(source.x, source.y, source.z));
|
||||
KernelVec3::new(point.x, point.y, point.z)
|
||||
};
|
||||
let v = Vector3::new(mapped.x, mapped.y, mapped.z);
|
||||
let qx = (v.x) as f32;
|
||||
let qy = (v.y) as f32;
|
||||
let qz = (v.z) as f32;
|
||||
|
||||
Vendored
+9
@@ -91,6 +91,15 @@ pub fn general_section(entity: &EntityType) -> PropSection {
|
||||
],
|
||||
};
|
||||
|
||||
if matches!(entity, EntityType::Point(_)) {
|
||||
section.props.retain(|prop| prop.field != "handle");
|
||||
let hyperlink = section.props.iter().position(|prop| prop.field == "hyperlink");
|
||||
let transparency = section.props.iter().position(|prop| prop.field == "transparency");
|
||||
if let (Some(hyperlink), Some(transparency)) = (hyperlink, transparency) {
|
||||
section.props.swap(hyperlink, transparency);
|
||||
}
|
||||
}
|
||||
|
||||
// Thickness (DXF 39) is a General-group property, but only the entity
|
||||
// types that carry an extrusion thickness expose it (line, circle, arc,
|
||||
// polyline, text, 2D solid, …). Show it right after Hyperlink for those.
|
||||
|
||||
@@ -748,6 +748,7 @@ fn tessellate_entity_inner(
|
||||
Vec::new()
|
||||
};
|
||||
return vec![WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -1107,6 +1108,7 @@ fn tessellate_entity_inner(
|
||||
(ins.insert_point.z) as f32,
|
||||
);
|
||||
let marker = WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -1504,6 +1506,7 @@ fn lod_stub_wire(
|
||||
// LOD boundary. #19.
|
||||
let stored_color = if selected { WireModel::SELECTED } else { color };
|
||||
WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -1597,6 +1600,7 @@ fn lod_stub_wire_3d(
|
||||
}
|
||||
let stored_color = if selected { WireModel::SELECTED } else { color };
|
||||
WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
|
||||
@@ -145,6 +145,7 @@ fn point_cloud_wires(
|
||||
};
|
||||
let (points, points_low) = points_to_ds(body_points);
|
||||
let mut wires = vec![WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -500,6 +501,7 @@ pub fn tessellate(
|
||||
None
|
||||
};
|
||||
elem_wires.push(WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -807,6 +809,7 @@ pub fn tessellate(
|
||||
ftl.push(lo);
|
||||
}
|
||||
wires.push(WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -856,6 +859,7 @@ pub fn tessellate(
|
||||
fpl.push(lo);
|
||||
}
|
||||
wires.push(WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -907,6 +911,7 @@ pub fn tessellate(
|
||||
low.push(ll);
|
||||
}
|
||||
wires.push(WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -939,6 +944,7 @@ pub fn tessellate(
|
||||
});
|
||||
}
|
||||
wires.push(WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -1001,6 +1007,7 @@ pub fn tessellate(
|
||||
(Vec::new(), Vec::new(), Vec::new())
|
||||
};
|
||||
out.push(WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -1045,6 +1052,7 @@ pub fn tessellate(
|
||||
(Vec::new(), Vec::new(), Vec::new())
|
||||
};
|
||||
out.push(WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -1086,6 +1094,7 @@ pub fn tessellate(
|
||||
// are empty → the early-return path above).
|
||||
if !sdf_verts.is_empty() {
|
||||
out.push(WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -1120,6 +1129,7 @@ pub fn tessellate(
|
||||
|
||||
if out.is_empty() {
|
||||
out.push(WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -1188,6 +1198,7 @@ pub fn tessellate(
|
||||
.map(|[kx, ky, kz]| [kx, ky, kz])
|
||||
.collect();
|
||||
return vec![WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -1310,7 +1321,10 @@ pub fn tessellate(
|
||||
} else {
|
||||
(Vec::new(), Vec::new(), Vec::new())
|
||||
};
|
||||
let point_marker =
|
||||
crate::entities::point::relative_marker_spec(entity, document);
|
||||
out.push(WireModel {
|
||||
point_marker,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: polyline_band_width(entity),
|
||||
depth_override: None,
|
||||
@@ -1354,6 +1368,7 @@ pub fn tessellate(
|
||||
(Vec::new(), Vec::new(), Vec::new())
|
||||
};
|
||||
out.push(WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
pick_tris: Vec::new(),
|
||||
@@ -1388,6 +1403,7 @@ pub fn tessellate(
|
||||
|
||||
if out.is_empty() {
|
||||
out.push(WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -1435,6 +1451,7 @@ pub fn tessellate(
|
||||
// treatment as the Contour arm, restarting the dash per segment.
|
||||
let (pick_tris, pick_tris_low) = points_to_ds(te.pick_tris);
|
||||
return vec![WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: polyline_band_width(entity),
|
||||
depth_override: None,
|
||||
@@ -1483,6 +1500,7 @@ pub fn tessellate(
|
||||
let (pick_tris, pick_tris_low) = points_to_ds(te.pick_tris);
|
||||
let world_width = widths.iter().copied().fold(0.0f32, f32::max);
|
||||
return vec![WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: widths,
|
||||
world_width,
|
||||
depth_override: None,
|
||||
@@ -1604,6 +1622,7 @@ pub fn tessellate(
|
||||
_ => (Vec::new(), Vec::new()),
|
||||
};
|
||||
vec![WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
|
||||
+49
-9
@@ -7367,14 +7367,30 @@ impl Scene {
|
||||
&self,
|
||||
wires: &Arc<Vec<WireModel>>,
|
||||
base_radius_px: f32,
|
||||
viewport_height_px: f32,
|
||||
include_line_weight: bool,
|
||||
) -> f32 {
|
||||
if let Some((base_epoch, base, changes)) = self.interaction_overlay_base() {
|
||||
let (_, changed) =
|
||||
self.interaction_overlay_changed_index(base_epoch, &changes);
|
||||
base.pick_radius_px(changed.pick_radius_px(base_radius_px))
|
||||
base.pick_radius_px(
|
||||
changed.pick_radius_px(
|
||||
base_radius_px,
|
||||
viewport_height_px,
|
||||
include_line_weight,
|
||||
),
|
||||
viewport_height_px,
|
||||
include_line_weight,
|
||||
)
|
||||
} else {
|
||||
self.cached_interaction_index(wires)
|
||||
.map_or(base_radius_px, |index| index.pick_radius_px(base_radius_px))
|
||||
.map_or(base_radius_px, |index| {
|
||||
index.pick_radius_px(
|
||||
base_radius_px,
|
||||
viewport_height_px,
|
||||
include_line_weight,
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7532,11 +7548,12 @@ impl Scene {
|
||||
{
|
||||
return crate::scene::pick::interaction_index::InteractionCandidates::all(wires);
|
||||
}
|
||||
let radius_px = if include_line_weight {
|
||||
self.indexed_interaction_pick_radius(&wires, radius_px)
|
||||
} else {
|
||||
radius_px
|
||||
};
|
||||
let radius_px = self.indexed_interaction_pick_radius(
|
||||
&wires,
|
||||
radius_px,
|
||||
bounds.height,
|
||||
include_line_weight,
|
||||
);
|
||||
let flat_ortho = view_rot.z_axis.x.abs() < 1e-9
|
||||
&& view_rot.z_axis.y.abs() < 1e-9
|
||||
&& (view_rot.w_axis.w - 1.0).abs() < 1e-6;
|
||||
@@ -7605,12 +7622,35 @@ impl Scene {
|
||||
{
|
||||
return crate::scene::pick::interaction_index::InteractionCandidates::all(wires);
|
||||
}
|
||||
let pad_px =
|
||||
self.indexed_interaction_pick_radius(&wires, 0.0, bounds.height, true);
|
||||
if flat_ortho {
|
||||
self.indexed_interaction_candidates_xy(wires, aabb, false)
|
||||
let world_x_px = ((view_rot.x_axis.x * bounds.width * 0.5).powi(2)
|
||||
+ (view_rot.x_axis.y * bounds.height * 0.5).powi(2))
|
||||
.sqrt();
|
||||
let world_y_px = ((view_rot.y_axis.x * bounds.width * 0.5).powi(2)
|
||||
+ (view_rot.y_axis.y * bounds.height * 0.5).powi(2))
|
||||
.sqrt();
|
||||
let scale = world_x_px.min(world_y_px);
|
||||
let pad = if scale > 1e-6 {
|
||||
pad_px as f64 / scale as f64
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
self.indexed_interaction_candidates_xy(
|
||||
wires,
|
||||
[aabb[0] - pad, aabb[1] - pad, aabb[2] + pad, aabb[3] + pad],
|
||||
false,
|
||||
)
|
||||
} else {
|
||||
self.indexed_interaction_candidates_screen(
|
||||
wires,
|
||||
screen_rect,
|
||||
[
|
||||
screen_rect[0] - pad_px,
|
||||
screen_rect[1] - pad_px,
|
||||
screen_rect[2] + pad_px,
|
||||
screen_rect[3] + pad_px,
|
||||
],
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
|
||||
+125
-13
@@ -49,6 +49,26 @@ pub enum TangentGeom {
|
||||
},
|
||||
}
|
||||
|
||||
/// Viewport-relative display transform for a point marker.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct PointMarker {
|
||||
pub origin: glam::DVec3,
|
||||
pub normal: glam::DVec3,
|
||||
pub axis_x: glam::DVec3,
|
||||
pub axis_y: glam::DVec3,
|
||||
pub viewport_percent: f32,
|
||||
}
|
||||
|
||||
impl PointMarker {
|
||||
pub fn resolve(self, point: glam::DVec3, view_height: f64) -> glam::DVec3 {
|
||||
let normal = self.normal.normalize_or(glam::DVec3::Z);
|
||||
let delta = point - self.origin;
|
||||
let axial = normal * delta.dot(normal);
|
||||
let scale = self.viewport_percent.max(0.0) as f64 * 0.01 * view_height.max(0.0);
|
||||
self.origin + axial + (delta - axial) * scale
|
||||
}
|
||||
}
|
||||
|
||||
/// A 1-D entity (line, arc, polyline) represented as an ordered set of
|
||||
/// world-space points rendered as a quad strip (TriangleList).
|
||||
///
|
||||
@@ -66,6 +86,8 @@ pub struct WireModel {
|
||||
/// "all-zero residual" (interactive draw / preview wires whose coordinates
|
||||
/// don't need sub-f32 precision). Tessellation from CAD f64 fills it.
|
||||
pub points_low: Vec<[f32; 3]>,
|
||||
/// Point-marker scaling shared by the GPU, picking, and plotting paths.
|
||||
pub point_marker: Option<PointMarker>,
|
||||
/// RGBA colour in [0, 1].
|
||||
pub color: [f32; 4],
|
||||
/// Whether this wire is currently selected.
|
||||
@@ -225,6 +247,7 @@ impl WireModel {
|
||||
/// Create a solid wire (no dash pattern, 1px weight).
|
||||
pub fn solid(name: String, points: Vec<[f32; 3]>, color: [f32; 4], selected: bool) -> Self {
|
||||
Self {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -263,10 +286,11 @@ impl WireModel {
|
||||
out.name = format!("preview_{}", self.name);
|
||||
out.color = Self::CYAN;
|
||||
out.selected = false;
|
||||
for p in &mut out.points {
|
||||
p[0] += delta.x;
|
||||
p[1] += delta.y;
|
||||
p[2] += delta.z;
|
||||
map_points(&mut out.points, &mut out.points_low, |point| {
|
||||
point + delta.as_dvec3()
|
||||
});
|
||||
if let Some(marker) = &mut out.point_marker {
|
||||
marker.origin += delta.as_dvec3();
|
||||
}
|
||||
if !out.text_verts.is_empty() {
|
||||
let (dx, dy, dz) = (delta.x as f64, delta.y as f64, delta.z as f64);
|
||||
@@ -301,6 +325,17 @@ impl WireModel {
|
||||
for p in &mut out.points_low {
|
||||
*p = (rotation * glam::Vec3::from_array(*p)).to_array();
|
||||
}
|
||||
if let Some(marker) = &mut out.point_marker {
|
||||
let center = center.as_dvec3();
|
||||
let rotation = glam::DQuat::from_axis_angle(
|
||||
axis.as_dvec3().normalize_or(glam::DVec3::Z),
|
||||
angle_rad as f64,
|
||||
);
|
||||
marker.origin = center + rotation * (marker.origin - center);
|
||||
marker.normal = (rotation * marker.normal).normalize_or(glam::DVec3::Z);
|
||||
marker.axis_x = (rotation * marker.axis_x).normalize_or(glam::DVec3::X);
|
||||
marker.axis_y = (rotation * marker.axis_y).normalize_or(glam::DVec3::Y);
|
||||
}
|
||||
if !out.text_verts.is_empty() {
|
||||
let center = center.as_dvec3();
|
||||
let axis = axis.as_dvec3().normalize_or_zero();
|
||||
@@ -323,10 +358,23 @@ impl WireModel {
|
||||
out.name = format!("preview_{}", self.name);
|
||||
out.color = Self::CYAN;
|
||||
out.selected = false;
|
||||
for p in &mut out.points {
|
||||
p[0] = center.x + (p[0] - center.x) * factor;
|
||||
p[1] = center.y + (p[1] - center.y) * factor;
|
||||
p[2] = center.z + (p[2] - center.z) * factor;
|
||||
if let Some(marker) = out.point_marker {
|
||||
let center = center.as_dvec3();
|
||||
let normal = marker.normal.normalize_or(glam::DVec3::Z);
|
||||
let target_origin = center + (marker.origin - center) * factor as f64;
|
||||
map_points(&mut out.points, &mut out.points_low, |point| {
|
||||
let delta = point - marker.origin;
|
||||
let axial = normal * delta.dot(normal);
|
||||
target_origin + (delta - axial) + axial * factor as f64
|
||||
});
|
||||
if let Some(target) = &mut out.point_marker {
|
||||
target.origin = target_origin;
|
||||
}
|
||||
} else {
|
||||
let center = center.as_dvec3();
|
||||
map_points(&mut out.points, &mut out.points_low, |point| {
|
||||
center + (point - center) * factor as f64
|
||||
});
|
||||
}
|
||||
if !out.text_verts.is_empty() {
|
||||
let (cx, cy, cz) = (center.x as f64, center.y as f64, center.z as f64);
|
||||
@@ -373,11 +421,22 @@ pub fn stretched_windows(
|
||||
})
|
||||
};
|
||||
|
||||
for p in &mut out.points {
|
||||
if inside(p[0], p[1]) {
|
||||
p[0] += delta.x;
|
||||
p[1] += delta.y;
|
||||
p[2] += delta.z;
|
||||
if let Some(marker) = out.point_marker {
|
||||
if inside(marker.origin.x as f32, marker.origin.y as f32) {
|
||||
map_points(&mut out.points, &mut out.points_low, |point| {
|
||||
point + delta.as_dvec3()
|
||||
});
|
||||
if let Some(target) = &mut out.point_marker {
|
||||
target.origin += delta.as_dvec3();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for p in &mut out.points {
|
||||
if inside(p[0], p[1]) {
|
||||
p[0] += delta.x;
|
||||
p[1] += delta.y;
|
||||
p[2] += delta.z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,6 +497,20 @@ pub fn stretched_windows(
|
||||
let point = glam::Vec3::from_array(*p);
|
||||
*p = (point - 2.0 * plane_normal.dot(point) * plane_normal).to_array();
|
||||
}
|
||||
if let Some(marker) = &mut out.point_marker {
|
||||
let p1 = p1.as_dvec3();
|
||||
let normal = plane_normal.as_dvec3();
|
||||
marker.origin -= 2.0 * normal.dot(marker.origin - p1) * normal;
|
||||
marker.normal =
|
||||
(marker.normal - 2.0 * normal.dot(marker.normal) * normal)
|
||||
.normalize_or(glam::DVec3::Z);
|
||||
marker.axis_x =
|
||||
(marker.axis_x - 2.0 * normal.dot(marker.axis_x) * normal)
|
||||
.normalize_or(glam::DVec3::X);
|
||||
marker.axis_y =
|
||||
(marker.axis_y - 2.0 * normal.dot(marker.axis_y) * normal)
|
||||
.normalize_or(glam::DVec3::Y);
|
||||
}
|
||||
// Glyph quads reflect wholesale (true mirror) — the caller only routes
|
||||
// text through here for MIRRTEXT-on; MIRRTEXT-off relocates via
|
||||
// `translated` so glyphs stay readable.
|
||||
@@ -466,6 +539,44 @@ pub fn stretched_windows(
|
||||
})
|
||||
.sum()
|
||||
}
|
||||
|
||||
pub fn point_world(&self, index: usize, view_height: f64) -> glam::DVec3 {
|
||||
let high = self.points[index];
|
||||
let low = self.points_low.get(index).copied().unwrap_or([0.0; 3]);
|
||||
let point = glam::DVec3::new(
|
||||
high[0] as f64 + low[0] as f64,
|
||||
high[1] as f64 + low[1] as f64,
|
||||
high[2] as f64 + low[2] as f64,
|
||||
);
|
||||
self.point_marker
|
||||
.map_or(point, |marker| marker.resolve(point, view_height))
|
||||
}
|
||||
}
|
||||
|
||||
fn map_points(
|
||||
points: &mut [[f32; 3]],
|
||||
points_low: &mut Vec<[f32; 3]>,
|
||||
map: impl Fn(glam::DVec3) -> glam::DVec3,
|
||||
) {
|
||||
let old_low = std::mem::take(points_low);
|
||||
points_low.reserve(points.len());
|
||||
for (index, high) in points.iter_mut().enumerate() {
|
||||
if !high[0].is_finite() || !high[1].is_finite() || !high[2].is_finite() {
|
||||
points_low.push([0.0; 3]);
|
||||
continue;
|
||||
}
|
||||
let low = old_low.get(index).copied().unwrap_or([0.0; 3]);
|
||||
let mapped = map(glam::DVec3::new(
|
||||
high[0] as f64 + low[0] as f64,
|
||||
high[1] as f64 + low[1] as f64,
|
||||
high[2] as f64 + low[2] as f64,
|
||||
));
|
||||
let (hx, lx) = WireModel::split_ds(mapped.x);
|
||||
let (hy, ly) = WireModel::split_ds(mapped.y);
|
||||
let (hz, lz) = WireModel::split_ds(mapped.z);
|
||||
*high = [hx, hy, hz];
|
||||
points_low.push([lx, ly, lz]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Map every glyph vertex's double-single world position through `f`, re-
|
||||
@@ -502,6 +613,7 @@ pub(crate) fn map_text_verts(
|
||||
impl Default for WireModel {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
point_marker: None,
|
||||
text_verts: Vec::new(),
|
||||
name: String::new(),
|
||||
points: Vec::new(),
|
||||
|
||||
+176
-20
@@ -208,6 +208,31 @@ pub fn click_hit<'a, W: WireSource + ?Sized>(
|
||||
let mut best_dist = f32::MAX;
|
||||
let mut best: Option<&str> = None;
|
||||
|
||||
for wire in wires.iter().filter(|wire| wire.point_marker.is_some()) {
|
||||
let tolerance = pick_tolerance_px(wire, lw_display, base_radius_px);
|
||||
let mut previous = None;
|
||||
for (index, point) in wire.points.iter().enumerate() {
|
||||
if !point[0].is_finite() {
|
||||
previous = None;
|
||||
continue;
|
||||
}
|
||||
let screen = world_to_screen(
|
||||
wire_point_world(wire, index, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
);
|
||||
if let Some(start) = previous {
|
||||
let distance = dist_point_to_segment(cursor, start, screen);
|
||||
if distance < tolerance && distance < best_dist {
|
||||
best_dist = distance;
|
||||
best = Some(wire.name.as_str());
|
||||
}
|
||||
}
|
||||
previous = Some(screen);
|
||||
}
|
||||
}
|
||||
|
||||
// World z only shifts the *screen* x/y when the view is tilted (orbit /
|
||||
// perspective). In the flat top-down ortho view — the case where hover lag
|
||||
// on large drawings actually bites — a wire's screen position depends only
|
||||
@@ -224,18 +249,21 @@ pub fn click_hit<'a, W: WireSource + ?Sized>(
|
||||
let Some(wire) = wires.source_wire(segment.wire) else {
|
||||
continue;
|
||||
};
|
||||
if wire.point_marker.is_some() {
|
||||
continue;
|
||||
}
|
||||
let start = segment.start as usize;
|
||||
if start + 1 >= wire.points.len() {
|
||||
continue;
|
||||
}
|
||||
let p0 = world_to_screen(
|
||||
wp64(wire.points[start], &wire.points_low, start),
|
||||
wire_point_world(wire, start, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
);
|
||||
let p1 = world_to_screen(
|
||||
wp64(wire.points[start + 1], &wire.points_low, start + 1),
|
||||
wire_point_world(wire, start + 1, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
@@ -249,23 +277,27 @@ pub fn click_hit<'a, W: WireSource + ?Sized>(
|
||||
} else {
|
||||
// Q: lazy projection — no Vec allocation per wire; NaN resets the segment chain.
|
||||
for wire in wires.iter() {
|
||||
if wire.point_marker.is_some() {
|
||||
continue;
|
||||
}
|
||||
let tol = pick_tolerance_px(wire, lw_display, base_radius_px);
|
||||
// Cheap AABB pre-reject (flat view only; never for the unbounded
|
||||
// sentinel used by previews / greeked text).
|
||||
if z_flat
|
||||
&& wire.point_marker.is_none()
|
||||
&& wire.aabb != WireModel::UNBOUNDED_AABB
|
||||
&& aabb_rejects(wire.aabb, cursor, tol, view_rot, eye, bounds)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let mut prev: Option<Point> = None;
|
||||
for (i, &[px, py, pz]) in wire.points.iter().enumerate() {
|
||||
for (i, &[px, _, _]) in wire.points.iter().enumerate() {
|
||||
if px.is_nan() {
|
||||
prev = None;
|
||||
continue;
|
||||
}
|
||||
let cur = world_to_screen(
|
||||
wp64([px, py, pz], &wire.points_low, i),
|
||||
wire_point_world(wire, i, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
@@ -450,24 +482,55 @@ pub fn click_hits_all<'a, W: WireSource + ?Sized>(
|
||||
return Vec::new();
|
||||
}
|
||||
let mut hits: Vec<(f32, &str)> = Vec::new();
|
||||
let mut marker_hits: HashMap<&str, f32> = HashMap::default();
|
||||
for wire in wires.iter().filter(|wire| wire.point_marker.is_some()) {
|
||||
let tolerance = pick_tolerance_px(wire, lw_display, base_radius_px);
|
||||
let mut previous = None;
|
||||
for (index, point) in wire.points.iter().enumerate() {
|
||||
if !point[0].is_finite() {
|
||||
previous = None;
|
||||
continue;
|
||||
}
|
||||
let screen = world_to_screen(
|
||||
wire_point_world(wire, index, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
);
|
||||
if let Some(start) = previous {
|
||||
let distance = dist_point_to_segment(cursor, start, screen);
|
||||
if distance < tolerance {
|
||||
marker_hits
|
||||
.entry(wire.name.as_str())
|
||||
.and_modify(|best| *best = best.min(distance))
|
||||
.or_insert(distance);
|
||||
}
|
||||
}
|
||||
previous = Some(screen);
|
||||
}
|
||||
}
|
||||
hits.extend(marker_hits.into_iter().map(|(name, distance)| (distance, name)));
|
||||
if let Some(segments) = wires.segments() {
|
||||
let mut best_by_wire: HashMap<u32, f32> = HashMap::default();
|
||||
for segment in segments {
|
||||
let Some(wire) = wires.source_wire(segment.wire) else {
|
||||
continue;
|
||||
};
|
||||
if wire.point_marker.is_some() {
|
||||
continue;
|
||||
}
|
||||
let start = segment.start as usize;
|
||||
if start + 1 >= wire.points.len() {
|
||||
continue;
|
||||
}
|
||||
let p0 = world_to_screen(
|
||||
wp64(wire.points[start], &wire.points_low, start),
|
||||
wire_point_world(wire, start, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
);
|
||||
let p1 = world_to_screen(
|
||||
wp64(wire.points[start + 1], &wire.points_low, start + 1),
|
||||
wire_point_world(wire, start + 1, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
@@ -487,17 +550,20 @@ pub fn click_hits_all<'a, W: WireSource + ?Sized>(
|
||||
}));
|
||||
} else {
|
||||
for wire in wires.iter() {
|
||||
if wire.point_marker.is_some() {
|
||||
continue;
|
||||
}
|
||||
let tol = pick_tolerance_px(wire, lw_display, base_radius_px);
|
||||
let mut prev: Option<Point> = None;
|
||||
let mut best_for_wire = tol;
|
||||
let mut hit = false;
|
||||
for (i, &[px, py, pz]) in wire.points.iter().enumerate() {
|
||||
for (i, &[px, _, _]) in wire.points.iter().enumerate() {
|
||||
if px.is_nan() {
|
||||
prev = None;
|
||||
continue;
|
||||
}
|
||||
let cur = world_to_screen(
|
||||
wp64([px, py, pz], &wire.points_low, i),
|
||||
wire_point_world(wire, i, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
@@ -1104,13 +1170,13 @@ fn indexed_box_crossing_hits<'a, W: WireSource + ?Sized>(
|
||||
continue;
|
||||
}
|
||||
let a = world_to_screen(
|
||||
wp64(wire.points[start], &wire.points_low, start),
|
||||
wire_point_world(wire, start, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
);
|
||||
let b = world_to_screen(
|
||||
wp64(wire.points[start + 1], &wire.points_low, start + 1),
|
||||
wire_point_world(wire, start + 1, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
@@ -1119,6 +1185,14 @@ fn indexed_box_crossing_hits<'a, W: WireSource + ?Sized>(
|
||||
out.push(wire.name.as_str());
|
||||
}
|
||||
}
|
||||
for wire in wires.iter().filter(|wire| wire.point_marker.is_some()) {
|
||||
if !seen.contains(wire.name.as_str())
|
||||
&& marker_segment_hit(wire, view_rot, eye, bounds, |a, b| segment_hits(a, b))
|
||||
&& seen.insert(wire.name.as_str())
|
||||
{
|
||||
out.push(wire.name.as_str());
|
||||
}
|
||||
}
|
||||
for (triangles, pick_only) in [
|
||||
(wires.fill_triangles().unwrap_or_default(), false),
|
||||
(wires.pick_triangles().unwrap_or_default(), true),
|
||||
@@ -1181,7 +1255,7 @@ fn indexed_box_crossing_hits<'a, W: WireSource + ?Sized>(
|
||||
if wire.points.iter().enumerate().any(|(index, &point)| {
|
||||
point[0].is_finite()
|
||||
&& inside(world_to_screen(
|
||||
wp64(point, &wire.points_low, index),
|
||||
wire_point_world(wire, index, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
@@ -1231,13 +1305,13 @@ pub fn poly_fence_hit<'a, W: WireSource + ?Sized>(
|
||||
continue;
|
||||
}
|
||||
let a = world_to_screen(
|
||||
wp64(wire.points[start], &wire.points_low, start),
|
||||
wire_point_world(wire, start, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
);
|
||||
let b = world_to_screen(
|
||||
wp64(wire.points[start + 1], &wire.points_low, start + 1),
|
||||
wire_point_world(wire, start + 1, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
@@ -1246,6 +1320,14 @@ pub fn poly_fence_hit<'a, W: WireSource + ?Sized>(
|
||||
out.push(wire.name.as_str());
|
||||
}
|
||||
}
|
||||
for wire in wires.iter().filter(|wire| wire.point_marker.is_some()) {
|
||||
if !seen.contains(wire.name.as_str())
|
||||
&& marker_segment_hit(wire, view_rot, eye, bounds, |a, b| cuts(a, b))
|
||||
&& seen.insert(wire.name.as_str())
|
||||
{
|
||||
out.push(wire.name.as_str());
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
for wire in wires.iter() {
|
||||
@@ -1254,13 +1336,13 @@ pub fn poly_fence_hit<'a, W: WireSource + ?Sized>(
|
||||
}
|
||||
let hit = (0..wire.points.len() - 1).any(|k| {
|
||||
let a = world_to_screen(
|
||||
wp64(wire.points[k], &wire.points_low, k),
|
||||
wire_point_world(wire, k, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
);
|
||||
let b = world_to_screen(
|
||||
wp64(wire.points[k + 1], &wire.points_low, k + 1),
|
||||
wire_point_world(wire, k + 1, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
@@ -1292,13 +1374,13 @@ fn indexed_polygon_crossing_hits<'a, W: WireSource + ?Sized>(
|
||||
continue;
|
||||
}
|
||||
let a = world_to_screen(
|
||||
wp64(wire.points[start], &wire.points_low, start),
|
||||
wire_point_world(wire, start, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
);
|
||||
let b = world_to_screen(
|
||||
wp64(wire.points[start + 1], &wire.points_low, start + 1),
|
||||
wire_point_world(wire, start + 1, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
@@ -1311,6 +1393,18 @@ fn indexed_polygon_crossing_hits<'a, W: WireSource + ?Sized>(
|
||||
out.push(wire.name.as_str());
|
||||
}
|
||||
}
|
||||
for wire in wires.iter().filter(|wire| wire.point_marker.is_some()) {
|
||||
if !seen.contains(wire.name.as_str())
|
||||
&& marker_segment_hit(wire, view_rot, eye, bounds, |a, b| {
|
||||
point_in_polygon(a, poly)
|
||||
|| point_in_polygon(b, poly)
|
||||
|| segment_crosses_polygon(a, b, poly)
|
||||
})
|
||||
&& seen.insert(wire.name.as_str())
|
||||
{
|
||||
out.push(wire.name.as_str());
|
||||
}
|
||||
}
|
||||
for (triangles, pick_only) in [
|
||||
(wires.fill_triangles().unwrap_or_default(), false),
|
||||
(wires.pick_triangles().unwrap_or_default(), true),
|
||||
@@ -1371,7 +1465,12 @@ fn indexed_polygon_crossing_hits<'a, W: WireSource + ?Sized>(
|
||||
if wire.points.iter().enumerate().any(|(index, &point)| {
|
||||
point[0].is_finite()
|
||||
&& point_in_polygon(
|
||||
world_to_screen(wp64(point, &wire.points_low, index), view_rot, eye, bounds),
|
||||
world_to_screen(
|
||||
wire_point_world(wire, index, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
),
|
||||
poly,
|
||||
)
|
||||
}) && seen.insert(wire.name.as_str())
|
||||
@@ -1473,7 +1572,12 @@ pub fn box_hit<'a, W: WireSource + ?Sized>(
|
||||
prev = None;
|
||||
continue;
|
||||
}
|
||||
let sp = world_to_screen(wp64([px, py, pz], low, i), view_rot, eye, bounds);
|
||||
let world = if !wire.points.is_empty() {
|
||||
wire_point_world(wire, i, view_rot, eye)
|
||||
} else {
|
||||
wp64([px, py, pz], low, i)
|
||||
};
|
||||
let sp = world_to_screen(world, view_rot, eye, bounds);
|
||||
if crossing {
|
||||
if inside(sp) {
|
||||
hit = true;
|
||||
@@ -1595,7 +1699,12 @@ pub fn poly_hit<'a, W: WireSource + ?Sized>(
|
||||
prev = None;
|
||||
continue;
|
||||
}
|
||||
let sp = world_to_screen(wp64([px, py, pz], low, i), view_rot, eye, bounds);
|
||||
let world = if !wire.points.is_empty() {
|
||||
wire_point_world(wire, i, view_rot, eye)
|
||||
} else {
|
||||
wp64([px, py, pz], low, i)
|
||||
};
|
||||
let sp = world_to_screen(world, view_rot, eye, bounds);
|
||||
// Reject points the GPU scissored out of a floating viewport so
|
||||
// the lasso can't reach clipped geometry. No-op in model space.
|
||||
if sp.x < 0.0 || sp.x > bounds.width || sp.y < 0.0 || sp.y > bounds.height {
|
||||
@@ -1694,6 +1803,53 @@ fn wp64(hi: [f32; 3], low: &[[f32; 3]], i: usize) -> glam::DVec3 {
|
||||
)
|
||||
}
|
||||
|
||||
fn wire_point_world(
|
||||
wire: &WireModel,
|
||||
index: usize,
|
||||
view_rot: Mat4,
|
||||
eye: glam::DVec3,
|
||||
) -> glam::DVec3 {
|
||||
let Some(marker) = wire.point_marker else {
|
||||
return wire.point_world(index, 0.0);
|
||||
};
|
||||
let row_y = glam::DVec3::new(
|
||||
view_rot.x_axis.y as f64,
|
||||
view_rot.y_axis.y as f64,
|
||||
view_rot.z_axis.y as f64,
|
||||
);
|
||||
let projection_scale = row_y.length().max(1.0e-12);
|
||||
let relative = (marker.origin - eye).as_vec3().extend(1.0);
|
||||
let clip_w = (view_rot * relative).w.abs().max(1.0e-6);
|
||||
wire.point_world(index, 2.0 * clip_w as f64 / projection_scale)
|
||||
}
|
||||
|
||||
fn marker_segment_hit(
|
||||
wire: &WireModel,
|
||||
view_rot: Mat4,
|
||||
eye: glam::DVec3,
|
||||
bounds: Rectangle,
|
||||
mut hit: impl FnMut(Point, Point) -> bool,
|
||||
) -> bool {
|
||||
let mut previous = None;
|
||||
for (index, point) in wire.points.iter().enumerate() {
|
||||
if !point[0].is_finite() {
|
||||
previous = None;
|
||||
continue;
|
||||
}
|
||||
let screen = world_to_screen(
|
||||
wire_point_world(wire, index, view_rot, eye),
|
||||
view_rot,
|
||||
eye,
|
||||
bounds,
|
||||
);
|
||||
if previous.is_some_and(|start| hit(start, screen)) {
|
||||
return true;
|
||||
}
|
||||
previous = Some(screen);
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Even-odd ray-casting test: is `p` inside the polygon?
|
||||
///
|
||||
/// Handles multi-path boundaries: NaN points (used as path separators by
|
||||
|
||||
@@ -557,7 +557,9 @@ pub struct InteractionIndex {
|
||||
pick_triangles: SpatialSet<TriangleRef>,
|
||||
glyphs: SpatialSet<GlyphRef>,
|
||||
unbounded_wires: Vec<u32>,
|
||||
screen_unbounded_wires: Vec<u32>,
|
||||
max_line_half_width_px: f32,
|
||||
max_marker_radius_fraction: f32,
|
||||
}
|
||||
|
||||
pub struct InteractionHandleIndex {
|
||||
@@ -574,7 +576,9 @@ struct WireIndexEntries {
|
||||
pick_triangles: Vec<Entry3<TriangleRef>>,
|
||||
glyphs: Vec<Entry3<GlyphRef>>,
|
||||
unbounded: bool,
|
||||
screen_unbounded: bool,
|
||||
max_line_half_width_px: f32,
|
||||
max_marker_radius_fraction: f32,
|
||||
}
|
||||
|
||||
fn collect_wire_index_entries(wire_idx: u32, wire: &WireModel) -> WireIndexEntries {
|
||||
@@ -591,28 +595,34 @@ fn collect_wire_index_entries(wire_idx: u32, wire: &WireModel) -> WireIndexEntri
|
||||
pick_triangles: Vec::with_capacity(wire.pick_tris.len() / 3),
|
||||
glyphs: Vec::with_capacity(wire.text_verts.len() / 6),
|
||||
unbounded: false,
|
||||
screen_unbounded: wire.point_marker.is_some(),
|
||||
max_line_half_width_px: if wire.line_weight_px.is_finite() {
|
||||
(wire.line_weight_px * 0.5).max(0.0)
|
||||
} else {
|
||||
0.0
|
||||
},
|
||||
max_marker_radius_fraction: wire.point_marker.map_or(0.0, |marker| {
|
||||
marker.viewport_percent.max(0.0) * 0.01 * std::f32::consts::SQRT_2
|
||||
}),
|
||||
};
|
||||
entries.unbounded = entries.wire.is_none();
|
||||
|
||||
for start in 0..wire.points.len().saturating_sub(1) {
|
||||
let Some(aabb) = points_aabb3([
|
||||
wire_point(wire, start),
|
||||
wire_point(wire, start + 1),
|
||||
]) else {
|
||||
continue;
|
||||
};
|
||||
entries.segments.push(Entry3 {
|
||||
aabb,
|
||||
value: SegmentRef {
|
||||
wire: wire_idx,
|
||||
start: start as u32,
|
||||
},
|
||||
});
|
||||
if wire.point_marker.is_none() {
|
||||
for start in 0..wire.points.len().saturating_sub(1) {
|
||||
let Some(aabb) = points_aabb3([
|
||||
wire_point(wire, start),
|
||||
wire_point(wire, start + 1),
|
||||
]) else {
|
||||
continue;
|
||||
};
|
||||
entries.segments.push(Entry3 {
|
||||
aabb,
|
||||
value: SegmentRef {
|
||||
wire: wire_idx,
|
||||
start: start as u32,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
for (index, (point, _)) in wire.snap_pts.iter().enumerate() {
|
||||
if point.is_finite() {
|
||||
@@ -773,7 +783,9 @@ impl InteractionIndex {
|
||||
let collect_started = iced::time::Instant::now();
|
||||
let mut wire_entries = Vec::with_capacity(wires.len());
|
||||
let mut unbounded_wires = Vec::new();
|
||||
let mut screen_unbounded_wires = Vec::new();
|
||||
let mut max_line_half_width_px = 0.0f32;
|
||||
let mut max_marker_radius_fraction = 0.0f32;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let per_wire: Vec<WireIndexEntries> = {
|
||||
@@ -804,12 +816,17 @@ impl InteractionIndex {
|
||||
for (wire_idx, entries) in per_wire.into_iter().enumerate() {
|
||||
max_line_half_width_px =
|
||||
max_line_half_width_px.max(entries.max_line_half_width_px);
|
||||
max_marker_radius_fraction =
|
||||
max_marker_radius_fraction.max(entries.max_marker_radius_fraction);
|
||||
if let Some(entry) = entries.wire {
|
||||
wire_entries.push(entry);
|
||||
}
|
||||
if entries.unbounded {
|
||||
unbounded_wires.push(wire_idx as u32);
|
||||
}
|
||||
if entries.screen_unbounded {
|
||||
screen_unbounded_wires.push(wire_idx as u32);
|
||||
}
|
||||
segment_parts.push(entries.segments);
|
||||
snap_point_parts.push(entries.snap_points);
|
||||
key_vertex_parts.push(entries.key_vertices);
|
||||
@@ -952,7 +969,9 @@ impl InteractionIndex {
|
||||
pick_triangles,
|
||||
glyphs,
|
||||
unbounded_wires,
|
||||
screen_unbounded_wires,
|
||||
max_line_half_width_px,
|
||||
max_marker_radius_fraction,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1002,12 +1021,30 @@ impl InteractionIndex {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pick_radius_px(&self, base_radius_px: f32) -> f32 {
|
||||
base_radius_px.max(self.max_line_half_width_px)
|
||||
pub fn pick_radius_px(
|
||||
&self,
|
||||
base_radius_px: f32,
|
||||
viewport_height_px: f32,
|
||||
include_line_weight: bool,
|
||||
) -> f32 {
|
||||
let radius = base_radius_px
|
||||
.max(self.max_marker_radius_fraction * viewport_height_px.max(0.0));
|
||||
if include_line_weight {
|
||||
radius.max(self.max_line_half_width_px)
|
||||
} else {
|
||||
radius
|
||||
}
|
||||
}
|
||||
|
||||
fn queried_wire_keys(&self, mut indices: Vec<u32>) -> Vec<(u64, u32)> {
|
||||
fn queried_wire_keys(
|
||||
&self,
|
||||
mut indices: Vec<u32>,
|
||||
include_screen_unbounded: bool,
|
||||
) -> Vec<(u64, u32)> {
|
||||
indices.extend_from_slice(&self.unbounded_wires);
|
||||
if include_screen_unbounded {
|
||||
indices.extend_from_slice(&self.screen_unbounded_wires);
|
||||
}
|
||||
let mut keys: Vec<(u64, u32)> = indices
|
||||
.into_iter()
|
||||
.filter_map(|index| {
|
||||
@@ -1029,7 +1066,7 @@ impl InteractionIndex {
|
||||
}
|
||||
|
||||
pub fn query_wire_keys_xy(&self, aabb: [f64; 4]) -> Vec<(u64, u32)> {
|
||||
self.queried_wire_keys(self.wires.query_xy(aabb))
|
||||
self.queried_wire_keys(self.wires.query_xy(aabb), false)
|
||||
}
|
||||
|
||||
pub fn query_wire_keys_screen(
|
||||
@@ -1039,7 +1076,10 @@ impl InteractionIndex {
|
||||
eye: DVec3,
|
||||
bounds: Rectangle,
|
||||
) -> Vec<(u64, u32)> {
|
||||
self.queried_wire_keys(self.wires.query_screen(screen_rect, view_rot, eye, bounds))
|
||||
self.queried_wire_keys(
|
||||
self.wires.query_screen(screen_rect, view_rot, eye, bounds),
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
fn remap_wire_index(
|
||||
@@ -1064,8 +1104,12 @@ impl InteractionIndex {
|
||||
&self,
|
||||
mut indices: Vec<u32>,
|
||||
slots: &rustc_hash::FxHashMap<(u64, u32), u32>,
|
||||
include_screen_unbounded: bool,
|
||||
) -> Vec<u32> {
|
||||
indices.extend_from_slice(&self.unbounded_wires);
|
||||
if include_screen_unbounded {
|
||||
indices.extend_from_slice(&self.screen_unbounded_wires);
|
||||
}
|
||||
let mut local: Vec<u32> = indices
|
||||
.into_iter()
|
||||
.filter_map(|index| self.remap_wire_index(index, slots))
|
||||
@@ -1100,7 +1144,11 @@ impl InteractionIndex {
|
||||
) -> InteractionCandidates {
|
||||
InteractionCandidates {
|
||||
wires,
|
||||
wire_indices: Some(self.remap_wire_indices(self.wires.query_xy(aabb), slots)),
|
||||
wire_indices: Some(self.remap_wire_indices(
|
||||
self.wires.query_xy(aabb),
|
||||
slots,
|
||||
false,
|
||||
)),
|
||||
segments: Some(self.remap_refs(
|
||||
self.segments.query_xy(aabb),
|
||||
slots,
|
||||
@@ -1164,6 +1212,7 @@ impl InteractionIndex {
|
||||
self.wires
|
||||
.query_screen(screen_rect, view_rot, eye, bounds),
|
||||
slots,
|
||||
true,
|
||||
)),
|
||||
segments: Some(self.remap_refs(
|
||||
self.segments
|
||||
@@ -1251,6 +1300,7 @@ impl InteractionIndex {
|
||||
) -> InteractionCandidates {
|
||||
let mut wire_indices = self.wires.query_screen(screen_rect, view_rot, eye, bounds);
|
||||
wire_indices.extend_from_slice(&self.unbounded_wires);
|
||||
wire_indices.extend_from_slice(&self.screen_unbounded_wires);
|
||||
wire_indices.sort_unstable();
|
||||
wire_indices.dedup();
|
||||
InteractionCandidates {
|
||||
@@ -1601,6 +1651,26 @@ impl<'a> Iterator for WireIter<'a> {
|
||||
}
|
||||
|
||||
fn finite_wire_aabb3(wire: &WireModel) -> Option<[f64; 6]> {
|
||||
if let Some(marker) = wire.point_marker {
|
||||
if !marker.origin.is_finite() {
|
||||
return None;
|
||||
}
|
||||
let normal = marker.normal.try_normalize().unwrap_or(DVec3::Z);
|
||||
let mut min_axial = 0.0f64;
|
||||
let mut max_axial = 0.0f64;
|
||||
for index in 0..wire.points.len() {
|
||||
let point = DVec3::from_array(wire_point(wire, index));
|
||||
if point.is_finite() {
|
||||
let axial = (point - marker.origin).dot(normal);
|
||||
min_axial = min_axial.min(axial);
|
||||
max_axial = max_axial.max(axial);
|
||||
}
|
||||
}
|
||||
return points_aabb3([
|
||||
(marker.origin + normal * min_axial).to_array(),
|
||||
(marker.origin + normal * max_axial).to_array(),
|
||||
]);
|
||||
}
|
||||
let [min_x, min_y, max_x, max_y] = wire.aabb;
|
||||
if !min_x.is_finite() || !min_y.is_finite() || !max_x.is_finite() || !max_y.is_finite() {
|
||||
return None;
|
||||
|
||||
+20
-1
@@ -14,6 +14,7 @@ use acadrust::entities::Insert;
|
||||
use acadrust::objects::{ObjectType, SpatialFilter};
|
||||
use acadrust::types::{Handle, Transform, Vector3};
|
||||
use acadrust::CadDocument;
|
||||
use cadkernel::geom2d::{contains, Curve, Line, Tolerance};
|
||||
|
||||
use crate::scene::model::wire_model::WireModel;
|
||||
|
||||
@@ -116,6 +117,12 @@ pub fn clip_wires(wires: &mut Vec<WireModel>, poly: &[[f64; 2]]) {
|
||||
.iter()
|
||||
.map(|&[x, y]| [(x - rx) as f32, (y - ry) as f32])
|
||||
.collect();
|
||||
let boundary: Vec<Curve> = poly
|
||||
.iter()
|
||||
.zip(poly.iter().cycle().skip(1))
|
||||
.take(poly.len())
|
||||
.map(|(&start, &end)| Curve::Line(Line { start, end }))
|
||||
.collect();
|
||||
|
||||
// Reconstruct an absolute-f64 wire point from its high/low pair, NaN-safe.
|
||||
let abs = |hi: [f32; 3], lo: [f32; 3]| -> [f64; 3] {
|
||||
@@ -127,7 +134,18 @@ pub fn clip_wires(wires: &mut Vec<WireModel>, poly: &[[f64; 2]]) {
|
||||
};
|
||||
|
||||
for w in wires.iter_mut() {
|
||||
if !w.points.is_empty() {
|
||||
let keep_marker = w.point_marker.map(|marker| {
|
||||
contains(
|
||||
&boundary,
|
||||
[marker.origin.x, marker.origin.y],
|
||||
Tolerance::default(),
|
||||
)
|
||||
});
|
||||
if keep_marker == Some(false) {
|
||||
w.points.clear();
|
||||
w.points_low.clear();
|
||||
w.point_marker = None;
|
||||
} else if keep_marker.is_none() && !w.points.is_empty() {
|
||||
// Absolute → local f32 (NaN separators preserved).
|
||||
let local: Vec<[f32; 3]> = (0..w.points.len())
|
||||
.map(|i| {
|
||||
@@ -257,6 +275,7 @@ pub fn frame_wire(
|
||||
lo.push([lx, ly, 0.0]);
|
||||
}
|
||||
WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
|
||||
@@ -111,7 +111,7 @@ impl WireInstance {
|
||||
}
|
||||
|
||||
/// Per-wire constants shared by every segment of a wire (storage path). std430
|
||||
/// layout: three vec4 then eight scalars = 80 B, matching `WireConst` in
|
||||
/// layout: three vec4, eight scalars, then three vec4 = 128 B, matching `WireConst` in
|
||||
/// wire_indexed.wgsl. `align_end` / `align_total` carry the "A"-type endpoint
|
||||
/// alignment (see `wire_distances`); 0.0 total = no alignment.
|
||||
#[repr(C)]
|
||||
@@ -132,6 +132,11 @@ pub struct WireConst {
|
||||
pub world_half_width: f32,
|
||||
pub _pad1: f32,
|
||||
pub _pad2: f32,
|
||||
/// Point-marker origin as a double-single pair. `marker_normal_scale.w`
|
||||
/// stores the viewport-height percentage; zero disables marker scaling.
|
||||
pub marker_origin_high: [f32; 4],
|
||||
pub marker_origin_low: [f32; 4],
|
||||
pub marker_normal_scale: [f32; 4],
|
||||
}
|
||||
|
||||
impl WireConst {
|
||||
@@ -189,6 +194,9 @@ pub struct PackedWireInstance {
|
||||
/// `world_half_width`). The shader interpolates across the segment.
|
||||
pub world_hw_a: f32,
|
||||
pub world_hw_b: f32,
|
||||
pub marker_origin_high: [f32; 4],
|
||||
pub marker_origin_low: [f32; 4],
|
||||
pub marker_normal_scale: [f32; 4],
|
||||
}
|
||||
|
||||
impl PackedWireInstance {
|
||||
@@ -213,6 +221,9 @@ impl PackedWireInstance {
|
||||
wgpu::VertexAttribute { offset: std::mem::offset_of!(PackedWireInstance, pos_b_low) as u64, shader_location: 8, format: wgpu::VertexFormat::Float32x3 },
|
||||
// taper = (world_hw_a, world_hw_b)
|
||||
wgpu::VertexAttribute { offset: std::mem::offset_of!(PackedWireInstance, world_hw_a) as u64, shader_location: 9, format: wgpu::VertexFormat::Float32x2 },
|
||||
wgpu::VertexAttribute { offset: std::mem::offset_of!(PackedWireInstance, marker_origin_high) as u64, shader_location: 10, format: wgpu::VertexFormat::Float32x4 },
|
||||
wgpu::VertexAttribute { offset: std::mem::offset_of!(PackedWireInstance, marker_origin_low) as u64, shader_location: 11, format: wgpu::VertexFormat::Float32x4 },
|
||||
wgpu::VertexAttribute { offset: std::mem::offset_of!(PackedWireInstance, marker_normal_scale) as u64, shader_location: 12, format: wgpu::VertexFormat::Float32x4 },
|
||||
];
|
||||
wgpu::VertexBufferLayout {
|
||||
array_stride: std::mem::size_of::<PackedWireInstance>() as u64,
|
||||
@@ -509,6 +520,22 @@ fn finite3(p: [f32; 3]) -> bool {
|
||||
p[0].is_finite() && p[1].is_finite() && p[2].is_finite()
|
||||
}
|
||||
|
||||
fn marker_metadata(wire: &WireModel) -> ([f32; 4], [f32; 4], [f32; 4]) {
|
||||
let Some(marker) = wire.point_marker else {
|
||||
return ([0.0; 4], [0.0; 4], [0.0; 4]);
|
||||
};
|
||||
let origin = marker.origin;
|
||||
let (hx, lx) = WireModel::split_ds(origin.x);
|
||||
let (hy, ly) = WireModel::split_ds(origin.y);
|
||||
let (hz, lz) = WireModel::split_ds(origin.z);
|
||||
let normal = marker.normal.as_vec3().normalize_or(glam::Vec3::Z);
|
||||
(
|
||||
[hx, hy, hz, 0.0],
|
||||
[lx, ly, lz, 0.0],
|
||||
[normal.x, normal.y, normal.z, marker.viewport_percent],
|
||||
)
|
||||
}
|
||||
|
||||
/// Emit packed per-segment instances (each carries the wire's constants).
|
||||
pub(crate) fn emit_wire_packed(
|
||||
wire: &WireModel,
|
||||
@@ -525,6 +552,7 @@ pub(crate) fn emit_wire_packed(
|
||||
return Vec::new();
|
||||
}
|
||||
let (dists, align_end, align_total) = wire_distances(wire);
|
||||
let (marker_origin_high, marker_origin_low, marker_normal_scale) = marker_metadata(wire);
|
||||
let low = |i: usize| -> [f32; 3] { wire.points_low.get(i).copied().unwrap_or([0.0; 3]) };
|
||||
let tw = |i: usize| -> f32 { wire.taper_widths.get(i).copied().unwrap_or(0.0) * 0.5 };
|
||||
let mut instances: Vec<PackedWireInstance> = Vec::with_capacity(seg_count);
|
||||
@@ -552,6 +580,9 @@ pub(crate) fn emit_wire_packed(
|
||||
world_half_width: wire.world_width * 0.5,
|
||||
world_hw_a: tw(i),
|
||||
world_hw_b: tw(i + 1),
|
||||
marker_origin_high,
|
||||
marker_origin_low,
|
||||
marker_normal_scale,
|
||||
});
|
||||
}
|
||||
instances
|
||||
@@ -566,6 +597,7 @@ pub(crate) fn emit_wire_native(
|
||||
draw_depth: f32,
|
||||
) -> (Vec<WireInstance>, WireConst) {
|
||||
let (dists, align_end, align_total) = wire_distances(wire);
|
||||
let (marker_origin_high, marker_origin_low, marker_normal_scale) = marker_metadata(wire);
|
||||
let cst = WireConst {
|
||||
color,
|
||||
pat0: [wire.pattern[0], wire.pattern[1], wire.pattern[2], wire.pattern[3]],
|
||||
@@ -578,6 +610,9 @@ pub(crate) fn emit_wire_native(
|
||||
world_half_width: wire.world_width * 0.5,
|
||||
_pad1: 0.0,
|
||||
_pad2: 0.0,
|
||||
marker_origin_high,
|
||||
marker_origin_low,
|
||||
marker_normal_scale,
|
||||
};
|
||||
let n = wire.points.len();
|
||||
let seg_count = n.saturating_sub(1);
|
||||
|
||||
+19
-5
@@ -160,6 +160,22 @@ impl Scene {
|
||||
let in_vp = |x: f32, y: f32| x >= vp_x0 && x <= vp_x1 && y >= vp_y0 && y <= vp_y1;
|
||||
|
||||
for wire in model_wires.iter() {
|
||||
let marker_view_height = wire.point_marker.map_or(view_height_eff, |marker| {
|
||||
if !use_perspective {
|
||||
return view_height_eff;
|
||||
}
|
||||
let relative = marker.origin
|
||||
- glam::DVec3::new(
|
||||
display_center_x,
|
||||
display_center_y,
|
||||
display_center_z,
|
||||
);
|
||||
let depth = relative.x * view_fwd_d.0
|
||||
+ relative.y * view_fwd_d.1
|
||||
+ relative.z * view_fwd_d.2;
|
||||
view_height_eff * (camera_dist_d - depth).max(0.001)
|
||||
/ camera_dist_d.max(0.001)
|
||||
});
|
||||
let projected_pts: Vec<[f32; 3]> = wire
|
||||
.points
|
||||
.iter()
|
||||
@@ -168,11 +184,8 @@ impl Scene {
|
||||
if mx.is_nan() || my.is_nan() || mz.is_nan() {
|
||||
return [f32::NAN; 3];
|
||||
}
|
||||
// Reconstruct absolute WCS from the double-single high
|
||||
// (`points`) + low (`points_low`) pair — the high f32
|
||||
// alone is ~0.5 m off at UTM scale.
|
||||
let lo = wire.points_low.get(pi).copied().unwrap_or([0.0; 3]);
|
||||
proj_abs(mx as f64 + lo[0] as f64, my as f64 + lo[1] as f64, mz as f64 + lo[2] as f64)
|
||||
let point = wire.point_world(pi, marker_view_height);
|
||||
proj_abs(point.x, point.y, point.z)
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -304,6 +317,7 @@ impl Scene {
|
||||
// residual is needed, and keeping the model wire's points_low
|
||||
// here would add a model-scale offset to the paper points.
|
||||
out.points_low = Vec::new();
|
||||
out.point_marker = None;
|
||||
out.snap_pts = snap_pts;
|
||||
out.key_vertices = key_vertices;
|
||||
// Tangent geometry is in model space and can't be trivially
|
||||
|
||||
@@ -309,6 +309,7 @@ pub fn apply_along(
|
||||
.into_iter()
|
||||
.filter(|s| s.len() >= 2)
|
||||
.map(|pts| WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
@@ -355,6 +356,7 @@ pub fn apply_along(
|
||||
xy = xy.max(y);
|
||||
}
|
||||
out.push(WireModel {
|
||||
point_marker: None,
|
||||
taper_widths: Vec::new(),
|
||||
world_width: 0.0,
|
||||
depth_override: None,
|
||||
|
||||
Reference in new issue
Block a user