Search code examples
autodesk-forgeautodesk-viewer

Forge viewer auto-play Fusion animation


I need some help to set up the AnimationExtension using custom options to play automatically the animation as soon the model is loaded on the viewer.

So far I loaded the Autodesk.Fusion360.Animation extension and set the viewable to the Fusion animation one (through its id, found in the manifest). If I try to play the extension from the console I can get the Autodesk.Fusion360.Animation extension and in the callback using play() or activate(); but if I try to do that from the code it's not working. Here is my code:

viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, (x) => {
  viewer.loadExtension('Autodesk.Fusion360.Animation').then((y)=> {
    y.options.startOnInitialize=true;
    y.activate();
    y.play();
  })
});

From the options I see there is the startOnInitialize property, but maybe I can't set the options to the builtin extension: I found this post about the options in the extensions and the tools...but I don't understand how to apply it in the code, in relation to a basic viewer.

Can you please give me info or a snippet to autoplay a Fusion animation in the viewer and set additional options to the extension?

Thanks


Solution

    1. Configure the Viewer with the Autodesk.Fusion360.Animation extension enabled from the beginning.
    2. Add a listener to the event Autodesk.Viewing.ANIMATION_READY_EVENT to the viewer.
    3. When event arrives, play the animation.