feat(ludic.anim): skin_joint - a bone looked up in the skin's own joints, not the file's first of that name

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 08:41:51 +03:00
parent 6e2212de7b
commit 473552cc81
4 changed files with 26 additions and 0 deletions

View file

@ -24,6 +24,7 @@ anim_play(sk, walk, t, idle, t2, 0.3) # 70% walk, 30% idle, into th
| `anim_play(sk, a, ta, b, tb, blend) -> bool` | `a` at `ta`, cross-faded toward `b` at `tb` by `blend` (0 all a, 1 all b; `b` may be null), folded into the joint matrices |
| `anim_mix(c, sk, t, w, rot, pos, hit)`, `anim_to_pose(sk, rot, pos, hit)`, `anim_key_at(c, ch, t)` | the pieces `anim_play` is made of, for a caller that mixes more than two |
| `anim_set_positions(on)`, `anim_positions()` | keyed translations applied or not (off: baking keys location on every bone, and rounding down an eighteen-bone chain is a collapsed animal) |
| `skin_joint(sk, name)`, `skin_joint_quiet(sk, name)` | a bone by name in the skin's OWN joints: a kit packs several rigs with the same bone names, and render3d's `skin_find` answers the file's first, which belongs to another rig (the pose is then stored and never drawn) |
| `anim_first_key(c) -> float` | the earliest key; a read warns when it is not zero |
## Rules it keeps

View file

@ -0,0 +1,16 @@
# bones.ludic - a bone is looked up in the skin's OWN joint list: every kit packs several rigs
# with the same bone names, and skin_find's first hit in the file belongs to whichever came first
export function skin_joint(sk: Skin, name: string) -> int {
let i = skin_joint_quiet(sk, name)
if i < 0 { print(`skin: no joint {name} in this skin`) }
return i
}
# the same lookup without the complaint: animal_pose asks every skin for "wing_l" and "leg_fl_u"
export function skin_joint_quiet(sk: Skin, name: string) -> int {
if sk == null { return -1 }
for j in 0 .. sk.n_joints {
let i = sk.joints[j]
if sk.names[i] == name { return i }
}
return -1
}

View file

@ -7,3 +7,4 @@ import "clip.ludic"
import "read.ludic"
import "mix.ludic"
import "pose.ludic"
import "bones.ludic"

View file

@ -86,6 +86,14 @@ program AnimTest {
expect_near(pose_z(sk), 0.0, 0.001)
}
test "a bone is found in the skin's own joints, not the file's first of that name" {
gltf_doc = Json.parse("{\"nodes\": [{\"name\": \"bone\"}, {\"name\": \"root\", \"children\": [2]}, {\"name\": \"bone\"}], \"skins\": [{\"joints\": [1, 2]}]}")
let sk = skin_load(0)
expect_eq(skin_joint(sk, "bone"), 2)
expect_eq(skin_joint_quiet(sk, "wing_l"), -1)
expect_eq(skin_joint_quiet(null, "bone"), -1)
}
test "no skin or no clip plays nothing" {
expect(not anim_play(null, turn("t"), 0.0, null, 0.0, 0.0))
expect(not anim_play(skin(), null, 0.0, null, 0.0, 0.0))