Squash and Stretch: Non-Uniform Scale and Rotation in Bone Hierarchies
Squash and Stretch: Non-Uniform Scale and Rotation in Bone Hierarchies
Search
Ask the AI

Squash and Stretch: Non-Uniform Scale and Rotation in Bone Hierarchies

Squash and stretch in a bone hierarchy needs an explicit deformation space. Non-uniform scale and rotation generally do not commute. Putting the same scale on a parent, in a local channel, or in a final world-space pass can produce different shapes.

Start with area compensation, then check hierarchy matrices, scaling pivots, timing, and smears for fast motion.

In two dimensions, volume preservation means area

Area compensation makes a flattened part wider and a stretched part thinner while preserving its 2D size. Here “volume preservation” refers to area, rather than three-dimensional volume.

For finite positive s, scale one axis by s and the other by 1/s. The area factor s · (1/s) = 1 stays unchanged. Zero would divide by zero; this parameter curve also excludes the reflection introduced by negative scale.

def squash(s):
    return (s, 1.0 / s)        # s along the main axis, the other compensates

Alongside area compensation, inspect perimeter and strokes, and the appearance of extreme poses.

The first is perimeter. A circle of radius r becomes an ellipse with semi-axes rs and r/s. For s ≠ 1 its area is unchanged but its perimeter increases. Non-uniform scale can also change stroke width. SVG supports non-scaling-stroke to preserve stroke width. For raster artwork, accept the deformed outline or redraw it around the deformed silhouette. A separate, unscaled copy of the original outline will not automatically follow the new shape.

The second is the visual choice at extreme values. Strict 1/s at s = 0.4 requires the other axis to grow to 2.5×. If that exaggeration does not suit the artwork, reduce the compensation exponent:

sy = 1.0 / (s ** alpha)        # alpha around 0.6 to 0.8

alpha = 1 preserves area exactly. Otherwise the area factor is s^(1−alpha). For example, s = 0.4 and alpha = 0.7 give about 0.759658 of the original area. Weaker compensation changes area and should be chosen for the visual goal.

Keep the scaling pivot at the contact point

Before any hierarchy code, there is a more basic trap: what point does the scale happen around?

To keep a landing ball’s underside fixed while the top compresses, scale around the contact point. Scaling vertically about the centre instead, with s = 0.7, raises the bottom edge by 0.15 · height: the vertical size shrinks by 0.3 of the height, split equally above and below the centre.

The fix is to anchor the scale at the contact point — whichever position ought to stay fixed through the deformation:

def scale_about(p, anchor, sx, sy):
    return (anchor.x + (p.x - anchor.x) * sx,
            anchor.y + (p.y - anchor.y) * sy)

Generalised: the anchor belongs at the point that is semantically stationary. The bottom for a landing ball, the shoulder for an arm hoisting a weight, the fixed end of a rope being pulled. Getting it wrong raises no error; it just adds a drift nobody can quite name.

Scale and rotation order in a hierarchy

A bone’s world matrix is usually its parent’s world matrix multiplied by its local matrix. This is also the correct composition rule for non-uniform scale. The question is whether it expresses the intended deformation space.

Multiply a parent’s scale matrix S by a child’s rotation matrix R to inspect the result. Take S = diag(sx, sy) and R a rotation by θ:

S · R = | sx·cosθ   -sx·sinθ |
        | sy·sinθ    sy·cosθ |

The dot product of the columns is (sy²−sx²)sinθcosθ. For positive unequal scales, sx ≠ sy, the columns are non-orthogonal only when sinθcosθ ≠ 0, so the result cannot be represented as one rotation followed on the right by a diagonal scale in the local TRS form. At integer multiples of 90°, the columns remain orthogonal. If negative scales are allowed, compare their magnitudes too: sx = −sy gives orthogonal columns at every angle.

A rectangular child at a general angle beneath a non-uniformly scaled parent can become a parallelogram, but not every nonzero angle does this. At zero angle, S · R = S because θ = 0; at 90° the columns are also orthogonal, with the axis-scale correspondence exchanged. Commuting S and R requires the stronger condition (sx−sy)sinθ = 0. For positive unequal scales, only integer multiples of 180° satisfy it.

With column vectors, the rightmost matrix acts first. Thus S R means rotate the child first, then scale along the parent-space axes. This has a clear geometric meaning and can be intentional. Preserving right angles between each part’s local axes requires a different inheritance or deformation convention.

Three deformation conventions

The first option is to adjust scale inheritance, controlling child scale separately while following the position and direction required by the rig. Follow the engine’s actual contract. For example, Spine’s scale inheritance interacts with direction and position; it is not simply deletion of one matrix factor. Disabling inheritance can also change how child offsets behave, so test joint positions and reflections.

The second option is to apply whole-image deformation last. Compute the unscaled hierarchy, then scale all world vertices about the contact point. This explicitly compresses the character as one image, but does not remove non-orthogonality in rotated parts: the final linear block can still be S R. If the same global S was previously applied only at the root, associativity makes the two arrangements identical. This suits whole-image deformation; a single leg needs a separate group.

world = parent_trs_without_scale @ local_trs_without_scale
p = world @ vertex
p = scale_about(p, contact_point, sx, sy)   # last step, in world space

The third option is to decompose and rebuild by a defined convention. A nonsingular matrix has a polar decomposition A = QH, where Q is orthogonal and H is symmetric positive definite; when det(A) > 0, Q is a rotation. The decomposition is well defined and is not inherently unstable. Replacing H with diag(H11, H22) and rebuilding Q diag(H11, H22) defines an approximation that generally differs from A. Handle near-singular cases and reflections explicitly, and measure runtime cost. See Higham’s paper on polar decomposition for algorithms and error analysis.

Choose by the deformation goal. A final world-space pass suits whole-image compression. Local axis and joint control require explicit inheritance or decomposition rules. When combining approaches, check that the same scale is not applied twice.

Let velocity drive the squash

To make stretch respond to motion, drive the curve below with speed. The original direction calculation requires nonzero velocity:

speed = length(velocity)
s = 1.0 + clamp(speed * gain, 0.0, max_stretch)   # stretch along the motion
axis = normalize(velocity)                        # the direction to stretch in

Combine s with perpendicular 1/s^alpha along axis for speed-driven stretch. A separate contact offset can squash s below 1, provided s remains finite and positive. The gain, max_stretch, alpha, contact offset, and direction threshold all need settings appropriate to the asset.

Zero velocity has no direction; near zero, the normalised direction is sensitive to noise. If that direction drives a visible deformation, the edges can jitter; inspect the silhouette even when s is close to 1.

One option retains the last valid direction below a positive speed threshold. Initialise last_axis to a valid unit rest direction before using it:

if speed > MIN_SPEED:
    last_axis = normalize(velocity)
axis = last_axis          # reuse the last valid direction when slow

As deformation approaches zero, the effect of freezing the axis also approaches zero. If a contact squash is still visible, however, axis choice still changes the shape; a contact normal or rest axis may be more suitable. Other vector-driven effects also need defined near-zero behaviour, such as retaining direction, returning to a default axis, or fading out.

Initialise once, then apply the threshold update above:

last_axis = Vec2(1.0, 0.0)  # unit rest direction
assert MIN_SPEED > 0

Choose the deformation duration

Beyond the mathematics, squash and stretch depends heavily on how many frames it occupies.

One landing sequence is anticipation → contact → squash → rebound stretch → settle. A squash can be a brief drawing, but distinguish frames from drawings: at 24 fps one frame lasts 1/24 second, while one drawing held on twos lasts two frames, or 1/12 second. Choose the duration for the intended rhythm.

Preview whether the contact reads clearly, whether the squash holds too long, and whether the material suits the character. A longer hold can suit a soft body; a brief squash can suit firmer contact. This is an art choice.

Choose rebound magnitude and easing for the material and action too. A stretch of half to two thirds of the squash can be a starting point for preview, but that ratio is not a physical bound. A larger stretch does not by itself imply a weightless object.

Use a geometric test to identify smear candidates

For fast motion, a smear can use an elongated or connected silhouette to suggest the motion path.

A geometric test can identify candidates: if per-frame displacement exceeds the object’s size along its motion, a shape undergoing translation alone, without changing shape, no longer overlaps its previous image along that direction. The condition below is a smear heuristic. Visible strobing also depends on frame rate, exposure, and display behaviour; the inequality alone does not establish it.

need_smear = speed_px_per_frame > object_size_along_motion

Start by trying a smear length near one frame’s displacement, then adjust for direction, exposure cues, and silhouette. A smear draws an elongated or connected shape to suggest speed. Motion blur integrates images over the exposure interval; the two effects are generated differently.

A smear can relax area compensation when the silhouette calls for it. Strict compensation may make a long smear too thin, but whether to preserve area remains a visual choice.

What can be checked automatically

Most of this is judged by eye, but three things can be written as checks and caught during rigging.

First, check orthogonality. For nondegenerate columns u and v of a linear block, inspect the normalised dot product (u·v)/(|u||v|). Near zero means orthogonal axes. A nonzero result identifies non-orthogonality, but does not identify its source or establish that it is unwanted. Compare it with the part’s intended shear convention, and report degenerate columns separately.

Second, check area. At a fixed pose, or when revisiting the same pose, compare each part’s |det(A)| with its expected area factor to help detect duplicate scale. The visible character silhouette also changes with occlusion, clipping, and overlap, so its area alone cannot attribute a change to duplicated scale.

Third, check anchor displacement. Hold the parent reference frame and other transforms fixed, then compare the declared contact point before and after this deformation. The difference should lie below the chosen floating-point tolerance. If it exceeds that tolerance, inspect pivot coordinates, transform order, and reference frames.

Leave a Reply

Scroll down