Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[glTF] Load buffers and images in parallel #286

Open
dmnsgn opened this issue May 5, 2021 · 1 comment
Open

[glTF] Load buffers and images in parallel #286

dmnsgn opened this issue May 5, 2021 · 1 comment
Assignees
Labels
scope/gltf type/perf A code change that improves performance
Milestone

Comments

@dmnsgn
Copy link
Member

dmnsgn commented May 5, 2021

As convenient as it is, a for-of loop will run sequentially. Need to use:

   await Promise.all(images.map(async (image) => {
    await loadImage(image)
   // ...
  }));

for (let image of json.images) {
// https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#uris
if (isBinary || image.bufferView) {
const bufferView = json.bufferViews[image.bufferView]
bufferView.byteOffset = bufferView.byteOffset || 0
const buffer = json.buffers[bufferView.buffer]
const data = buffer._data.slice(
bufferView.byteOffset,
bufferView.byteOffset + bufferView.byteLength
)
const blob = new Blob([data], { type: image.mimeType })
const uri = URL.createObjectURL(blob)
image._img = await loadImage({ url: uri, crossOrigin: 'anonymous' })
} else if (isBase64(image.uri)) {
image._img = await loadImage({
url: image.uri,
crossOrigin: 'anonymous'
})
} else {
// TODO why are we replacing uri encoded spaces?
image._img = await loadImage({
url: [basePath, image.uri].join('/').replace(/%/g, '%25'),
crossOrigin: 'anonymous'
})
}
}
}

for (let buffer of json.buffers) {
if (isBinary) {
buffer._data = bin
} else {
if (isBase64(buffer.uri)) {
buffer._data = decodeBase64(buffer.uri)
} else {
buffer._data = await loadBinary([basePath, buffer.uri].join('/'))
}
}
}

@dmnsgn dmnsgn self-assigned this May 5, 2021
@dmnsgn dmnsgn added scope/gltf type/perf A code change that improves performance and removed performance labels Jul 5, 2022
@dmnsgn dmnsgn added this to the 4.0.0 milestone Oct 19, 2022
@vorg
Copy link
Member

vorg commented Aug 30, 2023

Revisit when refactoring glt loader. Pushed to v5

@vorg vorg modified the milestones: 4.0.0, 5.0.0 Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope/gltf type/perf A code change that improves performance
Projects
None yet
Development

No branches or pull requests

2 participants