Help with importing models from an embeded gltf file's text

Help me! well i am creating a babylon.js extension for turbowarp using javascript. i have done most of the things and now it is time to do gltf model importation. i want to make a function that can take in an embeded gltf file (an embeded gltf file that contains all the images and everything in a single file) as input and then add that gltf meshes using that text. and yeah i am a starter in javascript so i don’t have much experience.

Did you try Babylon GLTF loader?

For example, Babylon.js Playground

yes but that works for only model files and model url but i want to load through the embeded gltf file’s text instead. i mean like imagine opening the model file as a text document then copying all the data and then pasting it to babylon’s gltf loader

Do you mean like loading from a string? - Babylon.js Playground

ah, yes! exactly. thanks a lot! i overcomplicated things and started thinking that i have to use base64 and stuff.

wait, i tried it but it doesn’t work for my case :frowning: what have i done wrong? here is my code:

async gltfFile(input) {
let gltf = input.file;

            await BABYLON.AppendSceneAsync(`data:${gltf}`, scene);
            scene.createDefaultCameraOrLight(true, true, true);

            gltf = null;
        }

it gives a big chunk of error saying that it cannot load it

Embedded GLTF is actually a JSON. Please add checks that you load or parse it as it should be :slight_smile:
Probably you may need JSON.stringify()…

For example - Babylon.js Playground

1 Like

well that stingify function doesn’t work. after i made it, there is no errors at all but there is no mesh imported

well i just found out that using blobs do the job