M13.2: Create VR Environment nests the scene as a collapsed 3D precomp in each face comp (lights copied)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Thomas
2026-10-03 04:22:49 -04:00
co-authored by Claude Opus 5.5
parent 7ac5317ce9
commit e1296a57c2
2 changed files with 39 additions and 27 deletions
+36 -25
View File
@@ -433,8 +433,8 @@ fn ae(v: [f64; 3]) -> Vec3 {
} }
/// Composition ▸ VR ▸ Create VR Environment: renders the active comp's 3D scene in every /// Composition ▸ VR ▸ Create VR Environment: renders the active comp's 3D scene in every
/// direction. Six face comps (a 90° camera each at `position`, default the comp centre, with a /// direction. Six face comps (a 90° camera each at `position`, default the comp centre, looking
/// copy of the scene's layers), a 3:2 cube map of them, and an equirectangular output comp /// at the scene nested as a collapsed 3D precomp), a 3:2 cube map of them, and an equirectangular output comp
/// (VR Converter, cube map → equirectangular). One undo step. /// (VR Converter, cube map → equirectangular). One undo step.
fn create_vr_environment(s: &mut Session, p: &Value) -> Result<Value> { fn create_vr_environment(s: &mut Session, p: &Value) -> Result<Value> {
let cid = comp_id(s, p)?; let cid = comp_id(s, p)?;
@@ -462,30 +462,41 @@ fn create_vr_environment(s: &mut Session, p: &Value) -> Result<Value> {
id_of(&s.execute("layer.newCamera", json!({"comp": fc, "name": format!("{fname} Camera"), "angleOfView": 90.0, "type": "oneNode"}))?, "layer")?; id_of(&s.execute("layer.newCamera", json!({"comp": fc, "name": format!("{fname} Camera"), "angleOfView": 90.0, "type": "oneNode"}))?, "layer")?;
s.execute("prop.set", json!({"comp": fc, "layer": cam, "path": "transform/position", "value": center}))?; s.execute("prop.set", json!({"comp": fc, "layer": cam, "path": "transform/position", "value": center}))?;
s.execute("prop.set", json!({"comp": fc, "layer": cam, "path": "transform/orientation", "value": o}))?; s.execute("prop.set", json!({"comp": fc, "layer": cam, "path": "transform/orientation", "value": o}))?;
// The scene's layers (not its cameras), in the scene's coordinates, under the face // The scene, nested as a collapsed 3D precomp whose layer maps the scene's
// camera. // coordinates onto the face comp's unchanged (anchor = position): its 3D layers are
let layers: Vec<effectcraft_project::Layer> = src.layers.iter().filter(|l| !l.is_camera()).cloned().collect(); // seen through the face camera and edits to the scene show in every face. Lights
s.edit("Create VR Environment", None, |proj, _| { // inside a collapsed precomp do not light it (the containing comp's do), so the
let mut next = proj.next_id; // scene's lights are copied next to it.
let mut map = std::collections::BTreeMap::new(); let pre = id_of(&s.execute("layer.addItem", json!({"comp": fc, "item": cid.0, "time": 0.0}))?, "layer")?;
let mut copies = vec![]; let mid = [src.width as f64 / 2.0, src.height as f64 / 2.0, 0.0];
for l in &layers { s.execute("layer.setSwitch", json!({"comp": fc, "layers": [pre], "switch": "threeD", "value": true}))?;
let mut c = l.clone(); s.execute("layer.setSwitch", json!({"comp": fc, "layers": [pre], "switch": "collapse", "value": true}))?;
super::edit::reid(&mut c, &mut next); s.execute("prop.set", json!({"comp": fc, "layer": pre, "path": "transform/anchor", "value": mid}))?;
map.insert(l.id, c.id); s.execute("prop.set", json!({"comp": fc, "layer": pre, "path": "transform/position", "value": mid}))?;
copies.push(c); let lights: Vec<effectcraft_project::Layer> = src.layers.iter().filter(|l| l.is_light()).cloned().collect();
} if !lights.is_empty() {
for c in &mut copies { s.edit("Create VR Environment", None, |proj, _| {
c.parent = c.parent.and_then(|p| map.get(&p).copied()); let mut next = proj.next_id;
if let Some(m) = &mut c.track_matte { let mut map = std::collections::BTreeMap::new();
m.layer = map.get(&m.layer).copied().unwrap_or(m.layer); let mut copies = vec![];
for l in &lights {
let mut c = l.clone();
super::edit::reid(&mut c, &mut next);
map.insert(l.id, c.id);
copies.push(c);
} }
} for c in &mut copies {
proj.next_id = next; c.parent = c.parent.and_then(|p| map.get(&p).copied());
let comp = proj.comp_mut(ItemId(fc)).ok_or(EngineError::NoComp)?; }
comp.layers.extend(copies); proj.next_id = next;
Ok(()) let comp = proj.comp_mut(ItemId(fc)).ok_or(EngineError::NoComp)?;
})?; let at = comp.layers.len().saturating_sub(1);
for (k, c) in copies.into_iter().enumerate() {
comp.layers.insert(at + k, c);
}
Ok(())
})?;
}
faces.push(fc); faces.push(fc);
} }
let cube = id_of( let cube = id_of(
+3 -2
View File
@@ -476,8 +476,9 @@ fn create_vr_environment_and_extract_cubemap() {
let c = s.project.comp(ItemId(*f)).unwrap(); let c = s.project.comp(ItemId(*f)).unwrap();
assert_eq!((c.width, c.height), (64, 64)); assert_eq!((c.width, c.height), (64, 64));
assert!(c.layers.iter().any(|l| l.is_camera())); assert!(c.layers.iter().any(|l| l.is_camera()));
assert!(c.layers.iter().any(|l| l.name == aname && l.is_3d()), "the scene's layers"); let nested = c.layers.iter().find(|l| matches!(l.source, effectcraft_project::LayerSource::Comp { item } if item == main)).expect("the scene, nested");
let _ = main; assert!(nested.switches.collapse && nested.is_3d(), "collapsed 3D precomp");
let _ = &aname;
} }
let cube = s.project.comp(ItemId(r["cubeMap"].as_u64().unwrap())).unwrap(); let cube = s.project.comp(ItemId(r["cubeMap"].as_u64().unwrap())).unwrap();
assert_eq!((cube.width, cube.height, cube.layers.len()), (192, 128, 6)); assert_eq!((cube.width, cube.height, cube.layers.len()), (192, 128, 6));