Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(gpui): add 3D camera shot panels and look controls

Richie McIlroy9a44a5439c43
diff --git a/apps/desktop-gpui/src/editor_panels.rs b/apps/desktop-gpui/src/editor_panels.rs
index a69a36a43..4ad482e30 100644
--- a/apps/desktop-gpui/src/editor_panels.rs
+++ b/apps/desktop-gpui/src/editor_panels.rs
@@ -843,57 +843,6 @@ pub const SCENE_MODES: [(SceneMode, &str, &str, &str); 5] = [
),
];
-/// `CAMERA3D_SLIDERS` (`:4519-4530`) with its icons (`:4544-4557`).
-pub const CAMERA3D_POSE_SLIDERS: [(Camera3DProperty, &str, &str, &str); 9] = [
- (
- Camera3DProperty::TiltX,
- "Tilt X",
- "\u{b0}",
- "icons/rotate-3d.svg",
- ),
- (
- Camera3DProperty::TiltY,
- "Tilt Y",
- "\u{b0}",
- "icons/rotate-3d.svg",
- ),
- (
- Camera3DProperty::Roll,
- "Roll",
- "\u{b0}",
- "icons/rotate-cw.svg",
- ),
- (
- Camera3DProperty::RotateX,
- "Rotate X",
- "\u{b0}",
- "icons/rotate-3d.svg",
- ),
- (
- Camera3DProperty::RotateY,
- "Rotate Y",
- "\u{b0}",
- "icons/rotate-3d.svg",
- ),
- (
- Camera3DProperty::Fov,
- "Field of view",
- "\u{b0}",
- "icons/maximize.svg",
- ),
- (Camera3DProperty::Zoom, "Zoom", "", "icons/search.svg"),
- (Camera3DProperty::PanX, "Pan X", "", "icons/move.svg"),
- (Camera3DProperty::PanY, "Pan Y", "", "icons/move.svg"),
-];
-
-/// `CAMERA3D_BLUR_MODE_OPTIONS` (`:4560-4569`).
-pub const CAMERA3D_BLUR_MODES: [(Camera3DBlurMode, &str); 4] = [
- (Camera3DBlurMode::None, "None"),
- (Camera3DBlurMode::Radial, "Radial"),
- (Camera3DBlurMode::Directional, "Directional"),
- (Camera3DBlurMode::TiltShift, "Tilt Shift"),
-];
-
/// `CAMERA3D_BLUR_SLIDERS` (`:4577-4602`): each mode exposes only the
/// parameters it reads, in display order.
pub fn camera3d_blur_sliders(mode: Camera3DBlurMode) -> &'static [(Camera3DBlurKey, &'static str)] {
@@ -1015,16 +964,6 @@ pub struct AnglePreset {
pub blur: fn() -> Camera3DBlur,
}
-/// `CAMERA3D_ANGLE_PRESET_KEYS` (`three-d.ts`): only these five decide whether
-/// a pose *is* a preset -- `rotateX` / `rotateY` are the fold, not the angle.
-const ANGLE_PRESET_KEYS: [Camera3DProperty; 5] = [
- Camera3DProperty::TiltX,
- Camera3DProperty::TiltY,
- Camera3DProperty::Roll,
- Camera3DProperty::Zoom,
- Camera3DProperty::Fov,
-];
-
/// `ANGLE_PRESETS` (`three-d.ts:340-418`), in order.
pub static ANGLE_PRESETS: &[AnglePreset] = &[
AnglePreset {
@@ -1327,20 +1266,6 @@ pub fn angle_preset_motion(preset: &AnglePreset) -> MotionTemplate {
}
}
-/// `matchAnglePreset` (`three-d.ts:446-454`). Half a slider step is the
-/// tightest a pose can be "the same as" a preset and still be reachable.
-pub fn match_angle_preset(poseation: &Camera3DProperties) -> Option<&'static str> {
- ANGLE_PRESETS
- .iter()
- .find(|preset| {
- ANGLE_PRESET_KEYS.iter().all(|key| {
- let epsilon = f64::from(key.limits().2 / 2.).max(1e-4);
- (key.read(poseation) - key.read(&preset.values)).abs() <= epsilon
- })
- })
- .map(|preset| preset.id)
-}
-
/// `applyMotionTemplate` (`three-d.ts`): the whole camera animation replaced,
/// blur included, on the linear easing every template is authored against.
pub fn apply_motion_template(segment: &mut Camera3DSegment, template: &MotionTemplate) {
@@ -1364,13 +1289,6 @@ pub struct Camera3DScene {
pub shots: &'static [SceneShot],
}
-struct Camera3DSection<'a> {
- id: &'static str,
- name: &'static str,
- icon: &'static str,
- summary: Option<&'a str>,
-}
-
/// The showcase's third shot has its own defocus, authored inline.
fn showcase_push_blur() -> Camera3DBlur {
Camera3DBlur {
@@ -1586,17 +1504,245 @@ pub static CAMERA3D_SCENES: &[Camera3DScene] = &[
const fn card_grid_width(columns: f32, gap: f32) -> f32 {
(350. - gap * (columns - 1.)) / columns
}
-/// `grid-cols-2 gap-2`, `grid-cols-3 gap-2`, `grid-cols-4 gap-2`,
-/// `grid-cols-5 gap-1.5`.
+/// `grid-cols-2 gap-2`.
const CARD_GRID_WIDTH_2: f32 = card_grid_width(2., 8.);
-const CARD_GRID_WIDTH_3: f32 = card_grid_width(3., 8.);
-const CARD_GRID_WIDTH_4: f32 = card_grid_width(4., 8.);
-const CARD_GRID_WIDTH_5: f32 = card_grid_width(5., 6.);
+/// `grid-cols-3 gap-1.5`.
+const CARD_GRID_WIDTH_3: f32 = card_grid_width(3., 6.);
+
+// -- The 3D shot panel's geometry -------------------------------------------
+// This panel draws its own groups rather than sitting in the shared card, so
+// its content is the sidebar less the scroll body's `p-4`.
+
+/// The panel's content column.
+const CAMERA3D_PANEL_WIDTH: f32 = crate::editor_window::SIDEBAR_WIDTH - 32.;
+/// Every group's inner padding.
+const CAMERA3D_GROUP_PADDING: f32 = 12.;
+/// What is left inside a group, its hairline and padding removed.
+const CAMERA3D_GROUP_WIDTH: f32 = CAMERA3D_PANEL_WIDTH - 2. - CAMERA3D_GROUP_PADDING * 2.;
+/// Four Look tiles to a row, 8px apart, with a pixel of slack.
+const CAMERA3D_LOOK_TILE: f32 = (CAMERA3D_GROUP_WIDTH - 24. - 4.) / 4.;
+/// The tiles' 4:3 thumbnails.
+const CAMERA3D_LOOK_THUMB: f32 = CAMERA3D_LOOK_TILE * 0.75;
+/// Three sequence cards to a row.
+const CAMERA3D_SEQUENCE_CARD: f32 = (CAMERA3D_GROUP_WIDTH - 16. - 3.) / 3.;
+/// The orbit pad.
+const CAMERA3D_ORBIT_PAD: f32 = 132.;
+/// The pose strip's two cards: half the group each, less the swap between
+/// them, at 4:3.
+const CAMERA3D_POSE_CARD: f32 = (CAMERA3D_GROUP_WIDTH - 24. - 16.) / 2.;
+const CAMERA3D_POSE_CARD_HEIGHT: f32 = CAMERA3D_POSE_CARD * 0.75;
+/// The panel's compact slider rows: the sidebar's own 96px label column does
+/// not fit beside the pad.
+const CAMERA3D_ROW_LABEL: f32 = 62.;
+const CAMERA3D_ROW_VALUE: f32 = 42.;
+
+/// The Look tiles' and orbit pad's backdrop. The plate drawn on it stands for
+/// the recording rather than for the chrome, so it stays light in both
+/// appearances -- these are the mock's own values.
+fn camera3d_thumb_bg(dark: bool) -> Hsla {
+ Hsla::from(gpui::rgb(if dark { 0x26262b } else { 0xdcdce2 }))
+}
+const CAMERA3D_PLATE: u32 = 0xffffff;
+const CAMERA3D_PLATE_DARK: u32 = 0xf2f2f4;
+const CAMERA3D_PLATE_LINE: u32 = 0xb8b8c2;
+/// What the Depth blur toggle seeds when it is switched on.
+const CAMERA3D_DEFAULT_BLUR_STRENGTH: f64 = 18.;
+const CAMERA3D_DEFAULT_BLUR_FALLOFF: f64 = 0.7;
+
+/// The Focus segmented control: the three real modes, in the order the source
+/// lists them. "None" is the toggle, not an option.
+const CAMERA3D_FOCUS_MODES: [(Camera3DBlurMode, &str); 3] = [
+ (Camera3DBlurMode::Radial, "Radial"),
+ (Camera3DBlurMode::Directional, "Directional"),
+ (Camera3DBlurMode::TiltShift, "Tilt shift"),
+];
+
+// ---------------------------------------------------------------------------
+// Seeking to a pose, and the Auto scene's shot pool
+// ---------------------------------------------------------------------------
+
+/// The first whole frame at or after `time`.
+///
+/// The renderer quantises a seek by flooring it onto a frame, so seeking to a
+/// shot's own `start` lands on the frame *before* the shot whenever the start
+/// is not on a frame boundary -- and the player then shows the previous scene
+/// instead of the move that was just clicked.
+fn camera3d_frame_at_or_after(time: f64, fps: u32) -> f64 {
+ let fps = f64::from(fps.max(1));
+ ((time * fps - 1e-6).ceil() / fps).max(0.)
+}
+
+/// The last whole frame that still belongs to a shot ending at `end`.
+fn camera3d_frame_before(end: f64, fps: u32) -> f64 {
+ let fps = f64::from(fps.max(1));
+ (((end - 1e-3) * fps).floor() / fps).max(0.)
+}
+
+/// `camera3DPoseSeekTime`: where the playhead goes to show one end of a shot.
+///
+/// The end pose is the last frame inside the shot rather than its boundary,
+/// which belongs to whatever comes next; it never lands before the start
+/// frame, so a shot shorter than a frame still shows its own pose.
+pub fn camera3d_pose_seek_time(segment: &Camera3DSegment, end: bool, fps: u32) -> f64 {
+ let start_frame = camera3d_frame_at_or_after(segment.start, fps);
+ if !end {
+ return start_frame;
+ }
+ camera3d_frame_before(segment.end, fps).max(start_frame)
+}
+
+/// How many shots the Auto scene picker offers.
+pub const AUTO_CAMERA3D_MAX_SHOTS: usize = 6;
+
+/// `maxAutoCamera3DShots`: a recording only holds so many shots at the one
+/// second below which a cut reads as a glitch.
+pub fn max_auto_camera3d_shots(total: f64) -> usize {
+ if !total.is_finite() || total <= 0. {
+ return 0;
+ }
+ ((total / CAMERA3D_MIN_SHOT_DURATION).floor() as usize).min(AUTO_CAMERA3D_MAX_SHOTS)
+}
+
+/// `AUTO_SHOT_POOL`: the three authored scenes' nine shots, in scene order,
+/// re-weighted equally -- the picker's Nth scene is the first N of these, so
+/// asking for one more shot keeps the ones already there and adds to them.
+pub fn auto_camera3d_shots(count: usize) -> Vec<SceneShot> {
+ CAMERA3D_SCENES
+ .iter()
+ .flat_map(|scene| scene.shots.iter())
+ .take(count)
+ .map(|shot| SceneShot {
+ weight: 1.,
+ from: shot.from,
+ to: shot.to,
+ blur: shot.blur,
+ })
+ .collect()
+}
+
+/// `autoCamera3DScene(count)` laid across a range: one shot is the opening
+/// move over the whole thing, and anything more is the pool cut on the clips.
+pub fn auto_camera3d_layout(
+ count: usize,
+ start: f64,
+ end: f64,
+ clip_cuts: &[f64],
+) -> Vec<Camera3DSegment> {
+ if end <= start || !(end - start).is_finite() || count == 0 {
+ return Vec::new();
+ }
+ if count == 1 {
+ return vec![new_camera3d_shot(start, end)];
+ }
+ apply_camera3d_shots_to_range(&auto_camera3d_shots(count), start, end, clip_cuts)
+}
+
+/// One stroke of the drawn plate: its points in plate space, and the ink it
+/// takes -- `None` being the plate's own fill.
+type Camera3DPlateShape = (&'static [(f32, f32)], Option<u32>);
+
+/// The plate's four corners in plate space, in order.
+const CAMERA3D_PLATE_CORNERS: [(f32, f32); 4] = [(-1., 1.), (1., 1.), (1., -1.), (-1., -1.)];
-/// The three template grids' preview heights (`ConfigSidebar.tsx:4647-4650`).
-const CAMERA3D_ANGLE_PREVIEW_HEIGHT: f32 = 30.;
-const CAMERA3D_TEMPLATE_PREVIEW_HEIGHT: f32 = 40.;
-const CAMERA3D_SCENE_PREVIEW_HEIGHT: f32 = 48.;
+/// How much a pose's projected plate has to shrink to stay inside its tile,
+/// and the pose to draw it with.
+///
+/// A pose close enough to push the plate's far corners through the camera
+/// projects as a bowtie rather than a card -- true to the renderer, useless as
+/// a picture. Those are drawn from further back instead: the orientation the
+/// tile is there to show survives, and the fit normalises the size away
+/// anyway.
+fn camera3d_plate_fit(pose: &Camera3DProperties) -> Option<(Camera3DProperties, f32)> {
+ let mut preview = *pose;
+ for step in 0..10 {
+ // A plate whose far corner runs off to several frame widths is a
+ // sliver once it is scaled to fit, so those pull back too.
+ if let Some(extent) =
+ camera3d_plate_extent(&preview).filter(|extent| *extent <= 1.2 || step == 9)
+ {
+ // 0.44 leaves a hair of margin inside the tile. A plate that fits
+ // keeps its true size, so a distant pose reads as distant -- but a
+ // pose that had to be pulled back is normalised, or the tile would
+ // report a distance nobody asked for.
+ let scale = if extent > 0.44 || step > 0 {
+ 0.44 / extent
+ } else {
+ 1.
+ };
+ return Some((preview, scale));
+ }
+ preview.zoom *= 1.4;
+ }
+ None
+}
+
+/// The plate's half-extent in view space, or `None` when it does not project
+/// as a plain convex quad -- which is what a pose close enough to push its far
+/// corners through the camera does.
+fn camera3d_plate_extent(pose: &Camera3DProperties) -> Option<f32> {
+ let mut corners = [(0_f32, 0_f32); 4];
+ let mut extent = 0_f32;
+ for (index, (x, y)) in CAMERA3D_PLATE_CORNERS.into_iter().enumerate() {
+ let (px, py) = camera3d_projected_point(pose, x, y)?;
+ corners[index] = (px, py);
+ extent = extent.max((px - 0.5).abs()).max((py - 0.5).abs());
+ }
+ if !extent.is_finite() {
+ return None;
+ }
+ let mut sign = 0_f32;
+ for index in 0..4 {
+ let (ax, ay) = corners[index];
+ let (bx, by) = corners[(index + 1) % 4];
+ let (cx, cy) = corners[(index + 2) % 4];
+ let cross = (bx - ax) * (cy - by) - (by - ay) * (cx - bx);
+ if cross.abs() < 1e-6 {
+ return None;
+ }
+ if sign == 0. {
+ sign = cross.signum();
+ } else if cross.signum() != sign {
+ return None;
+ }
+ }
+ (extent > 0.).then_some(extent)
+}
+
+/// One plate-space point, projected and then fitted about the frame centre.
+fn camera3d_plate_point(pose: &Camera3DProperties, fit: f32, x: f32, y: f32) -> Option<(f32, f32)> {
+ let (px, py) = camera3d_projected_point(pose, x, y)?;
+ Some((0.5 + (px - 0.5) * fit, 0.5 + (py - 0.5) * fit))
+}
+
+/// Where the orbit pad's dot sits for a pose: `tiltY` across, `tiltX` up, each
+/// linear across its own `CAMERA3D_LIMITS` range with the centre on zero.
+fn camera3d_orbit_point(pose: &Camera3DProperties) -> (f32, f32) {
+ let axis = |property: Camera3DProperty| {
+ let (min, max, _) = property.limits();
+ let span = f64::from(max - min);
+ if span <= 0. {
+ return 0.5_f32;
+ }
+ (((property.read(pose) - f64::from(min)) / span) as f32).clamp(0., 1.)
+ };
+ // Positive tilt X is the camera looking down, which belongs at the top.
+ (
+ axis(Camera3DProperty::TiltY),
+ 1. - axis(Camera3DProperty::TiltX),
+ )
+}
+
+/// The inverse: a point on the pad back onto the two tilts.
+fn camera3d_orbit_tilts(x: f64, y: f64) -> (f64, f64) {
+ let axis = |property: Camera3DProperty, fraction: f64| {
+ let (min, max, _) = property.limits();
+ f64::from(min) + fraction.clamp(0., 1.) * f64::from(max - min)
+ };
+ (
+ axis(Camera3DProperty::TiltX, 1. - y),
+ axis(Camera3DProperty::TiltY, x),
+ )
+}
/// `CAMERA3D_MIN_SHOT_DURATION` (`three-d.ts:831`): below a second a cut reads
/// as a glitch rather than an edit.
@@ -1617,16 +1763,27 @@ pub fn apply_scene_to_range(
start: f64,
end: f64,
clip_cuts: &[f64],
+) -> Vec<Camera3DSegment> {
+ apply_camera3d_shots_to_range(scene.shots, start, end, clip_cuts)
+}
+
+/// The same, over a shot list that is not one of the three authored scenes --
+/// which is what the Auto scene picker builds.
+pub fn apply_camera3d_shots_to_range(
+ shots: &[SceneShot],
+ start: f64,
+ end: f64,
+ clip_cuts: &[f64],
) -> Vec<Camera3DSegment> {
let length = end - start;
- if length <= 0. || !length.is_finite() || scene.shots.is_empty() {
+ if length <= 0. || !length.is_finite() || shots.is_empty() {
return Vec::new();
}
let keep = ((length / CAMERA3D_MIN_SHOT_DURATION).floor() as usize)
- .min(scene.shots.len())
+ .min(shots.len())
.max(1);
- let shots = &scene.shots[..keep];
+ let shots = &shots[..keep];
let total_weight: f64 = shots.iter().map(|shot| shot.weight.max(0.)).sum();
let share = |shot: &SceneShot| {
if total_weight > 0. {
@@ -1689,6 +1846,200 @@ pub fn apply_scene_to_range(
.collect()
}
+// ---------------------------------------------------------------------------
+// Shots: placement, look matching, labels
+// ---------------------------------------------------------------------------
+
+/// `DEFAULT_SHOT_DURATION`: the length a new 3D shot opens at.
+pub const CAMERA3D_DEFAULT_SHOT_DURATION: f64 = 4.;
+
+/// The move a brand-new shot is born with, and what the ghost calls it.
+pub const CAMERA3D_DEFAULT_LOOK: &str = "glide-across";
+pub const CAMERA3D_DEFAULT_LOOK_NAME: &str = "Glide across";
+
+/// Where a new shot lands, given the shots already on the track.
+///
+/// A click in free space starts the shot there and runs it for `duration`,
+/// shortened to whatever the gap holds and slid left when the gap's tail is
+/// too short. A click **inside** an existing shot is not a no-op -- it takes
+/// the next free gap after that shot, then the first free gap anywhere. Only a
+/// track with no gap at least [`CAMERA3D_MIN_SHOT_DURATION`] long returns
+/// `None`, which is the one case the caller reports rather than silently
+/// swallowing.
+pub fn place_camera3d_shot(
+ existing: &[(f64, f64)],
+ time: f64,
+ duration: f64,
+ total: f64,
+) -> Option<(f64, f64)> {
+ if ![time, duration, total]
+ .iter()
+ .all(|value| value.is_finite())
+ || duration <= 0.
+ || total <= 0.
+ {
+ return None;
+ }
+ let minimum = CAMERA3D_MIN_SHOT_DURATION.min(total);
+
+ // The occupied spans, clamped to the timeline, sorted and merged, so an
+ // overlapping pair cannot hand out a gap that is really inside a shot.
+ let mut taken: Vec<(f64, f64)> = existing
+ .iter()
+ .copied()
+ .filter(|(start, end)| start.is_finite() && end.is_finite() && end > start && *end > 0.)
+ .map(|(start, end)| (start.max(0.), end.min(total)))
+ .filter(|(start, end)| end > start)
+ .collect();
+ taken.sort_by(|a, b| a.0.total_cmp(&b.0));
+ let mut occupied: Vec<(f64, f64)> = Vec::with_capacity(taken.len());
+ for (start, end) in taken {
+ match occupied.last_mut() {
+ Some(last) if start <= last.1 => last.1 = last.1.max(end),
+ _ => occupied.push((start, end)),
+ }
+ }
+
+ let mut gaps: Vec<(f64, f64)> = Vec::new();
+ let mut cursor = 0.;
+ for &(start, end) in &occupied {
+ if start - cursor >= minimum {
+ gaps.push((cursor, start));
+ }
+ cursor = cursor.max(end);
+ }
+ if total - cursor >= minimum {
+ gaps.push((cursor, total));
+ }
+
+ let time = time.clamp(0., total);
+ let (gap_start, gap_end) = gaps
+ .iter()
+ .copied()
+ .find(|(start, end)| time >= *start && time < *end)
+ .or_else(|| gaps.iter().copied().find(|(start, _)| *start >= time))
+ .or_else(|| gaps.first().copied())?;
+
+ // A gap the click did not land in is filled from its own start.
+ let anchor = if time >= gap_start && time < gap_end {
+ time
+ } else {
+ gap_start
+ };
+ let mut start = anchor;
+ let mut end = (start + duration).min(gap_end);
+ // Only a tail too short to read as a shot slides the start back.
+ if end - start < minimum {
+ start = (gap_end - minimum).max(gap_start);
+ end = gap_end;
+ }
+ (end - start >= minimum).then_some((start, end))
+}
+
+/// A new shot: the default segment with the opening move already on it, so
+/// what lands on the timeline is a complete look rather than a still frame.
+pub fn new_camera3d_shot(start: f64, end: f64) -> Camera3DSegment {
+ let mut segment = crate::editor_edits::default_camera3d_segment(start, end);
+ if let Some(template) = MOTION_TEMPLATES
+ .iter()
+ .find(|template| template.id == CAMERA3D_DEFAULT_LOOK)
+ {
+ apply_motion_template(&mut segment, template);
+ }
+ segment.transition_in = 0.;
+ segment.transition_out = 0.;
+ segment
+}
+
+/// Which half of the Look grid a look belongs to.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum LookKind {
+ Move,
+ Angle,
+}
+
+/// One entry of the Look grid, resolved back from a segment.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct Look {
+ pub kind: LookKind,
+ pub id: &'static str,
+ pub name: &'static str,
+}
+
+/// Half a slider step -- the tightest two poses can differ and still be "the
+/// same pose", which is the tolerance `matchAnglePreset` is written against.
+fn camera3d_poses_match(a: &Camera3DProperties, b: &Camera3DProperties) -> bool {
+ Camera3DProperty::ALL.iter().all(|property| {
+ let epsilon = f64::from(property.limits().2 / 2.).max(1e-4);
+ (property.read(a) - property.read(b)).abs() <= epsilon
+ })
+}
+
+/// `matchCamera3DLook`: which Look tile, if any, this shot is sitting on.
+///
+/// Both ends have to match, because the grid's ring means "clicking this tile
+/// would change nothing" -- and a template writes both. Blur is not part of
+/// the comparison: a shot whose defocus was dialled in by hand is still the
+/// move it was given.
+pub fn match_camera3d_look(segment: &Camera3DSegment) -> Option<Look> {
+ let start = start_pose(segment);
+ let end = end_pose(segment);
+ MOTION_TEMPLATES
+ .iter()
+ .find(|template| {
+ camera3d_poses_match(&start, &template.from) && camera3d_poses_match(&end, &template.to)
+ })
+ .map(|template| Look {
+ kind: LookKind::Move,
+ id: template.id,
+ name: template.name,
+ })
+ .or_else(|| {
+ ANGLE_PRESETS
+ .iter()
+ .find(|preset| {
+ camera3d_poses_match(&start, &preset.values)
+ && camera3d_poses_match(&end, &preset.drift)
+ })
+ .map(|preset| Look {
+ kind: LookKind::Angle,
+ id: preset.id,
+ name: preset.name,
+ })
+ })
+}
+
+/// What the timeline box and the panel header call this shot.
+pub fn camera3d_shot_label(segment: &Camera3DSegment) -> &'static str {
+ if let Some(look) = match_camera3d_look(segment) {
+ return look.name;
+ }
+ if poses_equal(&start_pose(segment), &end_pose(segment)) {
+ "Still shot"
+ } else {
+ "Custom move"
+ }
+}
+
+/// The Look tiles' little plate, projected through the pose's own homography.
+///
+/// `x` / `y` are in the plate's own [-1, 1] space; the result is the point in
+/// [0, 1] view space to paint it at, or `None` when the pose folds the plate
+/// through the camera and there is nothing to draw.
+pub fn camera3d_projected_point(pose: &Camera3DProperties, x: f32, y: f32) -> Option<(f32, f32)> {
+ let projection = cap_rendering::camera3d::camera3d_inverse_homography(pose, 16.0 / 9.0, None)?;
+ let [[a, b, c], [d, e, f], [g, h, i]] = projection.inverse_rows;
+ let x = x * projection.half_extents.0;
+ let y = y * projection.half_extents.1;
+ let w = (d * h - e * g) * x + (b * g - a * h) * y + a * e - b * d;
+ if w.abs() < 0.00001 {
+ return None;
+ }
+ let px = ((e * i - f * h) * x + (c * h - b * i) * y + b * f - c * e) / w;
+ let py = ((f * g - d * i) * x + (a * i - c * g) * y + c * d - a * f) / w;
+ (px.is_finite() && py.is_finite()).then_some(((px + 1.0) / 2.0, (1.0 - py) / 2.0))
+}
+
/// `MOTION_STILL_EPSILON` (`three-d.ts:1233`).
const MOTION_STILL_EPSILON: f64 = 1e-4;
/// `CAMERA3D_TRANSITION_LIMITS` (`three-d.ts:191`).
@@ -2163,6 +2514,9 @@ pub enum PanelSlider {
Camera3DPose(Camera3DProperty),
Camera3DBlur(Camera3DBlurKey),
+ /// The 3D shot's `transitionIn` / `transitionOut`, in seconds.
+ Camera3DTransitionIn,
+ Camera3DTransitionOut,
}
// ---------------------------------------------------------------------------
@@ -2196,9 +2550,6 @@ pub enum FieldKey {
CaptionEnd(usize),
KeyboardStart(usize),
KeyboardEnd(usize),
- /// Kobalte `NumberField`s.
- Camera3DEaseIn(usize),
- Camera3DEaseOut(usize),
SyncOffset(usize, OffsetKind),
/// The crop dialog's four `BoundInput`s (`Editor.tsx:1199-1216`). They do
/// not edit the project at all -- they drive the open cropper, which is
@@ -2331,12 +2682,6 @@ impl EditorWindow {
FieldKey::KeyboardEnd(index) => {
format!("{:.2}", timeline.keyboard_segments.get(index)?.end)
}
- FieldKey::Camera3DEaseIn(index) => {
- ui::format_number(timeline.camera3d_segments.get(index)?.transition_in)
- }
- FieldKey::Camera3DEaseOut(index) => {
- ui::format_number(timeline.camera3d_segments.get(index)?.transition_out)
- }
// `Math.round((props.value ?? 0) * 1000)` -- the offset field is in
// milliseconds (`:6182`).
FieldKey::SyncOffset(clip, kind) => {
@@ -2577,31 +2922,6 @@ impl EditorWindow {
true
});
}
- // Kobalte's `NumberField` fires `onRawValueChange` per keystroke,
- // and its `onBlur` falls back to 0 for anything unparseable.
- FieldKey::Camera3DEaseIn(index) | FieldKey::Camera3DEaseOut(index) => {
- let (min, max, _) = CAMERA3D_TRANSITION_LIMITS;
- let value = match ui::parse_number(&text) {
- Some(value) => value.clamp(min, max),
- None if final_commit => 0.,
- None => return,
- };
- let ease_in = matches!(key, FieldKey::Camera3DEaseIn(_));
- self.edit_camera3d_segment("camera3d-ease", index, window, cx, move |segment| {
- if ease_in {
- if (segment.transition_in - value).abs() < f64::EPSILON {
- return false;
- }
- segment.transition_in = value;
- } else {
- if (segment.transition_out - value).abs() < f64::EPSILON {
- return false;
- }
- segment.transition_out = value;
- }
- true
- });
- }
FieldKey::SyncOffset(clip, kind) => {
let value = match ui::parse_number(&text) {
Some(value) => value,
@@ -2784,6 +3104,10 @@ impl EditorWindow {
PanelSlider::MaskDarkness | PanelSlider::MaskFade => (0., 1., 0.01),
PanelSlider::SceneTransitionIn | PanelSlider::SceneTransitionOut => (0., 2., 0.05),
PanelSlider::SceneScreenZoom | PanelSlider::SceneCameraZoom => (100., 300., 1.),
+ PanelSlider::Camera3DTransitionIn | PanelSlider::Camera3DTransitionOut => {
+ let (min, max, step) = CAMERA3D_TRANSITION_LIMITS;
+ (min as f32, max as f32, step as f32)
+ }
PanelSlider::Camera3DPose(property) => property.limits(),
PanelSlider::Camera3DBlur(key) => {
let blur = self
@@ -2924,6 +3248,15 @@ impl EditorWindow {
.camera3d_segments
.get(index)
.map_or(0., |segment| key.read(&segment.blur)),
+ PanelSlider::Camera3DTransitionIn | PanelSlider::Camera3DTransitionOut => {
+ timeline.camera3d_segments.get(index).map_or(0., |segment| {
+ if slider == PanelSlider::Camera3DTransitionIn {
+ segment.transition_in as f32
+ } else {
+ segment.transition_out as f32
+ }
+ })
+ }
}
}
@@ -3124,6 +3457,16 @@ impl EditorWindow {
true
})
}
+ PanelSlider::Camera3DTransitionIn | PanelSlider::Camera3DTransitionOut => self
+ .edit_camera3d_segment("camera3d-ease", index, window, cx, move |segment| {
+ let value = f64::from(value);
+ if slider == PanelSlider::Camera3DTransitionIn {
+ segment.transition_in = value;
+ } else {
+ segment.transition_out = value;
+ }
+ true
+ }),
}
}
@@ -3313,6 +3656,29 @@ impl EditorWindow {
true
})
}
+ // The 3D orbit pad. A still shot moves both ends together, the
+ // same rule the pose sliders follow.
+ PadKey::Camera3DOrbit(index) => {
+ let editing_end = self.sidebar.editing_end_pose;
+ let (tilt_x, tilt_y) = camera3d_orbit_tilts(x, y);
+ self.edit_camera3d_segment("camera3d-orbit", index, window, cx, move |segment| {
+ let start = start_pose(segment);
+ let end = end_pose(segment);
+ let still = poses_equal(&start, &end);
+ let mut selected = if still || !editing_end { start } else { end };
+ selected.tilt_x = tilt_x;
+ selected.tilt_y = tilt_y;
+ let (_, _, out, into) = MOTION_EASINGS[motion_easing(segment)];
+ if still {
+ set_motion(segment, &selected, &selected, (out, into));
+ } else if editing_end {
+ set_motion(segment, &start, &selected, (out, into));
+ } else {
+ set_motion(segment, &selected, &end, (out, into));
+ }
+ true
+ });
+ }
// `setAllManualPositions` (`:5952-5958`).
PadKey::ZoomMulti => {
let indices = self.zoom_selection_indices();
@@ -3358,6 +3724,21 @@ impl EditorWindow {
Some(ZoomMode::Manual { x, y }) => (f64::from(*x), f64::from(*y)),
_ => (0.5, 0.5),
},
+ // The orbit pad draws its own dot from the pose being edited; this
+ // is only the value the shared drag layer reads back.
+ PadKey::Camera3DOrbit(index) => timeline
+ .camera3d_segments
+ .get(index)
+ .map(|segment| {
+ let pose = if self.sidebar.editing_end_pose {
+ end_pose(segment)
+ } else {
+ start_pose(segment)
+ };
+ let (x, y) = camera3d_orbit_point(&pose);
+ (f64::from(x), f64::from(y))
+ })
+ .unwrap_or((0.5, 0.5)),
// `averageManualPosition` (`:5926-5935`).
PadKey::ZoomMulti => {
let positions: Vec<(f64, f64)> = self
@@ -3525,21 +3906,21 @@ impl EditorWindow {
cx,
|this, index, cx| this.render_keyboard_panel(index, cx),
),
- // `<Show when={segments.length === 1 && segments[0]}>` -- a
- // multi-selection of 3D segments draws the header and nothing else
- // (`:1652-1665`).
+ // One shot draws the whole panel, header included -- it carries
+ // `Play shot`, which the shared header has no room for. A
+ // multi-selection keeps the shared header and nothing else.
TrackKind::ThreeD => {
let indices = count(timeline.camera3d_segments.len());
- div()
- .flex()
- .flex_col()
- .gap(px(16.))
- .child(self.panel_header("3d", "3D", indices.len(), cx))
- .children(
- (indices.len() == 1)
- .then(|| self.panel_card(self.render_camera3d_panel(indices[0], cx))),
- )
- .into_any_element()
+ if indices.len() == 1 {
+ self.render_camera3d_panel(indices[0], cx)
+ } else {
+ div()
+ .flex()
+ .flex_col()
+ .gap(px(16.))
+ .child(self.panel_header("3d", "3D", indices.len(), cx))
+ .into_any_element()
+ }
}
TrackKind::Scene => {
let indices = count(timeline.scene_segments.len());
@@ -4154,12 +4535,15 @@ impl EditorWindow {
input,
)
.flex(true)
- // `px-3 py-2 rounded-lg`
- .padding_x(px(12.))
- .height(px(36.))
- .text_size(px(14.))
- .bg(Hsla::from(theme.gray_2))
- .border(Hsla::from(theme.editor.line)),
+ // `h-[30px] rounded-[7px] border-0 bg-ed-ctl px-2 text-[12px]`
+ .padding_x(px(8.))
+ .height(px(30.))
+ .radius(px(7.))
+ .text_size(px(12.))
+ .bg(Hsla::from(theme.editor.ctl))
+ .border(gpui::transparent_black())
+ .text_color(Hsla::from(theme.editor.text_1))
+ .caret_color(Hsla::from(theme.editor.accent)),
),
);
}
@@ -5879,783 +6263,1387 @@ impl EditorWindow {
});
}
- /// The 3D panel's `Templates` field (`:5091-5170`): three grids over the
- /// same card -- a `Camera3DPosePreview` and a name -- at three column
- /// counts. The scene cards carry a shot-count pill; the angle presets carry
- /// the blue ring when the shot **opens** on that pose, which is what keeps
- /// the ring still while the end pose is being edited (`:4973`).
- fn render_camera3d_templates(
+ /// One Look tile's thumbnail, or the orbit pad's live card: the plate the
+ /// pose folds, drawn through the renderer's own homography.
+ ///
+ /// The projection is the real one, so a tile shows the shot's actual
+ /// framing -- but a pose that pushes the plate past the frame would draw
+ /// nothing recognisable, so anything larger than the tile shrinks about the
+ /// frame centre until it fits. A distant pose keeps its true, smaller size,
+ /// which is what makes "Pull back" read as pulled back.
+ fn camera3d_plate(pose: Camera3DProperties, stroke: f32, dark: bool) -> impl IntoElement {
+ gpui::canvas(
+ |bounds, _, _| bounds,
+ move |_, bounds, window, _| {
+ let Some((pose, fit)) = camera3d_plate_fit(&pose) else {
+ return;
+ };
+ // The 16:9 frame, centred in whatever box the tile gave us.
+ let width =
+ f32::from(bounds.size.width).min(f32::from(bounds.size.height) * 16. / 9.);
+ let height = width * 9. / 16.;
+ let origin_x =
+ f32::from(bounds.origin.x) + (f32::from(bounds.size.width) - width) / 2.;
+ let origin_y =
+ f32::from(bounds.origin.y) + (f32::from(bounds.size.height) - height) / 2.;
+
+ let shapes: &[Camera3DPlateShape] = &[
+ (&[(-1., 1.), (1., 1.), (1., -1.), (-1., -1.)], None),
+ (&[(-0.8, 0.56), (0.4, 0.56)], Some(CAMERA3D_PLATE_LINE)),
+ (&[(-0.8, 0.12), (0.7, 0.12)], Some(CAMERA3D_PLATE_LINE)),
+ (
+ &[(-0.8, -0.32), (-0.1, -0.32)],
+ Some(crate::editor_timeline::track_color::THREE_D),
+ ),
+ ];
+ for &(points, ink) in shapes {
+ let mut path = match ink {
+ None => gpui::PathBuilder::fill(),
+ Some(_) => gpui::PathBuilder::stroke(px(stroke)),
+ };
+ let mut valid = true;
+ for (index, &(x, y)) in points.iter().enumerate() {
+ let Some((x, y)) = camera3d_plate_point(&pose, fit, x, y) else {
+ valid = false;
+ break;
+ };
+ let point =
+ gpui::point(px(origin_x + width * x), px(origin_y + height * y));
+ if index == 0 {
+ path.move_to(point);
+ } else {
+ path.line_to(point);
+ }
+ }
+ if ink.is_none() {
+ path.close();
+ }
+ if valid && let Ok(path) = path.build() {
+ window.paint_path(
+ path,
+ Hsla::from(gpui::rgb(ink.unwrap_or(if dark {
+ CAMERA3D_PLATE_DARK
+ } else {
+ CAMERA3D_PLATE
+ }))),
+ );
+ }
+ }
+ },
+ )
+ .size_full()
+ }
+
+ /// The Look grid's tile: the plate, the arrow badge a move carries, and the
+ /// name under it. Selected is a 2px accent ring, which is the panel's only
+ /// "this is what you have" mark.
+ fn render_camera3d_look(
&self,
index: usize,
- start: &Camera3DProperties,
+ look: &MotionTemplate,
+ kind: LookKind,
+ selected: bool,
cx: &mut Context<Self>,
) -> AnyElement {
let theme = self.theme;
- let active_angle = match_angle_preset(start);
-
- // `Camera3DPosePreview` is a CSS-3D plane under a `perspective`; this
- // rev has no transform, so every card shows the flat plate it would
- // fold. See the README's deviation.
- let plate = move |height: f32| {
- div()
- .w_full()
- .h(px(height))
- .rounded(px(6.))
- .bg(Hsla::from(theme.gray_3))
- .p(px(4.))
- .child(
- div()
- .size_full()
- .rounded(px(3.))
- .border_1()
- .border_color(Hsla::from(theme.gray_6))
- .bg(Hsla::from(if theme.is_dark() {
- theme.gray_5
- } else {
- theme.gray_1
- })),
- )
- };
-
- // `class="flex flex-col gap-1 p-1 rounded-lg border"`, blue-ringed when
- // selected, `hover:border-gray-7` otherwise.
- let card = move |id: SharedString,
- name: &'static str,
- width: f32,
- height: f32,
- selected: bool,
- pill: Option<SharedString>| {
- div()
- .id(id)
- // An explicit width, not `flex_1`: a flex item that has to be
- // measured intrinsically makes taffy shape the label once per
- // sizing probe, and sixteen cards of that is 40ms a frame --
- // enough to drop the player from 59.8fps to 19. The grid is
- // fixed-column anyway, so the width is arithmetic.
- .w(px(width))
- .flex_none()
- .flex()
- .flex_col()
- .gap(px(4.))
- .p(px(4.))
- .rounded(px(8.))
- .border_1()
- .border_color(if selected {
- Hsla::from(theme.blue_9)
- } else {
- Hsla::from(theme.gray_4)
- })
- .when(!selected, |this| {
- this.hover(|style| style.border_color(Hsla::from(theme.gray_7)))
- })
- .child(
- div()
- .relative()
- .child(plate(height))
- .children(pill.map(|pill| {
- div()
- .absolute()
- .top(px(4.))
- .right(px(4.))
- .rounded(px(3.))
- .px(px(3.))
- .text_size(px(9.))
- .bg(crate::editor_sidebar::with_alpha(
- if theme.is_dark() {
- theme.gray_2
- } else {
- theme.gray_1
- },
- 0.8,
- ))
- .text_color(Hsla::from(theme.gray_11))
- .child(pill)
- })),
- )
- .child(
- div()
- .w_full()
- .text_size(px(10.))
- .text_center()
- .text_color(Hsla::from(theme.gray_11))
- .child(name),
- )
- };
-
+ let id = look.id;
+ let name = look.name;
+ let pose = look.from;
div()
+ .id(SharedString::from(format!("c3d-look-{index}-{id}")))
+ .w(px(CAMERA3D_LOOK_TILE))
+ .flex_none()
.flex()
.flex_col()
- .gap(px(12.))
- // `grid-cols-3 gap-2` -- the scenes.
+ .items_center()
+ .gap(px(5.))
+ .cursor_pointer()
.child(
div()
- .flex()
- .flex_row()
- .gap(px(8.))
- .children(CAMERA3D_SCENES.iter().map(|scene| {
- let shots = scene.shots.len();
- let id = scene.id;
- card(
- SharedString::from(format!("c3d-scene-{index}-{id}")),
- scene.name,
- CARD_GRID_WIDTH_3,
- CAMERA3D_SCENE_PREVIEW_HEIGHT,
- false,
- Some(SharedString::from(format!(
- "{shots} {}",
- if shots == 1 { "shot" } else { "shots" }
- ))),
+ .relative()
+ .w_full()
+ .h(px(CAMERA3D_LOOK_THUMB))
+ .rounded(px(8.))
+ .overflow_hidden()
+ .bg(camera3d_thumb_bg(theme.is_dark()))
+ .border_2()
+ .border_color(if selected {
+ Hsla::from(theme.editor.accent)
+ } else {
+ gpui::transparent_black()
+ })
+ .child(Self::camera3d_plate(pose, 2., theme.is_dark()))
+ .when(kind == LookKind::Move, |this| {
+ this.child(
+ div()
+ .absolute()
+ .right(px(4.))
+ .bottom(px(4.))
+ .px(px(3.))
+ .h(px(13.))
+ .flex()
+ .items_center()
+ .rounded(px(4.))
+ .bg(crate::editor_sidebar::with_alpha(theme.editor.card, 0.85))
+ .child(
+ svg()
+ .path("icons/move-right.svg")
+ .size(px(9.))
+ .text_color(Hsla::from(theme.editor.text_2)),
+ ),
)
- .on_click(cx.listener(
- move |this, _, window, cx| {
- this.apply_camera3d_scene(index, id, window, cx);
- },
- ))
- })),
+ }),
)
- // `grid-cols-5 gap-1.5` -- the angle presets.
.child(
div()
- .flex()
- .flex_row()
- .gap(px(6.))
- .children(ANGLE_PRESETS.iter().map(|preset| {
- let id = preset.id;
- card(
- SharedString::from(format!("c3d-angle-{index}-{id}")),
- preset.name,
- CARD_GRID_WIDTH_5,
- CAMERA3D_ANGLE_PREVIEW_HEIGHT,
- active_angle == Some(id),
- None,
- )
- .on_click(cx.listener(
- move |this, _, window, cx| {
- this.apply_camera3d_angle(index, id, window, cx);
- },
- ))
- })),
- )
- // `grid-cols-4 gap-2` -- the motion templates, two rows of four.
- .children(MOTION_TEMPLATES.chunks(4).map(|row| {
- div()
- .flex()
- .flex_row()
- .gap(px(8.))
- .children(row.iter().map(|template| {
- let id = template.id;
- card(
- SharedString::from(format!("c3d-template-{index}-{id}")),
- template.name,
- CARD_GRID_WIDTH_4,
- CAMERA3D_TEMPLATE_PREVIEW_HEIGHT,
- false,
- None,
- )
- .on_click(cx.listener(
- move |this, _, window, cx| {
- this.apply_camera3d_template(index, id, window, cx);
- },
- ))
+ .w_full()
+ .text_center()
+ .text_size(px(11.))
+ .truncate()
+ .when(selected, |this| this.font_weight(FontWeight::MEDIUM))
+ .text_color(Hsla::from(if selected {
+ theme.editor.text_1
+ } else {
+ theme.editor.text_2
}))
+ .child(name),
+ )
+ .on_click(cx.listener(move |this, _, window, cx| {
+ this.apply_camera3d_look(index, kind, id, window, cx);
}))
.into_any_element()
}
- /// `applyTemplate` (`:4983-4993`): the whole camera animation replaced, as
- /// one history entry, with the playhead returned to the segment's start so
- /// the result plays from its first pose.
- fn apply_camera3d_template(
- &mut self,
- index: usize,
- id: &'static str,
- window: &mut Window,
- cx: &mut Context<Self>,
- ) {
- let Some(template) = MOTION_TEMPLATES.iter().find(|t| t.id == id) else {
- return;
- };
- self.write_camera3d_template(index, template, window, cx);
- }
-
- /// `applyAnglePreset` (`:4997-4998`): the preset read as a motion template.
- fn apply_camera3d_angle(
- &mut self,
- index: usize,
- id: &'static str,
- window: &mut Window,
- cx: &mut Context<Self>,
- ) {
- let Some(preset) = ANGLE_PRESETS.iter().find(|p| p.id == id) else {
- return;
- };
- let template = angle_preset_motion(preset);
- self.write_camera3d_template(index, &template, window, cx);
- }
-
- fn write_camera3d_template(
- &mut self,
- index: usize,
- template: &MotionTemplate,
- window: &mut Window,
- cx: &mut Context<Self>,
- ) {
- let template = MotionTemplate {
- id: template.id,
- name: template.name,
- from: template.from,
- to: template.to,
- blur: template.blur,
- };
- let start = self
+ /// The Look group: `Moves | Angles` over a four-column grid, then the three
+ /// sequences.
+ fn render_camera3d_looks(&self, index: usize, cx: &mut Context<Self>) -> AnyElement {
+ let theme = self.theme;
+ let angles = self.sidebar.camera3d_angles;
+ let matched = self
.timeline()
.and_then(|timeline| timeline.camera3d_segments.get(index))
- .map(|segment| segment.start);
- self.edit_camera3d_segment("camera3d-template", index, window, cx, move |segment| {
- apply_motion_template(segment, &template);
- true
- });
- // `setEditingEnd(false)` and the playhead back to the first pose.
- self.sidebar.editing_end_pose = false;
- if let Some(start) = start {
- self.seek_to_time(start, cx);
- }
- cx.notify();
- }
+ .and_then(match_camera3d_look);
- /// `projectActions.applyCamera3DScene` (`ED/context.ts:700-731`): the one
- /// segment replaced by the scene's whole chain of shots, and the selection
- /// moved onto every segment it generated.
- fn apply_camera3d_scene(
- &mut self,
- index: usize,
- id: &'static str,
- window: &mut Window,
- cx: &mut Context<Self>,
- ) {
- let Some(scene) = CAMERA3D_SCENES.iter().find(|scene| scene.id == id) else {
- return;
- };
- let Some((start, end)) = self
- .timeline()
- .and_then(|timeline| timeline.camera3d_segments.get(index))
- .map(|segment| (segment.start, segment.end))
- else {
- return;
- };
- // `camera3DClipCuts(start, end)` (`ED/context.ts:444-460`): every clip
- // boundary inside the range, in output time.
- let cuts: Vec<f64> = self.timeline().map_or_else(Vec::new, |timeline| {
- let offsets = crate::editor_timeline::clip_timeline_offsets(timeline);
- timeline
- .segments
+ let looks: Vec<AnyElement> = if angles {
+ ANGLE_PRESETS
.iter()
- .enumerate()
- .flat_map(|(clip, segment)| {
- let base = offsets.get(clip).copied().unwrap_or_default();
- [base, base + segment.duration()]
+ .map(|preset| {
+ let selected = matched
+ .is_some_and(|look| look.kind == LookKind::Angle && look.id == preset.id);
+ self.render_camera3d_look(
+ index,
+ &angle_preset_motion(preset),
+ LookKind::Angle,
+ selected,
+ cx,
+ )
})
- .filter(|cut| *cut > start && *cut < end)
.collect()
- });
-
- let generated = apply_scene_to_range(scene, start, end, &cuts);
- if generated.is_empty() {
- return;
- }
- let count = generated.len();
- self.edit_project("camera3d-scene", window, cx, move |project| {
- let Some(timeline) = project.timeline.as_mut() else {
- return false;
- };
- if index >= timeline.camera3d_segments.len() {
- return false;
- }
- timeline
- .camera3d_segments
- .splice(index..index + 1, generated);
- timeline
- .camera3d_segments
- .sort_by(|a, b| a.start.total_cmp(&b.start));
- true
- });
- self.sidebar.editing_end_pose = false;
- self.set_selection(
- Some(Selection {
- track: TrackKind::ThreeD,
- indices: (index..index + count).collect(),
- }),
- cx,
- );
- self.seek_to_time(start, cx);
- cx.notify();
- }
-
- /// `Camera3DSegmentConfig` (`:4882-5435`).
- fn render_camera3d_panel(&self, index: usize, cx: &mut Context<Self>) -> AnyElement {
- let theme = self.theme;
- let Some(segment) = self
- .timeline()
- .and_then(|timeline| timeline.camera3d_segments.get(index))
- else {
- return div().into_any_element();
- };
- let start = start_pose(segment);
- let end = end_pose(segment);
- let still = poses_equal(&start, &end);
- let editing_end = self.sidebar.editing_end_pose;
- let blur = segment.blur;
- let blur_label = CAMERA3D_BLUR_MODES
- .iter()
- .find(|(mode, _)| *mode == blur.mode)
- .map_or("None", |(_, label)| *label);
- let easing_index = motion_easing(segment);
- let easing_label = MOTION_EASINGS[easing_index].1;
- // `blurSummary()` (`:5010-5018`).
- let blur_summary = if blur.mode == Camera3DBlurMode::None {
- "Off".to_string()
} else {
- format!("{blur_label} {}", blur.strength.round())
+ MOTION_TEMPLATES
+ .iter()
+ .map(|template| {
+ let selected = matched
+ .is_some_and(|look| look.kind == LookKind::Move && look.id == template.id);
+ self.render_camera3d_look(index, template, LookKind::Move, selected, cx)
+ })
+ .collect()
};
- let camera_section = self.sidebar.section(PanelSection::Camera3DCamera);
- let blur_section = self.sidebar.section(PanelSection::Camera3DBlur);
- let advanced_section = self.sidebar.section(PanelSection::Camera3DAdvanced);
+ let grid = div()
+ .flex()
+ .flex_row()
+ .flex_wrap()
+ .gap(px(8.))
+ .children(looks);
- let templates = self.render_camera3d_templates(index, &start, cx);
- let pose_card = |label: &'static str, is_end: bool| {
- let selected = editing_end == is_end;
+ let sequences =
div()
- .id(SharedString::from(format!("camera3d-pose-{label}")))
- .flex_1()
.flex()
- .flex_col()
- .gap(px(4.))
- .p(px(4.))
- .rounded(px(8.))
- .border_1()
- .border_color(if selected {
- Hsla::from(theme.blue_9)
- } else {
- Hsla::from(theme.gray_4)
- })
- // `Camera3DPosePreview` is a CSS-3D plane under a `perspective`
- // -- no transform in this rev, so the card shows the flat plate
- // it would fold. See the README's deviation.
- .child(
+ .flex_row()
+ .gap(px(8.))
+ .children(CAMERA3D_SCENES.iter().map(|scene| {
+ let id = scene.id;
+ let shots = scene.shots.len();
div()
- .w_full()
- .h(px(56.))
- .rounded(px(6.))
- .bg(Hsla::from(theme.gray_3))
- .p(px(6.))
+ .id(SharedString::from(format!("c3d-seq-{index}-{id}")))
+ .w(px(CAMERA3D_SEQUENCE_CARD))
+ .flex_none()
+ .flex()
+ .flex_col()
+ .gap(px(3.))
+ .px(px(10.))
+ .py(px(8.))
+ .rounded(px(8.))
+ .bg(Hsla::from(theme.editor.ctl))
+ .cursor_pointer()
+ .hover(|style| style.bg(Hsla::from(theme.editor.ctl_hover)))
.child(
div()
- .size_full()
- .rounded(px(3.))
- .border_1()
- .border_color(Hsla::from(theme.gray_6))
- .bg(Hsla::from(if theme.is_dark() {
- theme.gray_5
- } else {
- theme.gray_1
- })),
- ),
- )
- .child(
- div()
- .w_full()
- .text_size(px(10.))
- .text_center()
- .text_color(Hsla::from(theme.gray_11))
- .child(label),
- )
- .on_click(cx.listener(move |this, _, _window, cx| {
- this.select_camera3d_pose(index, is_end, cx);
- }))
- };
+ .text_size(px(11.))
+ .font_weight(FontWeight::MEDIUM)
+ .text_color(Hsla::from(theme.editor.text_1))
+ .truncate()
+ .child(scene.name),
+ )
+ .child(
+ div()
+ .text_size(px(10.))
+ .text_color(Hsla::from(theme.editor.text_2))
+ .child(format!("{shots} shots")),
+ )
+ .child(div().flex().flex_row().gap(px(3.)).pt(px(3.)).children(
+ (0..shots).map(|_| {
+ div().h(px(4.)).flex_1().rounded(px(2.)).bg(with_alpha(
+ gpui::rgb(crate::editor_timeline::track_color::THREE_D),
+ 0.7,
+ ))
+ }),
+ ))
+ .on_click(cx.listener(move |this, _, window, cx| {
+ this.apply_camera3d_scene(index, id, window, cx);
+ }))
+ }));
div()
.flex()
.flex_col()
- .gap(px(16.))
+ .gap(px(10.))
.child(
- ui::Field::section(&theme, "Motion")
- .child(
- div()
- .flex()
- .flex_col()
- .gap(px(8.))
- .child(
- div()
- .flex()
- .flex_row()
- .gap(px(8.))
- .items_center()
- .child(pose_card("Start", false))
- .child(
- ui::EditorButton::plain(&theme, "camera3d-swap")
- .left_icon("icons/arrow-left-right.svg")
- .tooltip(&theme, "Swap start and end")
- .on_click(cx.listener(move |this, _, window, cx| {
- this.swap_camera3d_poses(index, window, cx);
- })),
- )
- .child(pose_card("End", true)),
- )
+ self.camera3d_group_label("Look").child(
+ ui::SegmentedControl::editor(
+ &theme,
+ "camera3d-look-tab",
+ vec![
+ ui::SegmentOption::new("Moves", !angles),
+ ui::SegmentOption::new("Angles", angles),
+ ],
+ )
+ .text_size(px(11.))
+ .item_height(px(21.))
+ .item_padding(px(9.), px(0.))
+ .on_select(cx.listener(|this, choice: &usize, _, cx| {
+ this.sidebar.camera3d_angles = *choice == 1;
+ cx.notify();
+ })),
+ ),
+ )
+ .child(grid)
+ .child(sequences)
+ .into_any_element()
+ }
+
+ /// The Camera group's orbit pad: `tiltY` across, `tiltX` up, with the pose
+ /// being edited drawn inside it.
+ fn render_camera3d_orbit(&self, index: usize, cx: &mut Context<Self>) -> AnyElement {
+ let theme = self.theme;
+ let pose = self
+ .timeline()
+ .and_then(|timeline| timeline.camera3d_segments.get(index))
+ .map(|segment| {
+ if self.sidebar.editing_end_pose {
+ end_pose(segment)
+ } else {
+ start_pose(segment)
+ }
+ })
+ .unwrap_or(DEFAULT_POSE);
+ let (x, y) = camera3d_orbit_point(&pose);
+ let key = PadKey::Camera3DOrbit(index);
+ let cell = self.sidebar.pad(key);
+ let line = Hsla::from(theme.editor.line_strong);
+
+ div()
+ .id(SharedString::from(format!("c3d-orbit-{index}")))
+ .relative()
+ .size(px(CAMERA3D_ORBIT_PAD))
+ .flex_none()
+ .overflow_hidden()
+ .rounded(px(10.))
+ .bg(camera3d_thumb_bg(theme.is_dark()))
+ .cursor(gpui::CursorStyle::Crosshair)
+ .child(
+ gpui::canvas(move |bounds, _, _| cell.set(Some(bounds)), |_, _, _, _| {})
+ .absolute()
+ .inset_0(),
+ )
+ // The 3x3 rule of thirds, which is what makes the drag read as an
+ // orbit rather than a scrub.
+ .children([1_u8, 2].map(|step| {
+ div()
+ .absolute()
+ .top_0()
+ .bottom_0()
+ .left(gpui::relative(f32::from(step) / 3.))
+ .w(px(1.))
+ .bg(line)
+ }))
+ .children([1_u8, 2].map(|step| {
+ div()
+ .absolute()
+ .left_0()
+ .right_0()
+ .top(gpui::relative(f32::from(step) / 3.))
+ .h(px(1.))
+ .bg(line)
+ }))
+ .child(
+ div()
+ .absolute()
+ .inset_0()
+ .p(px(14.))
+ .child(Self::camera3d_plate(pose, 3., theme.is_dark())),
+ )
+ .child(
+ div()
+ .absolute()
+ .left(gpui::relative(x))
+ .top(gpui::relative(y))
+ .ml(px(-6.))
+ .mt(px(-6.))
+ .size(px(12.))
+ .rounded_full()
+ .bg(Hsla::from(theme.editor.accent))
+ .border_2()
+ .border_color(camera3d_thumb_bg(theme.is_dark())),
+ )
+ .child(
+ div()
+ .absolute()
+ .left_0()
+ .right_0()
+ .bottom(px(6.))
+ .text_center()
+ .text_size(px(10.))
+ .text_color(Hsla::from(theme.editor.text_2))
+ .child("Drag to orbit"),
+ )
+ .on_mouse_down(
+ gpui::MouseButton::Left,
+ cx.listener(move |this, event: &MouseDownEvent, window, cx| {
+ cx.stop_propagation();
+ // Double-click puts the camera back on axis, the way the
+ // canvas pads reset their point.
+ if event.click_count >= 2 {
+ this.reset_camera3d_tilt(index, window, cx);
+ return;
+ }
+ this.pad_mouse_down(PadKey::Camera3DOrbit(index), event, window, cx);
+ }),
+ )
+ .into_any_element()
+ }
+
+ /// A group's 12px/500 label row, with whatever control sits beside it.
+ fn camera3d_group_label(&self, name: &'static str) -> gpui::Div {
+ div()
+ .flex()
+ .flex_row()
+ .items_center()
+ .gap(px(8.))
+ .min_h(px(22.))
+ .text_size(px(12.))
+ .font_weight(FontWeight::MEDIUM)
+ .text_color(Hsla::from(self.theme.editor.text_2))
+ .child(div().flex_none().child(name))
+ .child(div().flex_1())
+ }
+
+ /// The hairline box every group sits in.
+ fn camera3d_group(&self, content: AnyElement) -> AnyElement {
+ div()
+ .flex()
+ .flex_col()
+ .p(px(CAMERA3D_GROUP_PADDING))
+ .rounded(px(10.))
+ .border_1()
+ .border_color(Hsla::from(self.theme.editor.line))
+ .child(content)
+ .into_any_element()
+ }
+
+ /// One compact `label | slider | value` row. The sidebar's own inline row
+ /// reserves 96px for the label, which the Camera group's 214px column
+ /// cannot spare.
+ fn camera3d_slider_row(
+ &self,
+ label: &'static str,
+ slider: SliderKey,
+ unit: &'static str,
+ cx: &mut Context<Self>,
+ ) -> AnyElement {
+ let theme = self.theme;
+ let value = crate::editor_sidebar::format_slider_value(self.slider_value(slider), unit);
+ div()
+ .flex()
+ .flex_row()
+ .items_center()
+ .h(px(32.))
+ .gap(px(8.))
+ .text_size(px(12.))
+ .text_color(Hsla::from(theme.editor.text_2))
+ .child(div().w(px(CAMERA3D_ROW_LABEL)).flex_none().child(label))
+ .child(
+ div()
+ .flex_1()
+ .min_w_0()
+ .child(self.slider_flex(slider, unit, cx)),
+ )
+ .child(
+ div()
+ .w(px(CAMERA3D_ROW_VALUE))
+ .flex_none()
+ .text_right()
+ .child(value),
+ )
+ .into_any_element()
+ }
+
+ /// A 24px icon action on a group's own label row.
+ fn camera3d_action(
+ &self,
+ id: &'static str,
+ icon: &'static str,
+ label: Option<&'static str>,
+ tooltip: &'static str,
+ active: bool,
+ ) -> ui::EditorButton {
+ let theme = self.theme;
+ let mut button = ui::EditorButton::plain(&theme, id)
+ .left_icon(icon)
+ .icon_size(px(13.))
+ .height(px(24.))
+ .padding_x(px(7.))
+ .pressed(active)
+ .tooltip(&theme, tooltip);
+ if let Some(label) = label {
+ button = button.label(label).text_size(px(11.));
+ }
+ button
+ }
+
+ /// One half of the pose strip: the pose as the camera sees it, its clock
+ /// time under it, and the two marks that say which pose is being edited
+ /// and which one the playhead is on.
+ #[allow(clippy::too_many_arguments)]
+ fn render_camera3d_pose_card(
+ &self,
+ index: usize,
+ end: bool,
+ pose: Camera3DProperties,
+ time: f64,
+ editing: bool,
+ at_playhead: bool,
+ still: bool,
+ cx: &mut Context<Self>,
+ ) -> AnyElement {
+ let theme = self.theme;
+ // A still shot's end is not a second pose to look at, so it reads as
+ // the hold it is.
+ let dim = still && end;
+ let caption = if dim {
+ "End \u{b7} same as start".to_string()
+ } else {
+ format!(
+ "{} \u{b7} {}",
+ if end { "End" } else { "Start" },
+ format_time(time)
+ )
+ };
+
+ div()
+ .id(SharedString::from(format!(
+ "c3d-pose-{index}-{}",
+ if end { "end" } else { "start" }
+ )))
+ .flex_1()
+ .min_w_0()
+ .flex()
+ .flex_col()
+ .gap(px(5.))
+ .cursor_pointer()
+ .child(
+ div()
+ .w_full()
+ .h(px(CAMERA3D_POSE_CARD_HEIGHT))
+ .rounded(px(9.))
+ .overflow_hidden()
+ .bg(camera3d_thumb_bg(theme.is_dark()))
+ .border_2()
+ .border_color(if editing {
+ Hsla::from(theme.editor.accent)
+ } else {
+ gpui::transparent_black()
+ })
+ .when(dim, |this| this.opacity(0.55))
+ .child(Self::camera3d_plate(pose, 2.5, theme.is_dark())),
+ )
+ .child(
+ div()
+ .w_full()
+ .flex()
+ .flex_row()
+ .items_center()
+ .justify_center()
+ .gap(px(5.))
+ .text_size(px(11.))
+ .when(editing, |this| this.font_weight(FontWeight::MEDIUM))
+ .text_color(Hsla::from(if editing {
+ theme.editor.text_1
+ } else {
+ theme.editor.text_2
+ }))
+ // The playhead's own mark: this is the pose on screen.
+ .when(at_playhead, |this| {
+ this.child(
+ div()
+ .size(px(5.))
+ .flex_none()
+ .rounded_full()
+ .bg(Hsla::from(theme.editor.accent)),
+ )
+ })
+ .child(div().min_w_0().truncate().child(caption)),
+ )
+ .on_click(cx.listener(move |this, _, _window, cx| {
+ this.select_camera3d_pose(index, end, cx);
+ }))
+ .into_any_element()
+ }
+
+ /// The Camera group's pose strip: the two ends of the shot, side by side,
+ /// with the swap between them and the still-shot switch under.
+ ///
+ /// This is what replaced the `Start | End` segmented control: two words
+ /// asked the user to hold the whole move in their head, where two pictures
+ /// just show it.
+ fn render_camera3d_pose_strip(&self, index: usize, cx: &mut Context<Self>) -> AnyElement {
+ let Some(segment) = self
+ .timeline()
+ .and_then(|timeline| timeline.camera3d_segments.get(index))
+ else {
+ return div().into_any_element();
+ };
+ let start = start_pose(segment);
+ let end = end_pose(segment);
+ let still = poses_equal(&start, &end);
+ let editing_end = self.sidebar.editing_end_pose;
+ let fps = crate::editor_window::EDITOR_PREVIEW_FPS;
+ let start_time = camera3d_pose_seek_time(segment, false, fps);
+ let end_time = camera3d_pose_seek_time(segment, true, fps);
+ // "The playhead is on this pose" is a frame's tolerance, which is as
+ // close as a seek can land.
+ let on = |time: f64| (self.playhead_time() - time).abs() < 1. / f64::from(fps.max(1));
+
+ div()
+ .flex()
+ .flex_col()
+ .gap(px(8.))
+ .child(
+ div()
+ .flex()
+ .flex_row()
+ .items_start()
+ .gap(px(8.))
+ .child(self.render_camera3d_pose_card(
+ index,
+ false,
+ start,
+ segment.start,
+ !editing_end,
+ on(start_time),
+ still,
+ cx,
+ ))
+ .child(
+ div()
+ .flex_none()
+ .h(px(CAMERA3D_POSE_CARD_HEIGHT))
+ .flex()
+ .items_center()
.child(
- div()
- .flex()
- .flex_row()
- .gap(px(4.))
- .items_center()
- .child(
- ui::EditorButton::plain(&theme, "camera3d-flip-h")
- .left_icon("icons/flip-horizontal-2.svg")
- .tooltip(&theme, "Flip horizontal")
- .on_click(cx.listener(move |this, _, window, cx| {
- this.flip_camera3d(index, true, window, cx);
- })),
- )
- .child(
- ui::EditorButton::plain(&theme, "camera3d-flip-v")
- .left_icon("icons/flip-vertical-2.svg")
- .tooltip(&theme, "Flip vertical")
- .on_click(cx.listener(move |this, _, window, cx| {
- this.flip_camera3d(index, false, window, cx);
- })),
- )
- .child(if still {
- div()
- .text_size(px(11.))
- .text_color(Hsla::from(theme.gray_10))
- .child(
- "Open Customize camera to choose a move or adjust the end pose",
- )
- .into_any_element()
+ self.camera3d_action(
+ "camera3d-swap",
+ "icons/arrow-left-right.svg",
+ None,
+ if still {
+ "Nothing to swap on a still shot"
} else {
- div()
- .id("camera3d-still")
- .text_size(px(11.))
- .text_color(Hsla::from(theme.gray_11))
- .cursor_pointer()
- .child("Still shot")
- .on_click(cx.listener(move |this, _, window, cx| {
- this.make_camera3d_still(index, window, cx);
- }))
- .into_any_element()
- }),
+ "Swap start and end"
+ },
+ false,
+ )
+ .disabled(still)
+ .on_click(cx.listener(
+ move |this, _, window, cx| {
+ this.swap_camera3d_poses(index, window, cx);
+ },
+ )),
),
+ )
+ .child(self.render_camera3d_pose_card(
+ index,
+ true,
+ end,
+ segment.end,
+ editing_end,
+ on(end_time) && !still,
+ still,
+ cx,
+ )),
+ )
+ .child(
+ div().flex().flex_row().items_center().gap(px(6.)).child(
+ self.camera3d_action(
+ "camera3d-still",
+ "icons/pause.svg",
+ Some("Still shot"),
+ if still {
+ "Already a still shot"
+ } else {
+ "Hold the opening pose for the whole shot"
+ },
+ still,
+ )
+ .disabled(still)
+ .on_click(cx.listener(move |this, _, window, cx| {
+ this.make_camera3d_still(index, window, cx);
+ })),
+ ),
+ )
+ .into_any_element()
+ }
+
+ /// The Auto scene row, above the Look group: how many shots the whole
+ /// track should be, as six pills. Hovering one shows the layout on the
+ /// lane; pressing one commits it.
+ fn render_camera3d_auto_row(&self, cx: &mut Context<Self>) -> AnyElement {
+ let theme = self.theme;
+ let count = self
+ .timeline()
+ .map_or(0, |timeline| timeline.camera3d_segments.len());
+ let maximum = max_auto_camera3d_shots(self.total_duration());
+
+ self.camera3d_group(
+ div()
+ .flex()
+ .flex_row()
+ .items_center()
+ .gap(px(8.))
+ .child(
+ div()
+ .flex_none()
+ .text_size(px(12.))
+ .font_weight(FontWeight::MEDIUM)
+ .text_color(Hsla::from(theme.editor.text_2))
+ .child("Auto scene"),
+ )
+ .child(div().flex_1())
+ .child(self.render_camera3d_count_pills("panel", count, maximum, cx))
+ .id("camera3d-auto-row")
+ .tooltip_show_delay(ui::TOOLTIP_SHOW_DELAY)
+ .tooltip(move |_window, cx| {
+ ui::Tooltip::new(&theme, "Rebuilds every 3D shot on the track").view(cx)
+ })
+ .into_any_element(),
+ )
+ }
+
+ /// The `1 2 3 4 5 6` pills the picker and the panel share. `selected` is
+ /// the count the track already is; anything past `maximum` has nowhere to
+ /// fit and is disabled.
+ pub(crate) fn render_camera3d_count_pills(
+ &self,
+ id: &'static str,
+ selected: usize,
+ maximum: usize,
+ cx: &mut Context<Self>,
+ ) -> AnyElement {
+ let theme = self.theme;
+ div()
+ .flex()
+ .flex_row()
+ .gap(px(4.))
+ .children((1..=AUTO_CAMERA3D_MAX_SHOTS).map(|count| {
+ let available = count <= maximum;
+ let active = count == selected;
+ div()
+ .id(SharedString::from(format!("c3d-count-{id}-{count}")))
+ .w(px(24.))
+ .h(px(24.))
+ .flex()
+ .items_center()
+ .justify_center()
+ .rounded(px(7.))
+ .text_size(px(12.))
+ .font_weight(FontWeight::MEDIUM)
+ .when(active, |this| {
+ this.bg(Hsla::from(theme.editor.accent))
+ .text_color(gpui::white())
+ })
+ .when(!active, |this| {
+ this.bg(Hsla::from(theme.editor.ctl))
+ .text_color(Hsla::from(theme.editor.text_2))
+ })
+ .when(!available, |this| this.opacity(0.35))
+ .when(available && !active, |this| {
+ this.cursor_pointer()
+ .hover(|style| style.bg(Hsla::from(theme.editor.ctl_hover)))
+ })
+ .when(available, |this| {
+ this.on_hover(cx.listener(move |this, hovered: &bool, _, cx| {
+ this.hover_camera3d_count(hovered.then_some(count), cx);
+ }))
+ .on_click(cx.listener(
+ move |this, _, window, cx| {
+ this.apply_auto_camera3d_scene(count, window, cx);
+ },
+ ))
+ })
+ .child(format!("{count}"))
+ }))
+ .into_any_element()
+ }
+
+ /// `Camera3DSegmentConfig`, rebuilt: Look, Camera, Depth blur, and one
+ /// drill for the timing controls nobody opens twice.
+ fn render_camera3d_panel(&self, index: usize, cx: &mut Context<Self>) -> AnyElement {
+ let theme = self.theme;
+ let Some(segment) = self
+ .timeline()
+ .and_then(|timeline| timeline.camera3d_segments.get(index))
+ else {
+ return div().into_any_element();
+ };
+ let start = start_pose(segment);
+ let end = end_pose(segment);
+ let still = poses_equal(&start, &end);
+ let blur = segment.blur;
+ let blur_on = blur.mode != Camera3DBlurMode::None;
+ let easing_index = motion_easing(segment);
+ let easing_label = MOTION_EASINGS[easing_index].1;
+ let duration = segment.end - segment.start;
+ let look = camera3d_shot_label(segment);
+ let advanced = self.sidebar.section(PanelSection::Camera3DAdvanced);
+ let tune = self.sidebar.section(PanelSection::Camera3DBlurTune);
+
+ // -- header ---------------------------------------------------------
+ let header = div()
+ .flex()
+ .flex_row()
+ .items_center()
+ .gap(px(6.))
+ .child(
+ ui::EditorButton::plain(&theme, "camera3d-done")
+ .left_icon("icons/check.svg")
+ .label("Done")
+ .text_size(px(12.))
+ .on_click(cx.listener(|this, _, _window, cx| this.set_selection(None, cx))),
+ )
+ .child(
+ div()
+ .flex_1()
+ .min_w_0()
+ .truncate()
+ .text_size(px(12.))
+ .text_color(Hsla::from(theme.editor.text_2))
+ .child(format!("3D shot \u{b7} {look} \u{b7} {duration:.1}s")),
+ )
+ .child(
+ ui::EditorButton::plain(&theme, "camera3d-play-shot")
+ .left_icon("icons/play.svg")
+ .icon_size(px(12.))
+ .label("Play shot")
+ .text_size(px(12.))
+ .tooltip(&theme, "Play this shot")
+ .on_click(cx.listener(move |this, _, _window, cx| {
+ this.play_camera3d_shot(index, cx);
+ })),
+ )
+ .child(
+ ui::EditorButton::plain(&theme, "camera3d-delete")
+ .danger(&theme)
+ .left_icon("icons/trash.svg")
+ .icon_size(px(13.))
+ .label("Delete")
+ .text_size(px(12.))
+ .tooltip(&theme, "Delete this shot")
+ .on_click(cx.listener(|this, _, window, cx| {
+ this.delete_selection(window, cx);
+ })),
+ );
+
+ // -- Camera ----------------------------------------------------------
+ let camera = div()
+ .flex()
+ .flex_col()
+ .gap(px(10.))
+ .child(
+ div()
+ .flex()
+ .flex_row()
+ .items_center()
+ .gap(px(8.))
+ .min_h(px(24.))
+ .child(
+ div()
+ .flex_none()
+ .text_size(px(12.))
+ .font_weight(FontWeight::MEDIUM)
+ .text_color(Hsla::from(theme.editor.text_2))
+ .child("Camera"),
+ )
+ .child(div().flex_1())
+ .child(
+ self.camera3d_action(
+ "camera3d-flip-h",
+ "icons/flip-horizontal-2.svg",
+ None,
+ "Flip horizontally",
+ false,
+ )
+ .on_click(cx.listener(
+ move |this, _, window, cx| {
+ this.flip_camera3d(index, true, window, cx);
+ },
+ )),
+ )
+ .child(
+ self.camera3d_action(
+ "camera3d-flip-v",
+ "icons/flip-vertical-2.svg",
+ None,
+ "Flip vertically",
+ false,
+ )
+ .on_click(cx.listener(
+ move |this, _, window, cx| {
+ this.flip_camera3d(index, false, window, cx);
+ },
+ )),
),
)
+ .child(self.render_camera3d_pose_strip(index, cx))
.child(
- self.camera3d_section(
- Camera3DSection {
- id: "camera3d-camera",
- name: "Customize camera",
- icon: "icons/video.svg",
- summary: Some(if editing_end {
- "End pose"
- } else {
- "Start pose"
- }),
- },
- PanelSection::Camera3DCamera,
- &camera_section,
+ div()
+ .flex()
+ .flex_row()
+ .gap(px(12.))
+ .child(self.render_camera3d_orbit(index, cx))
+ .child(
+ div()
+ .flex_1()
+ .min_w_0()
+ .flex()
+ .flex_col()
+ .child(self.camera3d_slider_row(
+ "Distance",
+ SliderKey::Panel(
+ PanelSlider::Camera3DPose(Camera3DProperty::Zoom),
+ index,
+ ),
+ "",
+ cx,
+ ))
+ .child(self.camera3d_slider_row(
+ "Roll",
+ SliderKey::Panel(
+ PanelSlider::Camera3DPose(Camera3DProperty::Roll),
+ index,
+ ),
+ "deg",
+ cx,
+ ))
+ .child(self.camera3d_slider_row(
+ "Shift X",
+ SliderKey::Panel(
+ PanelSlider::Camera3DPose(Camera3DProperty::PanX),
+ index,
+ ),
+ "",
+ cx,
+ ))
+ .child(self.camera3d_slider_row(
+ "Shift Y",
+ SliderKey::Panel(
+ PanelSlider::Camera3DPose(Camera3DProperty::PanY),
+ index,
+ ),
+ "",
+ cx,
+ )),
+ ),
+ );
+
+ // -- Depth blur -------------------------------------------------------
+ let mut depth = div().flex().flex_col().gap(px(6.)).child(
+ self.camera3d_group_label("Depth blur").child(
+ ui::Toggle::plain(
+ &theme,
+ SharedString::from(format!("camera3d-blur-{index}")),
+ blur_on,
+ )
+ .on_click(cx.listener(move |this, _, window, cx| {
+ this.toggle_camera3d_blur(index, window, cx);
+ })),
+ ),
+ );
+ if blur_on {
+ depth = depth
+ .child(self.camera3d_slider_row(
+ "Amount",
+ SliderKey::Panel(PanelSlider::Camera3DBlur(Camera3DBlurKey::Strength), index),
+ "int",
+ cx,
+ ))
+ .child(
div()
.flex()
- .flex_col()
- .gap(px(12.))
- .child(ui::Field::stacked(&theme, "Templates").child(templates))
- .children(CAMERA3D_POSE_SLIDERS.map(|(property, label, unit, icon)| {
- div()
- .flex()
- .flex_col()
- .gap(px(4.))
- .child(
- div()
- .flex()
- .flex_row()
- .gap(px(6.))
- .items_center()
- .text_size(px(12.))
- .text_color(Hsla::from(theme.gray_11))
- .child(
- svg()
- .path(icon)
- .size(px(16.))
- .text_color(Hsla::from(theme.gray_11)),
- )
- .child(label),
- )
- .child(self.slider(
- SliderKey::Panel(PanelSlider::Camera3DPose(property), index),
- unit,
- cx,
- ))
- .into_any_element()
- }))
+ .flex_row()
+ .items_center()
+ .h(px(32.))
+ .gap(px(8.))
+ .text_size(px(12.))
+ .text_color(Hsla::from(theme.editor.text_2))
+ .child(div().w(px(CAMERA3D_ROW_LABEL)).flex_none().child("Focus"))
.child(
- ui::EditorButton::plain(&theme, "camera3d-reset")
- .left_icon("icons/rotate-ccw.svg")
- .label("Reset camera")
- .on_click(cx.listener(move |this, _, window, cx| {
- this.reset_camera3d_pose(index, window, cx);
- })),
- )
- .into_any_element(),
- cx,
- ),
- )
- .child(
- self.camera3d_section(
- Camera3DSection {
- id: "camera3d-blur",
- name: "Blur",
- icon: "icons/wind.svg",
- summary: Some(&blur_summary),
- },
- PanelSection::Camera3DBlur,
- &blur_section,
+ div().flex_1().min_w_0().child(
+ ui::SegmentedControl::editor(
+ &theme,
+ "camera3d-blur-mode-tab",
+ CAMERA3D_FOCUS_MODES
+ .iter()
+ .map(|(mode, label)| {
+ ui::SegmentOption::new(*label, blur.mode == *mode)
+ })
+ .collect(),
+ )
+ .text_size(px(11.))
+ .item_height(px(22.))
+ .item_padding(px(6.), px(0.))
+ .stretch()
+ .on_select(cx.listener(
+ move |this, choice: &usize, window, cx| {
+ let Some((mode, _)) = CAMERA3D_FOCUS_MODES.get(*choice)
+ else {
+ return;
+ };
+ this.set_camera3d_blur_mode(index, *mode, window, cx);
+ },
+ )),
+ ),
+ ),
+ )
+ .child(crate::editor_sidebar::disclosure_row(
+ &theme,
+ "camera3d-blur-tune",
+ "Fine-tune",
+ tune.is_open(),
+ cx.listener(|this, _, window, cx| {
+ this.sidebar
+ .section(PanelSection::Camera3DBlurTune)
+ .toggle();
+ this.animate_collapsibles(window, cx);
+ }),
+ ))
+ .child(collapsible(
+ &tune,
div()
.flex()
.flex_col()
- .gap(px(12.))
- .child(
- ui::Subfield::plain(&theme, "Mode").child(div().w(px(160.)).child(
- self.menu_select(
- SidebarMenu::Camera3DBlurMode(index),
- "camera3d-blur-mode",
- blur_label,
- cx,
- ),
- )),
- )
- .children(if blur.mode == Camera3DBlurMode::None {
- vec![
- div()
- .text_size(px(12.))
- .text_color(Hsla::from(theme.gray_11))
- .child("Pick a mode to blur everything outside the focus area.")
- .into_any_element(),
- ]
- } else {
- let mut rows: Vec<AnyElement> = camera3d_blur_sliders(blur.mode)
+ .children(
+ camera3d_blur_sliders(blur.mode)
.iter()
+ .filter(|(key, _)| *key != Camera3DBlurKey::Strength)
.map(|(key, label)| {
- self.labelled_small(
+ self.camera3d_slider_row(
label,
- self.slider(
- SliderKey::Panel(
- PanelSlider::Camera3DBlur(*key),
- index,
- ),
- if *key == Camera3DBlurKey::Angle {
- "deg"
- } else {
- ""
- },
- cx,
- )
- .into_any_element(),
- )
- })
- .collect();
- rows.push(
- ui::Subfield::plain(&theme, "Bokeh")
- .child(
- ui::Toggle::plain(
- &theme,
- SharedString::from(format!("camera3d-bokeh-{index}")),
- blur.bokeh,
- )
- .on_click(
- cx.listener(move |this, _, window, cx| {
- this.set_camera3d_bokeh(index, window, cx);
- }),
- ),
+ SliderKey::Panel(PanelSlider::Camera3DBlur(*key), index),
+ if *key == Camera3DBlurKey::Angle {
+ "deg"
+ } else {
+ ""
+ },
+ cx,
)
- .into_any_element(),
- );
- rows.push(
- ui::EditorButton::plain(&theme, "camera3d-blur-reset")
- .left_icon("icons/rotate-ccw.svg")
- .label("Turn blur off")
- .on_click(cx.listener(move |this, _, window, cx| {
- this.edit_camera3d_segment(
- "camera3d-blur-reset",
- index,
- window,
- cx,
- |segment| {
- segment.blur = default_camera3d_blur();
- true
- },
- );
- }))
- .into_any_element(),
- );
- rows
- })
- .into_any_element(),
- cx,
- ),
- )
- .child(
- self.camera3d_section(
- Camera3DSection {
- id: "camera3d-advanced",
- name: "Advanced",
- icon: "icons/timer.svg",
- summary: None,
- },
- PanelSection::Camera3DAdvanced,
- &advanced_section,
- div()
- .flex()
- .flex_col()
- .gap(px(12.))
- .child(
- ui::Subfield::plain(&theme, "Motion style").child(
- div()
- .w(px(160.))
- // A still shot has no span to shape and nowhere
- // to store a curve, so the picker is disabled
- // (`:5357-5360`).
- .when(still, |this| this.opacity(0.5))
- .child(if still {
- ui::Select::plain(&theme, "camera3d-easing", easing_label)
- .stretch_label()
- .disabled(true)
- .into_any_element()
- } else {
- self.easing_select(index, easing_index, cx)
- }),
- ),
+ }),
)
.child(
div()
.flex()
- .flex_col()
+ .flex_row()
+ .items_center()
+ .h(px(32.))
.gap(px(8.))
+ .text_size(px(12.))
+ .text_color(Hsla::from(theme.editor.text_2))
+ .child(div().w(px(CAMERA3D_ROW_LABEL)).flex_none().child("Bokeh"))
+ .child(div().flex_1())
.child(
- div()
- .flex()
- .flex_row()
- .justify_between()
- .items_center()
- .child(
- div()
- .text_size(px(12.))
- .text_color(Hsla::from(theme.gray_11))
- .child("Ease in"),
- )
- .child(self.render_number_field(
- FieldKey::Camera3DEaseIn(index),
- "s",
- 80.,
- )),
- )
- .child(
- div()
- .flex()
- .flex_row()
- .justify_between()
- .items_center()
- .child(
- div()
- .text_size(px(12.))
- .text_color(Hsla::from(theme.gray_11))
- .child("Ease out"),
- )
- .child(self.render_number_field(
- FieldKey::Camera3DEaseOut(index),
- "s",
- 80.,
- )),
+ ui::Toggle::plain(
+ &theme,
+ SharedString::from(format!("camera3d-bokeh-{index}")),
+ blur.bokeh,
+ )
+ .on_click(cx.listener(
+ move |this, _, window, cx| {
+ this.set_camera3d_bokeh(index, window, cx);
+ },
+ )),
),
)
.into_any_element(),
- cx,
- ),
+ ));
+ }
+
+ // -- Timing & advanced -------------------------------------------------
+ let timing = div()
+ .flex()
+ .flex_col()
+ .child(
+ div()
+ .id("camera3d-advanced")
+ .flex()
+ .flex_row()
+ .items_center()
+ .h(px(34.))
+ .px(px(CAMERA3D_GROUP_PADDING))
+ .gap(px(8.))
+ .rounded(px(10.))
+ .border_1()
+ .border_color(Hsla::from(theme.editor.line))
+ .cursor_pointer()
+ .text_size(px(12.))
+ .font_weight(FontWeight::MEDIUM)
+ .text_color(Hsla::from(theme.editor.text_1))
+ .child("Timing & advanced")
+ .child(div().flex_1())
+ .child(
+ div()
+ .font_weight(FontWeight::NORMAL)
+ .text_color(Hsla::from(theme.editor.text_2))
+ .child(format!(
+ "{easing_label} \u{b7} Lens {}",
+ start.fov.round() as i32
+ )),
+ )
+ .child(
+ svg()
+ .path(if advanced.is_open() {
+ "icons/chevron-down.svg"
+ } else {
+ "icons/chevron-right.svg"
+ })
+ .size(px(13.))
+ .flex_none()
+ .text_color(Hsla::from(theme.editor.text_3)),
+ )
+ .on_click(cx.listener(|this, _, window, cx| {
+ this.sidebar
+ .section(PanelSection::Camera3DAdvanced)
+ .toggle();
+ this.animate_collapsibles(window, cx);
+ })),
)
+ .child(collapsible(
+ &advanced,
+ div()
+ .pt(px(10.))
+ .px(px(CAMERA3D_GROUP_PADDING))
+ .flex()
+ .flex_col()
+ .gap(px(2.))
+ .child(
+ ui::Subfield::plain(&theme, "Motion style").child(
+ div()
+ .w(px(150.))
+ // A still shot has no span to shape and nowhere
+ // to store a curve (`:5357-5360`).
+ .when(still, |this| this.opacity(0.5))
+ .child(if still {
+ ui::Select::plain(&theme, "camera3d-easing", easing_label)
+ .stretch_label()
+ .disabled(true)
+ .into_any_element()
+ } else {
+ self.easing_select(index, easing_index, cx)
+ }),
+ ),
+ )
+ .child(self.camera3d_slider_row(
+ "Ease in",
+ SliderKey::Panel(PanelSlider::Camera3DTransitionIn, index),
+ "secs",
+ cx,
+ ))
+ .child(self.camera3d_slider_row(
+ "Ease out",
+ SliderKey::Panel(PanelSlider::Camera3DTransitionOut, index),
+ "secs",
+ cx,
+ ))
+ .child(self.camera3d_slider_row(
+ "Lens",
+ SliderKey::Panel(PanelSlider::Camera3DPose(Camera3DProperty::Fov), index),
+ "deg",
+ cx,
+ ))
+ .child(self.camera3d_slider_row(
+ "Rotate X",
+ SliderKey::Panel(
+ PanelSlider::Camera3DPose(Camera3DProperty::RotateX),
+ index,
+ ),
+ "deg",
+ cx,
+ ))
+ .child(self.camera3d_slider_row(
+ "Rotate Y",
+ SliderKey::Panel(
+ PanelSlider::Camera3DPose(Camera3DProperty::RotateY),
+ index,
+ ),
+ "deg",
+ cx,
+ ))
+ .child(
+ div().pt(px(4.)).pb(px(4.)).child(
+ ui::EditorButton::plain(&theme, "camera3d-reset")
+ .left_icon("icons/rotate-ccw.svg")
+ .label("Reset camera")
+ .on_click(cx.listener(move |this, _, window, cx| {
+ this.reset_camera3d_pose(index, window, cx);
+ })),
+ ),
+ )
+ .into_any_element(),
+ ));
+
+ div()
+ .flex()
+ .flex_col()
+ .gap(px(12.))
+ .child(header)
+ .child(self.render_camera3d_auto_row(cx))
+ .child(self.camera3d_group(self.render_camera3d_looks(index, cx)))
+ .child(self.camera3d_group(camera.into_any_element()))
+ .child(self.camera3d_group(depth.into_any_element()))
+ .child(timing)
.into_any_element()
}
- /// `Camera3DSection` (`:4660-4688`): a `Field`-rhythm header that folds
- /// away, with an optional summary on the right.
- fn camera3d_section(
- &self,
- header: Camera3DSection<'_>,
- key: PanelSection,
- state: &ui::CollapsibleState,
- content: AnyElement,
+ /// Clicking a Look tile: the whole camera animation replaced, as one
+ /// history entry, with the playhead back on the shot's first pose so the
+ /// result plays from what the tile showed.
+ fn apply_camera3d_look(
+ &mut self,
+ index: usize,
+ kind: LookKind,
+ id: &'static str,
+ window: &mut Window,
+ cx: &mut Context<Self>,
+ ) {
+ // The grid stays on the half the click came from, so the ring lands
+ // back under the tile that was just pressed.
+ self.sidebar.camera3d_angles = kind == LookKind::Angle;
+ match kind {
+ LookKind::Move => self.apply_camera3d_template(index, id, window, cx),
+ LookKind::Angle => self.apply_camera3d_angle(index, id, window, cx),
+ }
+ }
+
+ /// `applyTemplate` (`:4983-4993`).
+ fn apply_camera3d_template(
+ &mut self,
+ index: usize,
+ id: &'static str,
+ window: &mut Window,
+ cx: &mut Context<Self>,
+ ) {
+ let Some(template) = MOTION_TEMPLATES.iter().find(|t| t.id == id) else {
+ return;
+ };
+ self.write_camera3d_template(index, template, window, cx);
+ }
+
+ /// `applyAnglePreset` (`:4997-4998`): the preset read as a motion template.
+ fn apply_camera3d_angle(
+ &mut self,
+ index: usize,
+ id: &'static str,
+ window: &mut Window,
+ cx: &mut Context<Self>,
+ ) {
+ let Some(preset) = ANGLE_PRESETS.iter().find(|p| p.id == id) else {
+ return;
+ };
+ let template = angle_preset_motion(preset);
+ self.write_camera3d_template(index, &template, window, cx);
+ }
+
+ fn write_camera3d_template(
+ &mut self,
+ index: usize,
+ template: &MotionTemplate,
+ window: &mut Window,
cx: &mut Context<Self>,
- ) -> AnyElement {
- let Camera3DSection {
- id,
- name,
- icon,
- summary,
- } = header;
- let theme = self.theme;
- let open = state.is_open();
- let summary = summary.map(|summary| SharedString::from(summary.to_string()));
+ ) {
+ let template = MotionTemplate {
+ id: template.id,
+ name: template.name,
+ from: template.from,
+ to: template.to,
+ blur: template.blur,
+ };
+ self.edit_camera3d_segment("camera3d-template", index, window, cx, move |segment| {
+ apply_motion_template(segment, &template);
+ true
+ });
+ // `setEditingEnd(false)` and the playhead back to the first pose.
+ self.sidebar.editing_end_pose = false;
+ self.seek_camera3d_pose(index, false, cx);
+ cx.notify();
+ }
- div()
- .flex()
- .flex_col()
- .child(
- div()
- .id(id)
- .flex()
- .flex_row()
- .gap(px(6.))
- .items_center()
- .w_full()
- .text_size(px(14.))
- .font_weight(FontWeight::MEDIUM)
- .text_color(Hsla::from(theme.gray_12))
- .cursor_pointer()
- .child(
- svg()
- .path(icon)
- .size(px(16.))
- .text_color(Hsla::from(theme.gray_12)),
- )
- .child(name)
- .child(
- div()
- .ml_auto()
- .flex()
- .flex_row()
- .gap(px(6.))
- .items_center()
- .text_size(px(12.))
- .font_weight(FontWeight::NORMAL)
- .text_color(Hsla::from(theme.gray_10))
- .children(summary)
- .child(
- svg()
- .path(if open {
- "icons/chevron-down.svg"
- } else {
- "icons/chevron-right.svg"
- })
- .size(px(14.))
- .text_color(Hsla::from(theme.gray_10)),
- ),
- )
- .on_click(cx.listener(move |this, _, window, cx| {
- this.sidebar.section(key).toggle();
- this.animate_collapsibles(window, cx);
- })),
- )
- .child(collapsible(
- state,
- div().pt(px(16.)).child(content).into_any_element(),
- ))
- .into_any_element()
+ /// `projectActions.applyCamera3DScene`: this one shot replaced by the
+ /// sequence's whole chain.
+ ///
+ /// Two departures from the source, both of which the old behaviour got
+ /// wrong: the chain is clamped to the shot it replaced, so a rounding
+ /// error can never push a generated shot over a neighbour, and only the
+ /// **first** shot ends up selected -- multi-selecting all three closed the
+ /// panel the moment the sequence was applied.
+ fn apply_camera3d_scene(
+ &mut self,
+ index: usize,
+ id: &'static str,
+ window: &mut Window,
+ cx: &mut Context<Self>,
+ ) {
+ let Some(scene) = CAMERA3D_SCENES.iter().find(|scene| scene.id == id) else {
+ return;
+ };
+ let Some((start, end)) = self
+ .timeline()
+ .and_then(|timeline| timeline.camera3d_segments.get(index))
+ .map(|segment| (segment.start, segment.end))
+ else {
+ return;
+ };
+ // `camera3DClipCuts(start, end)`: every clip boundary inside the range.
+ let cuts: Vec<f64> = self.timeline().map_or_else(Vec::new, |timeline| {
+ let offsets = crate::editor_timeline::clip_timeline_offsets(timeline);
+ timeline
+ .segments
+ .iter()
+ .enumerate()
+ .flat_map(|(clip, segment)| {
+ let base = offsets.get(clip).copied().unwrap_or_default();
+ [base, base + segment.duration()]
+ })
+ .filter(|cut| *cut > start && *cut < end)
+ .collect()
+ });
+
+ let mut generated = apply_scene_to_range(scene, start, end, &cuts);
+ for shot in &mut generated {
+ shot.start = shot.start.clamp(start, end);
+ shot.end = shot.end.clamp(shot.start, end);
+ }
+ generated.retain(|shot| shot.end > shot.start);
+ if generated.is_empty() {
+ return;
+ }
+ let first = generated[0].start;
+ self.edit_project("camera3d-scene", window, cx, move |project| {
+ let Some(timeline) = project.timeline.as_mut() else {
+ return false;
+ };
+ if index >= timeline.camera3d_segments.len() {
+ return false;
+ }
+ timeline
+ .camera3d_segments
+ .splice(index..index + 1, generated);
+ timeline
+ .camera3d_segments
+ .sort_by(|a, b| a.start.total_cmp(&b.start));
+ true
+ });
+ self.sidebar.editing_end_pose = false;
+ let selected = self
+ .timeline()
+ .and_then(|timeline| {
+ timeline
+ .camera3d_segments
+ .iter()
+ .position(|segment| segment.start == first)
+ })
+ .unwrap_or(index);
+ self.set_selection(Some(Selection::single(TrackKind::ThreeD, selected)), cx);
+ self.seek_camera3d_pose(selected, false, cx);
+ cx.notify();
+ }
+
+ /// The Depth blur toggle: on seeds a radial defocus, off keeps every other
+ /// scalar so turning it back on restores what was dialled in.
+ fn toggle_camera3d_blur(&mut self, index: usize, window: &mut Window, cx: &mut Context<Self>) {
+ self.edit_camera3d_segment("camera3d-blur-toggle", index, window, cx, |segment| {
+ if segment.blur.mode == Camera3DBlurMode::None {
+ seed_blur_mode(&mut segment.blur, Camera3DBlurMode::Radial);
+ if segment.blur.strength <= 0. {
+ segment.blur.strength = CAMERA3D_DEFAULT_BLUR_STRENGTH;
+ }
+ if segment.blur.falloff <= 0. {
+ segment.blur.falloff = CAMERA3D_DEFAULT_BLUR_FALLOFF;
+ }
+ } else {
+ segment.blur.mode = Camera3DBlurMode::None;
+ }
+ true
+ });
+ }
+
+ fn set_camera3d_blur_mode(
+ &mut self,
+ index: usize,
+ mode: Camera3DBlurMode,
+ window: &mut Window,
+ cx: &mut Context<Self>,
+ ) {
+ self.edit_camera3d_segment("camera3d-blur-mode", index, window, cx, move |segment| {
+ if segment.blur.mode == mode {
+ return false;
+ }
+ seed_blur_mode(&mut segment.blur, mode);
+ true
+ });
+ }
+
+ /// Double-clicking the orbit pad: the camera back on axis, both ends of a
+ /// still shot together.
+ fn reset_camera3d_tilt(&mut self, index: usize, window: &mut Window, cx: &mut Context<Self>) {
+ let editing_end = self.sidebar.editing_end_pose;
+ self.edit_camera3d_segment("camera3d-orbit", index, window, cx, move |segment| {
+ let start = start_pose(segment);
+ let end = end_pose(segment);
+ let still = poses_equal(&start, &end);
+ let easing = MOTION_EASINGS[motion_easing(segment)];
+ let level = |mut pose: Camera3DProperties| {
+ pose.tilt_x = 0.;
+ pose.tilt_y = 0.;
+ pose
+ };
+ if still {
+ let pose = level(start);
+ set_motion(segment, &pose, &pose, (easing.2, easing.3));
+ } else if editing_end {
+ set_motion(segment, &start, &level(end), (easing.2, easing.3));
+ } else {
+ set_motion(segment, &level(start), &end, (easing.2, easing.3));
+ }
+ true
+ });
}
fn easing_select(&self, index: usize, current: usize, cx: &mut Context<Self>) -> AnyElement {
@@ -6669,19 +7657,41 @@ impl EditorWindow {
/// `selectPose` (`:4933-4937`): flip the card **and** park the playhead on
/// the pose being edited, which is what makes the canvas show it.
+ /// Park the playhead on one end of a shot, on the frame the renderer will
+ /// actually draw for it.
+ pub(crate) fn seek_camera3d_pose(&mut self, index: usize, end: bool, cx: &mut Context<Self>) {
+ let Some(time) = self
+ .timeline()
+ .and_then(|timeline| timeline.camera3d_segments.get(index))
+ .map(|segment| {
+ camera3d_pose_seek_time(segment, end, crate::editor_window::EDITOR_PREVIEW_FPS)
+ })
+ else {
+ return;
+ };
+ self.seek_to_time(time, cx);
+ }
+
+ /// The timeline's own pose dots, which reach the same action the strip's
+ /// cards do.
+ pub(crate) fn select_camera3d_pose_from_timeline(
+ &mut self,
+ index: usize,
+ end: bool,
+ cx: &mut Context<Self>,
+ ) {
+ self.select_camera3d_pose(index, end, cx);
+ }
+
fn select_camera3d_pose(&mut self, index: usize, end: bool, cx: &mut Context<Self>) {
self.sidebar.editing_end_pose = end;
- if let Some(segment) = self
+ if let Some(time) = self
.timeline()
.and_then(|timeline| timeline.camera3d_segments.get(index))
+ .map(|segment| {
+ camera3d_pose_seek_time(segment, end, crate::editor_window::EDITOR_PREVIEW_FPS)
+ })
{
- // The end pose is sampled a hair inside the segment so the playhead
- // stays on this segment rather than falling into the next.
- let time = if end {
- (segment.end - 0.01).max(segment.start)
- } else {
- segment.start
- };
self.seek_to_time(time, cx);
}
cx.notify();
@@ -6875,13 +7885,6 @@ impl EditorWindow {
fields.push(FieldKey::KeyboardEnd(index));
}
}
- TrackKind::ThreeD => {
- let selected = indices(timeline.camera3d_segments.len());
- if selected.len() == 1 {
- fields.push(FieldKey::Camera3DEaseIn(selected[0]));
- fields.push(FieldKey::Camera3DEaseOut(selected[0]));
- }
- }
_ => {}
}
}
@@ -7370,28 +8373,21 @@ mod tests {
}
#[test]
- fn an_angle_preset_matches_its_own_opening_pose() {
- for preset in ANGLE_PRESETS {
- assert_eq!(
- match_angle_preset(&preset.values),
- Some(preset.id),
- "{} did not match itself",
- preset.id
- );
- }
- // The reset pose is none of them.
- assert_eq!(match_angle_preset(&CAMERA3D_RESET_POSE), None);
- // `rotateX` / `rotateY` are the fold, not the angle: changing one
- // leaves the preset matched (`CAMERA3D_ANGLE_PRESET_KEYS`).
- let mut pose = ANGLE_PRESETS[0].values;
- pose.rotate_x = -30.;
- assert_eq!(match_angle_preset(&pose), Some("spotlight"));
- // Half a slider step is the tolerance; a whole step is not.
- pose = ANGLE_PRESETS[2].values;
+ fn half_a_slider_step_is_how_close_a_pose_has_to_be() {
+ // The tolerance `matchAnglePreset` was written against, now the one
+ // `match_camera3d_look` compares both ends with.
+ let mut pose = ANGLE_PRESETS[2].values;
+ assert!(camera3d_poses_match(&pose, &ANGLE_PRESETS[2].values));
pose.zoom += f64::from(Camera3DProperty::Zoom.limits().2) / 2.;
- assert_eq!(match_angle_preset(&pose), Some("center"));
+ assert!(camera3d_poses_match(&pose, &ANGLE_PRESETS[2].values));
pose.zoom += f64::from(Camera3DProperty::Zoom.limits().2);
- assert_eq!(match_angle_preset(&pose), None);
+ assert!(!camera3d_poses_match(&pose, &ANGLE_PRESETS[2].values));
+ // The reset pose is none of the presets.
+ assert!(
+ !ANGLE_PRESETS
+ .iter()
+ .any(|preset| camera3d_poses_match(&CAMERA3D_RESET_POSE, &preset.values))
+ );
}
#[test]
@@ -7462,11 +8458,207 @@ mod tests {
let mut segment = camera3d(0., 4.);
apply_motion_template(&mut segment, &angle_preset_motion(&ANGLE_PRESETS[1]));
assert_eq!(
- match_angle_preset(&start_pose(&segment)),
+ match_camera3d_look(&segment).map(|look| look.id),
Some("perspective")
);
}
+ // -- 3D shots ----------------------------------------------------------
+
+ #[test]
+ fn a_shot_starts_where_the_click_landed_and_stops_at_the_gap() {
+ // An empty track: the shot opens at the click and runs its default.
+ assert_eq!(
+ place_camera3d_shot(&[], 4., CAMERA3D_DEFAULT_SHOT_DURATION, 30.),
+ Some((4., 8.))
+ );
+ // The gap's tail is shorter than the default, so the shot shortens
+ // rather than moving.
+ assert_eq!(
+ place_camera3d_shot(&[(8., 12.)], 6., CAMERA3D_DEFAULT_SHOT_DURATION, 30.),
+ Some((6., 8.))
+ );
+ // Under a second left in front of the next shot: the start slides back
+ // just far enough, rather than the click being refused.
+ assert_eq!(
+ place_camera3d_shot(&[(8., 12.)], 7.6, CAMERA3D_DEFAULT_SHOT_DURATION, 30.),
+ Some((7., 8.))
+ );
+ // And it clamps to the timeline's own end.
+ assert_eq!(
+ place_camera3d_shot(&[], 28., CAMERA3D_DEFAULT_SHOT_DURATION, 30.),
+ Some((28., 30.))
+ );
+ // The caller's list is never touched.
+ let existing = [(8., 12.)];
+ let before = existing;
+ let _ = place_camera3d_shot(&existing, 6., CAMERA3D_DEFAULT_SHOT_DURATION, 30.);
+ assert_eq!(existing, before);
+ }
+
+ #[test]
+ fn a_click_inside_a_shot_takes_the_next_free_gap() {
+ // Richie's second scene: the playhead sat inside the first shot and the
+ // old `scene_range` returned None. The gap after it is the answer.
+ let existing = [(0., 6.), (10., 14.)];
+ assert_eq!(
+ place_camera3d_shot(&existing, 3., CAMERA3D_DEFAULT_SHOT_DURATION, 30.),
+ Some((6., 10.))
+ );
+ // With nothing after it, the first free gap anywhere.
+ assert_eq!(
+ place_camera3d_shot(&[(0., 4.), (6., 20.)], 10., 4., 20.),
+ Some((4., 6.))
+ );
+ // A track with no gap at least a second long is the only refusal.
+ assert_eq!(place_camera3d_shot(&[(0., 20.)], 10., 4., 20.), None);
+ assert_eq!(
+ place_camera3d_shot(&[(0., 9.5), (10., 20.)], 9.6, 4., 20.),
+ None
+ );
+ // As are the degenerate inputs.
+ for value in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
+ assert!(place_camera3d_shot(&[], value, 4., 20.).is_none());
+ assert!(place_camera3d_shot(&[], 0., value, 20.).is_none());
+ assert!(place_camera3d_shot(&[], 0., 4., value).is_none());
+ }
+ assert!(place_camera3d_shot(&[], 0., 0., 20.).is_none());
+ assert!(place_camera3d_shot(&[], 0., 4., 0.).is_none());
+ }
+
+ #[test]
+ fn a_new_shot_carries_the_opening_move() {
+ let shot = new_camera3d_shot(2., 6.);
+ assert_eq!((shot.start, shot.end), (2., 6.));
+ assert_eq!(shot.transition_in, 0.);
+ assert_eq!(shot.transition_out, 0.);
+ assert_eq!(
+ match_camera3d_look(&shot).map(|look| look.id),
+ Some("glide-across")
+ );
+ assert_eq!(camera3d_shot_label(&shot), "Glide across");
+ }
+
+ #[test]
+ fn every_look_matches_the_shot_it_was_just_applied_to() {
+ for template in MOTION_TEMPLATES {
+ let mut segment = camera3d(0., 4.);
+ apply_motion_template(&mut segment, template);
+ assert_eq!(
+ match_camera3d_look(&segment),
+ Some(Look {
+ kind: LookKind::Move,
+ id: template.id,
+ name: template.name
+ }),
+ "{} did not match itself",
+ template.id
+ );
+ }
+ for preset in ANGLE_PRESETS {
+ let mut segment = camera3d(0., 4.);
+ apply_motion_template(&mut segment, &angle_preset_motion(preset));
+ assert_eq!(
+ match_camera3d_look(&segment),
+ Some(Look {
+ kind: LookKind::Angle,
+ id: preset.id,
+ name: preset.name
+ }),
+ "{} did not match itself",
+ preset.id
+ );
+ }
+ // Thirteen looks in the grid, and every one of them is reachable.
+ assert_eq!(MOTION_TEMPLATES.len() + ANGLE_PRESETS.len(), 13);
+ }
+
+ #[test]
+ fn a_hand_flown_shot_is_a_custom_move_and_a_held_one_is_a_still() {
+ let mut segment = camera3d(0., 4.);
+ apply_motion_template(&mut segment, &MOTION_TEMPLATES[0]);
+ // One end nudged well past the tolerance and the tile lets go.
+ let start = start_pose(&segment);
+ let mut end = end_pose(&segment);
+ end.roll += 30.;
+ set_motion(&mut segment, &start, &end, ([0., 0.], [1., 1.]));
+ assert_eq!(match_camera3d_look(&segment), None);
+ assert_eq!(camera3d_shot_label(&segment), "Custom move");
+
+ set_motion(&mut segment, &start, &start, ([0., 0.], [1., 1.]));
+ assert_eq!(camera3d_shot_label(&segment), "Still shot");
+ }
+
+ #[test]
+ fn a_pose_seeks_to_a_frame_inside_its_own_shot() {
+ // The renderer floors a seek onto a frame, so a shot starting between
+ // two frames used to show the one before it -- the previous scene.
+ let segment = camera3d(3.025, 5.83);
+ assert!((camera3d_pose_seek_time(&segment, false, 30) - 91. / 30.).abs() < 1e-9);
+ assert!((camera3d_pose_seek_time(&segment, true, 30) - 5.8).abs() < 1e-9);
+ // Both ends stay inside the shot.
+ assert!(camera3d_pose_seek_time(&segment, false, 30) >= segment.start);
+ assert!(camera3d_pose_seek_time(&segment, true, 30) < segment.end);
+
+ // A start already on a frame does not jump forward a frame.
+ let aligned = camera3d(3., 6.);
+ assert!((camera3d_pose_seek_time(&aligned, false, 30) - 3.).abs() < 1e-9);
+ assert!((camera3d_pose_seek_time(&aligned, true, 30) - (6. - 1. / 30.)).abs() < 1e-9);
+
+ // A shot shorter than a frame still shows its own opening pose.
+ let sliver = camera3d(2.0, 2.01);
+ assert_eq!(
+ camera3d_pose_seek_time(&sliver, true, 30),
+ camera3d_pose_seek_time(&sliver, false, 30)
+ );
+ }
+
+ #[test]
+ fn a_sequence_stays_inside_the_shot_it_replaces() {
+ // The panel replaces one shot with the whole chain, so the chain has
+ // to live entirely inside that shot's box or it would overlap the
+ // neighbours on either side.
+ let neighbours = [(0., 6.), (18., 24.)];
+ let (start, end) = (6., 18.);
+ for scene in CAMERA3D_SCENES {
+ for cuts in [vec![], vec![9.5, 13.]] {
+ let shots = apply_scene_to_range(scene, start, end, &cuts);
+ assert!(!shots.is_empty(), "{} generated nothing", scene.id);
+ assert!((shots[0].start - start).abs() < 1e-9);
+ assert!((shots[shots.len() - 1].end - end).abs() < 1e-9);
+ for pair in shots.windows(2) {
+ assert!((pair[1].start - pair[0].end).abs() < 1e-9);
+ }
+ for shot in &shots {
+ assert!(shot.end - shot.start >= CAMERA3D_MIN_SHOT_DURATION - 1e-9);
+ for (other_start, other_end) in neighbours {
+ assert!(
+ shot.end <= other_start + 1e-9 || shot.start >= other_end - 1e-9,
+ "{} overlapped a neighbour",
+ scene.id
+ );
+ }
+ }
+ }
+ }
+ }
+
+ #[test]
+ fn the_look_thumbnails_project_every_pose_in_the_grid() {
+ for template in MOTION_TEMPLATES {
+ for pose in [&template.from, &template.to] {
+ assert!(
+ camera3d_projected_point(pose, -1., 1.).is_some(),
+ "{} projects nothing",
+ template.id
+ );
+ }
+ }
+ for preset in ANGLE_PRESETS {
+ assert!(camera3d_projected_point(&preset.values, 0., 0.).is_some());
+ }
+ }
+
#[test]
fn the_font_picker_lists_the_generics_first() {
let options = font_picker_options();