Fix old rendering hack

This commit is contained in:
2026-10-10 19:07:51 -03:00
parent ceb1b1f0f0
commit 48f5b80776
3 changed files with 57 additions and 27 deletions
+8 -11
View File
@@ -26,8 +26,6 @@ import type { Vec3 } from "./player_renderer.ts";
// how big items on the ground are drawn, minecraft's ground transform
const BLOCK_SCALE = 0.25;
const ITEM_SCALE = 0.5;
// keeps texture lookups off the sprite's edge
const UV_PAD = 0.5;
// each face's corners in drawing order (counter clockwise from outside) on a unit cube, with its shade.
// top, bottom, front, back, left, right, like the chunk mesher
@@ -254,22 +252,21 @@ export function push_item(atlas: Texture, item: ItemStack, transform: ItemTransf
}
}
// where a model's uv in pixels (0-16) is in the atlas, kept off the sprite's edge
// where a model's uv in pixels (0-16) is in the atlas. the atlas's border around each sprite (see ATLAS_BORDER) keeps
// lookups that round past its edge on its own pixels
export function sprite_u(atlas: Texture, region: SpriteRegion, pixels: number) {
const t = Math.min(Math.max(pixels / TEXTURE_SIZE * region.width, UV_PAD), region.width - UV_PAD);
return (region.x + t) / atlas.width;
return (region.x + pixels / TEXTURE_SIZE * region.width) / atlas.width;
}
export function sprite_v(atlas: Texture, region: SpriteRegion, pixels: number) {
const t = Math.min(Math.max(pixels / TEXTURE_SIZE * region.height, UV_PAD), region.height - UV_PAD);
return (region.y + t) / atlas.height;
return (region.y + pixels / TEXTURE_SIZE * region.height) / atlas.height;
}
function push_textured_quad(atlas: Texture, region: SpriteRegion, corners: number[][], color: number[]) {
const u0 = (region.x + UV_PAD) / atlas.width;
const v0 = (region.y + UV_PAD) / atlas.height;
const u1 = (region.x + region.width - UV_PAD) / atlas.width;
const v1 = (region.y + region.height - UV_PAD) / atlas.height;
const u0 = region.x / atlas.width;
const v0 = region.y / atlas.height;
const u1 = (region.x + region.width) / atlas.width;
const v1 = (region.y + region.height) / atlas.height;
for (const i of [0, 1, 2, 0, 2, 3]) {
const [px, py, pz] = corners[i];