From ba7d7b6d6dfcb4c6598d9b06036d9bcdd4c7b052 Mon Sep 17 00:00:00 2001 From: Lucas Dower Date: Thu, 1 Jun 2023 20:47:59 +0100 Subject: [PATCH] Fixed progress bars not working, added progress tracking for importing, closes #121 --- src/importers/obj_importer.ts | 8 ++++++-- src/ui/layout.ts | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/importers/obj_importer.ts b/src/importers/obj_importer.ts index d27d50e..13b684a 100644 --- a/src/importers/obj_importer.ts +++ b/src/importers/obj_importer.ts @@ -1,3 +1,4 @@ +import { ProgressManager } from '../progress'; import { LOC } from '../localiser'; import { checkNaN } from '../math'; import { Mesh, Tri } from '../mesh'; @@ -183,10 +184,13 @@ export class ObjImporter extends IImporter { fileSource.replace('\r', ''); // Convert Windows carriage return const fileLines = fileSource.split('\n'); + const numLines = fileLines.length; - for (const line of fileLines) { + const progressHandle = ProgressManager.Get.start('VoxelMeshBuffer'); + fileLines.forEach((line, index) => { this.parseOBJLine(line); - } + ProgressManager.Get.progress(progressHandle, index / numLines); + }) return new Mesh(this._vertices, this._normals, this._uvs, this._tris, new Map()); }); diff --git a/src/ui/layout.ts b/src/ui/layout.ts index 1e8bee1..6d053a4 100644 --- a/src/ui/layout.ts +++ b/src/ui/layout.ts @@ -73,6 +73,13 @@ export class UI { EventManager.Get.add(EAppEvent.onLanguageChanged, () => { this._handleLanguageChange(); }); + + EventManager.Get.add(EAppEvent.onTaskProgress, (e: any) => { + const lastAction = this._appContext?.getLastAction(); + if (lastAction !== undefined) { + this.getActionButton(lastAction)?.setProgress(e[1]); + } + }); } public uiOrder = ['settings', 'import', 'materials', 'voxelise', 'assign', 'export'];