mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-10 10:20:47 -06:00
* frames: keep cached frames an edit can't reach Nudging, trimming or splitting a layer re-rendered the whole comp. The RAM preview now carries every frame whose stack of active layers is unchanged to the new comp identity; only the segments an edit touches re-render. * disk cache: never drop frame writes; save frames kept after edits Frames get their own write lane (bounded by bytes, written before layer buffers), so a burst of layer writes no longer drops frames and leaves gaps in the blue bar after reopening. Frames an edit kept in RAM are written to disk under the comp's new content key when idle. * frames: music and hidden layers keep the caches Layers that can't change pixels (audio-only footage, AV layers with Video off, when nothing reads them and there are no expressions) no longer count for the RAM preview's dirty segments or the disk cache's comp and footage keys. Adding, trimming or moving music keeps both caches. RENDER_VERSION bumps to effectcraft-render-3 for the new key formula. * ui-egui: background caching benchmark cache_bench fills a comp's RAM preview the way idle caching does and prints frames/s with decoder, footage-cache and disk-cache counters. * frames: soloed music and hidden layers aren't silent Solo hides every other layer, so soloing a music track or a layer with Video off changes the picture. silent_layers no longer drops soloed layers, so the RAM preview and the disk cache see Solo toggles. * disk cache: audio files a layer reads stay in the layer salt Audio-only footage left the disk layer salt so importing music keeps the keys, but Audio Spectrum and Audio Waveform draw from an audio layer. Footage another layer reads (or any, when a read layer is a precomp) counts again, so overwriting that file doesn't reuse stale buffers. * disk cache: retry frame writes the queue refused put_frame reports whether the frame is on disk or queued. persist_missing forgets the key of a refused write, so a full frame lane no longer leaves RAM frames that are never written. * ui-egui: cache_bench measures idle caching; checks --comp and --slots Frames go through request_background with one slot per frame thread, as Cache Frames When Idle does. An unknown --comp is an error (the active comp is used only without --comp), --slots is at least 1, and the disk report flushes queued writes instead of sleeping. * disk cache: RENDER_VERSION effectcraft-render-6 This branch changes the cache-key formula (silent layers, Solo, read audio in the footage salt), and upstream #2759 already took render-5 for the clip-clock change, so entries from either must not be reused. * frames: rewrite RAM frames the disk cache evicted persist_missing kept every disk key it ever queued, so a frame the disk cache evicted later was never written back. The disk cache now tracks frame writes still queued or in progress (frame_pending), and persist_missing only remembers keys while it converts them. * frames: idle passes continue while RAM frames wait for disk persist_missing reports whether there may be more to write (a content key being computed, frames being converted). Cache Frames When Idle then schedules another pass, so a refused write is retried without waiting for a UI event, and the passes stop once every frame is on disk or queued. * frames: rewrite an evicted frame once, not on every idle pass A disk cache smaller than the RAM preview, or a frame too large for it, made idle passes write, evict and rewrite the same frames every 500 ms. Each disk key is now written at most twice under one disk limit (the write and one rewrite after an eviction); a new limit resets the count. The persist test waits for the conversion to forget its keys before checking that no work is left. * frames: the work area doesn't change pixels Setting the work area (B, N) cleared every cached frame, in RAM and on disk: it was compared with the comp's pixel settings and hashed into the disk key. It is a preview and render range only, like the Resolution, so it no longer counts. * frames: audio edits keep frames unless something draws the audio Changing a clip's Audio Levels, its audio effects or its Audio switch cleared the clip's cached frames, and the comp's disk cache, although nothing drew that audio. The audio now counts only for the layers whose audio is heard (Project::heard_layers): those a layer picks in an effect (an Audio Waveform or Spectrum, even on itself), the layers of a picked precomp, and every layer while an expression (which can read Audio Levels) exists. Music in a precomp that a waveform in the outer comp picks is no longer treated as silent either. * frames: an expression only reaches the frames of its own layer One expression anywhere in the project made every edit clear the comp's whole cache, and so did editing a layer another layer reads (its parent, matte, or a layer it picks). Expressions can read anything, but they only draw in their own layer: an edit now re-renders the frames where it changed something, plus those of the layers with an expression and of the layers that read a reached layer. With expressions, an edit elsewhere (another comp, an item's name, a marker, music) reaches only the expression layers' frames. * frames: an edit inside a precomp re-renders only where the precomp shows it Editing anything inside a precomp cleared every cached frame of the comps that nest it, even a music level in it. Project::dirty_spans now follows precomps: it takes the spans their comp changed in, shifts and scales them by the precomp layer's start and stretch (its whole span under a time remap or Responsive Design timing), and keeps the outer comp's other frames. Layers that read a changed precomp (a matte, a waveform) re-render where they are active. * disk cache: keep the frames an edit can't reach The disk cache keys frames on a hash of the whole comp, so every edit lost the frames that were only on disk (the blue bar), even a rename; only those still in RAM were written again under the new key. When an edit keeps RAM frames, it now also queues a disk carry: on the frame pool, each kept frame of every disk series in use for that comp is hard linked (or copied) to its new key with DiskCache::link_frame, oldest edit first. The old entries stay, so undo finds them too. * frames: a keyframe edit re-renders only around the keys it changed Changing one keyframe (its value, interpolation or ease, in the Timeline or the Graph Editor) re-rendered the layer's whole length, so a key on a full-length layer cleared the whole cache. A layer that differs only in keyframes of its Transform properties now re-renders from two keys before the first changed key to two after the last (auto-Bezier and continuous tangents reach the neighbouring segments), to its in or out point past the first or last key. Static values, expressions, roving keys, time remap and time effects still reach the whole layer; effect keyframes do too for now (simulations and time effects read other frames). * frames: music volume keeps frames while no expression reads audio Any expression in the project (a wiggle on another layer, even a disabled one) made every layer's audio count as read, so changing a music layer's Audio Levels re-rendered every expression layer and changed the comp's disk key. Audio now counts for expressions only when one may read it (Heard::audio_exprs): its text names audio or walks properties by index. An audio-only change nothing reads no longer counts as a change elsewhere in dirty_spans either. * frames: a keyframe edit with few keys or beside a self-contained expression keeps the other frames Changing a Scale key of a layer with two or three keys re-rendered the layer's whole length: with fewer than two keys before (or after) the changed one, the span fell back to the in (or out) point instead of the first (or last) key, past which the value holds. And any layer with an expression re-rendered on every edit, so a wiggle on a full-length layer cleared the whole cache. An expression layer is now reached by edits elsewhere only when its text may read outside its layer (it names a comp, layer, footage, the project or its source); its parent and the layers it picks are still read through referenced_layers. * viewer: the caching chip stays up between uncached frames, with a spinner The "Caching frames…" chip showed only while playback waited for a frame, so during caching it flickered on and off with every frame that arrived. It now stays up 0.6 s after the last wait (and hides at once when playback stops). It is also smaller and quieter: a spinner, then "Caching frames" without the ellipsis in dimmed smaller text, on a fainter chip sized to its text. * preview: the Preview panel's cache bar counts the preview's Resolution With a preview Resolution set (Half, Third…), the frames a preview plays are cached at that scale, but the Preview panel's bar counted the series the viewer shows. When playback stopped, the viewer went back to the comp's Resolution and the bar dropped from full to the frames cached there. It now counts the preview's own series (Auto still follows the viewer). The viewer and the Timeline's cache bar are unchanged. * Contributors: add nazar-gavrylyk's name * frames: an expression reading its own layer's markers or audio re-renders that layer With expressions in the project, a layer's markers count when comparing it, and its audio counts when an expression may read audio, so a marker or volume edit re-renders the edited layer over its own span. Comp markers still count only through layers whose expressions name thisComp. * frames: a keyframe edit on a layer with an expression re-renders the layer An expression on the keyed layer can read the keyed property at other times (Rotation reading Position with valueAtTime), so the frames past the changed keys may change too. * cache_bench: read decoder counters through effectcraft-media Only crates/media, crates/export and crates/interchange may depend on the FilmCraft crates. * cache_bench: clips end where the next one starts * frames: write-back uses the worker's disk keys while a Roto Brush model is active persist_missing keyed disk frames on FrameKey::opts, which also carries the Roto Brush model stamp; the worker and disk_frames key on the render opts' hash alone. With a model active every RAM frame looked missing, was written again under keys nobody reads, and recorded a second disk series. * frames: an edit two precomps down reaches the outer comp A precomp layer whose comp Arc didn't change was skipped, but the comps nested in it may have (an edit in Inner leaves Mid's Arc as it was), so Outer kept every frame. Every nested comp is walked now, each once per edit. * cache_bench: stop when the disk cache can't be cleared * frames: one disk carry job at a time carry_disk runs on every timeline paint and idle pass, and spawned a pool job whenever carries were queued; during a drag the extra jobs waited on the carry lock and held frame-pool threads from the viewer. A scheduled flag keeps one job, which drains the queue in order until it's empty. * frames: a panicking disk carry is skipped, not left holding the job The carry job clears carry_scheduled only on its normal exit; a panic in a carry would have left it set for the session, so no later carry ran. Each carry is caught like the content key's hashing, so the job always reaches its exit. * frames: an expression reading its own in point or index re-renders its layer A trim or rename kept the layer's frames outside the cut when the layer drew the same apart from its span, but an expression on it can read its own inPoint, outPoint or name (a fade from inPoint), so every frame of the layer changes. Such a layer is no longer treated as only respanned. An expression reading `index` reads the layers above it too: a layer added or removed there shifts it, so `index` now counts as reading outside the layer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * frames: an edit of a comp reaches the expressions of the precomps it nests An expression in a precomp can read the comp that nests it (`comp("Main").layer("Controls")`), but the walk into nested comps only counted changes outside the edited top comp. Editing a hidden Controls layer there (or any layer, when the precomp is time-shifted or reads it at other times) kept every precomp frame in RAM and linked them all on disk under the new key. Nested comps now see an edit of the comp above them as an edit elsewhere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * frames: an edit in a precomp under a time effect reaches its whole layer A precomp layer running Echo, Posterize Time, Time Displacement or another effect that reads the layer at other times shows a nested change far from where it maps, but only the mapped span (a nested frame either side) re-rendered. Such a layer now gives its whole span, like a time remap. `reads_other_frames` lists those effects (every `ec.time.` and `ec.sim.` effect and the others that call `self_at`); keyframe spans use it too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * frames: a keyframe edit beside muted keys re-renders the whole layer Muted keys are skipped when a property is evaluated, so the keys that play around an edited key can be any distance away, but the span counted two stored keys either side. A segment from an earlier playing key kept its stale frames. Muted keys now give the layer's whole span, like roving keys. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * frames: one echo in the precomp time-effect test (three saturate alike), rustfmt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
615 lines
23 KiB
Rust
615 lines
23 KiB
Rust
use super::item::{ItemId, LayerId};
|
|
use super::settings::Marker;
|
|
use super::{BlendMode, Deserialize, GroupKind, Label, Node, ParamUi, PropGroup, Property, Serialize, Tick, Value};
|
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum LightKind {
|
|
Parallel,
|
|
Spot,
|
|
#[default]
|
|
Point,
|
|
Ambient,
|
|
Environment,
|
|
}
|
|
|
|
impl LightKind {
|
|
pub const ALL: [LightKind; 5] = [LightKind::Parallel, LightKind::Spot, LightKind::Point, LightKind::Ambient, LightKind::Environment];
|
|
pub fn label(self) -> &'static str {
|
|
match self {
|
|
LightKind::Parallel => "Parallel",
|
|
LightKind::Spot => "Spot",
|
|
LightKind::Point => "Point",
|
|
LightKind::Ambient => "Ambient",
|
|
LightKind::Environment => "Environment",
|
|
}
|
|
}
|
|
}
|
|
|
|
/// A parametric 3D primitive (Layer ▸ New ▸ Cube/Sphere/Plane/Torus/Cone/Cylinder).
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
pub enum PrimitiveKind {
|
|
#[default]
|
|
Cube,
|
|
Sphere,
|
|
Plane,
|
|
Torus,
|
|
Cone,
|
|
Cylinder,
|
|
}
|
|
|
|
impl PrimitiveKind {
|
|
pub const ALL: [PrimitiveKind; 6] =
|
|
[PrimitiveKind::Cube, PrimitiveKind::Sphere, PrimitiveKind::Plane, PrimitiveKind::Torus, PrimitiveKind::Cone, PrimitiveKind::Cylinder];
|
|
pub fn label(self) -> &'static str {
|
|
match self {
|
|
PrimitiveKind::Cube => "Cube",
|
|
PrimitiveKind::Sphere => "Sphere",
|
|
PrimitiveKind::Plane => "Plane",
|
|
PrimitiveKind::Torus => "Torus",
|
|
PrimitiveKind::Cone => "Cone",
|
|
PrimitiveKind::Cylinder => "Cylinder",
|
|
}
|
|
}
|
|
pub fn parse(s: &str) -> Option<PrimitiveKind> {
|
|
PrimitiveKind::ALL.into_iter().find(|k| k.label().eq_ignore_ascii_case(s.trim()))
|
|
}
|
|
}
|
|
|
|
/// What a layer shows.
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
#[serde(tag = "type")]
|
|
pub enum LayerSource {
|
|
/// Footage item (video, still, sequence, audio).
|
|
Footage {
|
|
item: ItemId,
|
|
},
|
|
/// Nested composition (precomp).
|
|
Comp {
|
|
item: ItemId,
|
|
},
|
|
/// Solid item (solids also back adjustment layers).
|
|
Solid {
|
|
item: ItemId,
|
|
},
|
|
Text,
|
|
Shape,
|
|
Null,
|
|
Camera,
|
|
Light {
|
|
kind: LightKind,
|
|
},
|
|
/// An imported 3D model (a footage item of kind [`FootageKind::Model`]; Advanced 3D).
|
|
Model {
|
|
item: ItemId,
|
|
},
|
|
/// A parametric 3D primitive (Advanced 3D).
|
|
Primitive {
|
|
kind: PrimitiveKind,
|
|
},
|
|
}
|
|
|
|
impl LayerSource {
|
|
pub fn item(&self) -> Option<ItemId> {
|
|
match self {
|
|
LayerSource::Footage { item } | LayerSource::Comp { item } | LayerSource::Solid { item } | LayerSource::Model { item } => Some(*item),
|
|
_ => None,
|
|
}
|
|
}
|
|
pub fn type_name(&self) -> &'static str {
|
|
match self {
|
|
LayerSource::Footage { .. } => "Footage",
|
|
LayerSource::Comp { .. } => "Composition",
|
|
LayerSource::Solid { .. } => "Solid",
|
|
LayerSource::Text => "Text",
|
|
LayerSource::Shape => "Shape",
|
|
LayerSource::Null => "Null",
|
|
LayerSource::Camera => "Camera",
|
|
LayerSource::Light { .. } => "Light",
|
|
LayerSource::Model { .. } => "3D Model",
|
|
LayerSource::Primitive { .. } => "3D Primitive",
|
|
}
|
|
}
|
|
/// Layers with pixels (cameras, lights and nulls have none).
|
|
pub fn is_av(&self) -> bool {
|
|
!matches!(self, LayerSource::Camera | LayerSource::Light { .. } | LayerSource::Null)
|
|
}
|
|
/// A 3D model or primitive layer (meshes; drawn by the Advanced 3D renderer).
|
|
pub fn is_model(&self) -> bool {
|
|
matches!(self, LayerSource::Model { .. } | LayerSource::Primitive { .. })
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum Quality {
|
|
#[default]
|
|
Best,
|
|
Draft,
|
|
Wireframe,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum Sampling {
|
|
#[default]
|
|
Bilinear,
|
|
Bicubic,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum FrameBlend {
|
|
#[default]
|
|
Off,
|
|
FrameMix,
|
|
PixelMotion,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct Switches {
|
|
pub video: bool,
|
|
pub audio: bool,
|
|
pub solo: bool,
|
|
pub locked: bool,
|
|
pub shy: bool,
|
|
/// Collapse transformations (precomps) / continuously rasterize (vector layers).
|
|
pub collapse: bool,
|
|
pub quality: Quality,
|
|
pub sampling: Sampling,
|
|
pub effects: bool,
|
|
pub frame_blend: FrameBlend,
|
|
pub motion_blur: bool,
|
|
pub adjustment: bool,
|
|
pub three_d: bool,
|
|
pub guide: bool,
|
|
}
|
|
|
|
impl Default for Switches {
|
|
fn default() -> Self {
|
|
Switches {
|
|
video: true,
|
|
audio: true,
|
|
solo: false,
|
|
locked: false,
|
|
shy: false,
|
|
collapse: false,
|
|
quality: Quality::Best,
|
|
sampling: Sampling::Bilinear,
|
|
effects: true,
|
|
frame_blend: FrameBlend::Off,
|
|
motion_blur: false,
|
|
adjustment: false,
|
|
three_d: false,
|
|
guide: false,
|
|
}
|
|
}
|
|
}
|
|
|
|
// What a frame's pixels depend on. Caches key on it: the Lock and Shy switches and Hide Shy
|
|
// Layers never change pixels, and the Audio switch, the Audio group and audio effects change them
|
|
// only when something draws the layer's audio (a waveform or spectrum picks it, see
|
|
// [`crate::Project::heard_layers`]), so editing those keeps cached frames (#103).
|
|
|
|
/// Is `id` an audio effect (applied by the audio mix rather than the compositor)?
|
|
pub fn is_audio_effect(id: &str) -> bool {
|
|
id.starts_with("ec.audio.")
|
|
}
|
|
|
|
/// Does effect `id` read its own layer at other times (`EffectHost::self_at`, `layer_at` on
|
|
/// itself): the time effects (Echo, Posterize Time, Timewarp…), simulations, temporal smoothing
|
|
/// and analysis (Remove Grain, Auto Levels, Color Stabilizer's reference frame, Warp Stabilizer,
|
|
/// Roto Brush…) and Clone strokes with a time offset? On a precomp layer, a change at one nested
|
|
/// time then reaches frames of the layer far from where it shows.
|
|
// ponytail: hand-kept list of the effects that call `self_at`; a new one must be added here.
|
|
pub fn reads_other_frames(id: &str) -> bool {
|
|
id.starts_with("ec.time.") || id.starts_with("ec.sim.") || READS_OTHER_FRAMES.contains(&id)
|
|
}
|
|
|
|
/// The effects outside `ec.time.` and `ec.sim.` that read their own layer at other times.
|
|
const READS_OTHER_FRAMES: &[&str] = &[
|
|
"ec.noise.removegrain",
|
|
"ec.color.autolevels",
|
|
"ec.color.autocontrast",
|
|
"ec.color.autocolor",
|
|
"ec.color.shadowhighlight",
|
|
"ec.color.colorstabilizer",
|
|
"ec.matte.refinesoft",
|
|
"ec.matte.refinehard",
|
|
"ec.matte.rotobrush",
|
|
"ec.matte.objectmatte",
|
|
"ec.blur.camerashakedeblur",
|
|
"ec.distort.rollingshutterrepair",
|
|
"ec.distort.warpstabilizer",
|
|
"ec.key.ccsimplewireremoval",
|
|
"ec.paint.paint",
|
|
];
|
|
|
|
impl Switches {
|
|
/// These switches with Audio, Lock and Shy at their defaults.
|
|
pub fn pixels(&self) -> Switches {
|
|
Switches { audio: true, locked: false, shy: false, ..self.clone() }
|
|
}
|
|
|
|
/// The switches that change the pixels of a layer: [`Self::pixels`], keeping Audio when
|
|
/// something draws the layer's audio (`heard`).
|
|
pub fn picture(&self, heard: bool) -> Switches {
|
|
Switches { audio: if heard { self.audio } else { true }, ..self.pixels() }
|
|
}
|
|
}
|
|
|
|
/// A node only the audio mix reads: the layer's Audio group, an audio effect.
|
|
fn audio_only(n: &Node, root: bool) -> bool {
|
|
match n {
|
|
Node::Group(g) => (root && g.match_id == "audio") || matches!(&g.kind, GroupKind::Effect { effect } if is_audio_effect(effect)),
|
|
Node::Prop(_) => false,
|
|
}
|
|
}
|
|
|
|
/// `a` and `b` are equal but for their audio-only nodes ([`audio_only`]: the root's Audio group,
|
|
/// the effects in its Effects group that are audio effects).
|
|
fn same_picture_props(a: &PropGroup, b: &PropGroup) -> bool {
|
|
fn head(a: &PropGroup, b: &PropGroup) -> bool {
|
|
// Every field (no `..`: a new field must be considered here).
|
|
let PropGroup { uid, match_id, name, kind, enabled, label, children: _ } = a;
|
|
*uid == b.uid && *match_id == b.match_id && *name == b.name && *kind == b.kind && *enabled == b.enabled && *label == b.label
|
|
}
|
|
fn children(a: &PropGroup, b: &PropGroup, root: bool) -> bool {
|
|
let mut x = a.children.iter().filter(|n| !audio_only(n, root));
|
|
let mut y = b.children.iter().filter(|n| !audio_only(n, root));
|
|
loop {
|
|
match (x.next(), y.next()) {
|
|
(None, None) => return true,
|
|
(Some(Node::Group(g)), Some(Node::Group(h))) if root && g.match_id == "effects" && h.match_id == "effects" => {
|
|
if !(head(g, h) && children(g, h, false)) {
|
|
return false;
|
|
}
|
|
}
|
|
(Some(m), Some(n)) if m == n => {}
|
|
_ => return false,
|
|
}
|
|
}
|
|
}
|
|
head(a, b) && children(a, b, true)
|
|
}
|
|
|
|
/// `g` (a layer's property tree) without its audio-only nodes ([`same_picture_props`]).
|
|
fn picture_props(g: &PropGroup) -> PropGroup {
|
|
let mut g = g.clone();
|
|
g.children.retain(|n| !audio_only(n, true));
|
|
for n in &mut g.children {
|
|
if let Node::Group(e) = n
|
|
&& e.match_id == "effects"
|
|
{
|
|
e.children.retain(|n| !audio_only(n, false));
|
|
}
|
|
}
|
|
g
|
|
}
|
|
|
|
impl Layer {
|
|
/// Draws the same pixels as `o`: equal but for the Audio, Lock and Shy switches and what only
|
|
/// the audio mix reads (nothing draws its audio).
|
|
pub fn same_pixels(&self, o: &Layer) -> bool {
|
|
self.same_pixels_with(o, true, false)
|
|
}
|
|
|
|
/// [`Self::same_pixels`], with the markers counting only when `with_markers` (they are read by
|
|
/// expressions alone, so a project without any can edit them freely) and the audio (the Audio
|
|
/// switch, the Audio group, audio effects) only when `heard`: something draws it.
|
|
pub fn same_pixels_with(&self, o: &Layer, with_markers: bool, heard: bool) -> bool {
|
|
// Every field (no `..`: a new field must be considered here); the property tree last.
|
|
let Layer {
|
|
id,
|
|
name,
|
|
source,
|
|
label,
|
|
comment,
|
|
start_time,
|
|
in_point,
|
|
out_point,
|
|
stretch,
|
|
switches,
|
|
blend_mode,
|
|
preserve_transparency,
|
|
track_matte,
|
|
parent,
|
|
markers,
|
|
markers_locked,
|
|
auto_orient,
|
|
environment,
|
|
environment_background,
|
|
props,
|
|
} = self;
|
|
*id == o.id
|
|
&& *name == o.name
|
|
&& *source == o.source
|
|
&& *label == o.label
|
|
&& *comment == o.comment
|
|
&& *start_time == o.start_time
|
|
&& *in_point == o.in_point
|
|
&& *out_point == o.out_point
|
|
&& *stretch == o.stretch
|
|
&& switches.picture(heard) == o.switches.picture(heard)
|
|
&& *blend_mode == o.blend_mode
|
|
&& *preserve_transparency == o.preserve_transparency
|
|
&& *track_matte == o.track_matte
|
|
&& *parent == o.parent
|
|
&& (!with_markers || *markers == o.markers)
|
|
&& *markers_locked == o.markers_locked
|
|
&& *auto_orient == o.auto_orient
|
|
&& *environment == o.environment
|
|
&& *environment_background == o.environment_background
|
|
&& (if heard { *props == o.props } else { same_picture_props(props, &o.props) })
|
|
}
|
|
|
|
/// The comp-time spans where `self` draws differently than `o` when the two differ only in
|
|
/// the keyframes of Transform properties (a key's value, ease or interpolation moved in the
|
|
/// Timeline or Graph Editor): from two keys before the first changed key to two after the
|
|
/// last (auto-Bezier and continuous tangents reach the neighbouring segments), to the
|
|
/// layer's in or out point past the first or last key (values hold there). `None` for any
|
|
/// other difference, a static value, an expression on the layer (it can read the keyed
|
|
/// property at other times), roving or muted keys, a time remap or a time effect (it reads other
|
|
/// times): those reach the layer's whole span.
|
|
pub fn keyframe_spans(&self, o: &Layer, with_markers: bool, heard: bool) -> Option<Vec<(Tick, Tick)>> {
|
|
let transform = |l: &Layer| l.props.group("transform").cloned();
|
|
let (t1, t0) = (transform(self)?, transform(o)?);
|
|
let reads_time = |l: &Layer| {
|
|
l.props.get("timeRemap").is_some()
|
|
|| l.props.group("effects").is_some_and(|e| {
|
|
e.children.iter().any(|n| matches!(n, Node::Group(f) if matches!(&f.kind, GroupKind::Effect { effect } if reads_other_frames(effect))))
|
|
})
|
|
};
|
|
let has_expr = |l: &Layer| {
|
|
let mut any = false;
|
|
l.props.walk("", &mut |_, p| any |= p.has_expression());
|
|
any
|
|
};
|
|
if reads_time(self) || reads_time(o) || has_expr(self) || has_expr(o) {
|
|
return None;
|
|
}
|
|
// Everything but the Transform group draws the same.
|
|
let rest = |l: &Layer| {
|
|
let mut l = l.clone();
|
|
l.props.children.retain(|n| !matches!(n, Node::Group(g) if g.match_id == "transform"));
|
|
l
|
|
};
|
|
let head = |g: &PropGroup| PropGroup { children: vec![], ..g.clone() };
|
|
if !rest(self).same_pixels_with(&rest(o), with_markers, heard) || head(&t1) != head(&t0) || t1.children.len() != t0.children.len() {
|
|
return None;
|
|
}
|
|
let mut spans = Vec::new();
|
|
for (n1, n0) in t1.children.iter().zip(&t0.children) {
|
|
if n1 == n0 {
|
|
continue;
|
|
}
|
|
let (Node::Prop(p1), Node::Prop(p0)) = (n1, n0) else { return None };
|
|
let bare = |p: &Property| Property { keys: vec![], value: Value::Scalar(0.0), ..p.clone() };
|
|
// (muted keys are skipped: the keys around an edit that play can be any distance away)
|
|
if bare(p1) != bare(p0) || p1.keys.is_empty() || p0.keys.is_empty() || p1.keys.iter().chain(&p0.keys).any(|k| k.roving || k.muted) {
|
|
return None;
|
|
}
|
|
// Keys only one side has as they are (added, removed, edited, moved).
|
|
let changed: Vec<Tick> =
|
|
p1.keys.iter().filter(|k| !p0.keys.contains(k)).chain(p0.keys.iter().filter(|k| !p1.keys.contains(k))).map(|k| k.time).collect();
|
|
let (Some(first), Some(last)) = (changed.iter().min(), changed.iter().max()) else { continue };
|
|
// Two keys before the first changed one and two after the last, on either side (the
|
|
// first or last key when there are fewer: values hold beyond it). Past the first or
|
|
// last key the change reaches the in or out point (`None`).
|
|
let mut lo = Some(Tick(i64::MAX));
|
|
let mut hi = Some(Tick(i64::MIN));
|
|
for keys in [&p1.keys, &p0.keys] {
|
|
let before = keys.iter().filter(|k| k.time < *first).count();
|
|
let back = if before == 0 { None } else { keys.get(before.saturating_sub(2)) };
|
|
lo = lo.zip(back).map(|(a, k)| a.min(k.time));
|
|
let upto = keys.iter().filter(|k| k.time <= *last).count();
|
|
let ahead = if upto >= keys.len() { None } else { keys.get(upto.saturating_add(1).min(keys.len().saturating_sub(1))) };
|
|
hi = hi.zip(ahead).map(|(a, k)| a.max(k.time));
|
|
}
|
|
let (x, y) = (lo.map_or(self.in_point, |t| self.comp_time(t)), hi.map_or(self.out_point, |t| self.comp_time(t)));
|
|
let (x, y) = (x.min(y).max(self.in_point), x.max(y).min(self.out_point));
|
|
if x <= y {
|
|
spans.push((x, y));
|
|
}
|
|
}
|
|
Some(spans)
|
|
}
|
|
|
|
/// This layer with what doesn't change its pixels at its defaults (see
|
|
/// [`Self::same_pixels_with`]), for keys that hash it; `None` when it already is.
|
|
pub fn picture_form(&self, heard: bool) -> Option<Layer> {
|
|
let switches = self.switches.picture(heard);
|
|
let audio = !heard
|
|
&& (self.props.children.iter().any(|n| audio_only(n, true))
|
|
|| self
|
|
.props
|
|
.children
|
|
.iter()
|
|
.any(|n| matches!(n, Node::Group(e) if e.match_id == "effects" && e.children.iter().any(|n| audio_only(n, false)))));
|
|
if switches == self.switches && !audio {
|
|
return None;
|
|
}
|
|
let mut l = Layer { switches, ..self.clone() };
|
|
if audio {
|
|
l.props = picture_props(&self.props);
|
|
}
|
|
Some(l)
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum MatteKind {
|
|
#[default]
|
|
Alpha,
|
|
AlphaInverted,
|
|
Luma,
|
|
LumaInverted,
|
|
}
|
|
|
|
impl MatteKind {
|
|
pub const ALL: [MatteKind; 4] = [MatteKind::Alpha, MatteKind::AlphaInverted, MatteKind::Luma, MatteKind::LumaInverted];
|
|
pub fn label(self) -> &'static str {
|
|
match self {
|
|
MatteKind::Alpha => "Alpha Matte",
|
|
MatteKind::AlphaInverted => "Alpha Inverted Matte",
|
|
MatteKind::Luma => "Luma Matte",
|
|
MatteKind::LumaInverted => "Luma Inverted Matte",
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct TrackMatte {
|
|
pub layer: LayerId,
|
|
pub kind: MatteKind,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum AutoOrient {
|
|
#[default]
|
|
Off,
|
|
AlongPath,
|
|
TowardsCamera,
|
|
TowardsPointOfInterest,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct Layer {
|
|
pub id: LayerId,
|
|
pub name: String,
|
|
pub source: LayerSource,
|
|
pub label: Label,
|
|
#[serde(default)]
|
|
pub comment: String,
|
|
/// Comp time where the layer's time 0 sits.
|
|
pub start_time: Tick,
|
|
/// Visible span in comp time.
|
|
pub in_point: Tick,
|
|
pub out_point: Tick,
|
|
/// Time stretch in percent (100 = normal, negative = reversed).
|
|
pub stretch: f64,
|
|
pub switches: Switches,
|
|
pub blend_mode: BlendMode,
|
|
#[serde(default)]
|
|
pub preserve_transparency: bool,
|
|
#[serde(default)]
|
|
pub track_matte: Option<TrackMatte>,
|
|
#[serde(default)]
|
|
pub parent: Option<LayerId>,
|
|
#[serde(default)]
|
|
pub markers: Vec<Marker>,
|
|
/// Layer ▸ Markers ▸ Lock Markers.
|
|
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
|
pub markers_locked: bool,
|
|
#[serde(default)]
|
|
pub auto_orient: AutoOrient,
|
|
/// Layer ▸ Environment Layer: the layer is the environment (image-based light and
|
|
/// reflections) of Advanced 3D comps instead of being drawn.
|
|
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
|
pub environment: bool,
|
|
/// Layer ▸ Light ▸ Create Environment Light Background Layer: the layer's (equirectangular)
|
|
/// image is drawn as the 3D scene's backdrop, seen through the camera, instead of as a card.
|
|
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
|
pub environment_background: bool,
|
|
/// The property tree (Masks, Effects, Transform, Text, Contents, Camera/Light options…).
|
|
pub props: PropGroup,
|
|
}
|
|
|
|
impl Layer {
|
|
/// The layers this layer reads: its parent, track matte, layer parameters (Displacement Map,
|
|
/// Audio Spectrum's Audio Layer…) and tracker targets.
|
|
pub fn referenced_layers(&self) -> Vec<LayerId> {
|
|
fn walk(g: &PropGroup, depth: usize, out: &mut Vec<LayerId>) {
|
|
if depth > 64 {
|
|
return;
|
|
}
|
|
if let GroupKind::Tracker { settings } = &g.kind
|
|
&& let Some(t) = settings.target
|
|
{
|
|
out.push(t);
|
|
}
|
|
for c in &g.children {
|
|
match c {
|
|
Node::Prop(p) => {
|
|
for v in std::iter::once(&p.value).chain(p.keys.iter().map(|k| &k.value)) {
|
|
if let Value::Layer(Some(id)) = v {
|
|
out.push(LayerId(*id));
|
|
}
|
|
}
|
|
}
|
|
Node::Group(sub) => walk(sub, depth + 1, out),
|
|
}
|
|
}
|
|
}
|
|
let mut out: Vec<LayerId> = self.parent.iter().copied().chain(self.track_matte.iter().map(|m| m.layer)).collect();
|
|
walk(&self.props, 0, &mut out);
|
|
out
|
|
}
|
|
|
|
/// Layers this one picks in an effect or tracker (an Audio Spectrum's Audio Layer, a
|
|
/// Displacement Map's map layer…), itself included: [`Self::referenced_layers`] without the
|
|
/// parent and the track matte.
|
|
pub fn picked_layers(&self) -> Vec<LayerId> {
|
|
let skip = usize::from(self.parent.is_some()) + usize::from(self.track_matte.is_some());
|
|
self.referenced_layers().into_iter().skip(skip).collect()
|
|
}
|
|
|
|
pub fn is_active_at(&self, t: Tick) -> bool {
|
|
t >= self.in_point && t < self.out_point
|
|
}
|
|
|
|
/// Layer time for a comp time (stretch-aware).
|
|
pub fn layer_time(&self, comp_t: Tick) -> Tick {
|
|
let d = comp_t - self.start_time;
|
|
if (self.stretch - 100.0).abs() < 1e-9 { d } else { Tick((d.0 as f64 * 100.0 / self.stretch) as i64) }
|
|
}
|
|
|
|
/// Comp time for a layer time.
|
|
pub fn comp_time(&self, layer_t: Tick) -> Tick {
|
|
if (self.stretch - 100.0).abs() < 1e-9 { self.start_time + layer_t } else { self.start_time + Tick((layer_t.0 as f64 * self.stretch / 100.0) as i64) }
|
|
}
|
|
|
|
pub fn transform(&self) -> Option<&PropGroup> {
|
|
self.props.sub("transform")
|
|
}
|
|
|
|
pub fn transform_mut(&mut self) -> Option<&mut PropGroup> {
|
|
self.props.sub_mut("transform")
|
|
}
|
|
|
|
pub fn effects(&self) -> Option<&PropGroup> {
|
|
self.props.sub("effects")
|
|
}
|
|
|
|
pub fn masks(&self) -> Option<&PropGroup> {
|
|
self.props.sub("masks")
|
|
}
|
|
|
|
/// The labels popup property `p` of this layer offers: Text Path Options ▸ Path lists None and
|
|
/// the layer's masks (value k = mask k), every other popup its own options. `None` when `p` is
|
|
/// not a popup.
|
|
pub fn popup_options<'a>(&'a self, p: &'a Property) -> Option<std::borrow::Cow<'a, [String]>> {
|
|
if self.props.prop("text/pathOptions/path").is_some_and(|q| q.uid == p.uid) {
|
|
let masks = self.masks().into_iter().flat_map(|m| m.groups().map(|g| g.name.clone()));
|
|
return Some(std::iter::once("None".to_string()).chain(masks).collect::<Vec<_>>().into());
|
|
}
|
|
match &p.ui {
|
|
ParamUi::Popup { options } => Some(options.as_slice().into()),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
pub fn is_camera(&self) -> bool {
|
|
matches!(self.source, LayerSource::Camera)
|
|
}
|
|
|
|
pub fn is_light(&self) -> bool {
|
|
matches!(self.source, LayerSource::Light { .. })
|
|
}
|
|
|
|
/// The layer participates in 3D (3D switch, or cameras/lights which are always 3D).
|
|
pub fn is_3d(&self) -> bool {
|
|
self.switches.three_d || self.is_camera() || self.is_light()
|
|
}
|
|
|
|
pub fn has_video(&self) -> bool {
|
|
self.source.is_av() && self.switches.video
|
|
}
|
|
}
|