Animation rows can target behavior variables and shader parameters (#104)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b278605c53
commit
beeea355d9
9 files changed
+273
-77
No files matched your search
@@ -1,15 +1,16 @@
|
||||
import { isHandleEnabled } from '../../core/graph';
|
||||
import {
|
||||
type AnimationPlayer,
|
||||
animatableDefsOf,
|
||||
animatedKind,
|
||||
animationPlayheadAt,
|
||||
isPositionKey,
|
||||
isPositionRow,
|
||||
playbackOf,
|
||||
trackWriteAt,
|
||||
} from '../../core/model/animation';
|
||||
import type { AnimationAsset, AnimationTrack } from '../../core/model/Asset';
|
||||
import { instanceChildId, splitInstanceId } from '../../core/model/instance';
|
||||
import { findAssetOf } from '../../core/model/Project';
|
||||
import { findAsset, findAssetOf } from '../../core/model/Project';
|
||||
import type { PropertyValue } from '../../core/model/Properties';
|
||||
import type { Entity } from '../Entity';
|
||||
import type { World } from '../World';
|
||||
@@ -113,7 +114,7 @@ function bind(world: World, asset: AnimationAsset, owner: Entity): Binding[] {
|
||||
entity = world.sceneId === root.id ? world.findByObjectId(track.target) : undefined;
|
||||
else if (track.target === '') entity = owner;
|
||||
else entity = world.findByObjectId(childId(owner.objectId, track.target));
|
||||
const kind = entity && animatedKind(entity.type, key);
|
||||
const kind = entity && kindOn(world, entity, key);
|
||||
if (entity && kind) {
|
||||
const aimed = entity;
|
||||
bindings.push({
|
||||
@@ -128,6 +129,15 @@ function bind(world: World, asset: AnimationAsset, owner: Entity): Binding[] {
|
||||
return bindings;
|
||||
}
|
||||
|
||||
/**
|
||||
* The kind `key` has on the entity as it is now: its bag names the shader it wears, and swapping that
|
||||
* shader at runtime takes the parameter rows with it (#104).
|
||||
*/
|
||||
function kindOn(world: World, entity: Entity, key: string): string | undefined {
|
||||
const asset = findAsset(world.project, entity.assetId);
|
||||
return asset && animatableDefsOf(world.project, asset, entity.props).find((d) => d.key === key)?.kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* The id a template object gets below a placed container – nested one deeper when the container is
|
||||
* content itself. `path` may run through containers placed inside the template (`a/b`).
|
||||
@@ -138,12 +148,12 @@ function childId(ownerId: string, path: string): string {
|
||||
}
|
||||
|
||||
function read(entity: Entity, key: string): PropertyValue {
|
||||
if (isPositionKey(key)) return entity[key];
|
||||
if (isPositionRow(entity.type, key)) return entity[key];
|
||||
return entity.props[key] ?? 0;
|
||||
}
|
||||
|
||||
function write(entity: Entity, key: string, value: PropertyValue): void {
|
||||
if (isPositionKey(key)) {
|
||||
if (isPositionRow(entity.type, key)) {
|
||||
const n = Number(value);
|
||||
if (Number.isFinite(n)) entity[key] = n;
|
||||
} else entity.props[key] = value;
|
||||
|
||||
Reference in new issue
Block a user