Face colours and opacity in STEP and 3MF export (and STEP import)
- Bodies carry a Paint for export (opacity, per-face colours), set by Document::painted from the appearance model. The paint comes from a face appearance, a body/component appearance's opacity or a material look (Glass), and falls back to the paint the body was imported with. - STEP: faces with colours of their own get a STYLED_ITEM on their ADVANCED_FACE. See-through looks add SURFACE_STYLE_TRANSPARENT. Differently coloured pieces are not merged into one face. - STEP import reads face styles and transparency. The reader tracks the file face of each kernel face (bands split in two keep it), so imported face colours land on the right faces; the design shows them through face_colors. - 3MF: per-triangle colours (pid/p1 into the base materials, carried through welding) and the object's alpha (#RRGGBBAA). - Tests: a blue half-transparent cube with a red top exports, re-imports with its opacity and the red top face, and keeps it when opened and exported again. 3MF writes the alpha and the face entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AS5Tn3xieewUSg3uxrMVdL
This commit is contained in:
1 parent
8045904c54
commit
294597cc96
12 files changed
+313
-49
No files matched your search
@@ -987,6 +987,35 @@ fn material_and_appearance_colours_export_to_step() {
|
||||
check(&step_round_trip(&mut s2, "colours2"));
|
||||
}
|
||||
|
||||
/// Face appearances and see-through bodies export: STEP styles on the faces with a
|
||||
/// transparency, read back as face colours.
|
||||
#[test]
|
||||
fn face_colours_and_opacity_export() {
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "PrimitiveBox", json!({"length": 10, "width": 10, "height": 10, "body_name": "Cube"}));
|
||||
run(&mut s, "AppearanceCommand", json!({"bodies": ["Cube"], "color": "#2040c0", "opacity": 0.5}));
|
||||
run(&mut s, "AppearanceCommand", json!({"faces": [[5, 5, 10]], "color": "#ff0000"}));
|
||||
let imp = step_round_trip(&mut s, "facecol");
|
||||
let b = &imp.bodies[0];
|
||||
let paint = b.body.paint().expect("paint read back");
|
||||
assert!((paint.opacity - 0.5).abs() < 1e-3, "{paint:?}");
|
||||
let faces = b.body.faces(0.01).unwrap();
|
||||
let top = faces.iter().position(|f| (f.centroid.z - 10.0).abs() < 1e-6).unwrap();
|
||||
assert_eq!(paint.faces.len(), 1, "{paint:?}");
|
||||
assert_eq!(paint.faces[0].face, top);
|
||||
assert!((paint.faces[0].color[0] - 1.0).abs() < 1e-3 && paint.faces[0].color[1].abs() < 1e-3, "{paint:?}");
|
||||
// Opened again, the face keeps its colour (shown and exported).
|
||||
let p = std::env::temp_dir().join(format!("solvecraft-facecol-{}.step", std::process::id()));
|
||||
run(&mut s, "ExportCommand", json!({"path": p.to_string_lossy()}));
|
||||
let mut s2 = Session::default();
|
||||
run(&mut s2, "doc.open", json!({"path": p.to_string_lossy()}));
|
||||
let _ = std::fs::remove_file(&p);
|
||||
let st = s2.world_state();
|
||||
let looks = s2.doc.face_colors(&st.bodies[0]);
|
||||
assert_eq!(looks.len(), 1);
|
||||
assert_eq!(looks[0].1.color, [255, 0, 0]);
|
||||
}
|
||||
|
||||
/// Components export as a STEP assembly: products, occurrences, placements.
|
||||
#[test]
|
||||
fn components_export_as_step_assembly() {
|
||||
|
||||
Reference in new issue
Block a user