Hey everyone
I’m trying to load and dispose skeletons&meshes on runtime working with the assetsManager.
I tried a method described by @Dad72 in the old Forum (link). Is it still a valid solution?
- You load your dummy model that contains the animations with ImportMesh, then you create animations skeleton.createAnimationRange (‘walk’, keyStart, KeyEnd). This dummy model can be disposed afterwards.
- You load the other models without animations which contains the same number of bones as the dummy model and you copy the animations there with skeleton.copyAnimationRange (skeleton, ‘walk’, true);
- You play the animations following the user interaction by calling the animation you need by name with skeleton.beginAnimation (‘’ walk ', true, 1.0);
I can’t seem getting it to work. The ‘dummy’ meshes show up in the scene playing their animations.
I get different results in Chrome and Mozilla. While Chrome is showing just one of the meshes. Firefox is showing all of them. Im using babylon 3.3.0
My theory is that I do something wrong with disposing the loaded meshes?
Ideas/hints on that problem are highly appreciated. Thanks in advance!
Here’s how I use it in my code:
load()
{
let fileName = this.name;
if(this.nameMesh != '')
{
fileName = this.nameMesh;
}
// LOADING THE ANIMATIONS
for (let i = 0; i < this.nameAnimations.length; i++) //nameAnimations: list of animationfilenames
{
// building the corresponding pathnames for each animation(file)
let nameTmp = this.name + '_' + this.nameAnimations[i] + '.babylon'
let taskLoad = this.assetsManager.addMeshTask(nameTmp + "Task", "",
ASSETPATH + "/anims/" + this.name + '/', nameTmp);
taskLoad.animation = this.nameAnimations[i];
taskLoad.parentObject = this;
taskLoad.onSuccess = function ()
{
this.parentObject.loadAnimation(this.loadedSkeletons, this.animation);
// We don't need the mesh of the animation file
for (let i = 0; i < this.loadedMeshes.length; i++)
{
this.loadedMeshes[i].dispose();
this.loadedMeshes[i] = null; //
}
// We don't need the skeleton of the animation file
for (let i = 0; i < this.loadedSkeletons.length; i++)
{
this.loadedSkeletons[i].dispose();
this.loadedSkeletons[i] = null;
}
}
}
// LOADING THE MESH
let taskLoad = this.assetsManager.addMeshTask(this.name + "Task", "",
ASSETPATH + "/meshes/", fileName + ".babylon");
taskLoad.parentObject = this;
taskLoad.onSuccess = function (task)
{
this.parentObject.skeletons = this.loadedSkeletons;
this.parentObject.applyMaterial(this.loadedMeshes);
for(let i=0; this.loadedMeshes.length; i++)
{
this.loadedMeshes[i].containedInSceneObject = this.parentObject; // Giving all meshes a reference to their SceneObject for GazeInteractions
this.parentObject.nameMeshes.push(this.loadedMeshes[i].id); // and creating a list of MeshID's for SceneObject to know which Meshes it contains
this.parentObject.containsMeshes.push(this.loadedMeshes[i]); // and creating a list of Meshobjects
}
}
}
Found further posts on dispose here. Maybe they help others:
(Sorry for the long post. I’m starting with babylon and JS. Please beware of very stupid mistakes )