use crate::data::{SlotId, VertexData};
use crate::skeleton::Skeleton;
impl Skeleton {
#[allow(clippy::too_many_arguments, clippy::many_single_char_names)]
pub(crate) fn compute_world_vertices(
&self,
vertex_data: &VertexData,
slot_id: SlotId,
start: usize,
count: usize,
world: &mut [f32],
offset: usize,
stride: usize,
) {
let end = offset + (count >> 1) * stride;
let bones = &vertex_data.bones;
let vertices = &vertex_data.vertices;
let deform = &self.slots[slot_id.index()].applied().deform;
if bones.is_empty() {
let verts: &[f32] = if deform.is_empty() { vertices } else { deform };
let slot_bone = self.data.slots[slot_id.index()].bone;
let b = self.bones[slot_bone.index()].applied();
let (x, y, a, bb, c, d) = (b.world_x, b.world_y, b.a, b.b, b.c, b.d);
let mut vv = start;
let mut w = offset;
while w < end {
let vx = verts[vv];
let vy = verts[vv + 1];
world[w] = vx * a + vy * bb + x;
world[w + 1] = vx * c + vy * d + y;
vv += 2;
w += stride;
}
return;
}
let mut v = 0_usize;
let mut skip = 0_usize;
let mut i = 0_usize;
while i < start {
let n = bones[v] as usize;
v += n + 1;
skip += n;
i += 2;
}
if deform.is_empty() {
let mut w = offset;
let mut b_idx = skip * 3;
while w < end {
let mut wx = 0.0_f32;
let mut wy = 0.0_f32;
let n_here = bones[v] as usize;
v += 1;
let n_end = v + n_here;
while v < n_end {
let bone_index = bones[v] as usize;
let bone = self.bones[bone_index].applied();
let vx = vertices[b_idx];
let vy = vertices[b_idx + 1];
let weight = vertices[b_idx + 2];
wx += (vx * bone.a + vy * bone.b + bone.world_x) * weight;
wy += (vx * bone.c + vy * bone.d + bone.world_y) * weight;
v += 1;
b_idx += 3;
}
world[w] = wx;
world[w + 1] = wy;
w += stride;
}
} else {
let mut w = offset;
let mut b_idx = skip * 3;
let mut f = skip << 1;
while w < end {
let mut wx = 0.0_f32;
let mut wy = 0.0_f32;
let n_here = bones[v] as usize;
v += 1;
let n_end = v + n_here;
while v < n_end {
let bone_index = bones[v] as usize;
let bone = self.bones[bone_index].applied();
let vx = vertices[b_idx] + deform[f];
let vy = vertices[b_idx + 1] + deform[f + 1];
let weight = vertices[b_idx + 2];
wx += (vx * bone.a + vy * bone.b + bone.world_x) * weight;
wy += (vx * bone.c + vy * bone.d + bone.world_y) * weight;
v += 1;
b_idx += 3;
f += 2;
}
world[w] = wx;
world[w + 1] = wy;
w += stride;
}
}
}
}