Render: allow picking in the product view with a Body, Face or Component filter and outline the selection in the product pass only (#6426)
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"en": {
|
||||
"render.pick_body": "Body",
|
||||
"render.pick_face": "Face",
|
||||
"render.pick_help": "Choose Body, Face or Component. Click empty space to clear; Shift or Ctrl adds or toggles. Highlights appear only in the live product view."
|
||||
},
|
||||
"de": {
|
||||
"render.pick_body": "Körper",
|
||||
"render.pick_face": "Fläche",
|
||||
"render.pick_help": "Körper, Fläche oder Komponente wählen. Ein Klick ins Leere löscht die Auswahl; Umschalt oder Strg fügt hinzu oder schaltet um. Hervorhebungen erscheinen nur in der Live-Produktansicht."
|
||||
},
|
||||
"ja": {
|
||||
"render.pick_body": "ボディ",
|
||||
"render.pick_face": "面",
|
||||
"render.pick_help": "ボディ、面、コンポーネントを選択します。空白をクリックすると選択解除、Shift または Ctrl で追加・切り替えます。ハイライトはライブ製品ビューのみに表示されます。"
|
||||
},
|
||||
"zh": {
|
||||
"render.pick_body": "实体",
|
||||
"render.pick_face": "面",
|
||||
"render.pick_help": "选择实体、面或组件。单击空白处清除选择;Shift 或 Ctrl 可添加或切换选择。高亮仅显示在实时产品视图中。"
|
||||
},
|
||||
"ko": {
|
||||
"render.pick_body": "바디",
|
||||
"render.pick_face": "면",
|
||||
"render.pick_help": "바디, 면 또는 구성요소를 선택합니다. 빈 공간을 클릭하면 선택이 해제되고 Shift 또는 Ctrl로 추가하거나 전환합니다. 강조 표시는 실시간 제품 뷰에만 나타납니다."
|
||||
},
|
||||
"ar": {
|
||||
"render.pick_body": "الجسم",
|
||||
"render.pick_face": "الوجه",
|
||||
"render.pick_help": "اختر جسمًا أو وجهًا أو مكوّنًا. انقر في فراغ للمسح؛ Shift أو Ctrl للإضافة أو التبديل. لا يظهر التمييز إلا في عرض المنتج الحي."
|
||||
},
|
||||
"he": {
|
||||
"render.pick_body": "גוף",
|
||||
"render.pick_face": "פאה",
|
||||
"render.pick_help": "בחר גוף, פאה או רכיב. לחץ על שטח ריק כדי לנקות; Shift או Ctrl להוספה או להחלפה. ההדגשה מופיעה רק בתצוגת המוצר החיה."
|
||||
},
|
||||
"vi": {
|
||||
"render.pick_body": "Thân",
|
||||
"render.pick_face": "Mặt",
|
||||
"render.pick_help": "Chọn Thân, Mặt hoặc Thành phần. Bấm vào chỗ trống để bỏ chọn; Shift hoặc Ctrl để thêm hoặc đảo. Phần tô sáng chỉ hiện ở chế độ xem sản phẩm trực tiếp."
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,8 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
CommandSpec::new("select.set", "Select", select_set).icon("select")
|
||||
.noundo()
|
||||
.params("items: [{type: body|edge|face|feature|sketch_curve|sketch_point|profile, …}], add?: bool"),
|
||||
CommandSpec::new("select.filter", "Selection filter", select_filter).icon("select").noundo().doc_only()
|
||||
.params("mode: body|face|component → validated UI pick granularity; headless echo only, no document edits or undo"),
|
||||
CommandSpec::new("select.clear", "Clear Selection", select_clear).icon("select").noundo(),
|
||||
];
|
||||
|
||||
@@ -1199,6 +1201,19 @@ fn select_set(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Ok(json!({"selected": s.selection.len()}))
|
||||
}
|
||||
|
||||
fn select_filter(_s: &mut Session, p: &Value) -> Result<Value> {
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct Request {
|
||||
mode: String,
|
||||
}
|
||||
let request: Request = serde_json::from_value(p.clone()).map_err(|e| bad("select.filter", e.to_string()))?;
|
||||
if !matches!(request.mode.as_str(), "body" | "face" | "component") {
|
||||
return Err(bad("select.filter", "mode must be body, face or component"));
|
||||
}
|
||||
Ok(json!({"mode": request.mode}))
|
||||
}
|
||||
|
||||
fn select_clear(s: &mut Session, _p: &Value) -> Result<Value> {
|
||||
s.selection.clear();
|
||||
s.revision += 1;
|
||||
|
||||
@@ -3242,6 +3242,7 @@ impl Renderer {
|
||||
if cb.product {
|
||||
res.product.take(device, queue, &res.uniform, &res.uniform_bgl, cb.key, &cb.slot, None, false);
|
||||
res.product.sort_glass(queue, cb.back);
|
||||
res.highlight.take(device, queue, &res.uniform, &res.uniform_bgl, cb.hl_key, &cb.hl_slot, None, false);
|
||||
queue.write_buffer(&res.uniform, 0, &uniform_bytes(cb, cb.size_px[0], cb.size_px[1], res.linear_out, res.target.reversed_depth()));
|
||||
// The product picture goes through the window's pass too: offscreen when the targets
|
||||
// differ or it is drawn smaller, else straight into the window's pass.
|
||||
@@ -3434,7 +3435,7 @@ impl Renderer {
|
||||
}
|
||||
};
|
||||
let (m, sk, h, pv) = if cb.product {
|
||||
(&res.product, &res.empty, &res.empty, &res.empty)
|
||||
(&res.product, &res.empty, &res.highlight, &res.empty)
|
||||
} else if cb.pv_hide {
|
||||
(&res.model, &res.sketch, &res.highlight, &res.empty)
|
||||
} else {
|
||||
|
||||
@@ -286,6 +286,7 @@ pub(crate) fn render_offscreen(
|
||||
#[cfg(all(test, not(target_arch = "wasm32")))]
|
||||
pub(crate) fn render_product_offscreen(
|
||||
scene: GpuScene,
|
||||
highlight: Option<GpuScene>,
|
||||
view_proj: [[f32; 4]; 4],
|
||||
back: [f32; 3],
|
||||
eye: [f32; 4],
|
||||
@@ -294,7 +295,7 @@ pub(crate) fn render_product_offscreen(
|
||||
) -> Option<Vec<u8>> {
|
||||
offscreen(
|
||||
scene,
|
||||
None,
|
||||
highlight,
|
||||
view_proj,
|
||||
back,
|
||||
eye,
|
||||
|
||||
@@ -686,7 +686,6 @@ mod tests {
|
||||
"Strip",
|
||||
"Pick",
|
||||
"Component",
|
||||
"Product picking is not supported yet.",
|
||||
"The live preview shows direct light only and no shadows.",
|
||||
] {
|
||||
assert_ne!(locale.label(label), label, "{language}: {label}");
|
||||
@@ -696,6 +695,9 @@ mod tests {
|
||||
// rather than requiring its spelling to differ from English.
|
||||
assert!(locale.0.messages().contains_key("toolbar.render_studio"));
|
||||
assert_eq!(locale.label("STUDIO"), locale.text("toolbar.render_studio"));
|
||||
for id in ["render.pick_label", "render.pick_body", "render.pick_face", "render.pick_component", "render.pick_help"] {
|
||||
assert_ne!(locale.text(id), Locale::for_language("en").text(id), "{language}: {id}");
|
||||
}
|
||||
let session = solidcraft_engine::Session::default();
|
||||
for command in solidcraft_engine::command_specs().into_iter().filter(|c| c.planned.is_some() && crate::workspace::render_tab(c.tab)) {
|
||||
assert_ne!(locale.label(command.label), command.label, "{language}: {}", command.id);
|
||||
|
||||
@@ -332,6 +332,8 @@ pub struct UiState {
|
||||
pub pick_off: Vec<String>,
|
||||
/// A click on a face picks its whole body.
|
||||
pub pick_bodies: bool,
|
||||
/// A face picks its exact component occurrence in Design and Render.
|
||||
pub pick_components: bool,
|
||||
/// 0: shaded with edges, 1: shaded, 2: wireframe, 3: shaded with hidden edges.
|
||||
pub visual_style: u8,
|
||||
/// A soft shadow on the ground under the model (seen from above).
|
||||
@@ -362,6 +364,7 @@ impl Default for UiState {
|
||||
dark: true,
|
||||
pick_off: Vec::new(),
|
||||
pick_bodies: false,
|
||||
pick_components: false,
|
||||
visual_style: 0,
|
||||
ground_shadow: true,
|
||||
up_axis: Default::default(),
|
||||
@@ -1039,6 +1042,12 @@ impl SolveApp {
|
||||
{
|
||||
render_workspace::select_stage(self, stage);
|
||||
}
|
||||
if id == "select.filter" {
|
||||
let mode = v.get("mode").and_then(Value::as_str);
|
||||
self.ui.pick_bodies = mode == Some("body");
|
||||
self.ui.pick_components = mode == Some("component");
|
||||
self.ui.pick_off.retain(|kind| kind != "faces");
|
||||
}
|
||||
if id == "view.shots_strip"
|
||||
&& let Some(visible) = v.get("visible").and_then(Value::as_bool)
|
||||
{
|
||||
|
||||
@@ -33,8 +33,8 @@ pub(crate) struct NavCaps {
|
||||
impl NavCaps {
|
||||
/// The modelling viewport.
|
||||
pub const MODEL: NavCaps = NavCaps { orbit: true, pick: true };
|
||||
/// The Render workspace's product preview: the same navigation, nothing to select.
|
||||
pub const RENDER: NavCaps = NavCaps { orbit: true, pick: false };
|
||||
/// The Render workspace's product preview: shared navigation and product picking.
|
||||
pub const RENDER: NavCaps = NavCaps { orbit: true, pick: true };
|
||||
}
|
||||
|
||||
/// Supplies the scroll phases browsers omit, before the shared navigation sees input.
|
||||
@@ -290,7 +290,9 @@ pub(crate) fn modifier_motion(
|
||||
&& app.viewport.point_drag.is_none()
|
||||
&& app.viewport.text_drag.is_none()
|
||||
&& app.viewport.boxsel.is_none()
|
||||
&& !(picking && hover.is_some_and(|p| app.viewport.rect.is_some_and(|rect| crate::canvas::owns_pointer(app, &projection(app, rect), p))))
|
||||
&& !(picking
|
||||
&& !crate::render_workspace::active(app)
|
||||
&& hover.is_some_and(|p| app.viewport.rect.is_some_and(|rect| crate::canvas::owns_pointer(app, &projection(app, rect), p))))
|
||||
&& !hover.is_some_and(|p| app.viewport.layout.as_ref().is_some_and(|l| l.navigation.contains(p)));
|
||||
let next = crate::prefs::nav_preset(&app.preferences.nav).motion_mode(mods).zip(hover.filter(|p| owns && p.is_finite()));
|
||||
let previous = app.viewport.modifier_nav;
|
||||
@@ -569,7 +571,8 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e
|
||||
return true;
|
||||
}
|
||||
let proj = projection(app, rect);
|
||||
pick(app, &proj, p).is_empty() && crate::dim_view::hit(p).is_none() && crate::sketch_tools::glyph_at(p).is_none()
|
||||
pick(app, &proj, p).is_empty()
|
||||
&& (crate::render_workspace::active(app) || (crate::dim_view::hit(p).is_none() && crate::sketch_tools::glyph_at(p).is_none()))
|
||||
})
|
||||
};
|
||||
let openscad_orbit =
|
||||
|
||||
@@ -68,23 +68,29 @@ fn stage_tools(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
use crate::render_workspace::Stage;
|
||||
match app.render_workspace.view.stage {
|
||||
Stage::Look => {
|
||||
let disabled = ui.add_enabled_ui(false, |ui| {
|
||||
ui_kit::StageBar::caption(ui, crate::i18n::tr_label("Pick"));
|
||||
let mut selected = 0;
|
||||
ui_kit::segmented(
|
||||
ui_kit::StageBar::caption(ui, app.tr("render.pick_label"));
|
||||
let modes = ["body", "face", "component"];
|
||||
let mut selected = modes.iter().position(|mode| *mode == current_pick_mode(app)).unwrap_or(0);
|
||||
let pick = ui.add_enabled_ui(!crate::render_workspace::result_active(app), |ui| {
|
||||
if ui_kit::segmented(
|
||||
ui,
|
||||
&mut selected,
|
||||
&[crate::i18n::tr_label("Body"), crate::i18n::tr_label("Face"), crate::i18n::tr_label("Component")],
|
||||
&[app.tr("render.pick_body"), app.tr("render.pick_face"), app.tr("render.pick_component")],
|
||||
ui_kit::Segments {
|
||||
targets: &["render:pick:body", "render:pick:face", "render:pick:component"],
|
||||
icons: &["body", "surface", "component"],
|
||||
workspace_accent: true,
|
||||
dense: true,
|
||||
intrinsic: true,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
) && let Some(mode) = modes.get(selected)
|
||||
{
|
||||
let _ = app.run("select.filter", serde_json::json!({"mode":mode}));
|
||||
}
|
||||
});
|
||||
disabled.response.on_disabled_hover_text(crate::i18n::tr_label("Product picking is not supported yet."));
|
||||
crate::scenario::publish_target("render:pick", pick.response.rect);
|
||||
pick.response.on_hover_text(app.tr("render.pick_help"));
|
||||
ui_kit::StageBar::tool_gap(ui);
|
||||
for (id, label, icon) in
|
||||
[("appearance.paint", "render.paint_label", "appearance"), ("appearance.pick_up", "render.pick_up_label", "select")]
|
||||
@@ -101,7 +107,8 @@ fn stage_tools(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
}
|
||||
}
|
||||
ui_kit::StageBar::separator(ui);
|
||||
ui_kit::StageBar::note(ui, app.tr("render.stage_preview_note")).on_hover_text(app.tr("render.preview_lighting_help"));
|
||||
let note = ui_kit::StageBar::note(ui, app.tr("render.stage_preview_note")).on_hover_text(app.tr("render.preview_lighting_help"));
|
||||
crate::scenario::publish_rect("render:preview_note", note.rect);
|
||||
if ui_kit::StageBar::icon_action(ui, "settings", app.tr("render.preview_image_settings_help")).clicked() {
|
||||
app.start("render.settings.get");
|
||||
}
|
||||
@@ -156,6 +163,16 @@ pub(crate) fn overlays(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
shots_pill(app, ui, free);
|
||||
}
|
||||
|
||||
fn current_pick_mode(app: &SolveApp) -> &'static str {
|
||||
if app.ui.pick_components {
|
||||
"component"
|
||||
} else if app.ui.pick_bodies {
|
||||
"body"
|
||||
} else {
|
||||
"face"
|
||||
}
|
||||
}
|
||||
|
||||
fn shots_pill(app: &mut SolveApp, ui: &mut egui::Ui, free: Rect) {
|
||||
crate::shell::register_panel(app, "render:shots:show", None, None);
|
||||
if app.preferences.render_shots_strip {
|
||||
|
||||
@@ -538,6 +538,7 @@ pub fn enter(app: &mut SolveApp, render: bool) -> Result<(), String> {
|
||||
app.ui.tab = "MODEL".into();
|
||||
crate::render_ui::reset_shell(app);
|
||||
}
|
||||
app.viewport.hover = None;
|
||||
app.cam_anim = None;
|
||||
if !render {
|
||||
app.pending_fit = None;
|
||||
@@ -1644,9 +1645,29 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
app.viewport.rect = Some(rect);
|
||||
crate::viewport::refresh_layout(app, ui.ctx().pixels_per_point());
|
||||
let response = ui.interact(rect, ui.id().with("render_preview"), Sense::click_and_drag());
|
||||
// The modelling viewport's camera input (preset, Orbit around, zoom to the cursor, middle
|
||||
// double-click), with nothing to pick or select here.
|
||||
crate::navigation::handle(app, ui, rect, &response, crate::navigation::NavCaps::RENDER);
|
||||
let input = crate::navigation::handle(app, ui, rect, &response, crate::navigation::NavCaps::RENDER);
|
||||
let navigating = input.scroll != 0.0
|
||||
|| input.pinch != 1.0
|
||||
|| input.pan != egui::Vec2::ZERO
|
||||
|| input.middle
|
||||
|| input.secondary_down
|
||||
|| (input.primary_nav.is_some() && input.primary_down)
|
||||
|| input.mode.is_some()
|
||||
|| app.viewport.axis_drag.is_some()
|
||||
|| app.viewport.spin
|
||||
|| app.cam_anim.is_some();
|
||||
let hits = input
|
||||
.hover
|
||||
.filter(|_| input.inside && !navigating)
|
||||
.map(|p| crate::viewport::pick_cached(app, &crate::viewport::projection(app, rect), p))
|
||||
.unwrap_or_default();
|
||||
let candidate = crate::viewport::candidate(app, &hits);
|
||||
app.viewport.hover = candidate.as_ref().map(|(hit, _)| hit.clone());
|
||||
if response.clicked_by(egui::PointerButton::Primary) && input.inside && !navigating {
|
||||
let (add, toggle) =
|
||||
crate::tool_modifiers::selection_click(crate::tool_modifiers::Held::from_modifiers(input.mods), app.preferences.selection_shift_add_only);
|
||||
crate::viewport::select(app, candidate.map(|(_, sel)| sel), add, toggle);
|
||||
}
|
||||
let bg = app.render_workspace.view.draft.background;
|
||||
ui.painter().rect_filled(rect, 0.0, Color32::from_rgb(bg[0], bg[1], bg[2]));
|
||||
let result = (|| -> Result<(), String> {
|
||||
@@ -1695,6 +1716,14 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
let camera = app.cam;
|
||||
let radius = scene.bounds.diagonal().max(10.0) + scene.bounds.center().dist(camera.target);
|
||||
let eye = camera.eye();
|
||||
let highlight_key = crate::viewport::highlight_key(app);
|
||||
if highlight_key != app.viewport.hl_key {
|
||||
let overlay = crate::viewport::build_highlight(app);
|
||||
if let Ok(mut slot) = app.viewport.hl_slot.lock() {
|
||||
*slot = Some(overlay);
|
||||
}
|
||||
app.viewport.hl_key = highlight_key;
|
||||
}
|
||||
let slot = app.render_workspace.slot.clone();
|
||||
let callback = ViewportCallback(Frame {
|
||||
product: true,
|
||||
@@ -1702,8 +1731,8 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
slot: slot.clone(),
|
||||
sketch_key: 0,
|
||||
sketch_slot: slot.clone(),
|
||||
hl_key: 0,
|
||||
hl_slot: slot.clone(),
|
||||
hl_key: app.viewport.hl_key,
|
||||
hl_slot: app.viewport.hl_slot.clone(),
|
||||
pv_key: 0,
|
||||
pv_slot: slot,
|
||||
pv_hide: false,
|
||||
@@ -1721,8 +1750,11 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
ao_radius: 0.0,
|
||||
eye: [eye.x as f32, eye.y as f32, eye.z as f32, if camera.fov > 0.0 { 1.0 } else { 0.0 }],
|
||||
ssaa: if width < full.0 { width as f32 / full.0 as f32 } else { 1.0 },
|
||||
hover_tint: [0.0; 3],
|
||||
selection_tint: [0.0; 3],
|
||||
hover_tint: [f32::from(Tokens::get().hover_face_lift) / 255.0; 3],
|
||||
selection_tint: {
|
||||
let c = Tokens::get().body_selected;
|
||||
[f32::from(c.r()) / 255.0, f32::from(c.g()) / 255.0, f32::from(c.b()) / 255.0]
|
||||
},
|
||||
});
|
||||
ui.painter().add(egui_wgpu::Callback::new_paint_callback(rect, callback));
|
||||
Ok(())
|
||||
|
||||
@@ -307,6 +307,7 @@ fn opaque_pbr_product_gpu_and_cpu_share_color_and_material_semantics() {
|
||||
for srgb in [false, true] {
|
||||
let Some(gpu) = crate::gpu::render_product_offscreen(
|
||||
gpu.clone(),
|
||||
None,
|
||||
camera.view_proj(1.0, radius).to_f32(),
|
||||
camera.back().to_f32(),
|
||||
[eye[0], eye[1], eye[2], 0.0],
|
||||
@@ -1427,7 +1428,7 @@ fn nav_app(render: bool, preset: &str, around: crate::prefs::OrbitAround) -> cra
|
||||
app.preferences.orbit_around = around;
|
||||
app.preferences.zoom_to_cursor = true;
|
||||
app.ui.perspective = true;
|
||||
let mut cam = Camera::default();
|
||||
let mut cam = Camera { fov: 0.6, ..Default::default() };
|
||||
cam.set_view(solidcraft_engine::render::StandardView::Iso);
|
||||
cam.fit(&solidcraft_engine::product_scene::extract(&app.session).unwrap().bounds);
|
||||
app.cam = cam;
|
||||
@@ -1454,7 +1455,7 @@ fn render_preview_navigates_like_the_modelling_viewport_in_every_preset() {
|
||||
};
|
||||
both(vec![], none, &mut design, &mut render);
|
||||
assert_eq!(design.viewport.rect, render.viewport.rect);
|
||||
// Presses start on empty space (the Render preview has nothing to pick), and the wheel
|
||||
// Presses start on empty space in both workspaces, and the wheel
|
||||
// turns over the model, so zoom to the cursor anchors on its surface.
|
||||
let empty = pos2(90.0, 520.0);
|
||||
let proj = crate::viewport::projection(&design, design.viewport.rect.unwrap());
|
||||
@@ -1499,7 +1500,7 @@ fn render_preview_navigates_like_the_modelling_viewport_in_every_preset() {
|
||||
both(vec![Event::PointerMoved(empty)], none, &mut design, &mut render);
|
||||
assert_eq!(design.cam, render.cam, "{preset} {around:?}: modifier motion with {mods:?}");
|
||||
}
|
||||
assert!(render.session.selection.is_empty(), "the Render preview never selects");
|
||||
assert!(render.session.selection.is_empty(), "camera navigation must not select");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2844,8 +2845,11 @@ fn render_workspace_stage_chips_dispatch_without_mutations_and_remember_each_doc
|
||||
for stage in Stage::ALL {
|
||||
h.frames(3);
|
||||
h.step(&json!({"click":{"handle":format!("render:stage:{}",stage.key())}})).unwrap();
|
||||
h.frames(2);
|
||||
assert_eq!(h.app.render_workspace.view.stage, stage);
|
||||
assert_eq!(h.app.render_workspace.view.inspector.page, stage.page());
|
||||
assert_eq!(crate::scenario::rect_of("render:pick").is_some(), stage == Stage::Look);
|
||||
assert_eq!(crate::scenario::rect_of("render:preview_note").is_some(), stage == Stage::Look);
|
||||
assert!(Arc::ptr_eq(&h.app.session.doc, &document));
|
||||
assert_eq!((h.app.session.revision, h.app.session.undo.len(), h.app.session.redo.len()), history);
|
||||
assert!(h.app.render_workspace.view.job.is_none());
|
||||
@@ -3165,3 +3169,249 @@ fn render_workspace_card_grips_swap_sides_and_resize_without_design_edits() {
|
||||
assert_eq!((h.app.session.undo.len(), h.app.session.redo.len()), history);
|
||||
}
|
||||
}
|
||||
|
||||
/// A small public-safe model, built through the sample recipe inside an occurrence.
|
||||
fn render_pick_sample() -> (Harness, u64) {
|
||||
let mut h = Harness::new();
|
||||
let part = h.app.run("component.create", json!({"name":"Sample","grounded":false})).unwrap();
|
||||
let occurrence = part["occurrence"].as_u64().unwrap();
|
||||
h.app.session.run_script(&solidcraft_engine::sample::script()).unwrap();
|
||||
h.app.run("component.activate", json!({"component":0})).unwrap();
|
||||
enter(&mut h.app, true).unwrap();
|
||||
h.frames(4);
|
||||
h.app.start("render.camera.fit");
|
||||
h.settle();
|
||||
(h, occurrence)
|
||||
}
|
||||
|
||||
fn product_pick_point(h: &Harness) -> egui::Pos2 {
|
||||
let rect = h.app.viewport.layout.as_ref().unwrap().drawable;
|
||||
let proj = crate::viewport::projection(&h.app, h.app.viewport.rect.unwrap());
|
||||
for y in 2..18 {
|
||||
for x in 2..18 {
|
||||
let at = rect.min + egui::vec2(rect.width() * x as f32 / 20.0, rect.height() * y as f32 / 20.0);
|
||||
if !crate::shell::covered(&h.app, at)
|
||||
&& crate::viewport::pick(&h.app, &proj, at).iter().any(|h| matches!(h, crate::viewport::Hit::Face { .. }))
|
||||
{
|
||||
return at;
|
||||
}
|
||||
}
|
||||
}
|
||||
panic!("sample must offer a visible product face outside the floating panels");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_workspace_pick_stage_tools_filter_sample_clicks_with_shots_shown_and_hidden() {
|
||||
use solidcraft_engine::Sel;
|
||||
let (mut h, occurrence) = render_pick_sample();
|
||||
let doc = h.app.session.doc.clone();
|
||||
let undo = h.app.session.undo.len();
|
||||
for shots in [true, false] {
|
||||
h.app.run("view.shots_strip", json!({"visible":shots})).unwrap();
|
||||
h.frames(3);
|
||||
let tools = crate::scenario::rect_of("render:stage_tools").unwrap();
|
||||
assert!(tools.contains_rect(crate::scenario::rect_of("render:pick").unwrap()));
|
||||
assert!(tools.contains_rect(crate::scenario::rect_of("render:preview_note").unwrap()));
|
||||
assert!(crate::scenario::rect_of("render:hud").is_none());
|
||||
for mode in ["body", "face", "component"] {
|
||||
assert!(crate::scenario::handle_at(&format!("render:pick:{mode}")).is_some(), "Pick must be enabled");
|
||||
h.step(&json!({"click":{"handle":format!("render:pick:{mode}")}})).unwrap();
|
||||
h.frames(2);
|
||||
let at = product_pick_point(&h);
|
||||
h.step(&json!({"move":[at.x,at.y]})).unwrap();
|
||||
assert!(matches!(h.app.viewport.hover, Some(crate::viewport::Hit::Face { .. })));
|
||||
h.step(&json!({"click":[at.x,at.y]})).unwrap();
|
||||
match h.app.session.selection.as_slice() {
|
||||
[Sel::Body { name }] if mode == "body" => assert_eq!(name, "Plate"),
|
||||
[Sel::Face { body, .. }] if mode == "face" => assert_eq!(body, "Plate"),
|
||||
[Sel::Occurrence { path }] if mode == "component" => assert_eq!(path, &[occurrence]),
|
||||
other => panic!("{mode}, Shots {shots}: wrong selection {other:?}"),
|
||||
}
|
||||
let selected = h.app.session.selection.clone();
|
||||
enter(&mut h.app, false).unwrap();
|
||||
h.frames(3);
|
||||
assert_eq!(h.app.session.selection, selected);
|
||||
enter(&mut h.app, true).unwrap();
|
||||
h.settle();
|
||||
assert_eq!(h.app.session.selection, selected);
|
||||
}
|
||||
}
|
||||
assert!(Arc::ptr_eq(&doc, &h.app.session.doc));
|
||||
assert_eq!(h.app.session.undo.len(), undo);
|
||||
assert!(h.app.tool.is_none() && h.app.dialog.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_workspace_click_modifiers_clear_and_browser_share_selection() {
|
||||
use solidcraft_engine::Sel;
|
||||
let mut h = Harness::new();
|
||||
for (name, x) in [("Left", -30), ("Right", 30)] {
|
||||
h.app.run("solid.box", json!({"corner":[x,0,0],"length":20,"width":20,"height":20,"body_name":name})).unwrap();
|
||||
}
|
||||
enter(&mut h.app, true).unwrap();
|
||||
h.settle();
|
||||
h.app.run("select.filter", json!({"mode":"body"})).unwrap();
|
||||
let proj = crate::viewport::projection(&h.app, h.app.viewport.rect.unwrap());
|
||||
let left = proj.to_screen(solidcraft_engine::geom::Vec3::new(-20.0, 10.0, 20.0)).unwrap();
|
||||
let right = proj.to_screen(solidcraft_engine::geom::Vec3::new(40.0, 10.0, 20.0)).unwrap();
|
||||
h.step(&json!({"click":[left.x,left.y]})).unwrap();
|
||||
assert_eq!(h.app.session.selection, [Sel::Body { name: "Left".into() }]);
|
||||
h.step(&json!({"click":[right.x,right.y],"shift":true})).unwrap();
|
||||
assert_eq!(h.app.session.selection.len(), 2);
|
||||
h.step(&json!({"click":[left.x,left.y],"ctrl":true})).unwrap();
|
||||
assert_eq!(h.app.session.selection, [Sel::Body { name: "Right".into() }]);
|
||||
h.app.preferences.selection_shift_add_only = true;
|
||||
h.step(&json!({"click":[right.x,right.y],"shift":true})).unwrap();
|
||||
assert_eq!(h.app.session.selection, [Sel::Body { name: "Right".into() }]);
|
||||
// A Browser body row writes the same selection and immediately feeds the product overlay.
|
||||
h.step(&json!({"click":{"handle":"row:Left"}})).unwrap();
|
||||
assert_eq!(h.app.session.selection, [Sel::Body { name: "Left".into() }]);
|
||||
assert!(!crate::viewport::build_highlight(&h.app).merged().tris.is_empty());
|
||||
let empty = h.app.viewport.layout.as_ref().unwrap().drawable.left_bottom() + egui::vec2(10.0, -10.0);
|
||||
h.step(&json!({"click":[empty.x,empty.y]})).unwrap();
|
||||
assert!(h.app.session.selection.is_empty());
|
||||
assert!(h.app.viewport.hover.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_workspace_selection_overlay_never_changes_started_frames_png_or_retained_results() {
|
||||
use solidcraft_engine::Sel;
|
||||
let (mut h, _) = render_pick_sample();
|
||||
let at = product_pick_point(&h);
|
||||
let proj = crate::viewport::projection(&h.app, h.app.viewport.rect.unwrap());
|
||||
let hit = crate::viewport::pick(&h.app, &proj, at).into_iter().next().unwrap();
|
||||
let face = crate::viewport::hit_sel(&hit).unwrap();
|
||||
let first = completed_preview(&mut h, [230, 230, 230]);
|
||||
let clean = h.app.session.render_job_handle(first).unwrap().frame().unwrap().unwrap();
|
||||
let clean_scene = gpu_scene(&solidcraft_engine::product_scene::extract(&h.app.session).unwrap()).unwrap();
|
||||
h.app.run("select.set", json!({"items":[face]})).unwrap();
|
||||
let face_overlay = crate::viewport::build_highlight(&h.app).merged();
|
||||
assert!(!face_overlay.tris.is_empty());
|
||||
h.app.run("select.set", json!({"items":[Sel::Body { name:"Plate".into() }]})).unwrap();
|
||||
let body_overlay = crate::viewport::build_highlight(&h.app).merged();
|
||||
assert!(body_overlay.tris.len() > face_overlay.tris.len(), "Face must only tint the selected face");
|
||||
h.app.viewport.hover = Some(hit);
|
||||
let second = completed_preview(&mut h, [230, 230, 230]);
|
||||
let selected = h.app.session.render_job_handle(second).unwrap().frame().unwrap().unwrap();
|
||||
assert_eq!(clean.png(), selected.png(), "started image job must never capture selection or hover pixels");
|
||||
let after = gpu_scene(&solidcraft_engine::product_scene::extract(&h.app.session).unwrap()).unwrap();
|
||||
assert_eq!(clean_scene.0, after.0);
|
||||
assert_eq!(clean_scene.1.tris, after.1.tris);
|
||||
h.app.render_workspace.view.completed = Some(second);
|
||||
h.app.render_workspace.view.result = true;
|
||||
h.frames(3);
|
||||
h.app.run("select.filter", json!({"mode":"face"})).unwrap();
|
||||
h.step(&json!({"click":{"handle":"render:pick:body"}})).unwrap();
|
||||
assert!(!h.app.ui.pick_bodies && !h.app.ui.pick_components, "result canvas must disable the stage's Pick control");
|
||||
let path = h.dir.join("overlay-free.png");
|
||||
h.app.run("render.export", json!({"job":second,"path":path})).unwrap();
|
||||
assert_eq!(std::fs::read(path).unwrap(), clean.png());
|
||||
assert_eq!(h.app.session.render_job_handle(second).unwrap().frame().unwrap().unwrap().png(), clean.png());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_workspace_pick_filter_rejects_invalid_requests_atomically() {
|
||||
let mut h = Harness::new();
|
||||
let doc = h.app.session.doc.clone();
|
||||
for mode in ["body", "face", "component"] {
|
||||
assert_eq!(h.app.run("select.filter", json!({"mode":mode})).unwrap()["mode"], mode);
|
||||
assert_eq!(h.app.ui.pick_bodies, mode == "body");
|
||||
assert_eq!(h.app.ui.pick_components, mode == "component");
|
||||
}
|
||||
for request in [json!({}), json!({"mode":"edge"}), json!({"mode":"body","extra":true})] {
|
||||
assert!(h.app.run("select.filter", request).is_err());
|
||||
assert!(!h.app.ui.pick_bodies && h.app.ui.pick_components);
|
||||
}
|
||||
assert!(Arc::ptr_eq(&doc, &h.app.session.doc));
|
||||
assert!(h.app.session.undo.is_empty());
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn render_workspace_product_pass_draws_only_requested_face_or_body_overlay() {
|
||||
let mut app = nav_app(true, "fusion", crate::prefs::OrbitAround::ViewCentre);
|
||||
let rect = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(256.0, 256.0));
|
||||
app.viewport.rect = Some(rect);
|
||||
let proj = crate::viewport::projection(&app, rect);
|
||||
let hit = crate::viewport::pick(&app, &proj, rect.center()).into_iter().find(|h| matches!(h, crate::viewport::Hit::Face { .. })).unwrap();
|
||||
let face = crate::viewport::hit_sel(&hit).unwrap();
|
||||
let scene = solidcraft_engine::product_scene::extract(&app.session).unwrap();
|
||||
let gpu = gpu_scene(&scene).unwrap().1;
|
||||
let radius = scene.bounds.diagonal().max(10.0) + scene.bounds.center().dist(app.cam.target);
|
||||
let eye = app.cam.eye().to_f32();
|
||||
let camera = app.cam;
|
||||
let draw = |overlay| {
|
||||
crate::gpu::render_product_offscreen(
|
||||
gpu.clone(),
|
||||
overlay,
|
||||
camera.view_proj(1.0, radius).to_f32(),
|
||||
camera.back().to_f32(),
|
||||
[eye[0], eye[1], eye[2], 1.0],
|
||||
256,
|
||||
false,
|
||||
)
|
||||
};
|
||||
let Some(clean) = draw(None) else {
|
||||
eprintln!("skipping: no GPU adapter for product overlay pixels");
|
||||
return;
|
||||
};
|
||||
app.run("select.set", json!({"items":[face]})).unwrap();
|
||||
let face_pixels = draw(Some(crate::viewport::build_highlight(&app))).unwrap();
|
||||
app.run("select.set", json!({"items":[{"type":"body","name":"Product"}]})).unwrap();
|
||||
let body_pixels = draw(Some(crate::viewport::build_highlight(&app))).unwrap();
|
||||
let changed = |image: &[u8]| clean.as_chunks::<4>().0.iter().zip(image.as_chunks::<4>().0).filter(|(a, b)| a != b).count();
|
||||
assert!(changed(&face_pixels) > 100, "Face overlay must reach the product pass");
|
||||
assert!(changed(&body_pixels) > changed(&face_pixels) + 100, "Face must leave the other faces untouched");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_workspace_pick_projection_matches_orthographic_and_custom_perspective_camera() {
|
||||
use egui::{Event, Modifiers, PointerButton};
|
||||
use solidcraft_engine::geom::Vec3;
|
||||
for fov in [0.0, 0.6, 1.1] {
|
||||
let mut app = nav_app(true, "fusion", crate::prefs::OrbitAround::ViewCentre);
|
||||
app.cam.fov = fov;
|
||||
let ctx = crate::fonts::test_context();
|
||||
let mut time = 0.0;
|
||||
nav_frame(&mut app, &ctx, true, &mut time, Modifiers::NONE, vec![]);
|
||||
let rect = app.viewport.rect.unwrap();
|
||||
let proj = crate::viewport::projection(&app, rect);
|
||||
assert_eq!(proj.cam.fov, fov);
|
||||
let (x, y, _) = app.cam.to_screen(Vec3::new(20.0, 15.0, 20.0), f64::from(rect.width()), f64::from(rect.height()), 100.0).unwrap();
|
||||
let pos = rect.min + egui::vec2(x as f32, y as f32);
|
||||
nav_frame(&mut app, &ctx, true, &mut time, Modifiers::NONE, vec![Event::PointerMoved(pos)]);
|
||||
assert!(matches!(app.viewport.hover, Some(crate::viewport::Hit::Face { .. })), "FOV {fov}");
|
||||
for pressed in [true, false] {
|
||||
nav_frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
true,
|
||||
&mut time,
|
||||
Modifiers::NONE,
|
||||
vec![Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }],
|
||||
);
|
||||
}
|
||||
assert!(matches!(app.session.selection.as_slice(), [solidcraft_engine::Sel::Face { body, .. }] if body == "Product"), "FOV {fov}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_workspace_component_filter_keeps_nested_repeated_occurrences_distinct() {
|
||||
use crate::viewport::{Hit, candidate};
|
||||
use solidcraft_engine::{Sel, geom::Vec3};
|
||||
let mut h = Harness::new();
|
||||
let parent = h.app.run("component.create", json!({"name":"Parent"})).unwrap();
|
||||
let child = h.app.run("component.create", json!({"name":"Part"})).unwrap();
|
||||
h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Solid"})).unwrap();
|
||||
h.app.run("component.activate", json!({"component":0})).unwrap();
|
||||
let second = h.app.run("occurrence.copy", json!({"occurrence":parent["occurrence"],"translate":[50,0,0]})).unwrap();
|
||||
enter(&mut h.app, true).unwrap();
|
||||
h.app.run("select.filter", json!({"mode":"component"})).unwrap();
|
||||
for top in [parent["occurrence"].as_u64().unwrap(), second["occurrence"].as_u64().unwrap()] {
|
||||
let path = vec![top, child["occurrence"].as_u64().unwrap()];
|
||||
let names = h.app.session.occurrence_bodies(&path, true).unwrap();
|
||||
assert_eq!(names.len(), 1);
|
||||
let hit = Hit::Face { body: names[0].clone(), index: 0, point: Vec3::ZERO };
|
||||
assert_eq!(candidate(&h.app, &[hit]).unwrap().1, Sel::Occurrence { path });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2091,7 +2091,9 @@ fn drag_ghost(app: &SolveApp, ctx: &egui::Context, id: &str, at: egui::Pos2, rem
|
||||
pub(crate) fn selection_filter(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
let t = Tokens::get();
|
||||
ui.label(egui::RichText::new(crate::i18n::tr_label("Selection filter")).color(t.text_dim).size(t.font_small));
|
||||
crate::ui_kit::checkbox(ui, crate::i18n::tr_label("Select bodies (a face picks its body)"), &mut app.ui.pick_bodies);
|
||||
if crate::ui_kit::checkbox(ui, crate::i18n::tr_label("Select bodies (a face picks its body)"), &mut app.ui.pick_bodies).changed() {
|
||||
app.ui.pick_components = false;
|
||||
}
|
||||
for (k, label) in [
|
||||
("faces", "Faces"),
|
||||
("edges", "Edges"),
|
||||
|
||||
@@ -12,6 +12,8 @@ use egui::{Ui, vec2};
|
||||
/// Text segments retain mixed states and optional compact clipping instead of dropdown fallback.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Segments<'a> {
|
||||
/// Optional stable scenario targets, independent of translated option labels.
|
||||
pub targets: &'a [&'a str],
|
||||
/// Optional leading icons retain the same text-segment geometry and accessibility.
|
||||
pub icons: &'a [&'a str],
|
||||
pub workspace_accent: bool,
|
||||
@@ -30,7 +32,7 @@ pub(crate) fn segmented(ui: &mut Ui, selected: &mut usize, options: &[&str], con
|
||||
if crate::prefs_search::querying(ui) && !crate::prefs_search::shows_all(ui) {
|
||||
crate::prefs_search::reveal(ui);
|
||||
}
|
||||
let Segments { icons, workspace_accent, dense, states, compact, primary, intrinsic, proportional } = config;
|
||||
let Segments { targets, icons, workspace_accent, dense, states, compact, primary, intrinsic, proportional } = config;
|
||||
let accent = crate::theme::TabAccent::current(ui.ctx());
|
||||
let t = Tokens::get();
|
||||
let segment_width = dimension(ui.available_width()) / options.len().max(1) as f32;
|
||||
@@ -132,6 +134,12 @@ pub(crate) fn segmented(ui: &mut Ui, selected: &mut usize, options: &[&str], con
|
||||
t.button_bevel_with_radius(ui, &response, on, rounding);
|
||||
response.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Button, ui.is_enabled(), on, *option));
|
||||
scenario::publish_handle(&format!("dialog:{}:{option}", label(ui)), segment.center());
|
||||
if let Some(target) = targets.get(index) {
|
||||
let visible = segment.intersect(ui.clip_rect());
|
||||
if visible.is_positive() {
|
||||
scenario::publish_target(target, visible);
|
||||
}
|
||||
}
|
||||
if response.on_hover_text(*option).clicked() {
|
||||
*selected = index;
|
||||
clicked = true;
|
||||
|
||||
+127
-70
@@ -130,8 +130,8 @@ pub struct ViewportState {
|
||||
sketch_key: u64,
|
||||
physical_scale: f32,
|
||||
pub(crate) display: std::sync::Mutex<crate::sketch_display::DisplayCache>,
|
||||
hl_slot: SceneSlot,
|
||||
hl_key: u64,
|
||||
pub(crate) hl_slot: SceneSlot,
|
||||
pub(crate) hl_key: u64,
|
||||
/// Browser/timeline body feedback, independent of the camera and reference widget scale.
|
||||
hover_block: std::sync::Mutex<Option<HoverBlock>>,
|
||||
/// Each shown body the model builds on the CPU: the block of the model scene that holds its
|
||||
@@ -361,7 +361,10 @@ pub fn scene_radius(app: &SolveApp) -> f64 {
|
||||
|
||||
pub fn projection(app: &SolveApp, rect: Rect) -> Proj {
|
||||
let mut cam = app.cam;
|
||||
cam.fov = if app.perspective_view() { 0.6 } else { 0.0 };
|
||||
// Render owns an explicit product camera, including its saved/custom FOV.
|
||||
if !crate::render_workspace::active(app) {
|
||||
cam.fov = if app.perspective_view() { 0.6 } else { 0.0 };
|
||||
}
|
||||
let aspect = rect.width() as f64 / rect.height().max(1.0) as f64;
|
||||
Proj { cam, vp: cam.view_proj_bounds(aspect, &scene_bounds(app)), rect }
|
||||
}
|
||||
@@ -615,6 +618,9 @@ fn shown_mesh(
|
||||
/// quality (finer or coarser faces and edges alike), falling back to the reference mesh when the
|
||||
/// body has no plan.
|
||||
fn drawn_mesh(app: &SolveApp, b: &solidcraft_engine::doc::ModelBody) -> std::sync::Arc<solidcraft_engine::geom::Mesh> {
|
||||
if crate::render_workspace::active(app) {
|
||||
return b.mesh();
|
||||
}
|
||||
use solidcraft_engine::doc::display_quality::{DisplayQuality, current};
|
||||
if let Some((_, mesh)) = refined(app, b) {
|
||||
return mesh;
|
||||
@@ -1957,6 +1963,7 @@ fn edge_pickable(app: &SolveApp, mesh: &solidcraft_engine::geom::Mesh, index: us
|
||||
/// unchanged.
|
||||
pub(crate) fn pick_cached(app: &mut SolveApp, proj: &Proj, pos: Pos2) -> Vec<Hit> {
|
||||
let mut h = std::collections::hash_map::DefaultHasher::new();
|
||||
crate::render_workspace::active(app).hash(&mut h);
|
||||
pos.x.to_bits().hash(&mut h);
|
||||
pos.y.to_bits().hash(&mut h);
|
||||
for v in [app.cam.yaw, app.cam.pitch, app.cam.roll, app.cam.distance, app.cam.target.x, app.cam.target.y, app.cam.target.z] {
|
||||
@@ -2112,7 +2119,13 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool,
|
||||
let wants_points = app.dialog.as_ref().and_then(|d| d.active_input()).is_some_and(|i| i.accept & crate::selection::POINTS != 0);
|
||||
let external_points =
|
||||
wants_points || other_sketch_points || (app.dialog.is_none() && app.tool.as_ref().is_none_or(|tool| tool.cmd == "sketch.project"));
|
||||
let point_sketches: Vec<u64> = if external_points { visible_sketches(app) } else { s.active_sketch.into_iter().collect() };
|
||||
let point_sketches: Vec<u64> = if crate::render_workspace::active(app) {
|
||||
Vec::new()
|
||||
} else if external_points {
|
||||
visible_sketches(app)
|
||||
} else {
|
||||
s.active_sketch.into_iter().collect()
|
||||
};
|
||||
// A face place (the Single hole's) snaps only to points their sketches show, so a nearer
|
||||
// point that isn't shown (a letter's outline) neither takes the pick nor hides a shown one.
|
||||
let snapping = app.dialog.as_ref().and_then(|d| d.active_input()).is_some_and(|i| crate::dialogs::snaps_to_points(i.accept));
|
||||
@@ -2155,7 +2168,7 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool,
|
||||
// Sketch curves: the active sketch's own before projected and other sketches' ones, then
|
||||
// nearest (the active sketch wins ties).
|
||||
let mut bestc = Near::new(all);
|
||||
for sid in visible_sketches(app) {
|
||||
for sid in visible_sketches(app).into_iter().filter(|_| !crate::render_workspace::active(app)) {
|
||||
let Some(ss) = st.sketch(sid) else { continue };
|
||||
let active = s.active_sketch == Some(sid);
|
||||
let bonus = if active { 2.0 } else { 0.0 };
|
||||
@@ -2251,6 +2264,9 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool,
|
||||
}
|
||||
}
|
||||
}
|
||||
if crate::render_workspace::active(app) {
|
||||
return if all { faces.sorted().into_iter().map(|(_, hit)| hit).collect() } else { bestf.into_iter().map(|(_, hit)| hit).collect() };
|
||||
}
|
||||
// The cut cap, where the plane crosses a body nearer than any kept face: it hides that face
|
||||
// and everything behind it, and is no face itself.
|
||||
let cap = section.and_then(|(so, sn)| {
|
||||
@@ -2753,9 +2769,9 @@ fn pick_allowed(app: &SolveApp, h: &Hit) -> bool {
|
||||
Hit::SketchCurve { .. } => !off("sketch") && !off("sketch_curves"),
|
||||
Hit::SketchPoint { .. } | Hit::SketchMidpoint { .. } => !off("sketch") && !off("sketch_points"),
|
||||
Hit::Profile { .. } => !off("sketch"),
|
||||
Hit::Vertex { .. } => !off("vertices") && !app.ui.pick_bodies,
|
||||
Hit::Edge { .. } => !off("edges") && !app.ui.pick_bodies,
|
||||
Hit::Face { .. } => !off("faces") || app.ui.pick_bodies,
|
||||
Hit::Vertex { .. } => !off("vertices") && !app.ui.pick_bodies && !app.ui.pick_components,
|
||||
Hit::Edge { .. } => !off("edges") && !app.ui.pick_bodies && !app.ui.pick_components,
|
||||
Hit::Face { .. } => !off("faces") || app.ui.pick_bodies || app.ui.pick_components,
|
||||
Hit::Plane { .. } | Hit::Axis { .. } | Hit::ConstructionPoint { .. } => true,
|
||||
}
|
||||
}
|
||||
@@ -2769,11 +2785,33 @@ fn hit_candidate(app: &SolveApp, h: &Hit) -> Option<(Hit, Sel)> {
|
||||
Hit::SketchPoint { sketch, id, .. } if app.session.active_sketch != Some(*sketch) => {
|
||||
Some((h.clone(), Sel::ExternalSketchPoint { sketch: *sketch, id: id.clone() }))
|
||||
}
|
||||
Hit::Face { body, .. } if app.ui.pick_components => Some((h.clone(), component_selection(app, body))),
|
||||
Hit::Face { body, .. } if app.ui.pick_bodies => Some((h.clone(), Sel::Body { name: body.clone() })),
|
||||
_ => hit_sel(h).map(|s| (h.clone(), s)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Use the Browser's exact occurrence identity, including nested/repeated placements.
|
||||
/// Root bodies have no occurrence row, so retain their body identity.
|
||||
fn component_selection(app: &SolveApp, body: &str) -> Sel {
|
||||
let doc = app.session.placed_document();
|
||||
let state = app.session.world_state();
|
||||
if let Some(b) = state.body(body) {
|
||||
let component = doc.model_body_component(b);
|
||||
let model = app.session.model.state();
|
||||
if let Some((_, path, _)) = doc
|
||||
.placements()
|
||||
.into_iter()
|
||||
.filter(|(c, _, _)| *c == component)
|
||||
.find(|(_, path, _)| doc.world_body_name(&model, b.definition_name(), component, path) == body)
|
||||
.filter(|(_, path, _)| !path.is_empty())
|
||||
{
|
||||
return Sel::Occurrence { path };
|
||||
}
|
||||
}
|
||||
Sel::Body { name: body.to_string() }
|
||||
}
|
||||
|
||||
/// A pick for the open dialog's active input (a click, or a Select Other row).
|
||||
pub(crate) fn dialog_pick(app: &mut SolveApp, hit: &Hit, sel: Sel) {
|
||||
// While OK computes, the dialog's inputs hold.
|
||||
@@ -3027,6 +3065,8 @@ fn highlight_geometry_key(app: &SolveApp) -> u64 {
|
||||
app.session.active_occurrence_path.hash(&mut h);
|
||||
app.ui.visual_style.hash(&mut h);
|
||||
app.ui.pick_bodies.hash(&mut h);
|
||||
app.ui.pick_components.hash(&mut h);
|
||||
crate::render_workspace::active(app).hash(&mut h);
|
||||
app.session.active_sketch.hash(&mut h);
|
||||
(app.dialog.is_some(), app.tool.is_some()).hash(&mut h);
|
||||
// Which input is active decides what a round edge or face under the cursor stands for.
|
||||
@@ -3047,7 +3087,7 @@ fn highlight_geometry_key(app: &SolveApp) -> u64 {
|
||||
h.finish()
|
||||
}
|
||||
|
||||
fn highlight_key(app: &SolveApp) -> u64 {
|
||||
pub(crate) fn highlight_key(app: &SolveApp) -> u64 {
|
||||
let mut h = std::collections::hash_map::DefaultHasher::new();
|
||||
highlight_geometry_key(app).hash(&mut h);
|
||||
let selected = app.highlighted();
|
||||
@@ -3095,6 +3135,9 @@ fn highlight_plan(
|
||||
b: &solidcraft_engine::doc::ModelBody,
|
||||
active_bodies: &Option<Vec<String>>,
|
||||
) -> Option<std::sync::Arc<solidcraft_engine::geom::tess::TessPlan>> {
|
||||
if crate::render_workspace::active(app) {
|
||||
return None;
|
||||
}
|
||||
drawn_plan(app, b, model_plan_class(app, b, active_bodies).is_some())
|
||||
}
|
||||
|
||||
@@ -3102,7 +3145,7 @@ fn highlight_plan(
|
||||
/// a live preview stands in for none, faded and see-through bodies stay on the CPU, and face
|
||||
/// opacities matter only where faces are shaded.
|
||||
fn highlight_opaque(app: &SolveApp, b: &solidcraft_engine::doc::ModelBody, active_bodies: &Option<Vec<String>>) -> bool {
|
||||
if app.preview.effective_replaced().contains(&b.name) {
|
||||
if crate::render_workspace::active(app) || app.preview.effective_replaced().contains(&b.name) {
|
||||
return false;
|
||||
}
|
||||
let doc = &app.session.doc;
|
||||
@@ -3177,7 +3220,7 @@ impl HighlightInstances {
|
||||
/// the window). See-through and faded bodies have no range here: they are not in the block's
|
||||
/// opaque triangles, and the CPU feedback colours them.
|
||||
fn highlight_block_tris(app: &SolveApp, b: &solidcraft_engine::doc::ModelBody) -> Option<crate::gpu::BlockTris> {
|
||||
if app.preview.effective_replaced().contains(&b.name) {
|
||||
if crate::render_workspace::active(app) || app.preview.effective_replaced().contains(&b.name) {
|
||||
return None;
|
||||
}
|
||||
let map = app.viewport.body_tris.lock().ok()?;
|
||||
@@ -3254,78 +3297,91 @@ pub(crate) fn build_highlight(app: &SolveApp) -> GpuScene {
|
||||
let s = &app.session;
|
||||
let active_bodies = s.active_occurrence_path.as_ref().and_then(|p| s.occurrence_bodies(p, true).ok());
|
||||
// Faces lit over the model use the triangles the model shows them with.
|
||||
let shown = |b: &solidcraft_engine::doc::ModelBody| shown_mesh(app, b, &active_bodies);
|
||||
let product = crate::render_workspace::active(app);
|
||||
let shown = |b: &solidcraft_engine::doc::ModelBody| if product { b.mesh() } else { shown_mesh(app, b, &active_bodies) };
|
||||
let items = app.highlighted();
|
||||
let sketches = selected_sketches(app, &items);
|
||||
let mut sel = Vec::new();
|
||||
for item in &items {
|
||||
for piece in displayed_selection(app, item) {
|
||||
for piece in displayed_selection(app, item).into_iter().filter(|s| !product || matches!(s, Sel::Body { .. } | Sel::Face { .. })) {
|
||||
if !sel.iter().any(|x| crate::selection::same_item(x, &piece)) {
|
||||
sel.push(piece);
|
||||
}
|
||||
}
|
||||
}
|
||||
let hover = app.viewport.hover.as_ref();
|
||||
// Component hover expands through the same occurrence selection as a Browser row.
|
||||
let component_hover = app
|
||||
.viewport
|
||||
.hover
|
||||
.as_ref()
|
||||
.filter(|h| app.ui.pick_components && matches!(h, Hit::Face { .. }))
|
||||
.and_then(|h| hit_candidate(app, h))
|
||||
.map(|(_, s)| displayed_selection(app, &s));
|
||||
let hover = app.viewport.hover.as_ref().filter(|_| component_hover.is_none());
|
||||
let size = origin_size(app.cam.half_height());
|
||||
// Origin planes and construction planes.
|
||||
let plane_state = |name: &str| {
|
||||
let selected = sel.iter().any(|x| matches!(x, Sel::Plane { name: n } if n == name));
|
||||
let hovered = matches!(hover, Some(Hit::Plane { name: n, .. }) if n == name);
|
||||
(selected, hovered)
|
||||
};
|
||||
let mut planes: Vec<(String, [Vec3; 4], Color32)> = origin_planes(app).into_iter().map(|(n, _, q)| (n.to_string(), q, t.origin_plane)).collect();
|
||||
planes.extend(construction_quads(app).into_iter().map(|(n, _, q)| (n, q, t.construction_plane)));
|
||||
let through = app.picking_plane() || app.preferences.reference_geometry_through_bodies;
|
||||
for (name, q, base) in &planes {
|
||||
let (selected, hovered) = plane_state(name);
|
||||
let fill = if hovered {
|
||||
t.origin_plane_hover
|
||||
} else if selected {
|
||||
Color32::from_rgba_unmultiplied(t.sel_face.r(), t.sel_face.g(), t.sel_face.b(), 150)
|
||||
} else {
|
||||
*base
|
||||
if !product {
|
||||
// Origin planes and construction planes.
|
||||
let plane_state = |name: &str| {
|
||||
let selected = sel.iter().any(|x| matches!(x, Sel::Plane { name: n } if n == name));
|
||||
let hovered = matches!(hover, Some(Hit::Plane { name: n, .. }) if n == name);
|
||||
(selected, hovered)
|
||||
};
|
||||
quad(&mut sc, q, fill, if selected { t.sel_edge } else { t.origin_plane_edge }, through);
|
||||
}
|
||||
// Origin axes: solid near the origin, dashed beyond.
|
||||
for (name, dir) in origin_axes(app) {
|
||||
let col = match name {
|
||||
"X" => t.axis_x,
|
||||
"Y" => t.axis_y,
|
||||
_ => t.axis_z,
|
||||
};
|
||||
let on = sel.iter().any(|x| matches!(x, Sel::Axis { name: n } if n == name)) || matches!(hover, Some(Hit::Axis { name: n }) if n == name);
|
||||
let w = if on { 4.0 } else { 2.0 };
|
||||
reference_line(&mut sc, [0.0; 3], (dir * size).to_f32(), c4(col), w, through);
|
||||
let dash = size * 0.08;
|
||||
let mut a = size + dash;
|
||||
while a < size * AXIS_LEN {
|
||||
reference_line(&mut sc, (dir * a).to_f32(), (dir * (a + dash)).to_f32(), c4(col), w * 0.75, through);
|
||||
a += dash * 2.0;
|
||||
let mut planes: Vec<(String, [Vec3; 4], Color32)> =
|
||||
origin_planes(app).into_iter().map(|(n, _, q)| (n.to_string(), q, t.origin_plane)).collect();
|
||||
planes.extend(construction_quads(app).into_iter().map(|(n, _, q)| (n, q, t.construction_plane)));
|
||||
let through = app.picking_plane() || app.preferences.reference_geometry_through_bodies;
|
||||
for (name, q, base) in &planes {
|
||||
let (selected, hovered) = plane_state(name);
|
||||
let fill = if hovered {
|
||||
t.origin_plane_hover
|
||||
} else if selected {
|
||||
Color32::from_rgba_unmultiplied(t.sel_face.r(), t.sel_face.g(), t.sel_face.b(), 150)
|
||||
} else {
|
||||
*base
|
||||
};
|
||||
quad(&mut sc, q, fill, if selected { t.sel_edge } else { t.origin_plane_edge }, through);
|
||||
}
|
||||
}
|
||||
// Construction axes (dashed, the length of the origin axes either side) and points (a
|
||||
// small star), in the construction colour.
|
||||
for (name, a, b) in construction_axis_segments(app) {
|
||||
let on = sel.iter().any(|x| matches!(x, Sel::Axis { name: n } if *n == name)) || matches!(hover, Some(Hit::Axis { name: n }) if *n == name);
|
||||
let col = c4(if on { t.sel_edge } else { t.construction_geom });
|
||||
let w = if on { 3.0 } else { 1.6 };
|
||||
let len = a.dist(b);
|
||||
let dash = size * 0.08;
|
||||
let mut s = 0.0;
|
||||
while s < len {
|
||||
let e = (s + dash).min(len);
|
||||
reference_line(&mut sc, a.lerp(b, s / len).to_f32(), a.lerp(b, e / len).to_f32(), col, w, through);
|
||||
s += dash * 1.6;
|
||||
// Origin axes: solid near the origin, dashed beyond.
|
||||
for (name, dir) in origin_axes(app) {
|
||||
let col = match name {
|
||||
"X" => t.axis_x,
|
||||
"Y" => t.axis_y,
|
||||
_ => t.axis_z,
|
||||
};
|
||||
let on = sel.iter().any(|x| matches!(x, Sel::Axis { name: n } if n == name)) || matches!(hover, Some(Hit::Axis { name: n }) if n == name);
|
||||
let w = if on { 4.0 } else { 2.0 };
|
||||
reference_line(&mut sc, [0.0; 3], (dir * size).to_f32(), c4(col), w, through);
|
||||
let dash = size * 0.08;
|
||||
let mut a = size + dash;
|
||||
while a < size * AXIS_LEN {
|
||||
reference_line(&mut sc, (dir * a).to_f32(), (dir * (a + dash)).to_f32(), c4(col), w * 0.75, through);
|
||||
a += dash * 2.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (name, p) in construction_points(app) {
|
||||
let on = sel.iter().any(|x| matches!(x, Sel::ConstructionPoint { name: n } if *n == name))
|
||||
|| matches!(hover, Some(Hit::ConstructionPoint { name: n }) if *n == name);
|
||||
let col = sc.color(c4(if on { t.sel_edge } else { t.construction_geom }));
|
||||
let r = size * 0.04;
|
||||
for d in [Vec3::X, Vec3::Y, Vec3::Z] {
|
||||
sc.line((p - d * r).to_f32(), (p + d * r).to_f32(), col, 2.0, true);
|
||||
// Construction axes (dashed, the length of the origin axes either side) and points (a
|
||||
// small star), in the construction colour.
|
||||
for (name, a, b) in construction_axis_segments(app) {
|
||||
let on =
|
||||
sel.iter().any(|x| matches!(x, Sel::Axis { name: n } if *n == name)) || matches!(hover, Some(Hit::Axis { name: n }) if *n == name);
|
||||
let col = c4(if on { t.sel_edge } else { t.construction_geom });
|
||||
let w = if on { 3.0 } else { 1.6 };
|
||||
let len = a.dist(b);
|
||||
let dash = size * 0.08;
|
||||
let mut s = 0.0;
|
||||
while s < len {
|
||||
let e = (s + dash).min(len);
|
||||
reference_line(&mut sc, a.lerp(b, s / len).to_f32(), a.lerp(b, e / len).to_f32(), col, w, through);
|
||||
s += dash * 1.6;
|
||||
}
|
||||
}
|
||||
for (name, p) in construction_points(app) {
|
||||
let on = sel.iter().any(|x| matches!(x, Sel::ConstructionPoint { name: n } if *n == name))
|
||||
|| matches!(hover, Some(Hit::ConstructionPoint { name: n }) if *n == name);
|
||||
let col = sc.color(c4(if on { t.sel_edge } else { t.construction_geom }));
|
||||
let r = size * 0.04;
|
||||
for d in [Vec3::X, Vec3::Y, Vec3::Z] {
|
||||
sc.line((p - d * r).to_f32(), (p + d * r).to_f32(), col, 2.0, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
// A round edge or face under the cursor (or picked) in an axis input shows its axis, and a
|
||||
@@ -3469,6 +3525,7 @@ pub(crate) fn build_highlight(app: &SolveApp) -> GpuScene {
|
||||
// Timeline modifiers light only their resulting faces; browser rows light whole bodies.
|
||||
let mut hovered = app.viewport.hover_feature.map(|id| feature_geometry(app, id)).unwrap_or_default();
|
||||
hovered.extend(app.viewport.hover_bodies.iter().map(|name| Sel::Body { name: name.clone() }));
|
||||
hovered.extend(component_hover.into_iter().flatten());
|
||||
// By name, once: a whole assembly holds thousands of bodies, and scanning the list for
|
||||
// each of them is quadratic (as is a body lookup by name in the world).
|
||||
let hovered_whole: std::collections::HashSet<&str> =
|
||||
|
||||
@@ -26,10 +26,10 @@ applies or saves settings or starts an image job. It focuses the existing Inspec
|
||||
page, while every Inspector page and registered Render command remains reachable.
|
||||
The headless command validates and echoes the request without changing the document.
|
||||
|
||||
Render, Cancel and the shared command search (S) occupy the top row. The former Pick
|
||||
HUD, icon-text Body/Face/Component segments, Paint/Pick Up actions and direct-light
|
||||
preview information chip occupy Look's second row with 8 pt side padding. Picking and changing the
|
||||
light coordinate frame remain disabled with their reason in this checkout. Frame
|
||||
Render, Cancel and the shared command search (S) occupy the top row. The Pick control's
|
||||
icon-text Body/Face/Component segments, Paint/Pick Up actions and direct-light
|
||||
preview information chip occupy Look's second row with 8 pt side padding. Changing the
|
||||
light coordinate frame remains disabled with its reason in this checkout. Frame
|
||||
uses the existing explicit camera command for projection; Output shows the current
|
||||
size/format and directs edits to the Output Inspector. No completion ticks are inferred.
|
||||
|
||||
@@ -148,9 +148,8 @@ resolved sRGB colours, opacity and face appearance overrides. Face indices are t
|
||||
existing mesh-to-B-rep mapping, resolved through document appearance references;
|
||||
they are not new persistent names or triangle-derived face identities.
|
||||
|
||||
There are no grid/axis/edge lines, sketches, construction objects, selection or hover
|
||||
colours, section cuts, analysis shading, active-component fading, canvases or decals
|
||||
in this initial product policy. Browser visibility still controls which bodies appear.
|
||||
There are no grid/axis/edge lines, sketches, construction objects, section cuts,
|
||||
analysis shading, active-component fading, canvases or decals in the product scene. Browser visibility still controls which bodies appear.
|
||||
The existing Design viewport and CPU snapshot routes keep their current policies.
|
||||
|
||||
Extraction refuses a stale live-drag model. The explicit model-reading `render.scene {}`
|
||||
@@ -237,7 +236,7 @@ distance, yaw, pitch, roll, FOV and up axis as view state. It neither edits the
|
||||
nor settles a stale model. The UI honours its up axis in Render; the Design camera
|
||||
is restored when returning. The camera moves exactly as in Design: the navigation preset,
|
||||
Orbit around, zoom to the cursor, the SpaceMouse, the middle double-click, F6 and the axis
|
||||
view or navigation cube all work (nothing is picked or selected here), and
|
||||
view or navigation cube all work and
|
||||
**Fit Product** frames visible product bodies without including sketches or selection.
|
||||
|
||||
Preview drafts do not make the document dirty until saved. Unknown backend preferences
|
||||
@@ -329,3 +328,22 @@ locale before falling back to English. Adding an untranslated Render alias no
|
||||
longer hides existing Library, Appearance or Checkpoint translations. Contextual
|
||||
Render labels still use their own stable IDs rather than borrowing a different
|
||||
feature's meaning.
|
||||
|
||||
## Picking in the product view
|
||||
|
||||
The Look stage bar's second-row **Pick** control selects Body, Face or Component granularity,
|
||||
using Design’s selection filter state through the `select.filter` command. Component
|
||||
picks use the Browser’s exact occurrence path, including nested and repeated
|
||||
placements; a body at the design root retains its body identity. Face picks use the
|
||||
existing mesh-to-B-rep mapping and connected-surface selection rules.
|
||||
|
||||
Hover highlights the target; clicking selects it. Clicking empty space clears the
|
||||
selection. Shift and Ctrl/Cmd follow Design’s add/toggle behavior and the Shift
|
||||
add-only preference. Browser row selections and product picks share the same
|
||||
selection commands and state, retained across Design/Render switches. Picking works
|
||||
with the Shots strip shown or hidden. Render picking never starts a geometry edit.
|
||||
|
||||
Selection and hover use Design’s highlight drawing and theme tokens in a separate
|
||||
GPU overlay on the live product view. The product scene and its upload stay unchanged.
|
||||
CPU image jobs, exported PNGs, retained images and the Render Result canvas never
|
||||
contain this overlay; the Pick control is disabled on the result canvas.
|
||||
|
||||
Reference in New Issue
Block a user