Skip to content

Commit

Permalink
fix: implement readAsDataURL
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Aug 25, 2023
1 parent 6fb762b commit a4d7f3d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ import {
WebGLRenderer,
} from 'three'

async function readAsDataURL(blob) {
const url = URL.createObjectURL(blob)
const buffer = await fetch(url).then((res) => res.arrayBuffer())
URL.revokeObjectURL(url)
const data = btoa(String.fromCharCode(...new Uint8Array(buffer)))
return `data:${blob.type || ''};base64,${data}`
}

let _renderer
let fullscreenQuadGeometry
let fullscreenQuadMaterial
Expand Down Expand Up @@ -561,7 +569,9 @@ class GLTFWriter {
})
} else {
if (json.buffers && json.buffers.length > 0) {
json.buffers[0].uri = URL.createObjectURL(blob)
readAsDataURL(blob).then((uri) => {
json.buffers[0].uri = uri
})
}

onDone(json)
Expand Down Expand Up @@ -1098,9 +1108,11 @@ class GLTFWriter {
imageDef.uri = canvas.toDataURL(mimeType)
} else {
pending.push(
getToBlobPromise(canvas, mimeType).then((blob) => {
imageDef.uri = URL.createObjectURL(blob)
}),
getToBlobPromise(canvas, mimeType)
.then(readAsDataURL)
.then((uri) => {
imageDef.uri = uri
}),
)
}
}
Expand Down

0 comments on commit a4d7f3d

Please sign in to comment.