Issue with three.js: animations not playing when changing characters

Hello everyone, I am new to this. I managed to load an .fbx character along with additional animation clips from Mixamo. My goal is to have the animations switch when a key ("Q") is clicked. Currently, the character loads and plays the first animation clip but the subsequent animation changes are not playing. You can check out where I'm currently at by visiting this link.

Below is the important piece of code...

        let Actions = [];
        let action;
        let animPaths = [ "./models/T-Pose.fbx","./models/Walking.fbx","./models/Running.fbx","./models/Idle.fbx" , "./models/Dancing.fbx"];
        let pathIDs = ["t-pose","walking", "running", "idle", "dancing"];
        let moe;
        let mixer;

        
        const loader = new FBXLoader();

        loader.load("./models/T-Pose.fbx", function(object){
            object.scale.set(0.1, 0.1, 0.1);
           /* object.traverse(function(child){
                if(child.isMesh){
                    child.material = material;
                }
            })*/
            moe = object;
            moe.position.y = -70;
            mixer = new THREE.AnimationMixer(object);
            action = mixer.clipAction(object.animations[0]);
            Actions.push(action);
            //action.play();
            scene.add(object);
            loadNextAnimation(loader);
            
        });


        function loadNextAnimation(loader){
            for(let i=1;i<animPaths.length;i++){
                
                loader.load(animPaths[i], (object) =>{
                    mixer = new THREE.AnimationMixer(moe);
                    Actions.push(mixer.clipAction(object.animations[0]));
                    scene.add(object);
                    action = Actions[i];
                    mixer.stopAllAction();
                    action.play();
                })
            }
            
        }


        let i = 0;
        let fwd = true;
        document.onkeydown = function(event) {
            // 81 = q
            
            if(event.keyCode == 81){
                if(i < 1) fwd = true;
                if(i > Actions.length) fwd = false;
                if(fwd){
                    i++;
                }else{
                    i--;
                }
                
                action = Actions[i];
                mixer.stopAllAction();
                //mixer.reset();
                action.play();
                
                console.log("i = " + i);
                console.log(animPaths[i]);
                document.getElementById("testtext").value = "currentClip = "+pathIDs[i];
                animate();
            }
        };

I would appreciate it if someone could point out where I might be making mistakes. Thank you.

Answer №1

Success discovered with the help of Harold. I made a blunder by creating a mixer while uploading the T-Pose. Subsequently, in the loadNextAnimation(loader) function, I mistakenly generated a new mixer for each animation load, unintentionally replacing the previous one. The issue was resolved by simply eliminating the line mixer = new THREE.AnimationMixer(moe);.

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

Detecting when a user navigates backwards on a mobile device using JavaScript

I am currently working on a basic HTML file that includes a JavaScript code snippet: <p>Press The Back Button and see a message!</p> <script> window.onpopstate = function(event) { alert("location: " + document.location); } ...

Error in Javascript: Character class range is not in order

My regular expression (regex) seems to be incorrect: var domain = "google\.com\.br"; var reEmail = new RegExp("^([A-Za-z0-9_\-\.])+\@" + domain + "$"); I am trying to use this regex to validate an email address. Here is an exampl ...

The distinction between a JSON file that is generated dynamically from a response and one that is

I've been working on configuring a bootstrap typeahead feature and here is the jquery code I am using: $(function () { $.ajax({ type: "GET", url: "http://example.com/search?callback=my_callback", data: { keyword: &apos ...

Angular 2's Multi-select dropdown feature allows users to select multiple options

Recently, I encountered an issue with customizing CSS for angular2-multiselect-dropdown. I found the solution in this link: https://www.npmjs.com/package/angular2-multiselect-dropdown. I have included my code below. Any assistance in resolving this matter ...

The smooth scrolling feature of jQuery does not function properly when combined with the Bootstrap 4 Navbar

Here is the code I have for the navigation bar on a website I am currently working on: <body data-spy="scroll" data-target="#navbar" data-offset="20"> <!-- navbar --> <div id="home"> <div id="navbar"> <nav class="n ...

Activating a link click inside a table with jquery

I have been attempting to trigger a click on an anchor within the table compareTable with the code below, however it does not appear to be working as expected. Would anyone be able to provide insight into a possible solution? $('#compareTable a' ...

The conditional statement within the EventListener does not seem to be functioning as intended

I am attempting to calculate BMI and then display additional information on the calculation result when a button is clicked. The 'what does this mean' button should show information based on the calculated BMI score. const generatebutton = doc ...

JavaScript XMLHttpRequest is always essential

I am currently working on a chat application that needs to constantly receive server information. After the request finishes, I have added an additional call to the function within the http.onreadystatechange=function() like this: request(); This sets ev ...

Discover the point where two Revit elements intersect within the APS (forge) viewer

I have a question regarding APS (forge) viewer version 7.*, which I am currently using to view Revit models. Is there a way to determine if two elements, such as a pipe and a duct, are intersecting each other using the viewer's rayIntersect method? If ...

Submit a form using AJAX validation with either jQuery or vanilla JavaScript

As a .NET coder with little (no) front-end experience, I must apologize upfront. Upon clicking Submit, the form should trigger a call to a REST service. If the service response is true, a warning about a duplicate entry should be displayed, and the user s ...

Leveraging ts-loader alongside strip-loader in Webpack

I am currently facing an issue with strip-loader in my Typescript project that is built with Webpack. The ts-loader statement in my project is as follows: { test: /\.ts$/, loader: 'babel-loader?presets[]=es2015!ts-loader' } Everything see ...

I used npm to install a package, but for some reason, it's not appearing in

When attempting to install jquery using npm, I entered the following command: npm install jquery However, upon opening the destination folder, it was empty. (The below text was copied from cmd) > C:\Users\mandar\Desktop\Mady> ...

Testing units with Jest using ES6 import syntax instead of module.exports

There's a script I created that contains all the logic in a single const variable, similar to Moment.js. I'd like to test the functions from this script using Jest. Unfortunately, using module.exports won't work when I publish the script. ...

The AJAX response consistently returns a 405 status code

I am experiencing an issue with an AJAX post request. $.ajax({ type: "POST", contentType: "application/json", url: "/rating/save", data: JSON.stringify(rating), dataType: "json", mimeType: "application/json" ...

Utilize JavaScript when sharing on social media to avoid the possibility of embedding the entire

This javascript code snippet is extracted from www.twitter.com (simply click to view the source code). I have reformatted it for better readability: if (window.top !== window.self) { document.write = ""; window.top.location = window.self.location; s ...

Error: The listen function in React + Redux Simple Router is undefined and cannot be found

I've been attempting to configure react + react-router + redux + redux-simple-router without success. I encounter an issue when adding redux-simple-router, resulting in the error message: "[TypeError: Cannot read property 'listen' of undefi ...

Creating MongoDB queries on-the-fly in a NodeJS environment

Upon receiving a POST argument structured as follows: sort: [ { field: 'name', dir: 'asc', compare: '' }, { field: 'org', dir: 'asc', compare: '' } ] } It is necessary ...

How to retrieve the values of a property from a JavaScript object

Looking for a fresh perspective on this issue. I'm currently retrieving historical data from the cryptocompare API, but I'm having trouble accessing the received values. https://i.sstatic.net/oH6hz.png When I hardcode it as res.data.OMG.USD, I ...

What is the best way to access elements in a grid-view using JavaScript?

I am trying to incorporate a date-picker bootstrap onto a text box that is located inside a gridview. I cannot seem to figure out how to access the text box within the gridview as I keep getting an error message saying 'txtStartDate does not exist&apo ...

How to Handle Empty Input Data in JQuery Serialization

Having an issue with a form that triggers a modal window containing another form when a button is clicked. The second form includes an input field and send/cancel buttons. The goal is to serialize the data from the modal form and send it to a server using ...