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

Can Scene.toJSON support image network URL? #30648

Open
Aurora-creeper opened this issue Mar 4, 2025 · 0 comments
Open

Can Scene.toJSON support image network URL? #30648

Aurora-creeper opened this issue Mar 4, 2025 · 0 comments

Comments

@Aurora-creeper
Copy link

Description

If the original image is large enough, currently Scene.toJSON will generate a huge image (starting with "data:").

This will cause a perceptible delay.

The calling chain is as follows: Scene.toJSON -> Texture.toJSON -> Source.serializeImage -> ImageUtils.getDataURL

According to the annotation, ImageUtils.getDataURL will return a URI instead of a URL (even though the name is getDataURL).

On modern platform, images will almost certainly be placed on the canvas, and turn into base64.

Solution

In this case, it still works well with ObjectLoader.parse

class ImageUtils {

    static enableNetworkURL = false; // added

    static getDataURL( image ) {

        if ( /^data:/i.test( image.src ) ) {

            return image.src;

        }

        // add begin
        if ( ImageUtils.enableNetworkURL ) {

            if ( image instanceof HTMLImageElement ) return image.src;

        }
        // add end

        if ( typeof HTMLCanvasElement === 'undefined' ) {

            return image.src;

        }

        // ...
    }
}

Alternatives

I think the natural way should be to pass some flags in the meta to control this behavior, but such a change would be too big.

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants