Skip to content

CompressedTextures: Add support for serialization/deserialization. #17974

@jespertheend

Description

@jespertheend
Description of the problem

When calling toJson() on an object that contains a CompressedTexture, an error gets thrown:

Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'
    at Object.getDataURL (js.js?v=000:4184)
    at CompressedTexture.toJSON (js.js?v=000:4398)
    at MeshStandardMaterial.toJSON (js.js?v=000:10171)
    at serialize (js.js?v=000:7295)
    at Mesh.toJSON (js.js?v=000:7349)
    at Object3D.toJSON (js.js?v=000:7363)
    at Scene.toJSON (js.js?v=000:7363)
    at Scene.toJSON (js.js?v=000:7507)

My specific use case is that I load textures in the basis universal format, and I call toJSON() to export my entire scene to a file in order to debug it in the threejs editor.

I don't think it's easy to convert a compressed texture to a data url. But I'll try to make a pull request that at leasts gives a warning and exports it without the texture. Instead of throwing an error.

Three.js version

r110

Browser

Chrome

OS

MacOS

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions