Guide 2: Control playback position

Overview

In this guide, we'll show a few common controls that allow users to control the playback of a 3D model animation in the display-3d-model component. This includes the ability to:

  • Start playing and pausing a 3D model animation

  • Moving the playback position forwards or backwards

  • Setting the playback position to a specified point

The view we'll build will look as follows:

Developer notes:

Please refer to the developer notes in the first guide. The same notes apply to this guide.

Load and display the 3D model in your view

Please refer to this section in the first guide. We'll use the same foundations from the first guide in the below guide.

Play and pause the 3D model animation

To play and/or pause the 3D model animation, we'll add the following buttons to our view XML:

Note that we have set the autoplay attribute to false, since we want users to be able to control the playback manually. We have also added an id attribute, which is used by component methods to identify the component in the view XML.

In the view JS, we'll initialize a global variable for isPlaying which is used to dynamically show and hide the play and pause buttons.

Next, we'll need to define the logic for playing and pausing the animation. In the view JS, we'll add two functions and add a playheadPosition variable to track the elapsed playback time:

Note that the above functions, to start and stop the animation playback, make use of multiple component methods of display-3d-model.

Move the playhead forwards, backwards or set it to a specific point

Here we are adding controls to move the animation playhead position forwards and backwards by a set amount, as well as directly specifying the playhead position.

We'll update the relevant part of the view XML code to the following:

In the view JS, we'll define the skipAnimation and setPlayhead functions:

Complete view code

Below is the complete View XML and JS code used in this guide:

Last updated