Skip to content

Commit

Permalink
regular pause to make UI more responsive
Browse files Browse the repository at this point in the history
  • Loading branch information
ghackenberg committed Jul 11, 2024
1 parent 6489cbd commit 2703e0e
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions packages/frontend/src/scripts/loaders/ldraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ function countParts(context: Model, model: Model) {
return count
}

async function parseModel(path: string, group: THREE.Group, context: Model, model: Model, loaded: number, total: number, update = empty) {
async function pause(milliseconds: number) {
return new Promise<void>(resolve => {
setTimeout(resolve, milliseconds)
})
}

async function parseModel(path: string, group: THREE.Group, context: Model, model: Model, loaded: number, total: number, update = empty, time = Date.now()) {

update(undefined, loaded, total)

Expand Down Expand Up @@ -161,11 +167,21 @@ async function parseModel(path: string, group: THREE.Group, context: Model, mode
group.add(child)

// Continue loading submodel
loaded = await parseModel(path, child, context, submodel, loaded, total, update)
const result = await parseModel(path, child, context, submodel, loaded, total, update, time)

loaded = result.loaded

time = result.time
}

if (Date.now() - time > 1000 / 60) {
await pause(0)

time = Date.now()
}
}

return loaded
return { loaded, time }
}

function parseFull(data: string) {
Expand Down

0 comments on commit 2703e0e

Please sign in to comment.