Skip to content

[GLTFExporter] I found invalid part of code - probably not used #30739

@Bajdzis

Description

@Bajdzis

Description

Hey the code that is in the else block has no right to work. (readAsDataURL is not return result)

https://github.com/mrdoob/three.js/blob/r174/examples/jsm/exporters/GLTFExporter.js#L1384-L1403

I'm so wondering if it's worth fix it or maybe remove the whole else block?

https://caniuse.com/?search=toDataURL

toDataURL has a lot of support so probably no one has had problems but it's weird looking at incorrect code. 😅

Solution

just remove else block

Alternatives

Fix it :

                if (canvas.toDataURL !== undefined) {
                    imageDef.uri = canvas.toDataURL(mimeType);
                } else {
                    pending.push(
                        getToBlobPromise(canvas, mimeType)
                            .then((blob) => {
                                const fileReader = new FileReader();

                                fileReader.readAsDataURL(blob);

                                return new Promise((resolve) => {
                                    fileReader.addEventListener('load', function () {
                                        resolve(fileReader.result);
                                    });
                                });
                            })
                            .then((dataURL) => {
                                imageDef.uri = dataURL;
                            }),
                    );
                }

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions