Write atlas_uv onto bones_by_id, not rig.bones

The render loop iterates bones_z_sorted, which contains references to
the bones_by_id objects build_rig constructs. rig.bones is the original
rig_table.bones source array, which is a separate set of bone objects.
load_textures was writing atlas_uv onto rig.bones entries, so render
never saw it and every textured bone fell through to the colored-rect
phase-1 fallback. Vagrant-skeleton's puppet rendered as bare rotated
rects instead of subterrain sprites.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Axel Meyer
2026-05-22 00:34:30 +02:00
parent 16c1cf6865
commit 58da7fd104

View File

@@ -1187,18 +1187,23 @@ function M.load_textures(rig, asset_aliases)
-- Bind each bone to its uv-rect; resolve anchor (uv.w/2, uv.h/2 default). -- Bind each bone to its uv-rect; resolve anchor (uv.w/2, uv.h/2 default).
-- Anchor is a rig-author concern: bone-level b.anchor (set in rig table) -- Anchor is a rig-author concern: bone-level b.anchor (set in rig table)
-- takes precedence; tile UV center is the fallback. -- takes precedence; tile UV center is the fallback.
for _, b in ipairs(rig.bones) do --
if b.texture then -- The render loop reads from bones_by_id (via bones_z_sorted), not from
local tile = by_name[b.texture] -- rig.bones (which keeps the original rig_table.bones reference). We
-- must write atlas_uv onto the bones_by_id objects so render sees it.
for _, b_src in ipairs(rig.bones) do
if b_src.texture then
local tile = by_name[b_src.texture]
if tile == nil then if tile == nil then
error("puppet.load_textures: atlas '" .. rig.asset_pack error("puppet.load_textures: atlas '" .. rig.asset_pack
.. "' has no tile '" .. b.texture .. "'") .. "' has no tile '" .. b_src.texture .. "'")
end end
b.atlas_uv = tile.uv local target = rig.bones_by_id[b_src.id]
target.atlas_uv = tile.uv
-- sprite_reach for locomotion: tile height minus anchor.y -- sprite_reach for locomotion: tile height minus anchor.y
b.texture_height = tile.uv.h target.texture_height = tile.uv.h
if b.anchor == nil then if target.anchor == nil then
b.anchor = { tile.uv.w / 2, tile.uv.h / 2 } target.anchor = { tile.uv.w / 2, tile.uv.h / 2 }
end end
end end
end end