Sorry for the many questions but I was not expecting this to happen.
I switched from using load async to meshtask to load models so previously I was using mesh container and in this container I get the .meshes and remove and dispose them. But now I am trying to do the same with my object in the scene and it is not working the same anymore? Why would this be?
Now some model parts might still be visible, I am trying to reuse the same object but just parent different meshes to it and then remove/dispose afterwards, then load new meshes.
var removeMeshes = function(meshParentObject) {
console.log('removeMeshes');
if(meshParentObject) {
if(meshParentObject._children) {
for(i = 0; i < meshParentObject._children.length; i++) {
let mesh = meshParentObject._children[i];
scene.removeMesh(mesh);
mesh.dispose();
mesh.parent = null;
mesh = null;
}
}
}
}
This bottom part is working fine but just to show you where I call this function before loading…
removeMeshes(RECOGNITION_flyer);
var randomMeshTask = RECOGNITION_assetsManager.addMeshTask("loadRandomModel", "", randomModelPath+'/', randomVehicleData.model_file);
// randomMeshTask.onProgress = function (task) { }
randomMeshTask.onSuccess = function (task) {
onRandomModelLoaded(task.loadedMeshes);
RECOGNITION_isLoadingModel = false;
}
randomMeshTask.onError = function (task, message, exception) {
console.log('failed to load');
RECOGNITION_isLoadingModel = false;
loadRandomModel(scene);
}