Optimize renderer
This commit is contained in:
+10
-5
@@ -180,6 +180,9 @@ export interface BakedQuad {
|
||||
cull: number;
|
||||
// on the block's edge facing straight out, so it's lit like a full block's face
|
||||
flush: boolean;
|
||||
// flat on a plane facing straight along face's axis, so it can only be seen from that side of the plane.
|
||||
// rotated quads, like the cross model's, aren't
|
||||
aligned: boolean;
|
||||
shade: boolean;
|
||||
}
|
||||
|
||||
@@ -245,7 +248,7 @@ export function bake_model(model: ModelJson, textures: BlockTextures | undefined
|
||||
|
||||
let cull = face_json.cullface ? FACE_INDEX[face_json.cullface] : -1;
|
||||
for (let t = 0; t < turns && cull >= 0; t++) cull = TURN_Y[cull];
|
||||
const { face: facing, flush } = classify(positions);
|
||||
const { face: facing, flush, aligned } = classify(positions);
|
||||
quads.push({
|
||||
positions,
|
||||
uvs,
|
||||
@@ -253,6 +256,7 @@ export function bake_model(model: ModelJson, textures: BlockTextures | undefined
|
||||
face: facing,
|
||||
cull,
|
||||
flush,
|
||||
aligned,
|
||||
shade: element.shade ?? true,
|
||||
});
|
||||
}
|
||||
@@ -285,8 +289,8 @@ function element_rotation(element: ModelElementJson): (point: number[]) => numbe
|
||||
};
|
||||
}
|
||||
|
||||
// which way a quad faces most, and whether it's flat against the block's edge
|
||||
function classify(p: number[]): { face: number; flush: boolean } {
|
||||
// which way a quad faces most, whether it's flat against the block's edge, and whether it faces straight along an axis
|
||||
function classify(p: number[]): { face: number; flush: boolean; aligned: boolean } {
|
||||
const e1 = [p[3] - p[0], p[4] - p[1], p[5] - p[2]];
|
||||
const e2 = [p[9] - p[0], p[10] - p[1], p[11] - p[2]];
|
||||
const normal = [e1[1] * e2[2] - e1[2] * e2[1], e1[2] * e2[0] - e1[0] * e2[2], e1[0] * e2[1] - e1[1] * e2[0]];
|
||||
@@ -303,6 +307,7 @@ function classify(p: number[]): { face: number; flush: boolean } {
|
||||
|
||||
const axis = FACE_NORMALS[face].findIndex((v) => v !== 0);
|
||||
const edge = FACE_NORMALS[face][axis] > 0 ? 1 : 0;
|
||||
const flush = [0, 1, 2, 3].every((k) => Math.abs(p[k * 3 + axis] - edge) < EPSILON);
|
||||
return { face, flush };
|
||||
const aligned = [1, 2, 3].every((k) => Math.abs(p[k * 3 + axis] - p[axis]) < EPSILON);
|
||||
const flush = aligned && Math.abs(p[axis] - edge) < EPSILON;
|
||||
return { face, flush, aligned };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user