# How to play the animation of GLTF model

**URL:** https://discourse.vtk.org/t/how-to-play-the-animation-of-gltf-model/3939
**Category:** Support
**Created:** [August 9, 2020, 8:52am UTC](https://discourse.vtk.org/t/how-to-play-the-animation-of-gltf-model/3939 "2020-08-09T08:52:33Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![yuhuimoon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/y/c6cbf5/32.png) [@yuhuimoon](https://discourse.vtk.org/u/yuhuimoon)
#### Post date: [August 9, 2020, 8:52am UTC](https://discourse.vtk.org/t/how-to-play-the-animation-of-gltf-model/3939/1 "2020-08-09T08:52:33Z")

</div>

I have load a GLTF with a simple translation animation successfully by **vtkGLTFReader** int VTK 9.0.1. I want to play the animation. But I fail after using:

`gltfReader->EnableAnimation(0); //0 is the correct animation index`

I notice the note of document said [**Use UPDATE\_TIME\_STEP**](https://vtk.org/doc/nightly/html/classvtkGLTFReader.html#ab2a86953bada66dcb26a7c25c95ff089). But I don’t know how to deal with it. Can anyone tell me some tips. Thanks in advance.

---

<div class="post-metadata">

### Author: ![Michael](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michael/32/16_2.png) [@Michael](https://discourse.vtk.org/u/Michael)
#### Post date: [August 10, 2020, 1:10pm UTC](https://discourse.vtk.org/t/how-to-play-the-animation-of-gltf-model/3939/2 "2020-08-10T13:10:30Z")

</div>

Just call `reader->UpdateTimeStep(timestep);` and render the scene again.  
You will have to handle a timer yourself to synchronize the animation.  
Note that the animation is currently computed on the CPU so it can be slow depending on your scene complexity.

---

<div class="post-metadata">

### Author: ![yuhuimoon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/y/c6cbf5/32.png) [@yuhuimoon](https://discourse.vtk.org/u/yuhuimoon)
#### Post date: [August 11, 2020, 4:33pm UTC](https://discourse.vtk.org/t/how-to-play-the-animation-of-gltf-model/3939/3 "2020-08-11T16:33:15Z")

</div>

Does **timestep** mean how much millisecond time that the animation takes in one render frame?

---

<div class="post-metadata">

### Author: ![yuhuimoon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/y/c6cbf5/32.png) [@yuhuimoon](https://discourse.vtk.org/u/yuhuimoon)
#### Post date: [August 12, 2020, 4:09am UTC](https://discourse.vtk.org/t/how-to-play-the-animation-of-gltf-model/3939/4 "2020-08-12T04:09:28Z")

</div>

I use **UpdateTimeStep()** in the timer callback. But the animation of the model is so fast that I can not see the its moving and changing smoothly. I want to play the animation in 10 seconds. Any tips or example? Thanks.

in main():

```
...

auto cb = vtkSmartPointer<vtkTimerCallback2>::New();
cb->setReader(gltfReader);

//call the timer per 100 milliseconds
rwi->AddObserver(vtkCommand::TimerEvent, cb);
int timeId = rwi->CreateRepeatingTimer(100);
cb->setTimeId(timeId);

gltfReader->SetApplyDeformationsToGeometry(true);
gltfReader->EnableAnimation(0);
gltfReader->UpdateTimeStep(10);

m_render->GetRenderWindow()->Render();

```

In the Excute() of Timer callback:

```
    virtual void Execute(vtkObject* caller, unsigned long eventId, void* vtkNotUsed(callData))
    {
        vtkRenderWindowInteractor* iren = dynamic_cast<vtkRenderWindowInteractor*>(caller);if (vtkCommand::TimerEvent == eventId)
        if (vtkCommand::TimerEvent == eventId)
        {
            ++TimerCount;

            if (TimerCount < 10)
            {
                reader->UpdateTimeStep(10); //I'm not sure how to set the timestep correctly
                reader->Modified();
                render->GetRenderWindow()->Render();
            }
            else
            {
                iren->DestroyTimer(timerId);
                reader->DisableAnimation(0);
                reader->Modified();
                render->GetRenderWindow()->Render();
            }
        }
    }
```

---

<div class="post-metadata">

### Author: ![Michael](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michael/32/16_2.png) [@Michael](https://discourse.vtk.org/u/Michael)
#### Post date: [August 12, 2020, 8:00am UTC](https://discourse.vtk.org/t/how-to-play-the-animation-of-gltf-model/3939/5 "2020-08-12T08:00:25Z")

</div>

You have to set the framerate first (SetFrameRate, default is 60).  
`CreateRepeatingTimer` should have a value of `1000 / FrameRate`.  
`UpdateTimeStep` value is `TimerCount * 1000 / FrameRate`.

---

<div class="post-metadata">

### Author: ![yuhuimoon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/y/c6cbf5/32.png) [@yuhuimoon](https://discourse.vtk.org/u/yuhuimoon)
#### Post date: [August 12, 2020, 9:12am UTC](https://discourse.vtk.org/t/how-to-play-the-animation-of-gltf-model/3939/6 "2020-08-12T09:12:57Z")

</div>

@Michael I follow your suggestion to modify the code, I’m not sure whether the **TimerCount** value(10, 100, 100, …, I’ve tried many different value) is suitable. The animation is still very fast. It seems to only have the first key frame and the last key frame without any smooth transition. Then I use the following code in the scope of **Execute()**:  
`double fps = 1.0 / renderer->GetLastRenderTimeInSeconds();`  
The fps is about 10000. Is that normal? I use the code after creating vtkRenderWindowInteractor :  
`rwi->SetStillUpdateRate(0.01667); // 1/60≈0.01667, I want to keep the fps value of scene to 60`  
But the fps I get is still about 10000. I guess the speed of the animation maybe relates to the scene fps. Or any other reason?

---

<div class="post-metadata">

### Author: ![yuhuimoon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/y/c6cbf5/32.png) [@yuhuimoon](https://discourse.vtk.org/u/yuhuimoon)
#### Post date: [August 17, 2020, 9:38am UTC](https://discourse.vtk.org/t/how-to-play-the-animation-of-gltf-model/3939/7 "2020-08-17T09:38:03Z")

</div>

@Michael, could you give some tips?

---

<div class="post-metadata">

### Author: ![yuhuimoon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/y/c6cbf5/32.png) [@yuhuimoon](https://discourse.vtk.org/u/yuhuimoon)
#### Post date: [August 22, 2020, 2:46am UTC](https://discourse.vtk.org/t/how-to-play-the-animation-of-gltf-model/3939/8 "2020-08-22T02:46:58Z")

</div>

The range of **UpdateTimeStep()** input parameter is from 0 to 1. I use int-type as the input so that the animation will end after one update loop. I modify the **TimerCount** in Execute() as the follow:  
`TimerCount = TimerCount + 0.01;`  
Now the animation plays correctly.
