* Viewport: keep the model scene in blocks and upload only what changed Every change rebuilt the whole model scene (every body's triangles and edges) and uploaded all of it again, so a design an agent builds one body at a time paid for the whole model on every command. The scene is now built in blocks of a few bodies, cut where a body's own key says, and each block's bytes and GPU buffers are kept while the block comes back unchanged. Body boxes (fit, picking, ground shadow) are kept per mesh. Rendering is unchanged: the bicycle from bench-agent opens to a byte-identical screenshot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Browser: find an occurrence's placed bodies by name, not by search per row Each body row of a placed component searched the placement's bodies for its own, every frame: quadratic in the component's bodies (720 for the bench-agent bicycle's hardware). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
3.0 KiB
Rust
56 lines
3.0 KiB
Rust
use super::build_scene;
|
|
use crate::{Services, SolveApp};
|
|
use serde_json::json;
|
|
use solidcraft_engine::{Session, doc, geom::Vec3, kernel};
|
|
|
|
#[test]
|
|
fn placed_step_body_uses_imported_opacity_until_a_design_look_overrides_it() {
|
|
let body = kernel::box_solid(Vec3::ZERO, Vec3::new(10.0, 10.0, 10.0))
|
|
.unwrap()
|
|
.with_color(Some([0.2, 0.6, 0.8]))
|
|
.with_paint(Some(kernel::Paint { opacity: 0.4, faces: Vec::new() }));
|
|
let step =
|
|
kernel::step_export_bodies(&[kernel::ExportBody { name: "Imported glass".into(), body: &body, color: body.color() }], &Default::default())
|
|
.unwrap();
|
|
let mut document = doc::Document::default();
|
|
let component = document.add_component(Some("Imported part"), 0).unwrap();
|
|
let feature =
|
|
document.add_feature(doc::FeatureKind::Import { file: "glass.step".into(), step: step.into(), components: Vec::new() }, None).unwrap();
|
|
document.features.iter_mut().find(|f| f.id == feature).unwrap().component = component;
|
|
let mut session = Session::new(document);
|
|
let source = session.model.state().bodies[0].name.clone();
|
|
assert!((session.doc.model_body_opacity(&session.model.state().bodies[0]) - 0.4).abs() < 1e-6);
|
|
session.execute("occurrence.copy", &json!({"component":component,"translate":[30,0,0]})).unwrap();
|
|
let mut app = SolveApp::new(session, Services::default());
|
|
app.ui.ground_shadow = false;
|
|
app.ui.show_origin = false;
|
|
let placed = app.session.world_state().bodies.iter().find(|b| b.name != source).unwrap().name.clone();
|
|
app.session.selection = vec![solidcraft_engine::Sel::Body { name: placed }];
|
|
app.start("appearance.assign");
|
|
let crate::dialogs::Kind::Appearance(appearance) = &app.dialog.as_ref().unwrap().kind else { panic!("appearance dialog") };
|
|
assert!((appearance.opacity - 0.4).abs() < 1e-6);
|
|
assert_eq!(appearance.color, [51, 153, 204]);
|
|
crate::dialogs::cancel(&mut app);
|
|
let scene = build_scene(&app).merged();
|
|
assert!(!scene.glass.is_empty());
|
|
assert!(
|
|
scene.tris.is_empty(),
|
|
"opaque triangles {}, bodies {:?}",
|
|
scene.tris.len(),
|
|
app.session.world_state().bodies.iter().map(|b| (&b.name, b.body.paint(), &b.imported)).collect::<Vec<_>>()
|
|
);
|
|
let (vertices, remainder) = scene.glass.as_chunks::<{ crate::gpu::TRI_SIZE }>();
|
|
assert!(remainder.is_empty());
|
|
assert!(vertices.iter().all(|v| v[27] == 102));
|
|
app.run("appearance.assign", json!({"bodies":[source],"color":"#336699","opacity":0.7})).unwrap();
|
|
let scene = build_scene(&app);
|
|
let (vertices, remainder) = scene.glass.as_chunks::<{ crate::gpu::TRI_SIZE }>();
|
|
assert!(remainder.is_empty());
|
|
assert!(vertices.iter().all(|v| v[27] == 179));
|
|
app.run("appearance.assign", json!({"bodies":[source]})).unwrap();
|
|
let scene = build_scene(&app);
|
|
let (vertices, remainder) = scene.glass.as_chunks::<{ crate::gpu::TRI_SIZE }>();
|
|
assert!(remainder.is_empty());
|
|
assert!(vertices.iter().all(|v| v[27] == 102));
|
|
}
|