diff --git a/init.lua b/init.lua index 2847e6e..4be5fe2 100644 --- a/init.lua +++ b/init.lua @@ -417,4 +417,44 @@ function M.update(dt) 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