Skip to main content

compute_skinned_mesh_vertices

Function compute_skinned_mesh_vertices 

Source
pub fn compute_skinned_mesh_vertices(
    influence_offsets: &[u32],
    bone_indices: &[u16],
    weights: &[f32],
    coords_x: &[f32],
    coords_y: &[f32],
    bone_world_matrices: &[SsMatrix4x4],
    deform: Option<SkinnedMeshDeform<'_>>,
    flip_y: bool,
    out_x: &mut [f32],
    out_y: &mut [f32],
)
Expand description

Computes skinned (bone-weighted) mesh vertex positions in world space.

For each vertex v:

  1. Skeletal — accumulate Σ bone_world_matrices[bone_indices[i]] · (coords_x[i], coords_y[i]) · weights[i] over the CSR influence slice influence_offsets[v]..influence_offsets[v + 1]. Translation IS applied (MultiplyPoint3x4 — the m[12], m[13] terms).
  2. Deform delta (optional) — for each entry in deform.0, add part_world_mat · (delta_x, delta_y) (rotation/scale only — MultiplyVector).

Bone indices are expected to be pre-resolved to part indices by ssconverter; no further TableIDPartsBone lookup is performed at runtime.

Layout: CSR for influence_offsets, SoA for weights/coords_x/coords_y. Vectorized across vertices, four at a time, mirroring compute_rigid_mesh_vertices: each f32x4 lane owns one vertex and the influence slots are walked lane-wise, so the accumulators never leave the lanes and no horizontal reduction is performed. Lanes whose vertex has run out of influences contribute weight 0.0, which makes ragged influence counts fall out of the same loop — there is no separate >4-influence path. Vectorizing the influence axis instead would cost two reduce_adds per vertex, which dominates for the 1–2 influence counts SS data actually contains.

flip_y negates the bind coords_y. SSAB-side bind coordinates are authored Y-up; set flip_y when the bone world matrices are Y-down so the bind-pose invariant (each influence resolves to the same rest position) holds.

Skins exactly out_x.len() vertices from the front of the binding. The SpriteStudio meshList appends 4 unbound placeholder vertices (the cell-quad corners) after the rendered mesh, so influence_offsets may be longer than out_x.len() + 1; the trailing entries are simply never read.