Some optimization
This commit is contained in:
@@ -63,6 +63,8 @@ const FACES: { rect: (w: number, h: number, d: number) => number[]; corners: num
|
||||
shade: 0.8,
|
||||
},
|
||||
];
|
||||
// a face's corners as two triangles
|
||||
const QUAD_CORNERS = [0, 1, 2, 0, 2, 3];
|
||||
|
||||
// how a player is posed this frame, for drawing them and what they wear
|
||||
export function player_pose(player: Player, partial_tick: number): PlayerPose {
|
||||
@@ -116,20 +118,24 @@ export function push_box(
|
||||
emit: VertexSink = push_vertex,
|
||||
) {
|
||||
const [w, h, d] = size;
|
||||
// the box's 8 corners, transformed once each rather than once per vertex. indexed by x * 4 + y * 2 + z, 0 for
|
||||
// the low end and 1 for the high one
|
||||
const points: Vec3[] = [];
|
||||
for (let i = 0; i < 8; i++) {
|
||||
points.push(transform(i & 4 ? high[0] : low[0], i & 2 ? high[1] : low[1], i & 1 ? high[2] : low[2]));
|
||||
}
|
||||
for (const face of FACES) {
|
||||
const [rx, ry, rw, rh] = face.rect(w, h, d);
|
||||
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);
|
||||
const r = tint[0] * face.shade;
|
||||
const g = tint[1] * face.shade;
|
||||
const b = tint[2] * face.shade;
|
||||
|
||||
for (const i of [0, 1, 2, 0, 2, 3]) {
|
||||
const [cx, cy, cz, cu, cv] = face.corners[i];
|
||||
const [px, py, pz] = transform(
|
||||
cx ? high[0] : low[0],
|
||||
cy ? high[1] : low[1],
|
||||
cz ? high[2] : low[2],
|
||||
);
|
||||
emit(px, py, pz, cu ? u1 : u0, cv ? v1 : v0, r, g, b, 1);
|
||||
for (const i of QUAD_CORNERS) {
|
||||
const corner = face.corners[i];
|
||||
const point = points[corner[0] * 4 + corner[1] * 2 + corner[2]];
|
||||
emit(point[0], point[1], point[2], corner[3] ? u1 : u0, corner[4] ? v1 : v0, r, g, b, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user