feat: add load_textures + extend load_rig with asset_aliases

puppet.load_textures(rig, asset_aliases):
- Resolves bone.texture atlas-ids to texture-handles via the asset-
  lib indirection. Reads asset_aliases[rig.asset_pack] to get the
  asset-lib id, loads the lib's atlas.json, looks up the atlas-entry
  by id, then calls engine.asset.load_texture on the resolved file
  path.
- Resolves bone.anchor from the atlas entry unless the bone has an
  explicit anchor override.
- Raises clear errors when alias/atlas-pack/atlas-id is missing.

puppet.load_rig(path, asset_aliases?) now optionally calls
load_textures after build_rig if asset_aliases is supplied.

README updated with new API entries (load_rig signature, load_textures,
bone_world_transform, write_bone_test_only) and CHANGELOG v0.2.0 entry.
This commit is contained in:
Axel Meyer
2026-05-18 03:09:26 +02:00
parent 7061ea079e
commit cff7986cde
2 changed files with 88 additions and 6 deletions

View File

@@ -576,9 +576,55 @@ end
-- ====================================================================
-- engine.asset.load_json(path) reads the file and parses JSON in one
-- call, returning a Lua table directly. No separate decode step needed.
function M.load_rig(path)
-- ====================================================================
-- Resolve atlas-ids to texture-handles via asset-lib indirection.
-- asset_aliases: { [alias-key] = asset-lib-id } from module's manifest.
-- ====================================================================
function M.load_textures(rig, asset_aliases)
if rig.asset_pack == nil then return end -- no-texture rig, nothing to do
local lib_id = asset_aliases[rig.asset_pack]
if lib_id == nil then
error("puppet.load_textures: asset-pack alias '" .. rig.asset_pack
.. "' not found in module asset_aliases")
end
local atlas_path = lib_id .. "/assets/atlas.json"
local atlas = engine.asset.load_json(atlas_path)
local pack = atlas[rig.asset_pack]
if pack == nil then
error("puppet.load_textures: asset_pack '" .. rig.asset_pack
.. "' not declared in atlas of '" .. lib_id .. "'")
end
for _, b in pairs(rig.bones_by_id) do
if b.texture then
local entry = pack[b.texture]
if entry == nil then
error("puppet.load_textures: atlas-id '" .. b.texture
.. "' not in asset_pack '" .. rig.asset_pack
.. "' of '" .. lib_id .. "'")
end
local tex_path = lib_id .. "/assets/" .. entry.file
b.texture_handle = engine.asset.load_texture(tex_path)
-- Resolve anchor: bone.anchor override beats atlas-default.
if b.anchor == nil then
b.anchor = entry.anchor or { 0, 0 }
end
end
end
end
-- ====================================================================
-- Load a rig from a JSON file and optionally resolve textures.
-- asset_aliases is the module-level alias map (from manifest.module);
-- pass engine.module.asset_aliases() in module init.lua.
-- ====================================================================
function M.load_rig(path, asset_aliases)
local rig_table = engine.asset.load_json(path)
return M.build_rig(rig_table)
local rig = M.build_rig(rig_table)
if asset_aliases then
M.load_textures(rig, asset_aliases)
end
return rig
end
function M.load_animation(path, rig)