Files
portfolio/src/utils/animateMesh.js
LJ5O 256654502e Added collisions with objects on scene
Player will now be stopped by fences
Also added the possibility to define the size of ground
Also edited speed of animations
Also optimized the loading of fences
2023-11-17 10:42:14 +01:00

28 lines
1.1 KiB
JavaScript

import * as THREE from 'three';
const ANIMATION_SPEED_MULTIPLIER = 1.6;
let mixersToUpdateEachFrame = [];
export function addAnimationMixerOnMesh(mesh, actions){
//See https://threejs.org/docs/#manual/en/introduction/Animation-system
/*Function used to add an animationMixer on a mesh, so we can easily start or stop animations
Takes the animated mesh, and a list of actions names that should become animated */
const mixer = new THREE.AnimationMixer(mesh.scene);//We create a new mixer to manage every animations on this mesh
mesh.animationMixer = mixer;//We add this mixer on the mesh
mesh.animationActions = {};//And create an object that will hold actions
actions.forEach(element => {
const clip = THREE.AnimationClip.findByName( mesh.animations, element );//For each given action name, we get a clip
mesh.animationActions[element] = mixer.clipAction(clip);//and save it as an action
});
mixersToUpdateEachFrame.push(mixer);
}
export function updateAnimations(deltaSeconds){
mixersToUpdateEachFrame.forEach(element => {
element.update(deltaSeconds * ANIMATION_SPEED_MULTIPLIER);
});
};