3d models for items
This commit is contained in:
@@ -49,9 +49,31 @@ export async function build_atlas(textures: Map<string, Uint8Array>) {
|
||||
}
|
||||
}));
|
||||
|
||||
// which pixels of each texture can be seen, for the 3d models of dropped items (see item_model.ts)
|
||||
const pixels = ctx.getImageData(0, 0, size, size).data;
|
||||
opaque.clear();
|
||||
for (const [id, region] of Object.entries(regions)) {
|
||||
const mask = new Uint8Array(TEXTURE_SIZE * TEXTURE_SIZE);
|
||||
for (let py = 0; py < TEXTURE_SIZE; py++) {
|
||||
for (let px = 0; px < TEXTURE_SIZE; px++) {
|
||||
const i = ((region.y * TEXTURE_SIZE + py) * size + region.x * TEXTURE_SIZE + px) * 4;
|
||||
mask[py * TEXTURE_SIZE + px] = pixels[i + 3] > 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
opaque.set(id, mask);
|
||||
}
|
||||
|
||||
return { image: canvas.transferToImageBitmap(), regions };
|
||||
}
|
||||
|
||||
// by texture id, TEXTURE_SIZE * TEXTURE_SIZE of 1 (can be seen) or 0, row by row from the top
|
||||
const opaque = new Map<string, Uint8Array>();
|
||||
|
||||
// which pixels of a texture aren't fully see-through, undefined before the atlas is built or for unknown textures
|
||||
export function opaque_pixels(texture_id: string): Uint8Array | undefined {
|
||||
return opaque.get(texture_id);
|
||||
}
|
||||
|
||||
// the engine's own textures, which come with the client instead of a mod. see build_engine_textures in build.ts
|
||||
export async function engine_textures(): Promise<Map<string, Uint8Array>> {
|
||||
const names: string[] = await (await fetch("/assets/textures/index.json")).json();
|
||||
|
||||
Reference in New Issue
Block a user