Atlas png on f3 gui
This commit is contained in:
+14
-1
@@ -111,7 +111,9 @@ export async function build_atlas(textures: Map<string, Uint8Array>, texture_jso
|
||||
}
|
||||
|
||||
// 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;
|
||||
const image_data = ctx.getImageData(0, 0, size, size);
|
||||
const pixels = image_data.data;
|
||||
built_atlas = image_data;
|
||||
opaque.clear();
|
||||
for (const [id, region] of Object.entries(regions)) {
|
||||
const mask = new Uint8Array(region.width * region.height);
|
||||
@@ -149,6 +151,17 @@ export function opaque_pixels(texture_id: string): OpaqueMask | undefined {
|
||||
return opaque.get(texture_id);
|
||||
}
|
||||
|
||||
// the last atlas built, before any animated texture moved on from its first frame
|
||||
let built_atlas: ImageData | undefined;
|
||||
|
||||
// the atlas as a png, undefined before one is built. for the f3 screen's copy button
|
||||
export function atlas_png(): Promise<Blob> | undefined {
|
||||
if (!built_atlas) return undefined;
|
||||
const canvas = new OffscreenCanvas(built_atlas.width, built_atlas.height);
|
||||
canvas.getContext("2d")!.putImageData(built_atlas, 0, 0);
|
||||
return canvas.convertToBlob({ type: "image/png" });
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
@@ -4,6 +4,7 @@ import { format_clock } from "$/common/time.ts";
|
||||
import { profiler, type SectionStats } from "$/client/profiler.ts";
|
||||
import { canvas, gpu_timer, render_debug, render_stats } from "$/client/renderer/mod.ts";
|
||||
import { RENDER_LAYERS } from "$/common/everything_registry.ts";
|
||||
import { atlas_png } from "$/client/atlas.ts";
|
||||
|
||||
// how often the totals that go through every chunk are worked out again, so the overlay doesn't slow the frames it's
|
||||
// measuring
|
||||
@@ -19,6 +20,11 @@ export class DebugOverlay {
|
||||
|
||||
DebugUI.begin("Entities", 10, 10, 300);
|
||||
DebugUI.text(`${format_clock(client.level.time)} (tick ${client.level.time})`);
|
||||
if (DebugUI.button("Copy texture atlas")) {
|
||||
// the promise goes in as is, so the copy still counts as coming from the click while the png encodes
|
||||
const png = atlas_png();
|
||||
if (png) navigator.clipboard?.write([new ClipboardItem({ "image/png": png })]).catch(() => {});
|
||||
}
|
||||
DebugUI.separator();
|
||||
|
||||
for (const entity of client.level.entities.values()) {
|
||||
|
||||
Reference in New Issue
Block a user