Hello there,
On the application that I currently working, I found myself refactoring the code that loads assets (mainly .obj files) from SceneLoader to AssetsManager, because of an annoying bug that happens with React 18 and StrictMode
(only development environment).
Even though AssetsManager
uses SceneLoader
internally, the bug doesn’t happen when using AssetsManager.load()
. However, using AssetsManager
, I cannot keep track of the download progress of the assets, because the following call does not use the onProgress
callback (MeshAssetTask.run()):
/**
* Execute the current task
* @param scene defines the scene where you want your assets to be loaded
* @param onSuccess is a callback called when the task is successfully executed
* @param onError is a callback called if an error occurs
*/
public override runTask(scene: Scene, onSuccess: () => void, onError: (message?: string, exception?: any) => void) {
SceneLoader.ImportMesh(
this.meshesNames,
this.rootUrl,
this.sceneFilename,
scene,
(meshes: AbstractMesh[], particleSystems: IParticleSystem[], skeletons: Skeleton[], animationGroups: AnimationGroup[], transformNodes: TransformNode[]) => {
this.loadedMeshes = meshes;
this.loadedTransformNodes = transformNodes;
this.loadedParticleSystems = particleSystems;
this.loadedSkeletons = skeletons;
this.loadedAnimationGroups = animationGroups;
onSuccess();
},
null, // <-- here is where it should be passed
(scene, message, exception) => {
onError(message, exception);
},
this.extension
);
}
Later on, I found that the “bug” that was happening to me is that the loadingUI
must be explicit hide after the mesh loading is finished (this is not necessary outside the StrictMode
). Thus, moving to AssetsManager
isn’t necessary anymore.
However, it would be nice to rely on a more robust implementation (AssetsManager
) and also use the underlying features that SceneLoader
provides.