feat: sprite-mode render with z_order sort and color-rect fallback
Walks bones in z-sorted order (rig.bones_z_sorted, lowest first = back). For each bone: - If texture_handle present: draw via engine.render.draw_sprite_transform using bone.scale and bone.anchor (negative scale mirrors the sprite, anchor is the in-texture pivot). - Else: fall back to colored rotated 16x4 rect via draw_rect_rotated (Phase 1 behavior preserved). bone_state[bid].world (cached by M.update's depth-first pipeline) is the source of (x, y, angle).
This commit is contained in:
37
init.lua
37
init.lua
@@ -542,27 +542,32 @@ update_bone_recursive = function(p, b, dt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- ====================================================================
|
-- ====================================================================
|
||||||
-- Rendering (engine.render.* -- only callable in render-phase)
|
-- Rendering (engine.render.*; only callable in render-phase).
|
||||||
|
-- Walks bones in z-sorted order (back-to-front). For each bone:
|
||||||
|
-- - If bone has texture_handle: draw via engine.render.draw_sprite_transform
|
||||||
|
-- - Else: fall back to engine.render.draw_rect_rotated with bone.color
|
||||||
-- ====================================================================
|
-- ====================================================================
|
||||||
function M.render(handle)
|
function M.render(handle)
|
||||||
local p = all_puppets[handle]
|
local p = all_puppets[handle]
|
||||||
if p == nil then return end
|
if p == nil then return end
|
||||||
|
|
||||||
-- Draw each bone as a rotated rect centered at the bone's world-pos.
|
for _, b in ipairs(p.rig.bones_z_sorted) do
|
||||||
-- v0.1 simplification: bone's world-pos = puppet origin + bone.rest offset.
|
local ws = p.bone_state[b.id].world
|
||||||
-- Bone "length" is approximated by a small constant; later versions will
|
if b.texture_handle then
|
||||||
-- derive from rig data.
|
local sx, sy = b.scale[1], b.scale[2]
|
||||||
local BONE_LENGTH = 16
|
local ax, ay = b.anchor and b.anchor[1] or 0,
|
||||||
local BONE_THICKNESS = 4
|
b.anchor and b.anchor[2] or 0
|
||||||
|
engine.render.draw_sprite_transform(
|
||||||
for _, b_src in ipairs(p.rig.bones) do
|
b.texture_handle,
|
||||||
local b = p.rig.bones_by_id[b_src.id]
|
ws.x, ws.y, ws.angle,
|
||||||
local x = p.x + b.rest.x
|
sx, sy, ax, ay,
|
||||||
local y = p.y + b.rest.y
|
0xFFFFFFFF
|
||||||
local angle = p.bone_state[b.id].angle
|
)
|
||||||
local c = b.color
|
else
|
||||||
local color = engine.render.rgb(c[1], c[2], c[3])
|
-- Phase-1 fallback: colored rotated rect (16x4 px).
|
||||||
engine.render.draw_rect_rotated(x, y, BONE_LENGTH, BONE_THICKNESS, angle, color)
|
local color = engine.render.rgb(b.color[1], b.color[2], b.color[3])
|
||||||
|
engine.render.draw_rect_rotated(ws.x, ws.y, 16, 4, ws.angle, color)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user