M7.3: Auto-Orient (along path, towards camera), Draft 3D, 3D switch off drops Z
- layer.autoOrient {mode: off|alongPath|towardsCamera|towardsPointOfInterest}
(Layer > Transform > Auto-Orient…, Cmd+Alt+O); render support for Orient
Along Path (2D and 3D) and Orient Towards Camera (with recursion guard).
- Layers parented to cameras/lights follow their full rotation.
- Draft 3D turns off lights and shadows (and DOF).
- Turning the 3D switch off discards Z values, Orientation and X/Y Rotation.
- Tests for all of the above.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
16a5fa7a83
commit
37c07ba5b1
@@ -363,13 +363,43 @@ fn set_switch_value(l: &mut Layer, name: &str, v: bool) {
|
||||
"frameBlend" => sw.frame_blend = if v { FrameBlend::FrameMix } else { FrameBlend::Off },
|
||||
"motionBlur" => sw.motion_blur = v,
|
||||
"adjustment" => sw.adjustment = v,
|
||||
"threeD" | "3d" | "3D" => sw.three_d = v,
|
||||
"threeD" | "3d" | "3D" => {
|
||||
if sw.three_d && !v {
|
||||
drop_3d_values(l);
|
||||
}
|
||||
l.switches.three_d = v;
|
||||
}
|
||||
"guide" => sw.guide = v,
|
||||
"preserveTransparency" => l.preserve_transparency = v,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Turning the 3D switch off discards Z values, Orientation and X/Y Rotation (as in AE).
|
||||
fn drop_3d_values(l: &mut Layer) {
|
||||
let Some(tr) = l.transform_mut() else { return };
|
||||
for (m, keep) in [("position", 0.0), ("anchor", 0.0), ("scale", 100.0)] {
|
||||
if let Some(pr) = tr.get_mut(m) {
|
||||
let flat = |v: &mut KV| {
|
||||
if let KV::Vec3(a) = v {
|
||||
a[2] = keep;
|
||||
}
|
||||
};
|
||||
flat(&mut pr.value);
|
||||
for k in &mut pr.keys {
|
||||
flat(&mut k.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (m, zero) in [("orientation", KV::Vec3([0.0; 3])), ("rotationX", KV::Scalar(0.0)), ("rotationY", KV::Scalar(0.0))] {
|
||||
if let Some(pr) = tr.get_mut(m) {
|
||||
pr.keys.clear();
|
||||
pr.expr = None;
|
||||
pr.value = zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn rename(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let (cid, lid) = layer_p(s, p, "layer.rename")?;
|
||||
let name = str_p(p, "name").ok_or_else(|| bad("layer.rename", "missing `name`"))?.to_string();
|
||||
|
||||
@@ -494,8 +494,52 @@ fn dolly(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
camera_tool(s, p, ToolOp::Dolly(f_p(p, "amount").or_else(|| f_p(p, "dz")).unwrap_or(0.0)), "camera.dolly", "Dolly Camera")
|
||||
}
|
||||
|
||||
/// Layer ▸ Transform ▸ Auto-Orient: off | alongPath | towardsCamera (3D layers) |
|
||||
/// towardsPointOfInterest (cameras and spot/parallel lights).
|
||||
fn auto_orient(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let (cid, ids) = super::layers_p(s, p)?;
|
||||
if ids.is_empty() {
|
||||
return Err(bad("layer.autoOrient", "select a layer first"));
|
||||
}
|
||||
let raw = str_p(p, "mode").ok_or_else(|| bad("layer.autoOrient", "missing `mode` (off|alongPath|towardsCamera|towardsPointOfInterest)"))?;
|
||||
let k = raw.to_ascii_lowercase().replace([' ', '-', '_'], "");
|
||||
let mode = match k.as_str() {
|
||||
"off" => AutoOrient::Off,
|
||||
"alongpath" | "orientalongpath" => AutoOrient::AlongPath,
|
||||
"towardscamera" | "orienttowardscamera" => AutoOrient::TowardsCamera,
|
||||
"towardspointofinterest" | "towardspoi" | "orienttowardspointofinterest" => AutoOrient::TowardsPointOfInterest,
|
||||
_ => return Err(bad("layer.autoOrient", format!("unknown mode `{raw}`"))),
|
||||
};
|
||||
s.edit("Auto-Orient", None, |proj, _| {
|
||||
let comp = proj.comp_mut(cid).ok_or(EngineError::NoComp)?;
|
||||
for l in comp.layers.iter_mut().filter(|l| ids.contains(&l.id)) {
|
||||
let rig = l.is_camera() || l.is_light();
|
||||
let ok = match mode {
|
||||
AutoOrient::Off | AutoOrient::AlongPath => true,
|
||||
AutoOrient::TowardsCamera => !rig,
|
||||
AutoOrient::TowardsPointOfInterest => rig && l.transform().is_some_and(|t| t.get("poi").is_some()),
|
||||
};
|
||||
if !ok {
|
||||
return Err(bad("layer.autoOrient", format!("`{raw}` is not available for layer `{}`", l.name)));
|
||||
}
|
||||
l.auto_orient = mode;
|
||||
}
|
||||
Ok(())
|
||||
})?;
|
||||
Ok(Value::Null)
|
||||
}
|
||||
|
||||
pub fn specs() -> Vec<CommandSpec> {
|
||||
vec![
|
||||
cmd!(
|
||||
"layer.autoOrient",
|
||||
"Auto-Orient…",
|
||||
["Layer", "Transform"],
|
||||
Some("Cmd+Alt+O"),
|
||||
"{mode: off|alongPath|towardsCamera|towardsPointOfInterest, layers?}",
|
||||
super::has_layers,
|
||||
auto_orient
|
||||
),
|
||||
cmd!(
|
||||
"layer.newLight",
|
||||
"Light…",
|
||||
|
||||
@@ -12,6 +12,20 @@ fn session() -> Session {
|
||||
s
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auto_orient_command() {
|
||||
let mut s = session();
|
||||
let id = s.execute("layer.newSolid", json!({"width": 100, "height": 100})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("layer.autoOrient", json!({"layer": id, "mode": "towardsCamera"})).unwrap();
|
||||
assert_eq!(s.active_comp().unwrap().layers[0].auto_orient, AutoOrient::TowardsCamera);
|
||||
s.undo();
|
||||
assert_eq!(s.active_comp().unwrap().layers[0].auto_orient, AutoOrient::Off);
|
||||
let cam = s.execute("layer.newCamera", json!({})).unwrap()["layer"].as_u64().unwrap();
|
||||
assert!(s.execute("layer.autoOrient", json!({"layer": cam, "mode": "towardsCamera"})).is_err());
|
||||
s.execute("layer.autoOrient", json!({"layer": cam, "mode": "off"})).unwrap();
|
||||
assert!(!effectcraft_render::three_d::camera::is_two_node(&s.active_comp().unwrap().layers[0]));
|
||||
}
|
||||
|
||||
fn layer_count(s: &Session) -> usize {
|
||||
s.active_comp().unwrap().layers.len()
|
||||
}
|
||||
@@ -102,6 +116,27 @@ fn three_d_switch_undo_redo() {
|
||||
assert!(!s.active_comp().unwrap().layers[0].is_3d());
|
||||
s.redo();
|
||||
assert!(s.active_comp().unwrap().layers[0].is_3d());
|
||||
// Turning 3D off discards Z and the 3D-only rotations.
|
||||
s.execute("prop.set", json!({"layer": id, "path": "transform/position", "value": [10, 20, 300]})).unwrap();
|
||||
s.execute("prop.set", json!({"layer": id, "path": "transform/rotationX", "value": 45})).unwrap();
|
||||
s.execute("layer.setSwitch", json!({"layer": id, "switch": "threeD", "value": false})).unwrap();
|
||||
assert_eq!(prop(&s, id, "transform/position").as_vec3(), [10.0, 20.0, 0.0]);
|
||||
assert_eq!(prop(&s, id, "transform/rotationX").as_f64(), 0.0);
|
||||
s.undo();
|
||||
assert_eq!(prop(&s, id, "transform/position").as_vec3(), [10.0, 20.0, 300.0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn draft_3d_turns_off_lighting() {
|
||||
let mut s = session();
|
||||
let cid = s.active_comp_id().unwrap();
|
||||
let id = s.execute("layer.newSolid", json!({"width": 640, "height": 360, "color": [1, 1, 1]})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("layer.setSwitch", json!({"layer": id, "switch": "threeD", "value": true})).unwrap();
|
||||
s.execute("layer.newLight", json!({"kind": "Point", "intensity": 50, "position": [320, 180, -400]})).unwrap();
|
||||
let px = |s: &Session| s.render(cid, s.time(), effectcraft_render::RenderOpts::default()).get(320, 180)[0];
|
||||
assert!(px(&s) < 0.5);
|
||||
s.execute("comp.setSwitch", json!({"switch": "draft3d", "value": true})).unwrap();
|
||||
assert!((px(&s) - 1.0).abs() < 1e-5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user