feat(render): per-entity sprite_scale on the Atlas-UV path

draw_entities path-1 reads an optional sprite_scale (number, default
1.0) and applies it as uniform scaleX/scaleY in
draw_sprite_transform around the visual center. Lets templates whose
native sprite resolution (e.g. TC_Basics 300×300 bed) doesn't match
the project tile-scale (~/sporel_tile_scale.md: 64 px = 0.5 m via the
puppet shoulder anchor) render at credible real-world sizes without
re-baking the atlas.

Consumers compute their per-atlas scale from
atlas_meta.pixels_per_meter (atlas-baker v0.4.0+ output) divided into
their project canonical px/m — one line in M.init, no per-entity
constants in the template.

Unset sprite_scale preserves v0.2.0 behavior — spine-prototype,
map-editor, vagrant's pre-TC_Basics items unaffected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
calic
2026-06-21 11:42:17 +02:00
parent 4b93d7efe8
commit ce88d3c216
3 changed files with 32 additions and 7 deletions

View File

@@ -1,8 +1,17 @@
-- =====================================================================
-- lib-core.render v0.2.0 — Tile-Grid + Entity Rendering
-- lib-core.render v0.3.0 — Tile-Grid + Entity Rendering
-- See: meta/docs/superpowers/specs/2026-05-09-p0-lib-render-design.md
-- meta/docs/superpowers/specs/2026-06-09-phase-A-...
--
-- v0.3.0 additions:
-- - draw_entities path (1) reads optional `sprite_scale` (number,
-- default 1.0); applied uniformly as scaleX/scaleY in
-- draw_sprite_transform. Lets templates whose native sprite size
-- doesn't match the project tile-scale (e.g. TC_Basics 600×300
-- bed at 64 px = 0.5 m) scale down without per-entity baker
-- re-runs or render-time hacks. Default 1.0 preserves v0.2.0
-- behaviour for unset consumers.
--
-- v0.2.0 additions:
-- - draw_entities(filter) — tag-based entity-render via composition.
-- Supports two sprite-property paths and a fallback:
@@ -124,9 +133,14 @@ function M.draw_entities(filter)
local uvh = get_num(e, "sprite_uv.h")
if uvx and uvy and uvw and uvh then
local tex = load_atlas(atlas)
-- position is visual-center: origin = uv center
-- v0.3.0: optional sprite_scale; default 1.0 keeps
-- v0.2.0 behaviour for entities that don't set it.
local s = get_num(e, "sprite_scale") or 1.0
-- position is visual-center: origin = uv center.
-- Origin stays in source-uv coords (pre-scale), so
-- draw_sprite_transform applies scale around it.
engine.render.draw_sprite_transform(
tex, px, py, 0, 1, 1, uvw / 2, uvh / 2,
tex, px, py, 0, s, s, uvw / 2, uvh / 2,
0xFFFFFFFF, uvx, uvy, uvw, uvh)
count = count + 1
end