BlendTreeAnimation
struct · iOS 15.0+ · SDK 27.1
struct BlendTreeAnimation<Value> where Value : AnimatableDataA collection of animations on the same property that the framework blends to a single animation. This structure provides a way to form a single animation by mixing several other animations together. You define a source node for each animation, and a weight, which determines how much each individual animation takes effect in the resulting animation. To create the blended animation, you define a _blend tree_ that sprouts from ``BlendTreeAnimation/root``, which consists of one or more blend-tree nodes (``BlendTreeNode``). Each node may be one of the following conforming types: - ``BlendTreeBlendNode``, which branches the tree for every element in ``BlendTreeBlendNode/sources`` - ``BlendTreeSourceNode``, which defines one of the animations to blend via its ``BlendTreeSourceNode/source`` property Because source nodes reference no other nodes, they represent leaf nodes in the tree. ### Blending two skeletal movements to a single movement The following animation plays a sampling of the animations named `anim1` and `anim2`. To fine-tune the interplay between the two animations, the code sets a blend weight for each animation. The weight of `0.25` for `anim1` determines that the first animation's behavior is 25% prominent in the final result. The `anim2` weight is `0.75`, as the cumulative blend weight across all animations in the tree needs to equal `1`. This determines that the second animation influences 75% of the visual behavior of the blended animation. ```swift let anim1 = FromToByAnimation<JointTransforms>( name: "anim1", from: JointTransforms([Transform(scale: SIMD3<Float>(1, 2, 3), rotation: simd_quatf(ix: 5, iy: 6, iz: 7, r: 8), translation: SIMD3<Float>(10, 20, 30))]), to: JointTransforms([Transform(scale: SIMD3<Float>(11, 21, 31), rotation: simd_quatf(ix: 50, iy: 60, iz: 70, r: 80), translation: SIMD3<Float>(100, 200, 300))]), duration: 1.0) let anim2 = FromToByAnimation<JointTransforms>( name: "anim2", from: JointTransforms([Transform(scale: SIMD3<Float>(10, 20, 30), rotation: simd_quatf(ix: 4, iy: 5, iz: 5, r: 7), translation: SIMD3<Float>(100, 200, 300))]), to: JointTransforms([Transform(scale: SIMD3<Float>(110, 210, 310), rotation: simd_quatf(ix: 500, iy: 60, iz: 70, r: 80), translation: SIMD3<Float>(1000, 2000, 3000))]), duration: 10.0) let blendTree = BlendTreeAnimation<JointTransforms>( blend( BlendTreeSourceNode( source: anim1, name: "anim1", weight: .value(0.25)), BlendTreeSourceNode( source: anim2, name: "anim2", weight: .value(0.75)), name: "blend"), name: "blendTree", bindTarget: .parameter("bar") ) ``` - Tip: To modify the weights for each frame, create a source node with a dynamic ``BlendWeight``, such as with the ``BlendWeight/bindTarget(_:defaultWeight:)`` or ``BlendWeight/parameter(_:defaultWeight:)`` enumeration cases.
Members (0)
This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.
Skipped declarations
No declarations were skipped in this snapshot.