loaders.gl
loaders.gl copied to clipboard
getTypedArrayForImageData failed to return data
Description
Hello, I'm trying to read image data into buffer via getTypedArrayForImageData, but result is empty array.
Model:
- https://github.com/KhronosGroup/glTF-Sample-Assets/blob/main/Models/BoxTextured/glTF-Binary/BoxTextured.glb
Minimal example
import { GLTFLoader, GLTFScenegraph, type GLTFMaterial, type GLTFMesh } from '@loaders.gl/gltf';
import { parse } from '@loaders.gl/core';
export const load = async (bytes: ArrayBuffer): Promise<Model> => {
const data = await parse(bytes, GLTFLoader);
const gltf = new GLTFScenegraph(data);
const defaultScene = gltf.getScene(0);
const stack = defaultScene.nodes ?? [];
while (stack.length) {
const [nodeId] = stack.pop()!;
const node = gltf.getNode(nodeId);
if (typeof node.mesh !== 'undefined') {
const mesh = gltf.getMesh(node.mesh);
for (const primitive of mesh.primitives) {
if (typeof primitive.material !== 'undefined') {
const material = gltf.getMaterial(primitive.material);
if (typeof material?.pbrMetallicRoughness?.baseColorTexture !== 'undefined') {
const image = gltf.getImage(material.pbrMetallicRoughness.baseColorTexture.index);
const data = gltf.getTypedArrayForImageData(image)
// ERROR -> DATA SIZE 0
}
}
}
}
if (typeof node.children !== 'undefined') {
stack.push(...node.children);
}
}
};