craft-mesh: compare joint slots without a temporary vector

check_skins now compares the four joint slots of a skinned vertex in
pairs instead of collecting the joints with nonzero weights into a Vec,
so validation does not allocate once per vertex. The rule is unchanged:
a joint may not appear in two slots whose weights are both nonzero.

The writer test adds a vertex that repeats a joint in slots 1 and 3.
This commit is contained in:
dotCooCoo committed 2026-11-24 19:00:54 -08:00
1 parent a25128ed40
commit 0e3bae4e8c
2 files changed
+5 -4

No files matched your search

+1 -4
View File
@@ -1647,10 +1647,7 @@ fn check_skins(scene: &Scene) -> Result<()> {
if let Some(m) = scene.meshes.iter().find(|m| m.joints.is_empty() != m.weights.is_empty()) {
return Err(malformed(KIND, format!("mesh `{}` has joints without weights or weights without joints", m.name)));
}
let repeated = |j: &[u16; 4], w: &[f32; 4]| {
let used: Vec<u16> = j.iter().zip(w).filter(|(_, w)| **w != 0.0).map(|(j, _)| *j).collect();
used.iter().enumerate().any(|(k, j)| used.get(k + 1..).is_some_and(|rest| rest.contains(j)))
};
let repeated = |j: &[u16; 4], w: &[f32; 4]| (0..4).any(|a| (a + 1..4).any(|b| w[a] != 0.0 && w[b] != 0.0 && j[a] == j[b]));
if let Some(m) = scene.meshes.iter().find(|m| m.joints.iter().zip(&m.weights).any(|(j, w)| repeated(j, w))) {
return Err(malformed(KIND, format!("mesh `{}` has a vertex that names a joint with a weight twice", m.name)));
}
+4
View File
@@ -466,6 +466,10 @@ fn writer_refuses_rigging_that_is_not_gltf() {
s.meshes[0].joints[0] = [0; 4];
assert!(refused(&s), "a joint named twice with weights other than 0");
let mut s = rig();
s.meshes[0].joints[1] = [0, 1, 0, 1];
s.meshes[0].weights[1] = [0.5, 0.25, 0.0, 0.25];
assert!(refused(&s), "a joint named twice in slots that are not next to each other");
let mut s = rig();
s.skins[0].joints = vec![2, 2];
assert!(refused(&s), "a joint node named twice in a skin");
let mut s = rig();