aframe icon indicating copy to clipboard operation
aframe copied to clipboard

model loaded event

Open Lupici opened this issue 6 months ago • 1 comments

Hi all, I have a code like this, to load glb models at runtime (and see them on a marker in AR):

`

<a-scene embedded gesture-detector id="scene" vr-mode-ui="enabled: false" arjs='sourceType: webcam; detectionMode: mono_and_matrix; matrixCodeType: 4x4_BCH_13_5_5;'>

    <a-marker id="barcode" type='barcode' value='1'>

        <a-entity
        id="dino"
        position="0 0 0.5"
        rotation="0 90 0"
        scale="0.25 0.25 0.25"
        animation-mixer="clip: Dinoterio_Walk_DEF"
        gltf-model="models/Acynodon_anim_SWIM_DEF.glb"
        class="clickable"
        gesture-handler
        ></a-entity>

    </a-marker>

    <a-entity camera></a-entity>
    <a-entity shadow="cast: true"></a-entity>

</a-scene>

`

in my script, in the same page I have:

`

function loadModel(id,rot,scale){
    console.log(id);
    console.log(rot);
    console.log(scale);

    $('#dino').attr('gltf-model','models/'+id).attr('scale', scale).attr('rotation', rot);

}

`

When I call the function, the actual model disappear and after some seconds (depending on the size of the model) the new model appears. Is there a way to know the new model is loaded, so I can add something in the window saying "waiting please" to be removed when the model is loaded??

I've tried so many pieces of code for event loaded, but noone of them works.....

Thanks to all!!!!

Lupici avatar Jun 20 '25 09:06 Lupici

When the gltf-model component finishes loading it emits the model-loaded event (see docs). This event should allow you to determine whether loading is still ongoing or not:

this.el.addEventListener('model-loaded', (e) => {
    // Model has finished loading.
    this.isLoading = false;
});

// ...

// Start loading the new model
this.isLoading = true;
this.el.setAttribute('gltf-model', 'model.glb');

Note that if the loading fails a model-error event will be emitted. You might want to listen to that event as well to avoid getting stuck in the loading state when an error does occur.

mrxz avatar Jun 20 '25 10:06 mrxz

@Lupici did that answer your question? If yes you can close. Also for such project issue, you can hang out on discord https://aframe.io/community/#discord

vincentfretin avatar Dec 19 '25 12:12 vincentfretin