Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions assets/locales/pending/move-drag-highlights.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
"en": {
"prefs.move_drag_highlights": "Highlight what is under the pointer while Move's arrows drag a component",
"prefs.move_drag_highlights_tip": "Off: while Move's arrows drag a component, nothing under the pointer is highlighted, which keeps large assemblies smooth. With a section or an analysis shown it is highlighted all the same, and a part dragged along its joints never highlights it."
},
"ar": {
"prefs.move_drag_highlights": "تمييز ما تحت المؤشر أثناء سحب مكوّن بأسهم أداة النقل",
"prefs.move_drag_highlights_tip": "عند الإيقاف: لا يُميَّز أي شيء تحت المؤشر أثناء سحب مكوّن بأسهم أداة النقل، فتبقى التجميعات الكبيرة سلسة. مع عرض مقطع أو تحليل يبقى التمييز كما هو، ولا يُميَّز شيء أبدًا عند سحب جزء على امتداد وصلاته."
},
"de": {
"prefs.move_drag_highlights": "Hervorheben, was unter dem Zeiger liegt, während die Pfeile von Verschieben eine Komponente ziehen",
"prefs.move_drag_highlights_tip": "Aus: Solange die Pfeile von Verschieben eine Komponente ziehen, wird nichts unter dem Zeiger hervorgehoben; so bleiben große Baugruppen flüssig. Mit einem Schnitt oder einer Analyse wird es trotzdem hervorgehoben, und ein entlang seiner Gelenke gezogenes Teil hebt nie etwas hervor."
},
"es": {
"prefs.move_drag_highlights": "Resaltar lo que hay bajo el puntero mientras las flechas de Mover arrastran un componente",
"prefs.move_drag_highlights_tip": "Desactivado: mientras las flechas de Mover arrastran un componente no se resalta nada bajo el puntero, y los ensamblajes grandes se mueven con fluidez. Con un corte o un análisis visible se resalta igualmente, y una pieza arrastrada a lo largo de sus uniones nunca lo resalta."
},
"fr": {
"prefs.move_drag_highlights": "Mettre en évidence ce qui est sous le pointeur pendant que les flèches de Déplacer font glisser un composant",
"prefs.move_drag_highlights_tip": "Désactivé : pendant que les flèches de Déplacer font glisser un composant, rien n’est mis en évidence sous le pointeur, ce qui garde les grands assemblages fluides. Avec une coupe ou une analyse affichée, la mise en évidence reste, et une pièce glissée le long de ses liaisons n’en montre jamais."
},
"he": {
"prefs.move_drag_highlights": "הדגשת מה שמתחת לסמן בזמן שחצי ההזזה גוררים רכיב",
"prefs.move_drag_highlights_tip": "כבוי: בזמן שחצי ההזזה גוררים רכיב, דבר אינו מודגש מתחת לסמן, וכך מכלולים גדולים נשארים חלקים. כשמוצג חתך או ניתוח ההדגשה נשארת, וחלק שנגרר לאורך המפרקים שלו לעולם אינו מדגיש."
},
"ja": {
"prefs.move_drag_highlights": "移動の矢印でコンポーネントをドラッグ中にポインターの下をハイライト",
"prefs.move_drag_highlights_tip": "オフ: 移動の矢印でコンポーネントをドラッグしている間はポインターの下をハイライトしないため、大きなアセンブリでも滑らかに動きます。断面や解析を表示中は通常どおりハイライトし、ジョイントに沿ってドラッグする部品ではハイライトしません。"
},
"ko": {
"prefs.move_drag_highlights": "이동 화살표로 구성 요소를 끄는 동안 포인터 아래 항목 강조 표시",
"prefs.move_drag_highlights_tip": "끄면 이동 화살표로 구성 요소를 끄는 동안 포인터 아래 항목을 강조 표시하지 않아 큰 어셈블리도 부드럽게 움직입니다. 단면이나 해석이 표시된 동안에는 그대로 강조 표시하며, 조인트를 따라 끄는 부품은 강조 표시하지 않습니다."
},
"vi": {
"prefs.move_drag_highlights": "Tô sáng thứ nằm dưới con trỏ khi các mũi tên của Di chuyển kéo một thành phần",
"prefs.move_drag_highlights_tip": "Tắt: khi các mũi tên của Di chuyển kéo một thành phần, không có gì dưới con trỏ được tô sáng, nhờ đó các cụm lắp ráp lớn vẫn mượt. Khi đang hiện mặt cắt hoặc phân tích thì vẫn tô sáng như thường, và chi tiết được kéo dọc theo khớp nối không bao giờ tô sáng."
},
"zh": {
"prefs.move_drag_highlights": "用移动的箭头拖动组件时高亮指针下的对象",
"prefs.move_drag_highlights_tip": "关闭:用移动的箭头拖动组件时,不高亮指针下的对象,大型装配体也能保持流畅。显示剖切或分析时仍照常高亮;沿关节拖动零件时从不高亮。"
}
}
34 changes: 26 additions & 8 deletions assets/shaders/viewport.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ struct U {
ana_c: array<vec4<f32>, 8>,
ana_f: vec4<f32>, // x = 1: stripe the negative draft and blocked faces
depth: vec4<f32>, // x = 1: reversed depth (1 near, 0 far); y, z: the faces' push (`FACE_BIAS`)
// Where the drawn geometry is moved in the world: identity, or a dragged component's move
// from where its scene was built (`MovingLayer`)
model: mat4x4<f32>,
tint: vec4<f32>, // xyz added to a whole hovered body's colour before lighting
sel: vec4<f32>, // xyz a whole selected body's colour before lighting
// the section hatch colours by part (`solidcraft_render::hatch`), the first the cap's own
Expand All @@ -25,6 +28,16 @@ struct U {
sky: vec4<f32>, // xyz = world up; w = 1: shade in linear light with a sky fill (#7974)
};

/// A scene's point in the world (see `U.model`).
fn placed(p: vec3<f32>) -> vec3<f32> {
return (u.model * vec4<f32>(p, 1.0)).xyz;
}

/// A scene's direction in the world (see `placed`).
fn turned(n: vec3<f32>) -> vec3<f32> {
return (u.model * vec4<f32>(n, 0.0)).xyz;
}

fn reversed() -> bool {
return u.depth.x > 0.5;
}
Expand Down Expand Up @@ -83,10 +96,11 @@ struct TOut {
};

@vertex
fn vs_tri(@location(0) p: vec3<f32>, @location(1) n: vec3<f32>, @location(2) c: u32) -> TOut {
fn vs_tri(@location(0) local: vec3<f32>, @location(1) n: vec3<f32>, @location(2) c: u32) -> TOut {
var o: TOut;
let p = placed(local);
o.pos = u.vp * vec4<f32>(p, 1.0);
o.n = n;
o.n = turned(n);
let e = palette_entry(c);
o.c = unpack_color(e.x);
o.h = e.y;
Expand All @@ -95,7 +109,8 @@ fn vs_tri(@location(0) p: vec3<f32>, @location(1) n: vec3<f32>, @location(2) c:
}

/// Shared triangles (in their part's own frame) drawn at one placement: the rows of its rigid
/// move (`r0`..`r2`, a point's coordinates are their dot products with (p, 1)) and its colour.
/// move (`r0`..`r2`, a point's coordinates are their dot products with (p, 1)) and its colour,
/// then moved like the rest of its scene (`placed`: a dragged component's layer).
/// The vertex colour (location 2) is not read.
@vertex
fn vs_tri_inst(
Expand All @@ -107,10 +122,11 @@ fn vs_tri_inst(
@location(6) c: u32,
) -> TOut {
let q = vec4<f32>(p, 1.0);
let wp = vec3<f32>(dot(r0, q), dot(r1, q), dot(r2, q));
let wp = placed(vec3<f32>(dot(r0, q), dot(r1, q), dot(r2, q)));
let pn = vec3<f32>(dot(r0.xyz, n), dot(r1.xyz, n), dot(r2.xyz, n));
var o: TOut;
o.pos = u.vp * vec4<f32>(wp, 1.0);
o.n = vec3<f32>(dot(r0.xyz, n), dot(r1.xyz, n), dot(r2.xyz, n));
o.n = turned(pn);
let e = palette_entry(c);
o.c = unpack_color(e.x);
o.h = e.y;
Expand Down Expand Up @@ -140,7 +156,7 @@ fn vs_tri_inst_flat(
@location(6) c: u32,
) -> FOut {
let q = vec4<f32>(p, 1.0);
let wp = vec3<f32>(dot(r0, q), dot(r1, q), dot(r2, q));
let wp = placed(vec3<f32>(dot(r0, q), dot(r1, q), dot(r2, q)));
var o: FOut;
o.pos = u.vp * vec4<f32>(wp, 1.0);
o.rp = wp - u.eye.xyz;
Expand Down Expand Up @@ -785,7 +801,9 @@ fn lifted_z(p: vec3<f32>, c: vec4<f32>, px: f32, half: vec2<f32>) -> f32 {
}

@vertex
fn vs_line(@builtin(vertex_index) vi: u32, @location(0) a: vec3<f32>, @location(1) b: vec3<f32>, @location(2) c: u32, @location(3) wbits: u32) -> LOut {
fn vs_line(@builtin(vertex_index) vi: u32, @location(0) local_a: vec3<f32>, @location(1) local_b: vec3<f32>, @location(2) c: u32, @location(3) wbits: u32) -> LOut {
let a = placed(local_a);
let b = placed(local_b);
var pa = a;
var pb = b;
var ca = u.vp * vec4<f32>(a, 1.0);
Expand Down Expand Up @@ -832,7 +850,7 @@ fn vs_line(@builtin(vertex_index) vi: u32, @location(0) a: vec3<f32>, @location(
var z = base.z;
if (lifted && base.w > 1e-6) {
let p = select(pa, pb, t > 0.5);
let g = grazing(p, octahedral(wbits & 4095u), octahedral((wbits >> 12u) & 4095u));
let g = grazing(p, turned(octahedral(wbits & 4095u)), turned(octahedral((wbits >> 12u) & 4095u)));
z = lifted_z(p, base, wd * 0.5 * g + 1.0, half);
}
var o: LOut;
Expand Down
72 changes: 72 additions & 0 deletions crates/doc/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,35 @@ impl ModelBody {
self.mesh.clone()
}

/// Identity of the display cells of the solid this body shows: its own, or for a rigidly
/// placed copy its definition's (shared by every placement of it).
fn solid_id(&self) -> usize {
self.mesh_placement.as_deref().map_or(Arc::as_ptr(&self.mesh) as usize, placed_mesh::PlacedMesh::definition_id)
}

/// How this body is drawn moved from `before`: [`crate::IDENTITY`] when it is `before` where
/// it stood (its meshes and plans the same), the rigid motion between them when it is the same
/// solid placed elsewhere (a dragged component's body: `before`'s meshes and plans drawn moved
/// show it; a definition shown where it is defined is its own placement), `None` when it is
/// another body or its geometry differs.
pub fn display_moved_from(&self, before: &ModelBody) -> Option<crate::Mat> {
if self.name != before.name || self.solid_id() != before.solid_id() {
return None;
}
let (now, was) = (self.mesh_placement.as_deref(), before.mesh_placement.as_deref());
if let (Some(now), Some(was)) = (now, was)
&& now.tolerance.to_bits() != was.tolerance.to_bits()
{
return None;
}
let at = |p: Option<&placed_mesh::PlacedMesh>| p.map_or(crate::IDENTITY, |p| *p.transform());
let (now, was) = (at(now), at(was));
if now == was {
return Some(crate::IDENTITY);
}
Some(crate::mat_mul(&now, &crate::mat_inverse(&was)?))
}

/// [`ModelBody::mesh`] as a shared mesh and the move that places it: for a rigid placement
/// of a definition, the definition's own mesh (the same one for every placement of it) and
/// the placement; for any other body its own mesh, unmoved. The mesh moved by the matrix is
Expand Down Expand Up @@ -8994,6 +9023,49 @@ mod world_placement_cache_tests {
assert!(Arc::ptr_eq(&original_mesh, &again.body("Block").unwrap().mesh()));
assert!(Arc::ptr_eq(&names, &crate::naming::face_names(again.body(&second_name).unwrap())));
}

/// A dragged component's bodies are drawn from the meshes and plans made where the drag found
/// them, moved: each is the same solid moved rigidly, the others stand where they were, and a
/// body whose geometry changed is no such move.
#[test]
fn a_moved_placement_is_drawn_moved_from_where_it_stood() {
// A placement moved, and the part moved off where it is defined.
for from_definition in [false, true] {
let mut doc = Document::new("placements");
let component = doc.add_component(Some("Part"), 0).unwrap();
doc.body_components.insert("Block".into(), component);
let start = if from_definition { crate::IDENTITY } else { crate::rigid(Vec3::new(10., 20., 0.), Vec3::ZERO, Vec3::Z, 0.4) };
let second = doc.add_occurrence(component, 0, start).unwrap();
let mut state = ModelState::default();
state.bodies.push(ModelBody::new("Block".into(), kernel::box_solid(Vec3::ZERO, Vec3::new(2., 3., 4.)).unwrap(), 1));
let before = world_state(&doc, &state).unwrap();
let delta = crate::rigid(Vec3::new(4., -7., 1.5), Vec3::new(1., 1., 0.), Vec3::new(0., 1., 1.), 0.6);
let moved = doc.occurrences.iter_mut().find(|o| o.id == second).unwrap();
moved.transform = crate::mat_mul(&delta, &moved.transform);
let after = world_state(&doc, &state).unwrap();
assert_eq!(after.bodies.len(), 2);
let mut moves = 0;
for now in &after.bodies {
let was = before.body(&now.name).unwrap();
let d = now.display_moved_from(was).unwrap();
if d == crate::IDENTITY {
assert!(Arc::ptr_eq(&now.mesh(), &was.mesh()), "{}: unchanged, the same mesh", now.name);
continue;
}
moves += 1;
assert!(d.iter().flatten().zip(delta.iter().flatten()).all(|(a, b)| (a - b).abs() < 1e-9), "{}: {d:?}", now.name);
// `was`'s mesh drawn moved is `now`'s.
for (p, q) in was.mesh().positions.iter().zip(&now.mesh().positions) {
assert!(crate::apply_point(&d, *p).dist(*q) < 1e-9);
}
}
assert_eq!(moves, 1, "from its definition: {from_definition}");
// Another body, or other geometry: no move draws it.
assert!(after.bodies[0].display_moved_from(&before.bodies[1]).is_none());
let other = ModelBody::new(before.bodies[0].name.clone(), kernel::box_solid(Vec3::ZERO, Vec3::new(1., 1., 1.)).unwrap(), 1);
assert!(other.display_moved_from(&before.bodies[0]).is_none());
}
}
}

#[cfg(test)]
Expand Down
10 changes: 10 additions & 0 deletions crates/doc/src/placed_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ impl PlacedMesh {
})
}

/// Identity of the definition's display cells, shared by every placement of it.
pub(super) fn definition_id(&self) -> usize {
Arc::as_ptr(&self.mesh) as usize
}

/// Where this placement puts the definition.
pub(super) fn transform(&self) -> &crate::Mat {
&self.transform
}

pub(super) fn mesh(&self) -> Arc<Mesh> {
Arc::new(self.moved(&reference_mesh(&self.body, &self.mesh, self.tolerance)))
}
Expand Down
Loading
Loading