Some optimization

This commit is contained in:
2026-10-25 21:31:32 -03:00
parent c955d8d143
commit f46058f9b5
5 changed files with 92 additions and 25 deletions
+11 -7
View File
@@ -367,17 +367,21 @@ function push_sprite(
) {
const region = get_sprite_region(texture_id);
for (const quad of quads) {
for (const i of [0, 1, 2, 0, 2, 3]) {
const [cx, cy, cz] = quad.corners[i];
const [px, py, pz] = transform(cx, cy, cz + Math.sign(cz) * gap);
const [pu, pv] = quad.uvs[i];
const u = (region.x + pu) / atlas.width;
const v = (region.y + pv) / atlas.height;
vertex(px, py, pz, u, v, quad.shade * r, quad.shade * g, quad.shade * b, 1);
// each corner transformed once, though corners 0 and 2 are in both triangles
const points = quad.corners.map(([cx, cy, cz]) => transform(cx, cy, cz + Math.sign(cz) * gap));
for (const i of QUAD_CORNERS) {
const point = points[i];
const uv = quad.uvs[i];
const u = (region.x + uv[0]) / atlas.width;
const v = (region.y + uv[1]) / atlas.height;
vertex(point[0], point[1], point[2], u, v, quad.shade * r, quad.shade * g, quad.shade * b, 1);
}
}
}
// a quad's corners as two triangles
const QUAD_CORNERS = [0, 1, 2, 0, 2, 3];
// the layers drawn over a flat item's texture (see ItemLayer), each in its tint's color, without the ones whose tint
// has no color for this stack
export function item_layers(item: ItemStack): { texture: string; color: Vec3 }[] {