I am rendering an animated 3D model from https://sketchfab.com/3d-models/hoverboard-d93296d2412b4997ae8cb96baaba5ccd which has 3 animations and 1 static pose listed. However, on inspecting the 3D model i noticed 4 animations and 1 static pose listed [ 0 – break , 1 – default, 2 – hover , 3—ollie , 4 --turns]. Initially , i used the simple code
mixer = new THREE.AnimationMixer(gltf.scene);
var action = mixer.clipAction( gltf.animations[1] );
action.play();
where i change gltf.animations[n] manually to see the different animations and i can successfully see all the animations. However, i tried introducing dat.GUI to enable the user to change the animations and i run into an issue. When i select the first option (which is ‘break’ ) , i get a console error “Uncaught TypeError : Cannot read property ‘reset’ of undefined”.
My code in this case looks like the following:
function createGUI(model, animations){
var states = ['break','default', 'hover', 'ollie','turns'];
gui = new dat.GUI();
mixer = new THREE.AnimationMixer(model);
actions={};
for ( var i = 0; i < animations.length; i++ ) {
var clip = animations[ i ];
var action = mixer.clipAction( clip );
actions[ clip.name ] = action;
}
// states
var statesFolder = gui.addFolder( 'States' );
var clipCtrl = statesFolder.add( api, 'state' ).options( states );
clipCtrl.onChange( function() {
fadeToAction( api.state, 0.5 );
} );
statesFolder.open();
activeAction = actions['ollie'];
activeAction.play();
}
function fadeToAction( name, duration ) {
previousAction = activeAction;
activeAction = actions[ name ];
if ( previousAction !== activeAction ) {
previousAction.fadeOut( duration );
}
activeAction
.reset()
.setEffectiveTimeScale( 1 )
.setEffectiveWeight( 1 )
.fadeIn( duration )
.play();
}
Not sure why manually selecting the first option from the GUI seems to not work in my case. Any help in understanding is highly appreciated