body_appearance_key hashed only the name of a body's assigned material, so after material.edit changed that material's colour (or an undo or redo changed it back) the key stayed the same and the viewport kept the cached old look. The key now also hashes the material's resolved look; with an unchanged material the cache is reused as before.
This commit is contained in:
@@ -941,7 +941,7 @@ fn hash_look(look: Option<&solidcraft_engine::doc::appearance::Look>, h: &mut im
|
||||
}
|
||||
|
||||
/// What a body's resolved look depends on: its geometry (imported paint), the body/component
|
||||
/// looks, its material, its face appearances, and component colouring.
|
||||
/// looks, its material and that material's look, its face appearances, and component colouring.
|
||||
fn body_appearance_key(
|
||||
doc: &solidcraft_engine::doc::Document,
|
||||
b: &solidcraft_engine::doc::ModelBody,
|
||||
@@ -954,7 +954,9 @@ fn body_appearance_key(
|
||||
let name = b.definition_name();
|
||||
hash_look(doc.appearances.bodies.get(name), &mut h);
|
||||
hash_look(doc.appearances.components.get(&b.component), &mut h);
|
||||
doc.materials.get(name).hash(&mut h);
|
||||
let material = doc.materials.get(name);
|
||||
material.hash(&mut h);
|
||||
hash_look(material.and_then(|m| doc.material_look(m)).as_ref(), &mut h);
|
||||
faces.get(name).copied().unwrap_or(0).hash(&mut h);
|
||||
colored.hash(&mut h);
|
||||
if colored {
|
||||
|
||||
@@ -201,6 +201,29 @@ fn a_colour_edit_reuses_every_block_vertex() {
|
||||
assert_eq!(first_vertex(&second, &block.bytes.vertices).1, Some([51, 102, 153, 255]), "the palette carries the new colour");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_material_colour_edit_its_undo_and_redo_reach_the_viewport() {
|
||||
let mut app = SolveApp::new(Session::default(), Services::default());
|
||||
app.ui.ground_shadow = false;
|
||||
app.set_origin_shown(false);
|
||||
app.run("solid.box", json!({"length": 20, "width": 15, "height": 10})).unwrap();
|
||||
let name = app.session.world_state().bodies[0].name.clone();
|
||||
app.run("material.create", json!({"name": "Wood dark", "density_g_cm3": 0.7, "color": "#c8a573"})).unwrap();
|
||||
app.run("material.assign", json!({"bodies": [name], "material": "Wood dark"})).unwrap();
|
||||
let colour = |app: &SolveApp| {
|
||||
let scene = build_scene(app);
|
||||
let block = scene.blocks.iter().find(|b| !b.bytes.vertices.is_empty()).expect("the box has a block");
|
||||
first_vertex(&scene, &block.bytes.vertices).1
|
||||
};
|
||||
assert_eq!(colour(&app), Some([0xc8, 0xa5, 0x73, 255]));
|
||||
app.run("material.edit", json!({"material": "Wood dark", "color": "#ccb799"})).unwrap();
|
||||
assert_eq!(colour(&app), Some([0xcc, 0xb7, 0x99, 255]), "the edited material colour is drawn");
|
||||
app.run("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(colour(&app), Some([0xc8, 0xa5, 0x73, 255]), "undo draws the old colour again");
|
||||
app.run("edit.redo", json!({})).unwrap();
|
||||
assert_eq!(colour(&app), Some([0xcc, 0xb7, 0x99, 255]), "redo draws the edited colour again");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_opacity_class_change_keeps_vertices_and_rewrites_only_the_runs() {
|
||||
let mut app = SolveApp::new(Session::default(), Services::default());
|
||||
|
||||
Reference in New Issue
Block a user