Ping-pong turns on the last key, and stepped rows hold the key they last passed (#112)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f68941fa3a
commit
cc14988338
7 files changed
+72
-22
No files matched your search
@@ -30,19 +30,21 @@ export const PREVIEW_ROOT_ID = PLACED_ROOT_ID;
|
||||
* container through its instance's edits – the same route an edit in the Scene tab takes, so a row
|
||||
* aimed into a placed container needs nothing of its own (#109). `undefined` without a root. Past
|
||||
* the end of a `once-reset` pass nothing is written: the player has put the starting values back.
|
||||
* `reverse` is ping-pong's way back, as `playheadAt` reports it.
|
||||
*/
|
||||
export function previewHolder(
|
||||
project: Project,
|
||||
animation: AnimationAsset,
|
||||
frame: number,
|
||||
reverse = false,
|
||||
): ObjectHolder | undefined {
|
||||
const root = findAsset(project, animation.root);
|
||||
if (!root) return undefined;
|
||||
const reset = playbackOf(animation) === 'once-reset' && frame >= frameCount(animation);
|
||||
const holder = root.type === 'scene' ? sceneCopy(root) : placedHolder(root);
|
||||
for (const track of reset ? [] : animation.tracks) {
|
||||
if (root.type === 'scene' && track.target === '') writeScene(holder, track, frame);
|
||||
else writeObject(project, holder, previewObjectId(root, track.target), track, frame);
|
||||
if (root.type === 'scene' && track.target === '') writeScene(holder, track, frame, reverse);
|
||||
else writeObject(project, holder, previewObjectId(root, track.target), track, frame, reverse);
|
||||
}
|
||||
return holder;
|
||||
}
|
||||
@@ -72,10 +74,10 @@ function placedHolder(root: Asset): ObjectHolder {
|
||||
}
|
||||
|
||||
/** A row on the scene itself: its value goes into the copy's own properties. */
|
||||
function writeScene(holder: ObjectHolder, track: AnimationTrack, frame: number): void {
|
||||
function writeScene(holder: ObjectHolder, track: AnimationTrack, frame: number, reverse: boolean): void {
|
||||
const def = animatableDefs('scene').find((d) => d.key === track.property);
|
||||
if (!def) return;
|
||||
const value = trackWriteAt(track, def.kind, frame, holder.props[track.property] ?? def.default);
|
||||
const value = trackWriteAt(track, def.kind, frame, holder.props[track.property] ?? def.default, reverse);
|
||||
if (value !== undefined) holder.props[track.property] = value;
|
||||
}
|
||||
|
||||
@@ -85,12 +87,13 @@ function writeObject(
|
||||
id: string,
|
||||
track: AnimationTrack,
|
||||
frame: number,
|
||||
reverse: boolean,
|
||||
): void {
|
||||
const ref = objectRef(project, holder, id);
|
||||
const asset = ref && findAsset(project, ref.object.assetId);
|
||||
const kind = asset && animatedKind(asset.type, track.property);
|
||||
if (!ref || !asset || !kind) return;
|
||||
const value = trackWriteAt(track, kind, frame, baseOf(project, asset, ref.object, track.property));
|
||||
const value = trackWriteAt(track, kind, frame, baseOf(project, asset, ref.object, track.property), reverse);
|
||||
if (value === undefined) return;
|
||||
if (isPositionKey(track.property))
|
||||
ref.setPosition({ ...ref.object.position, [track.property]: Number(value) });
|
||||
|
||||
Reference in new issue
Block a user