Messy but working chicken
This commit is contained in:
@@ -2,7 +2,7 @@ import { PLAYER_HEIGHT } from "$/common/constants.ts";
|
||||
import type { Player } from "$/client/entity/player.ts";
|
||||
import { push_vertex, type Texture } from "$/client/renderer/mod.ts";
|
||||
|
||||
type Vec3 = [number, number, number];
|
||||
export type Vec3 = [number, number, number];
|
||||
|
||||
// minecraft's player model is 32 skin pixels tall, it's scaled to the player's height
|
||||
const PIXEL = PLAYER_HEIGHT / 32;
|
||||
@@ -181,20 +181,32 @@ export function render_player(player: Player, skin: Texture, partial_tick: numbe
|
||||
function push_cube(
|
||||
skin: Texture,
|
||||
part: ModelPart,
|
||||
[u, v]: [number, number],
|
||||
uv: [number, number],
|
||||
inflate: number,
|
||||
transform: (x: number, y: number, z: number) => Vec3,
|
||||
) {
|
||||
const [w, h, d] = part.size;
|
||||
const low = part.from.map((n) => n - inflate);
|
||||
const high = part.from.map((n, i) => n + part.size[i] + inflate);
|
||||
const low = part.from.map((n) => n - inflate) as Vec3;
|
||||
const high = part.from.map((n, i) => n + part.size[i] + inflate) as Vec3;
|
||||
push_box(part.size, low, high, uv, (u, v) => [u / skin.width, v / skin.height], transform);
|
||||
}
|
||||
|
||||
// a box of a model, from low to high, textured like minecraft's box uv from [u, v] for a box of size (in texture
|
||||
// pixels). to_uv turns texture pixels into the current texture's coordinates, tint multiplies its colors
|
||||
export function push_box(
|
||||
size: Vec3,
|
||||
low: Vec3,
|
||||
high: Vec3,
|
||||
[u, v]: [number, number],
|
||||
to_uv: (u: number, v: number) => [number, number],
|
||||
transform: (x: number, y: number, z: number) => Vec3,
|
||||
tint: Vec3 = [1, 1, 1],
|
||||
) {
|
||||
const [w, h, d] = size;
|
||||
for (const face of FACES) {
|
||||
const [rx, ry, rw, rh] = face.rect(w, h, d);
|
||||
const u0 = (u + rx + UV_INSET) / skin.width;
|
||||
const v0 = (v + ry + UV_INSET) / skin.height;
|
||||
const u1 = (u + rx + rw - UV_INSET) / skin.width;
|
||||
const v1 = (v + ry + rh - UV_INSET) / skin.height;
|
||||
const [u0, v0] = to_uv(u + rx + UV_INSET, v + ry + UV_INSET);
|
||||
const [u1, v1] = to_uv(u + rx + rw - UV_INSET, v + ry + rh - UV_INSET);
|
||||
const [r, g, b] = tint.map((c) => c * face.shade);
|
||||
|
||||
for (const i of [0, 1, 2, 0, 2, 3]) {
|
||||
const [cx, cy, cz, cu, cv] = face.corners[i];
|
||||
@@ -203,7 +215,7 @@ function push_cube(
|
||||
cy ? high[1] : low[1],
|
||||
cz ? high[2] : low[2],
|
||||
);
|
||||
push_vertex(px, py, pz, cu ? u1 : u0, cv ? v1 : v0, face.shade, face.shade, face.shade, 1);
|
||||
push_vertex(px, py, pz, cu ? u1 : u0, cv ? v1 : v0, r, g, b, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user