In our projects, we have a workflow where the 3D Artist generates GLTF/GLB files with two different contents:
mesh files;
animation files of such meshes.
Until now, we’re being using BABYLON.SceneLoader.ImportMeshAsync to load those animations-only assets, but we are certainly a little picky and think maybe BABYLON.SceneLoader.ImporAnimationsAsync is a more semantic and proper way to make the job.
This said, We are able of course to load properly the animations with ImporAnimationsAsync, but once the different animation groups are created under the scene, animationGroups[i].targetedAnimations[j].target is always null, when formerly (I mean using ImportMeshAsync) we had always a valid value there. With target being null for all the targetedAnimations it’s not possible to assign the animations to the geometry nodes in the scene.
I didn’t write this part of the code, so I don’t know for sure, but it looks like ImportAnimations has a targetConverter callback that allow you to assign the target. Are you passing in this callback?
…as you can see, I process (assign) the scene.animationGroups this way:
function _assignAnimations(animationGroups) {
for (var i = 0; i < animationGroups.length; i++) {
animationGroups[i].stop();
for (var j = 0; j < animationGroups[i].targetedAnimations.length; j++) {
animationGroups[i].targetedAnimations[j].target =_scene.getNodeByName(animationGroups[i].targetedAnimations[j].target.name);
}
}
}
As said, that works flawless.
Going now to implement the same functionality by means of ImportAnimationAsync, I see that:
there’s not result.animationGroups anymore, and instead I need now to use scene.animationGroups;
following your clues, I must provide the aforementioned assignAnimations method as the 6th parameter of the call, isn’t it?.
Well, the case is that I’m trying all that in my own code, but it’s not working at all, because as I stated in my question, animationGroups[i].targetedAnimations[j].target is always null.
Maybe an existent PG would help, but I’couldn’t find none.
Are the node names from the animations already loaded? If not, this is expected as you are only loading the animations and not the node they point to. The default behavior is to find the node by name in the scene, but if there are not there, they will be null.
targetConverter defines a function used to convert animation targets from loaded scene to current scene (default: search node by name)