From 3cc95206857fce92661d38465f276bde385a6378 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Thu, 8 Oct 2026 20:17:35 +0700 Subject: [PATCH] Test: an imported GLB shows in a new composition in software (#264) The host test writes a binary glTF cube (built in the test), imports it with the real media layer, makes New Comp from Selection and renders with no accelerator (the CPU path an Intel HD Graphics 5500 most likely gets): the comp is Advanced 3D and the red cube covers part of the frame. Before the fix the comp stayed Classic 3D and drew nothing. The engine test checks the switch, its single undo step, the toasts, that a second model doesn't switch again, and primitives. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/tests_model3d.rs | 36 +++++++++++++++++++++ crates/host/src/lib.rs | 52 ++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/crates/engine/src/tests_model3d.rs b/crates/engine/src/tests_model3d.rs index 02e4e52a..1d8b80f9 100644 --- a/crates/engine/src/tests_model3d.rs +++ b/crates/engine/src/tests_model3d.rs @@ -193,3 +193,39 @@ fn material_commands_and_serde() { let back = Project::from_json(&json).unwrap(); assert_eq!(&back, &*s.project); } + +/// #264: only Advanced 3D draws models and primitives, and new comps are Classic 3D, so an +/// imported model was invisible. Adding one switches the comp to Advanced 3D (in the same undo +/// step, with a toast), as After Effects does. +#[test] +fn adding_models_switches_classic_comps_to_advanced_3d() { + let toasts = |s: &mut Session| -> Vec { + s.drain_events().into_iter().filter_map(|e| if let crate::Event::Toast { message, .. } = e { Some(message) } else { None }).collect() + }; + let mut s = session(); + let text = s.execute("layer.newText", json!({"text": "Hi"})).unwrap()["layer"].as_u64().unwrap(); + let item = s.execute("file.import", json!({"paths": [fixture("quad.glb")]})).unwrap()["items"][0].as_u64().unwrap(); + assert_eq!(s.active_comp().unwrap().renderer, Renderer::Classic3D); + toasts(&mut s); + let r = s.execute("layer.addItem", json!({"item": item})).unwrap(); + assert_eq!(r["advanced3d"], true); + assert_eq!(s.active_comp().unwrap().renderer, Renderer::Advanced3D); + // As with Composition Settings: the text layer gets Geometry Options. + assert!(layer(&s, text).props.sub("geometryOptions").is_some()); + assert!(toasts(&mut s).iter().any(|m| m.contains("Advanced 3D"))); + // A second model leaves the comp (and the user) alone. + s.execute("layer.addItem", json!({"item": item})).unwrap(); + assert!(toasts(&mut s).is_empty()); + s.undo(); + s.undo(); + assert_eq!(s.active_comp().unwrap().layers.len(), 1); + assert_eq!(s.active_comp().unwrap().renderer, Renderer::Classic3D); + assert!(layer(&s, text).props.sub("geometryOptions").is_none()); + // Primitives too. + s.execute("layer.newPrimitive", json!({"kind": "cube"})).unwrap(); + assert_eq!(s.active_comp().unwrap().renderer, Renderer::Advanced3D); + // Switching back to Classic 3D says why the model layers disappear. + toasts(&mut s); + s.execute("comp.renderer", json!({"renderer": "classic3d"})).unwrap(); + assert!(toasts(&mut s).iter().any(|m| m.contains("Classic 3D doesn't draw"))); +} diff --git a/crates/host/src/lib.rs b/crates/host/src/lib.rs index b4ca00a4..7f2d1a5c 100644 --- a/crates/host/src/lib.rs +++ b/crates/host/src/lib.rs @@ -205,6 +205,58 @@ mod tests { assert!(s.render(cid, s.time(), opts).data.iter().all(|p| p[3] == 0.0)); } + /// A binary glTF of a red cube 2 units wide (positions and indices only). + fn glb_cube() -> Vec { + let mut bin: Vec = (0..8u32).flat_map(|i| [i & 1, (i >> 1) & 1, (i >> 2) & 1].map(|b| b as f32 * 2.0 - 1.0)).flat_map(f32::to_le_bytes).collect(); + let faces: [[u16; 4]; 6] = [[0, 2, 3, 1], [4, 5, 7, 6], [0, 1, 5, 4], [2, 6, 7, 3], [0, 4, 6, 2], [1, 3, 7, 5]]; + bin.extend(faces.iter().flat_map(|f| [f[0], f[1], f[2], f[0], f[2], f[3]]).flat_map(u16::to_le_bytes)); + let gltf = json!({ + "asset": {"version": "2.0"}, + "scene": 0, + "scenes": [{"nodes": [0]}], + "nodes": [{"mesh": 0}], + "meshes": [{"primitives": [{"attributes": {"POSITION": 0}, "indices": 1, "material": 0}]}], + "materials": [{"pbrMetallicRoughness": {"baseColorFactor": [1, 0, 0, 1], "metallicFactor": 0, "roughnessFactor": 1}}], + "buffers": [{"byteLength": bin.len()}], + "bufferViews": [{"buffer": 0, "byteOffset": 0, "byteLength": 96}, {"buffer": 0, "byteOffset": 96, "byteLength": 72}], + "accessors": [ + {"bufferView": 0, "componentType": 5126, "count": 8, "type": "VEC3", "min": [-1, -1, -1], "max": [1, 1, 1]}, + {"bufferView": 1, "componentType": 5123, "count": 36, "type": "SCALAR"} + ] + }); + let mut text = gltf.to_string().into_bytes(); + text.resize(text.len().div_ceil(4) * 4, b' '); + let chunk = |kind: &[u8; 4], data: &[u8]| [&(data.len() as u32).to_le_bytes()[..], kind, data].concat(); + let body = [chunk(b"JSON", &text), chunk(b"BIN\0", &bin)].concat(); + [&b"glTF"[..], &2u32.to_le_bytes(), &(12 + body.len() as u32).to_le_bytes(), &body].concat() + } + + /// #264: a model imported into a new composition (Classic 3D by default) was invisible on + /// every renderer, because only Advanced 3D draws models. Adding it now switches the comp, + /// and the software renderer (no GPU, as on the reporter's Intel HD Graphics 5500) draws it. + #[test] + fn imported_glb_shows_in_a_new_composition() { + let path = std::env::temp_dir().join(format!("effectcraft-264-cube-{}.glb", std::process::id())); + std::fs::write(&path, glb_cube()).unwrap(); + let mut s = super::session(); + assert!(s.accel.is_none(), "renders in software"); + let r = s.execute("file.import", json!({"paths": [path.to_string_lossy()]})).unwrap(); + assert_eq!(r["errors"], json!([]), "{r}"); + s.state.project_selection = vec![effectcraft_project::ItemId(r["items"][0].as_u64().unwrap())]; + s.execute("file.newCompFromSelection", json!({})).unwrap(); + let comp = s.active_comp().unwrap(); + assert_eq!(comp.renderer, effectcraft_project::Renderer::Advanced3D); + let layer = comp.layers[0].id.0; + s.execute("prop.set", json!({"layer": layer, "path": "transform/rotationY", "value": 30})).unwrap(); + s.execute("prop.set", json!({"layer": layer, "path": "transform/rotationX", "value": 20})).unwrap(); + let cid = s.active_comp_id().unwrap(); + let img = s.render(cid, s.time(), effectcraft_engine::render::RenderOpts { scale: 0.25, ..Default::default() }); + let red = img.data.iter().filter(|p| p[3] > 0.99 && p[0] > 0.2 && p[1] < 0.05 && p[2] < 0.05).count(); + let _ = std::fs::remove_file(&path); + // Half the comp height wide, seen at an angle: well over 5% of the frame. + assert!(red * 20 > img.data.len(), "red cube pixels: {red} of {}", img.data.len()); + } + /// The web app's path: outputs go to a sink (downloads), never to the file system. #[test] fn render_queue_exports_to_a_sink() {