I’m having trouble getting animations to load for meshes being imported from glb files in my build that uses the ES6 modules. It may be related to the ES6 side effects, however I’m not sure what other modules I need to import. Based on other forum questions, it would appear to be @babylonjs/core/Animations/animatable, but that doesn’t seem to be enough.
Here’s a simple sandbox example of the expected behavior: Babylon.js Playground. This model has a single mesh with a spinning animation. It loads and plays properly. When I console.log the mesh.animations value it has an array with the animation data, as expected. It also works with ImportMeshAsync (https://playground.babylonjs.com/#IRBUI4#1)
However, when I try to load the same model in my own build, the animation data of the mesh is empty. I’ve also noticed that scene.animationGroups is not populated automatically, but the data is available in the result and I can manually assign it.
const sceneResult = await SceneLoader.ImportMeshAsync('', path, filename, scene);
console.log(scene.animationGroups); // This is empty until I assign it on the next line.
scene.animationGroups = sceneResult.animationGroups; // The data is available, just not assigned to scene on it's own, like it is in the sandbox
console.log(sceneResult.animationGroups);
sceneResult.meshes.forEach((m: AbstractMesh) => {
console.log(m.name);
console.log(m.animations); // There are no animations on the mesh here, but there are in the sandbox.
});
Here are my imports:
import '@babylonjs/core/Animations/animatable';
import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';
import { Animation } from '@babylonjs/core/Animations/animation';
import { AnimationGroup } from '@babylonjs/core/Animations/animationGroup';
import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';
import { Color3 } from '@babylonjs/core/Maths/math.color';
import { CubeTexture } from '@babylonjs/core/Materials/Textures/cubeTexture';
import { Engine } from '@babylonjs/core/Engines/engine';
import { Scene } from '@babylonjs/core/scene';
import { SceneLoader } from '@babylonjs/core/Loading/sceneLoader';
import { Vector3 } from '@babylonjs/core/Maths/math.vector';
import '@babylonjs/loaders/glTF/2.0/glTFLoader';
import '@babylonjs/core/Helpers/sceneHelpers';