Value at time v1 - #803
Open
pgilfernandez wants to merge 4 commits into
Open
Conversation
This reverts commit edc79d3.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi!
With the help of AI, this PR adds After Effects-style temporal sampling to Friction expressions through
valueAtTime(), it's been requested/discussed here and here.Expressions can now sample:
Usage
Sample the current property
This samples the current property's keyframed, pre-expression value half a second earlier. Using the base value prevents self-recursion.
Sample another property
The first argument is the binding name, passed as a string. The sampled result is the effective value of the bound property, including its own expression.
New
$timebindingThis PR also introduces:
$timeis the absolute scene time in seconds, calculated from the absolute scene frame and FPS.Although expressions could previously calculate time using:
that is not always equivalent.
$frameis relative to the property or layer and can be affected by frame shifts, whilevalueAtTime()uses absolute scene time.For example, at 24 FPS, with a layer shifted by 48 frames and the scene at frame 120:
Using
$timetherefore provides an unambiguous scene clock and matches the temporal model expected byvalueAtTime().API
The time argument:
Invalid binding names, argument types, FPS values, or internal frame ranges produce descriptive JavaScript errors.
Frame-shift handling
Sampling converts the requested time into an absolute scene frame and then converts that frame into the relative frame of the sampled property.
This ensures that expressions work correctly when the source and target properties belong to layers with different timeline shifts.
The same absolute-frame conversion was also applied to normal property binding evaluation at arbitrary frames.
Dependency and cycle handling
Existing expression dependency analysis also applies to temporal sampling.
Valid dependency:
Rejected circular dependency:
Cycles are rejected even when the expressions use different time offsets, because evaluating effective values would still create recursive expression dependencies.
The single-argument form is safe because it samples the current property's pre-expression value.
Expression invalidation
Expressions using temporal sampling are treated as time-dependent and non-static.
When a sampled binding changes, Friction conservatively invalidates the full expression range. This guarantees correctness for arbitrary time offsets. More precise dependency-range analysis could be added later as a performance optimization.
Editor integration
The expression editor now includes:
$timesyntax highlighting.$timeautocomplete support.valueAtTime(time)autocomplete.valueAtTime("bindingName", time)autocomplete.Using the current frame during validation fixes an issue where the editor's internal uninitialized-frame sentinel could incorrectly produce an out-of-range error.
Preset
A new Value at Time (Delay) expression preset is included.
It works immediately with the current property's base value:
The preset also explains how to replace
$valuewith another mapped property.Validation
It builds successfully on macOS, I guess it should work and any other OS.
I hope you like it 😊
Test builds