BabylonNative GLTF Loader texture

Hi there !

BabylonNative is an amazing work !!

Im trying to load a GLTF with external URI assets:
https://myservers/a2586430-c3d8-49c6-a858-1c631e3de3ef.gltf. → DamagedHelmet.gltf
https://myservers/59c91bc9-9833-497c-afaf-72c0cff60c2c.bin. → DamagedHelmet.bin
https://myservers/7c3f582f-7133-4572-990d-6222b2a98ae1.jpg. → Default_albedo.jpg
https://myservers/c75b60f8-6a90-4b65-a178-899633943b98.jpg. → Default_emissive.jpg
etc …

I overridden the _loadUriAsync (in an extend class from IGLTFLoaderExtension), it works fine in Babylon,js, but embedded in a BabyonNative app, it failed on the texture loading (loadTexture not seems to be mapped ? ).
It gives me the following stacktrace:

I use the 5.0.0-alpha.17 version.
Did I miss an override function/class or something ?
Or do you know a way to investigate this issue ?

@bghgary / @Cedric

Thanks is advance,
Best regards,
Eric

I guess the parameters for loadTexture are not the right types.
Can you repro with a playground? I can test and debug with BabylonNative then. Hard to do without a repro PG :slight_smile:

1 Like

Hi Cedric,

I am working on it, I will show you a playground as soon as I find a way to use IGLTFLoaderExtension in JS.

In a meantime, I can show you what I want in TS: https://playground.babylonjs.com/#IQU2YY#18

Regards,
Eric

2 Likes

Hi @Cedric ,

I generated a test.js file (from typescript code) that you could test in BabylonNative project.
I am not sure it is whttps://github.com/EricBeetsOfficial-Opuscope/WebXR/blob/master/test.jshat you need/want to test and debug…
Let me know if you need more information.

Thanks in advance,
Eric

I can repro! Let me see what I can find :slight_smile:

Great ! Let me know if I can help …

Hi @Cedric ,

Inpsired by the function glTFLoader.loadUriAsync and based on a custom BABYLON.IGLTFLoaderExtension plugin, I can make it work without the loadTexture call issue (using scene._loadFile instead of Tools.LoadFileAsync).
I don’t know exactly if it’s the correct fix…but it seems to works as expected.
What do you think of this solution ?

Regards,
Eric

I’m glad to hear it’s working for you. Loadtexture was failing because of the image data parameter type was not what was expected. I think you fix that so it’s working now.

1 Like

@Eric_Beets Are you aware of the glTFFileLoader.preprocessUrlAsync property? I’m not sure exactly what your scenario is, but maybe this will be easy to deal with than creating a glTF loader extension overriding an undocumented function. :slight_smile:

Hi @bghgary

I am not sure to understand the benefit of using public preprocessUrlAsync = (url: string) => Promise.resolve(url);. :confused:
It seems, as @Cedric said, the data parameter type was wrong: use new Uint8Array(buff as ArrayBuffer) instead of new DataView(buff) in Tools.LoadFileAsync fixes the loadTexture native call. :slight_smile:

Thank you both for your help ! :tada:
Eric

1 Like

It’s likely I don’t understand what you are doing exactly, but I think you are trying to redirect urls from one to another. This function allow you to control that. If you do something like the following, it should allow you to update the url without using a loader extension.

    loader.preprocessUrlAsync = function (url) {
        if (url === "from.bin") {
            url = "to.bin";
        }
        // ...
        return Promise.resolve(url);
    }

Maybe this is not what you want to. If so, then ignore me. :slight_smile:

2 Likes