question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accessing the duration of an animation

See original GitHub issue

model-viewer includes some very useful animation properties and methods including:

  • play()
  • pause()
  • currentTime

A notable absence seems to be animationDuration - i.e. the total time taken by an animation.

I am working on a ‘player’ interface where a user can scrub to a particular moment in the animation, but will need to use a hard coded value for the duration of the animation, rather than reading it from the interface. I suspect the animation duration would be used somewhere internally - it would be very useful if it were made available via a property on the model-viewer in the same way that currentTime is.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
elalishcommented, Mar 2, 2021

Thanks for adding this!

1reaction
dhruvadhia-celacommented, Dec 2, 2020

There is a way to access Threejs library from Model Viewer.

`<script>

    let mixer;
    let scene, model;

    const mv = document.querySelector("model-viewer");
    const clock = new THREE.Clock();
   
   mv.addEventListener('load', (event) => {

    //mv.onload = function () {
        let sceneObj = Object.getOwnPropertySymbols(mv).find(
            x => x.description === "scene"
        );
        scene = mv[sceneObj];
        model = scene.model.children.find(x => x.name === "ModelContainer");

        mixer = new THREE.AnimationMixer(model);
        
        // this will give you the duration of any given clip in the model. 
        console.log(scene.model.animations[1].duration);

        event.stopPropagation();
    }, true);
</script> `

Its a hacky way though, I like your proposal on adding those functionalities in core Model Viewer itself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

animation-duration - CSS: Cascading Style Sheets | MDN
The animation-duration CSS property sets the length of time that an animation takes to complete one cycle.
Read more >
Set the start time and speed of an animation effect
On the Animations tab, in the Duration box, enter the number of seconds that you want the effect to run. Set the speed...
Read more >
Understanding animation, duration and easing using ...
Timing your animations with requestAnimationFrame​​ The requestAnimationFrame passes one argument to your callback. It's a timestamp with how much milliseconds ...
Read more >
How to define the duration of an animation takes to complete ...
To do this, we have animation-duration property which sets the time interval that animation takes to complete one cycle. Syntax:
Read more >
CSS animation-duration Property - W3Schools
Definition and Usage. The animation-duration property defines how long an animation should take to complete one cycle. Default value: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found