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

getTypedArrayForImageData failed to return data #2894

Open
barvirm opened this issue Feb 26, 2024 · 0 comments
Open

getTypedArrayForImageData failed to return data #2894

barvirm opened this issue Feb 26, 2024 · 0 comments

Comments

@barvirm
Copy link

barvirm commented Feb 26, 2024

Description

Hello, I'm trying to read image data into buffer via getTypedArrayForImageData, but result is empty array.

Model:

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);
        }
    }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant