diff --git a/packages/ludic.anim/README.md b/packages/ludic.anim/README.md index 8cf0127e..b2d6a54d 100644 --- a/packages/ludic.anim/README.md +++ b/packages/ludic.anim/README.md @@ -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 diff --git a/packages/ludic.anim/bones.ludic b/packages/ludic.anim/bones.ludic new file mode 100644 index 00000000..ea79251f --- /dev/null +++ b/packages/ludic.anim/bones.ludic @@ -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 +} diff --git a/packages/ludic.anim/index.ludic b/packages/ludic.anim/index.ludic index fb1f8300..8a6785aa 100644 --- a/packages/ludic.anim/index.ludic +++ b/packages/ludic.anim/index.ludic @@ -7,3 +7,4 @@ import "clip.ludic" import "read.ludic" import "mix.ludic" import "pose.ludic" +import "bones.ludic" diff --git a/packages/ludic.anim/tests/anim_test.ludic b/packages/ludic.anim/tests/anim_test.ludic index 6cfe5c1e..e3997137 100644 --- a/packages/ludic.anim/tests/anim_test.ludic +++ b/packages/ludic.anim/tests/anim_test.ludic @@ -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))