Skip to content

Commit eba7bdf

Browse files
Fix large preview screenshots being half missing
1 parent 29f630d commit eba7bdf

4 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/HoloPrint.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ const HOLOGRAM_LAYER_MODES = createNumericEnum(["SINGLE", "ALL_BELOW"]);
5252
* @param {HoloPrintConfig} [config]
5353
* @param {ResourcePackStack} [resourcePackStack]
5454
* @param {HTMLElement} [previewCont]
55+
* @param {Function} [previewLoadedCallback] A function that will be called once the preview has finished loading
5556
* @returns {Promise<File>} Resource pack (`*.mcpack`)
5657
*/
57-
export async function makePack(structureFiles, config = {}, resourcePackStack, previewCont) {
58+
export async function makePack(structureFiles, config = {}, resourcePackStack, previewCont, previewLoadedCallback) {
5859
console.info(`Running HoloPrint ${VERSION}`);
5960
if(!resourcePackStack) {
6061
console.debug("Waiting for resource pack stack initialisation...");
@@ -491,14 +492,15 @@ export async function makePack(structureFiles, config = {}, resourcePackStack, p
491492
console.info(`Finished creating pack in ${(performance.now() - startTime).toFixed(0) / 1000}s!`);
492493

493494
if(previewCont) {
494-
let showPreview = () => {
495-
hologramGeo["minecraft:geometry"].filter(geo => geo["description"]["identifier"].startsWith("geometry.armor_stand.hologram_")).map((geo, structureI) => {
496-
PreviewRenderer.new(previewCont, packName, textureAtlas, structureSizes[structureI], blockPalette, boneTemplatePalette, allStructureIndicesByLayer[structureI], {
495+
let showPreview = async () => {
496+
await Promise.all(structureSizes.map(async (structureSize, structureI) => {
497+
await PreviewRenderer.new(previewCont, packName, textureAtlas, structureSize, blockPalette, boneTemplatePalette, allStructureIndicesByLayer[structureI], {
497498
showSkybox: config.SHOW_PREVIEW_SKYBOX,
498499
showFps: config.SHOW_PREVIEW_WIDGETS,
499500
showOptions: config.SHOW_PREVIEW_WIDGETS
500501
});
501-
});
502+
}));
503+
previewLoadedCallback?.();
502504
};
503505
if(totalBlockCount < config.PREVIEW_BLOCK_LIMIT) {
504506
showPreview();

src/PreviewRenderer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ export default class PreviewRenderer extends AsyncFactory {
187187
});
188188

189189
this.#addLighting();
190-
this.#initBackground();
191190
await this.#initBackground();
192191
this.#loop();
193192
loadingMessage.replaceWith(can);

src/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ img:not(#languageSelectorButton), canvas {
427427
padding: 0;
428428
contain: layout;
429429
text-align: center;
430+
width: min(80vmin, 100%);
430431

431432
& > .previewMessage, & > canvas {
432433
width: min(80vmin, 100%);

tests/testSampleStructures.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,17 @@ test(async page => {
4141
let structureFile = new File([bytes], structureFileName);
4242
let previewCont = document.querySelector("#previewCont");
4343
let startTime = performance.now();
44+
let { promise: previewLoadedPromise, resolve: previewLoadedTrigger } = Promise.withResolvers();
4445
let pack = await HoloPrint.makePack(structureFile, {
4546
SPAWN_ANIMATION_ENABLED: false,
4647
PREVIEW_BLOCK_LIMIT: browserEngine == "chrome"? Infinity : 0, // preview renderer doesn't work on headless Firefox
4748
SHOW_PREVIEW_SKYBOX: false,
4849
SHOW_PREVIEW_WIDGETS: false
49-
}, undefined, previewCont);
50+
}, undefined, previewCont, previewLoadedTrigger);
5051
let elapsedTime = performance.now() - startTime;
52+
if(browserEngine == "chrome") {
53+
await previewLoadedPromise;
54+
}
5155

5256
await fetch("/", {
5357
method: "POST",

0 commit comments

Comments
 (0)