Initiate the mixer animation at a designated time using either the playAt() or skipTo() function

I am currently working on a simple mesh animation stored in a .gltf file and I need it to start playing at a specific time in seconds.

Below is the setup for the loader and mixer:

GLTFLoader.load( 'myscene.gltf', function ( gltf ) {

    model = gltf.scene;
    scene.add( model );

    mixer = new THREE.AnimationMixer( model );
    mixer.clipAction(gltf.animations[0])
        .setDuration( 60 ) //total of 1 min
        .play(); 

    render();
});

Within the render() function, this code snippet can be found:

function render() {

        var delta = clock.getDelta();

        if (mixer != null) {
            mixer.update(delta);
        };

        //console.log(delta); //Doesn't show anything valuable.

        renderer.clear();
        composer.render();
        counter++;
}

I have experimented with the method .startAt(10), which acts only as a delay before playing. It should ideally be renamed to .delay(). The function startAt() seems more suitable for what I am trying to achieve. Additionally, attempting to use .play(10) has proven unsuccessful. Although mixer.time does provide the actual elapsed time since play in seconds, it cannot be manually set to a specific value.

I find the concept of clock.getDelta() puzzling, especially in terms of how it determines what part of the animation should be played next considering the seemingly repetitive numbers it outputs. How can I ensure that the animation starts at, let's say, 10 seconds in or even a specific keyframe number?

Answer №1

Utilizing the .clipAction() method will return an instance of type AnimationAction, which allows you to sequence commands as demonstrated in the example above. Rather than chaining commands, you have the option to store this instance in a variable and then utilize the .time property of the AnimationAction to specify the starting point.

var mixer = new THREE.AnimationMixer( model );
var action = mixer.clipAction( gltf.animations[ 0 ] );
action.setDuration( 60 )
action.play();
action.time = 5;

For further information on the .time property, refer to the documentation page.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error: Value of incoming scope in Angular Directive is not defined

When working in html, I passed an object into a directive like this: <lcd-code ldcCode="{{ detail.program.ldcCode }}"></lcd-code> The value of detail.program.ldcCode is "PSIH"... However, in the Directive, it is showing up as undefined: var ...

Leverage the power of React in tandem with Express

My web site is being created using the Express framework on NodeJS (hosted on Heroku) and I'm utilizing the React framework to build my components. In my project, I have multiple HTML files containing div elements along with React components that can ...

Tips for transforming a React sign in component into an already existing Material UI sign in component

I am looking to revamp my current sign-in page by transitioning it into a material UI style login page. Displayed below is the code for my existing sign-in component named "Navbar.js". This file handles state management and includes an axios call to an SQ ...

Problems arise when using $(window).width() in conjunction with scrolling functionality

I am attempting to ensure this code only activates when the device window exceeds 960px and triggers when the window scrolls down 700px. The second condition is functioning as intended, but the first condition is not working properly. The code functions f ...

Troubleshooting JavaScript Object allocation problem

As someone who is not an expert in JavaScript, I have a question that may seem silly. Let's say I have the following snippet of HTML: <div> <script type="text/javascript"> var variable_2 = new SomeObject(); </script ...

Challenges in Implementing Animated Counters on Mobile Platforms

My website is experiencing a strange issue with an animated counter. The counter works fine on desktop browsers, but when viewed on mobile devices in a live setting, it seems to have trouble parsing or converting numbers above 999. This results in the init ...

Utilizing MeteorJS Collection and Angular 2 for Efficient Data Visualization

I'm currently working on integrating the Rxjs Observable with the .zone() method to populate data in my Angular component from a MongoDB collection in MeteorJS. However, I've encountered an error stating 'Cannot read property 'title&apo ...

Exploring the differences between a fixed-top navbar and dark theme in Bootstrap 5.3

I've been struggling to find a solution for having a fixed top navigation bar that remains solid without being transparent in both dark and light themes. Switching between dark and light themes results in the fixed-top navigation bar appearing transp ...

What is the reason behind the cross-origin error thrown by JSON.parse?

When I don't use JSON.parse, my code works perfectly fine. However, as soon as I attempt to parse or stringify my data object, a cross-origin error is thrown. Why is this occurring and what steps can I take to resolve it? The snippet of code in Title ...

Error with Cross-Origin Resource Sharing (CORS) on my website

During the development of a website, I disabled web security in order to bypass CORS using the command chrome.exe --disable-web-security --user-data-dir=/path/to/foo However, after successfully completing the website and uploading it to my domain, I enco ...

Troubleshooting the issue: "Error - 'Missing "data" payload in the request' when using Vue.js with Strapi"

When attempting to create a new entry in strapi by sending a post request in vue.js, I encountered the following error: message: Missing "data" payload in the request P.S: I also need to be able to upload files. I have read that using formData is ...

Obtaining a Slug in the Server-Side Layout of a Next.js Component

I am facing an issue with passing a slug to a server-side function in my Next.js layout component. The problem arises when the slug is returning as undefined, and I am struggling to correctly access and utilize the slug on the server side within the layout ...

Transferring data from a child window to its parent container

My situation involves a parent web page where I open a new window using JavaScript. The new window is an ASP.NET server-side page that needs to save data in the database and return an ID after saving it. Now, the challenge is passing this ID from the child ...

Exploring the capabilities of ngWebDriver to interact with a dynamic ng-repeat through Selenium

I'm currently in the process of automating a web interface that contains frames built with Angular JS. I'm specifically looking to access an ng-repeat located within dynamic columns. Here's a snippet of the DOM structure I'm dealing wi ...

What are the common reasons for jQuery Image Slider malfunctioning?

After following a tutorial on Youtube (https://www.youtube.com/watch?v=KkzVFB3Ba_o) about creating a JQuery image gallery, I realized that my implementation is not working at all. Despite carefully reviewing my code and fixing any errors I could find, the ...

Leverage the power of an HTML button to trigger a JavaScript function

To find the solution when inputting values for a, b, and c (for example, a=1, b=-3, c=-4), simply press the button. function solve(a, b, c) { let x1 = (-1 * b + Math.sqrt(Math.pow(b, 2) - (4 * a * c))) / (2 * a); let x2 = (-1 * b - Math.sqrt(Mat ...

The error block in AJAX is not triggered when the API server responds with an HTTP 500 status code

I need to incorporate a retry mechanism in my JavaScript code for calling an API: $.ajax({ url: api_url + 'report', type: 'GET', dataType: 'json', async: false, tryC ...

Guide to dynamically insert rows in HTML using Vue.js based on the selected option

This is the initial row. Depending on the selection made here, different rows will be displayed <div class="row"> <div class="col-md-4"> <div class="form-group label-floating"> <label class="control-label">Case Type< ...

Displaying 100,000 sprites with a faint 0.1 opacity, utilizing see-through backgrounds and crisp antialiasing

In my current setup, I have the following key pieces of code: Renderer renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true, canvas: canvas }); Textures dot: THREE.ImageUtils.loadTexture('./assets/images/dot.png') Material ...

Filter an array of objects based on the values in a separate array

Just starting out with Angular and I'm attempting to filter values from an array that is nested inside an object, which in turn is located within another array. The second file that needs to be filtered consists of an array of objects. export const PA ...