From 0e3bae4e8cea48daed000f19935fe154bc2753ec Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 19:00:54 -0800 Subject: [PATCH] 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. --- crates/mesh/src/gltf.rs | 5 +---- crates/mesh/src/tests/gltf_write.rs | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/mesh/src/gltf.rs b/crates/mesh/src/gltf.rs index eee5fbbead..984e1e6e9a 100644 --- a/crates/mesh/src/gltf.rs +++ b/crates/mesh/src/gltf.rs @@ -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 = 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))); } diff --git a/crates/mesh/src/tests/gltf_write.rs b/crates/mesh/src/tests/gltf_write.rs index 3190e444ab..cfb69a7e76 100644 --- a/crates/mesh/src/tests/gltf_write.rs +++ b/crates/mesh/src/tests/gltf_write.rs @@ -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();