How to batch load gltfs

I have lot of gltfs right now , I want load them together. I suppose to code like this

 let folder = "/assets/gltf/";
    let model = [
        "base.gltf",
        "cannon.gltf",
        "machineGun.gltf"
    ]
    for (let i = 0; i < model.length; i++) {
        loader.load(folder + model[i], loadOk);
    }
    function loadOk(obj) {
        obj.scene.name="haha";//problem here
    }

I want to know which obj is loaded ok and give it name accordingly. How can I do this

excuse my stupid
I just solve it myself

 let folder = "/assets/gltf/";
    let model = [
        "base.gltf",
        "cannon.gltf",
        "machineGun.gltf"
    ]
    for (let i = 0; i < model.length; i++) {
        loader.load(folder + model[i], loadOk);
       function loadOk(obj) {
            obj.scene.name=model[i];//solve here
        }
    }

For further optimization, you should keep all your assets in a single GLTF file. That way you make less network requests. Then you could traverse through the GLTF scene, and pick out the base, cannon and machineGun objects.

1 Like

good, I shall change to this mode. thank you . That may be cause a little chaos in my model file