diff options
| author | cashmere <cashmere@autistici.org> | 2026-07-28 19:41:16 +0200 |
|---|---|---|
| committer | cashmere <cashmere@autistici.org> | 2026-07-28 19:41:16 +0200 |
| commit | f5a82152394fde4d8f740f664ab7737b82861618 (patch) | |
| tree | 5a51b181abead1ce03d2dbfc12b77918d3be0e1b /rust/crates/scene/src/animation.rs | |
| parent | e837e7504379e100ff3b56282577ec67bb88bec9 (diff) | |
| download | opencut-f5a82152394fde4d8f740f664ab7737b82861618.tar.gz | |
feat: GPUI desktop port foundation
- scene crate: full project/scene/element model, serde round-trip
proven against the web SerializedProject shape
- transfer crate: .ocp zip container, cross-compat with web fflate
archives proven in both directions
- storage crate: filesystem project store replacing IndexedDB,
.ocp import/export
- media crate: ffmpeg-next 8 decoder (frames, audio, thumbnails,
waveform summaries)
- playback crate: wall-clock anchored, frame-rounded playback clock
- gpu crate: native texture readback; compositor renders headless
offscreen on Vulkan (spike test)
- flake devshell: rust toolchain, GPUI native deps, ffmpeg dev,
bindgen clang args; GPUI hello-world builds
- port plan in notes/gpui-port.md
Diffstat (limited to 'rust/crates/scene/src/animation.rs')
| -rw-r--r-- | rust/crates/scene/src/animation.rs | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/rust/crates/scene/src/animation.rs b/rust/crates/scene/src/animation.rs new file mode 100644 index 00000000..d09dd3de --- /dev/null +++ b/rust/crates/scene/src/animation.rs @@ -0,0 +1,127 @@ +use serde::{Deserialize, Serialize}; +use std::collections::BTreeMap; +use time::MediaTime; + +use crate::params::ParamValue; + +pub const ANIMATION_PROPERTY_PATHS: &[&str] = &[ + "transform.positionX", + "transform.positionY", + "transform.scaleX", + "transform.scaleY", + "transform.rotate", + "opacity", + "volume", + "color", + "background.color", + "background.paddingX", + "background.paddingY", + "background.offsetX", + "background.offsetY", + "background.cornerRadius", +]; + +#[derive(Serialize, Deserialize, Clone, Copy, Debug, Eq, PartialEq)] +#[serde(rename_all = "camelCase")] +pub enum ScalarSegmentType { + Step, + Linear, + Bezier, +} + +#[derive(Serialize, Deserialize, Clone, Copy, Debug, Eq, PartialEq)] +#[serde(rename_all = "camelCase")] +pub enum TangentMode { + Auto, + Aligned, + Broken, + Flat, +} + +#[derive(Serialize, Deserialize, Clone, Copy, Debug, Eq, PartialEq)] +#[serde(rename_all = "camelCase")] +pub enum ChannelExtrapolationMode { + Hold, + Linear, +} + +#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq)] +pub struct CurveHandle { + pub dt: MediaTime, + pub dv: f64, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +#[serde(rename_all = "camelCase")] +pub struct ScalarAnimationKey { + pub id: String, + pub time: MediaTime, + pub value: f64, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub left_handle: Option<CurveHandle>, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub right_handle: Option<CurveHandle>, + pub segment_to_next: ScalarSegmentType, + pub tangent_mode: TangentMode, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +#[serde(untagged)] +pub enum DiscreteValue { + Bool(bool), + String(String), +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +#[serde(rename_all = "camelCase")] +pub struct DiscreteAnimationKey { + pub id: String, + pub time: MediaTime, + pub value: DiscreteValue, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +#[serde(rename_all = "camelCase")] +pub struct ChannelExtrapolation { + pub before: ChannelExtrapolationMode, + pub after: ChannelExtrapolationMode, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct ScalarChannel { + pub keys: Vec<ScalarAnimationKey>, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub extrapolation: Option<ChannelExtrapolation>, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct DiscreteChannel { + pub keys: Vec<DiscreteAnimationKey>, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +#[serde(untagged)] +pub enum AnimationChannel { + Scalar(ScalarChannel), + Discrete(DiscreteChannel), +} + +pub type CompositeChannelData = BTreeMap<String, AnimationChannel>; + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +#[serde(untagged)] +pub enum ChannelData { + Single(AnimationChannel), + Composite(CompositeChannelData), +} + +pub type ElementAnimations = BTreeMap<String, ChannelData>; + +impl From<DiscreteValue> for ParamValue { + fn from(value: DiscreteValue) -> Self { + match value { + DiscreteValue::Bool(b) => ParamValue::Bool(b), + DiscreteValue::String(s) => ParamValue::String(s), + } + } +} |
