{"record":{"id":"385f0380e0e35688","repo":"BabylonJS/Babylon.js","slug":"unsupported-pixel-format","errorCode":null,"errorMessage":"Unsupported pixel format!","messagePattern":"Unsupported pixel format!","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/serializers/src/glTF/2.0/glTFMaterialExporter.ts","lineNumber":163,"sourceCode":"    }\r\n\r\n    const rawTexture = RawTexture.CreateRGBATexture(data, width, height, scene);\r\n\r\n    return rawTexture;\r\n}\r\n\r\nfunction ConvertPixelArrayToFloat32(pixels: ArrayBufferView): Float32Array {\r\n    if (pixels instanceof Uint8Array) {\r\n        const length = pixels.length;\r\n        const buffer = new Float32Array(pixels.length);\r\n        for (let i = 0; i < length; ++i) {\r\n            buffer[i] = pixels[i] / 255;\r\n        }\r\n        return buffer;\r\n    } else if (pixels instanceof Float32Array) {\r\n        return pixels;\r\n    } else {\r\n        throw new Error(\"Unsupported pixel format!\");\r\n    }\r\n}\r\n\r\n/**\r\n * Utility methods for working with glTF material conversion properties.\r\n * @internal\r\n */\r\nexport class GLTFMaterialExporter {\r\n    // Mapping to store textures\r\n    private _textureMap = new Map<number, ITextureInfo>();\r\n\r\n    // Mapping of internal textures to images to avoid exporting duplicate images\r\n    private _internalTextureToImage: { [uniqueId: number]: { [mimeType: string]: Promise<number> } } = {};\r\n\r\n    constructor(private readonly _exporter: GLTFExporter) {}\r\n\r\n    public getTextureInfo(babylonTexture: Nullable<BaseTexture>): Nullable<ITextureInfo> {\r\n        return babylonTexture ? (this._textureMap.get(babylonTexture.uniqueId) ?? null) : null;\r","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/serializers/src/glTF/2.0/glTFMaterialExporter.ts#L145-L181","documentation":"ConvertPixelArrayToFloat32 converts texture pixel data into a Float32Array when converting specular/glossiness materials to metallic/roughness. It supports Uint8Array (normalized by /255) and Float32Array passthrough; any other pixel array type cannot be handled and triggers this throw.","triggerScenarios":"Exporting a scene with a KHR_materials_pbrSpecularGlossiness conversion where a texture's pixel data is neither Uint8Array nor Float32Array — e.g. pixel data read back as Uint16Array, Int32Array, or a half-float typed array from a nonstandard texture source.","commonSituations":"Exporting scenes with HDR/16-bit textures (e.g. RGBA16F readback producing Uint16Array), textures from custom loading pipelines that return exotic typed arrays, or KTX/Basis decoded frames whose arrays are not Uint8/Float32.","solutions":["Convert the pixel data to Uint8Array or Float32Array before export (e.g. new Uint8Array(pixels.buffer) if raw bytes are 8-bit, or normalize into a Float32Array)","Re-encode the texture source as standard 8-bit RGBA so the loader yields Uint8Array data","Avoid converting specular/glossiness materials: assign a PBRMetallicRoughness material before export","Catch the error and export with the original material unconverted if the target glTF allows it"],"exampleFix":"// before\nconst tex = texture.readPixels(); // Uint16Array -> throws\n// after\nconst pixels = texture.readPixels();\nconst floatPixels = new Float32Array(pixels.length);\nfor (let i = 0; i < pixels.length; i++) floatPixels[i] = pixels[i] / 65535; // normalize to Float32Array\n","handlingStrategy":"type-guard","validationCode":"function pixelsAreExportable(pixels: unknown): pixels is Uint8Array | Float32Array {\n    return pixels instanceof Uint8Array || pixels instanceof Float32Array;\n}","typeGuard":"const isUint8OrFloat32 = (p: unknown): p is Uint8Array | Float32Array =>\n    p instanceof Uint8Array || p instanceof Float32Array;","tryCatchPattern":"try {\n    await GLTF2Export.GLTFAsync(scene, \"scene\");\n} catch (e) {\n    if (e instanceof Error && e.message === \"Unsupported pixel format!\") {\n        // re-encode offending textures as 8-bit RGBA and retry\n    } else { throw e; }\n}","preventionTips":["Standardize texture sources on 8-bit RGBA for scenes that will be exported","Avoid 16-bit/half-float readbacks on textures used by specular/glossiness materials targeted for metallic-roughness conversion","Convert PBRSpecularGlossiness materials to PBRMetallicRoughness at authoring time instead of export time","Check readPixels()/texture data types when using HDR or KTX pipelines"],"tags":["gltf","export","texture","pixel-format","material-conversion"],"backgroundTag":"unsupported-pixel-format","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}