feat: add render + load_rig/load_animation convenience wrappers

Render: each bone drawn as a rotated rect of fixed length+thickness
(16x4 px) centered at the bone's world-position with its current
angle. Sprite-based rendering deferred to Phase 2 when tilesets exist.

Load helpers: engine.asset.load_json(path) + build_rig/build_animation.
The engine provides a single-call JSON loader (reads file + parses JSON
-> Lua table) via engine.asset.load_json; there is no separate cjson.decode
API. Confirmed by engine_lua_asset.c and maps lib usage.

v0.1 complete: skeleton + bones + tracks + rest + keyframe + procedural
+ look-at + render + load. Footplant deferred.
This commit is contained in:
Axel Meyer
2026-05-17 19:58:37 +02:00
parent 0b2bd7eab0
commit d7102e5b33

View File

@@ -417,4 +417,44 @@ function M.update(dt)
end end
end end
-- ====================================================================
-- Rendering (engine.render.* -- only callable in render-phase)
-- ====================================================================
function M.render(handle)
local p = all_puppets[handle]
if p == nil then return end
-- Draw each bone as a rotated rect centered at the bone's world-pos.
-- v0.1 simplification: bone's world-pos = puppet origin + bone.rest offset.
-- Bone "length" is approximated by a small constant; later versions will
-- derive from rig data.
local BONE_LENGTH = 16
local BONE_THICKNESS = 4
for _, b_src in ipairs(p.rig.bones) do
local b = p.rig.bones_by_id[b_src.id]
local x = p.x + b.rest.x
local y = p.y + b.rest.y
local angle = p.bone_state[b.id].angle
local c = b.color
local color = engine.render.rgb(c[1], c[2], c[3])
engine.render.draw_rect_rotated(x, y, BONE_LENGTH, BONE_THICKNESS, angle, color)
end
end
-- ====================================================================
-- Asset loading (convenience wrappers around build_rig/build_animation)
-- ====================================================================
-- 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)
local rig_table = engine.asset.load_json(path)
return M.build_rig(rig_table)
end
function M.load_animation(path, rig)
local anim_table = engine.asset.load_json(path)
return M.build_animation(anim_table, rig)
end
return M return M