I’m loading and showing at run-time GLB model based on this tutorial. My problem is that I cannont play the animation on them (in fact, play() don’t return any error or warning if the given name or ID is wrong).
In this code from the demo, we can see that animations are renamed, because by default, they may have strange name like “model_name/animation/1”.
var asset = new pc.Asset(filename, 'container', file, null, options);
asset.once('load', function (containerAsset) {
if (callback) {
// As we play animations by name, if we have only one animation, keep it the same name as
// the original container otherwise, postfix it with a number
var animations = containerAsset.resource.animations;
if (animations.length == 1) {
animations[0].name = assetName;
} else if (animations.length > 1) {
for (var i = 0; i < animations.length; ++i) {
animations[i].name = assetName + ' ' + i.toString();
}
}
callback(null, containerAsset);
}
});
But…Do we need to add an AnimationComponent to the entity created or is it already include?
I’m not sure because in this demo, we only rename the animations but don’t really associate them with this entity when doing this:
self.entity.model.asset = asset.resource.model;
To me, it’s just taking the model part.
I’m not sure if the demo really take care of the animations part of a GLB.
In this case, you can either add the animation component at runtime or in the Editor and then when the GLB is loaded, add the animation assets to the component.
Sorry to resurrect this conversation; I’m attempting this at the moment, and after adding the animations to the animation component I’m getting a ‘nodes is undefined’ error. Any idea what might be causing this?
It could well be the GLB export settings; I’m very new to the idea of morphtargets and baked animation. However I’ve tried my best to follow tutorials I’ve found online to export correctly, and it seems odd that the animation tracks are viewable in the editors viewer, but gives this error when adding the animation to the imported assed manually. I guess I might be assigning it wrong?
entity.animation.animations takes an array of animation resources (AnimationComponent | PlayCanvas API Reference) whereas asset.resource.animations is an array of animation assets hence the runtime error.
For future readers: I also found that I had to add a delay using setTimeout() to get the animation to play properly (playing the animation immediately seems to cause the mesh to disappear)
Sorry to bring this up again but I’m also struggling with loading a GLB (incl embedded animation) and playing it.
I tried to do it exactly like you two (@yaustar@hearsepileup ) but had no success. I always get a Trying to play animation 'flamingo_flyA_' which doesn't exist error but its exactly the name of the animation. Do you have any idea?