Allow for textures that aren't 16x16

This commit is contained in:
2026-09-28 16:20:37 -03:00
parent 52ef4e5ca6
commit fe149bb9ad
18 changed files with 268 additions and 136 deletions
+8 -8
View File
@@ -1,4 +1,4 @@
import { TEXTURE_SIZE } from "$/common/constants.ts";
import type { SpriteRegion } from "$/common/constants.ts";
import { BlockRegistry, EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts";
import { AssetManager } from "$/client/assets.ts";
import { get_sprite_region } from "$/client/sprites.ts";
@@ -91,8 +91,8 @@ export function push_item(atlas: Texture, item: ItemStack, transform: ItemTransf
const texture_id = item_texture(item);
const region = get_sprite_region(texture_id);
const u = (pixels: number) => (region.x * TEXTURE_SIZE + pixels) / atlas.width;
const v = (pixels: number) => (region.y * TEXTURE_SIZE + pixels) / atlas.height;
const u = (pixels: number) => (region.x + pixels) / atlas.width;
const v = (pixels: number) => (region.y + pixels) / atlas.height;
for (const quad of item_model(texture_id)) {
for (const i of [0, 1, 2, 0, 2, 3]) {
const [px, py, pz] = transform(...quad.corners[i]);
@@ -102,11 +102,11 @@ export function push_item(atlas: Texture, item: ItemStack, transform: ItemTransf
}
}
function push_textured_quad(atlas: Texture, region: { x: number; y: number }, corners: number[][], color: number[]) {
const u0 = (region.x * TEXTURE_SIZE + UV_PAD) / atlas.width;
const v0 = (region.y * TEXTURE_SIZE + UV_PAD) / atlas.height;
const u1 = ((region.x + 1) * TEXTURE_SIZE - UV_PAD) / atlas.width;
const v1 = ((region.y + 1) * TEXTURE_SIZE - UV_PAD) / 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;
for (const i of [0, 1, 2, 0, 2, 3]) {
const [px, py, pz] = corners[i];