Repository navigation
Animation Blending
Graphics3D 800, 600, 32, 2
SetBuffer BackBuffer()
model = LoadAnimMesh("walk_run.b3d")
PositionEntity model, 0, 0, 0
walkSeq = 0
runSeq = 1
While Not KeyHit(1)
speed# = 0
If KeyDown(200) Then speed# = 1
BlendAnim model, walkSeq, 1 - speed#, 1, 1, 2
BlendAnim model, runSeq, speed#, 1, 1, 2
UpdateWorld
RenderWorld
Flip
Wend
EndBlendAnim(object, seq, weight#, mode, speed#, fade#, additive, ref)Blends animation sequence seq on object toward weight#. mode is the usual loop mode (0 disable, 1 loop, 2 pingpong, 3 one shot), speed# is playback speed
fade# is a ramp rate in weight units per second, not a duration. Time to reach target is roughly |weight# - current| / fade# seconds. 0 or less snaps instantly instead of ramping. The same fade# also controls the ramp down when stopped with StopAnimBlend
additive defaults to 0. With 0 the sequence is an overlay layer: when a base animation is playing from Animate, the overlay blends on top of it by its weight, so a weight of 1 replaces the base pose and 0 leaves it untouched. When no base is playing, overlays combine with each other by weighted averaging, like the walk/run example above
With 1 the sequence becomes an additive layer: the pose delta relative to a reference pose is added on top of whatever is already playing, scaled by weight#. This is how you layer hit reactions, aim offsets, breathing and similar motion on top of locomotion
ref selects the sequence used for the additive reference pose. It defaults to -1, which means the layer's own sequence. The reference is taken at frame 0, so the delta is measured against the first frame of that sequence. Set ref to another sequence when the layer was authored against a different rest pose
Only one blend exists per seq on an object, calling this again with the same seq updates it instead of creating another
Returns an internal slot index, or -1 on failure. Don't hang onto this value, indices shift as blends finish. Use seq to refer back to a blend, StopAnimBlend and AnimBlendWeight both take seq
An additive reaction on top of a base walk:
Animate model, 1, 1, walkSeq
BlendAnim model, hitSeq, 1, 3, 1, 4, 1 ; >:D
...
StopAnimBlend model, hitSeqStopAnimBlend(object, seq)Ramps the blend for seq down to 0 using its own fade#, or stops instantly if fade# was 0 or less
AnimBlendWeight#(object, seq)Returns the current weight of the blend for seq, or 0 if none
CountAnimBlends(object)Returns how many blends are active on object
Blends on the same object combine by weighted averaging when there is no base animation, there is no cross-fade step between two sequences, each one just ramps its own weight. When a base animation is playing from Animate, each overlay blends on top of it by its own weight instead. Additive layers are applied last, each one adding its reference-relative delta scaled by its weight
blitz blitz blitz