Checking whether or not fbx is loaded before accessing it

I am trying to load an object and make some clones of it on start, however I cant seem to find a way to identify if a mesh has finished loading. Is there such a parameter? Or do I need to implement my own system for this? I don’t want to be constrained to the on complete callback, I should specify that. Otherwise it was easy

 loadFBX = (name: string, material: Material, raycastable: boolean, receiveshadow: boolean) => {
        this.loader.load('../../assets/meshes/' + name + '.fbx', (object: THREE.Group) => {
            object.traverse((child: THREE.Mesh) => {
                if (child.isMesh) {
                    child.material = material;
                    child.castShadow = true;

                    if (receiveshadow) {
                        child.receiveShadow = true;
                    }

                    material.isVisible = true;
                }
            });

            if (raycastable) {
                this.rayCastable.push(object);
            }
            object.name = name;
            this.scene.add(object);
        });
    }

What is wrong with the callback?

You could have a loaded boolean that you set to false before loading, and set to true in the callback. Then you could check that flag elsewhere. But do you really have good reason to not just use the callback as intended?

1 Like

Yes, I am doing this with runtime editing in mind. Objects don’t necessarily need to be interacted with when they are instanciated. but I need to check if they are available before requesting them from the scene.

1 Like