FieldConstraint

← prev index next →

Drives one property of a node from a field's weight at that node's position — the way to make position in space control a value like scale or opacity.

Remarks

This is the field-reading member of the Constraint family: like every constraint it drives its constrained target by recomputing from live scene state each frame — here it samples a SpatialField at the target's world position, turns the field weight into a scalar, and writes it to one target property. It is a single-node, CPU-evaluated constraint, distinct from its GPU per-clone counterpart.

Key attributes. field names the field to sample, by #id — any CPU-evaluable field such as the SpatialField shapes (the GPU-only sk-color-source-field has no effect here). target-property selects which property the weight writes (e.g. s for uniform scale, opacity); the raw 0–1 weight can be remapped into the value range that property needs. One field can drive several field-constraints at once by sharing its #id.

Related. Consumes a SpatialField — the same field a material or tonemap can also read, so one field can tint a surface and drive a property together. Its GPU-parallel sibling is the sk-simple-point-constraint, which applies a field weight to every clone of a Cloner at once rather than to a single node.

Constructor

constructor(config?: { field: Field; targetProperty: string; map: (weight: number) => number; priority?: number; composite?: CompositeOperation })

Properties

Config Properties

PropertyTypeDefaultDescriptionDeclared by
fieldanimatable Field The field used for evaluation. null when no field is currently FieldConstraint
targetProperty string The target property name. FieldConstraint
mapconfig-only (weight: number) => number Maps the normalized field weight to a property value. FieldConstraintConfig
priority number Gets the priority for this modifier in the effect stack. Constraint
compositeconfig-only CompositeOperation Composite operation for this modifier. FieldConstraintConfig

Other Properties

PropertyTypeDefaultDescriptionDeclared by
targetread-only SkenraAnimatable | null The node this constraint modifies. Constraint
sceneread-only any Gets the Scene this animatable belongs to, if any. SkenraAnimatable
animationsread-only SkenraAnimation[] Public getter for the animations affecting this target. SkenraAnimatable

Methods

MethodDescriptionDeclared by
animate(firstArg: TypedKeyframe<this>[] | TypedPropertyIndexedKeyframes<this> | Record<string, any> | globalThis.Keyframe[] | globalThis.PropertyIndexedKeyframes | null, secondArg?: number | KeyframeAnimationOptions | globalThis.KeyframeAnimationOptions): SkenraAnimation & Animation Creates a new SkenraAnimation for this target per Web Animations API. SkenraAnimatable
removeAnimation(animation: SkenraAnimation): boolean Removes a specific animation from this object. SkenraAnimatable
constrain(type: K, config: ConstraintConfigMap[K]): ConstraintReturnMap[K] Creates a constraint on this Animatable using a fluent API. SkenraAnimatable

Example

// Scale a sphere by its proximity to a spherical field.
sphere.constrain('field', {
    field: proximityField,
    targetProperty: 's',
    map: (weight) => 5 * weight + 1,
});