Skip to content

Commit

Permalink
Merge pull request #3 from dmnktoe/combine-animations
Browse files Browse the repository at this point in the history
add: idle and run animation from soldier
  • Loading branch information
dmnktoe authored Jan 31, 2024
2 parents fe2aa83 + 5d73ac7 commit e086457
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
Binary file added public/models/blob.glb
Binary file not shown.
39 changes: 29 additions & 10 deletions src/scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function init() {
{
const loader = new GLTFLoader(loadingManager)
loader.load(
'models/Soldier.glb',
'models/blob.glb',
(gltf) => {
model = gltf.scene
scene.add(model)
Expand All @@ -162,14 +162,12 @@ function init() {
console.log(animations);
mixer = new AnimationMixer(model);

idleAction = mixer.clipAction(animations[0]);
walkAction = mixer.clipAction(animations[3]);
runAction = mixer.clipAction(animations[1]);
walkAction = mixer.clipAction(animations[0]);


actions = [idleAction, walkAction, runAction];


activateAllActions();
animate();

},
(xhr) => {
console.log(`${(xhr.loaded / xhr.total) * 100}% loaded`)
Expand All @@ -179,8 +177,29 @@ function init() {
console.error(error)
}
)
const loader2 = new GLTFLoader(loadingManager)
loader2.load(
'models/Soldier.glb',
(gltf) => {


const animations2 = gltf.animations;


idleAction = mixer.clipAction(animations2[0]);
runAction = mixer.clipAction(animations2[1]);

actions = [idleAction, walkAction, runAction];

activateAllActions();
animate();
},

)
}



// ===== 🎥 CAMERA =====
{
camera = new PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 100);
Expand Down Expand Up @@ -275,7 +294,7 @@ function init() {

pausingFolder.add(settings, 'pause/continue');
pausingFolder.add(settings, 'make single step');
pausingFolder.add(settings, 'modify step size', 0.01, 0.1, 0.001);
pausingFolder.add(settings, 'modify step size', 0.01, 1, 0.01);

crossFadeControls.push(crossfadingFolder.add(settings, 'from walk to idle'));
crossFadeControls.push(crossfadingFolder.add(settings, 'from idle to walk'));
Expand All @@ -295,7 +314,7 @@ function init() {
setWeight(runAction, weight);
});

speedFolder.add(settings, 'modify time scale', 0.0, 1.5, 0.01).onChange(modifyTimeScale);
speedFolder.add(settings, 'modify time scale', 0.1, 2, 0.01).onChange(modifyTimeScale);

musicFolder.add(settings, 'play music').onChange(playMusic);
musicFolder.add(settings, 'modify music volume', 0.0, 1.0, 0.01).onChange(modifyVolume);
Expand Down Expand Up @@ -404,7 +423,7 @@ function prepareCrossFade(startAction: any, endAction: any, defaultDuration: any
singleStepMode = false;
unPauseAllActions();

if (startAction === idleAction) {
if (startAction === walkAction) {
executeCrossFade(startAction, endAction, duration);
} else {
synchronizeCrossFade(startAction, endAction, duration);
Expand Down

0 comments on commit e086457

Please sign in to comment.