Player rendering in the inventory
This commit is contained in:
@@ -82,6 +82,9 @@ export function render_player(skin: Texture, pose: PlayerPose, tint?: Vec3) {
|
||||
}
|
||||
}
|
||||
|
||||
// what a box's vertices go to: the batch, or something collecting them, like the player in the inventory
|
||||
export type VertexSink = typeof push_vertex;
|
||||
|
||||
// one layer of a part's box, its texture at uv and grown by inflate. transform takes points around the part's pivot
|
||||
export function push_cube(
|
||||
skin: Texture,
|
||||
@@ -90,10 +93,11 @@ export function push_cube(
|
||||
inflate: number,
|
||||
transform: (x: number, y: number, z: number) => Vec3,
|
||||
tint?: Vec3,
|
||||
emit: VertexSink = push_vertex,
|
||||
) {
|
||||
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, tint);
|
||||
push_box(part.size, low, high, uv, (u, v) => [u / skin.width, v / skin.height], transform, tint, emit);
|
||||
}
|
||||
|
||||
// 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
|
||||
@@ -106,6 +110,7 @@ export function push_box(
|
||||
to_uv: (u: number, v: number) => [number, number],
|
||||
transform: (x: number, y: number, z: number) => Vec3,
|
||||
tint: Vec3 = [1, 1, 1],
|
||||
emit: VertexSink = push_vertex,
|
||||
) {
|
||||
const [w, h, d] = size;
|
||||
for (const face of FACES) {
|
||||
@@ -121,7 +126,7 @@ export function push_box(
|
||||
cy ? high[1] : low[1],
|
||||
cz ? high[2] : low[2],
|
||||
);
|
||||
push_vertex(px, py, pz, cu ? u1 : u0, cv ? v1 : v0, r, g, b, 1);
|
||||
emit(px, py, pz, cu ? u1 : u0, cv ? v1 : v0, r, g, b, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user