Skip to content

Commit 35620a1

Browse files
fix animation export
1 parent 24f807b commit 35620a1

File tree

2 files changed

+55
-16
lines changed

2 files changed

+55
-16
lines changed

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
}
9292
#spriteSheetPanel {
9393
position: absolute;
94-
top: 150px;
94+
top: 190px;
9595
right: 10px;
9696
background-color: rgba(0, 0, 0, 0.7);
9797
padding: 10px;

js/fbxViewer.js

+54-15
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,19 @@ document.addEventListener('DOMContentLoaded', async function() {
241241
window.currentAnimationGroup.start(true);
242242
}
243243

244+
// Update animation list and play first animation
245+
if (container.animationGroups.length > 0) {
246+
// Store animation groups both locally and globally
247+
animationGroups = container.animationGroups;
248+
window.animationGroups = animationGroups;
249+
250+
// Update the animation list UI
251+
populateAnimationList();
252+
253+
// Play the first animation
254+
playAnimation(0);
255+
}
256+
244257
return window.currentCharacter;
245258
}
246259

@@ -425,8 +438,9 @@ document.addEventListener('DOMContentLoaded', async function() {
425438
// Rotate 90 degrees so character faces the camera from the side
426439
character.rotation = new BABYLON.Vector3(0, Math.PI/2, 0);
427440

428-
// Store animation groups
441+
// Store animation groups both locally and globally
429442
animationGroups = result.animationGroups;
443+
window.animationGroups = animationGroups;
430444

431445
// Handle no animations case
432446
if (animationGroups.length === 0) {
@@ -446,6 +460,11 @@ document.addEventListener('DOMContentLoaded', async function() {
446460
// Populate animation dropdown
447461
populateAnimationList();
448462

463+
// Make sure to play the first animation
464+
if (animationGroups.length > 0) {
465+
playAnimation(0);
466+
}
467+
449468
console.log(`Loaded character with ${animationGroups.length} animations`);
450469
}
451470

@@ -485,55 +504,75 @@ document.addEventListener('DOMContentLoaded', async function() {
485504
animationList.appendChild(option);
486505
});
487506

488-
// Select the first animation
507+
// Select and play the first animation
489508
if (animationGroups.length > 0) {
509+
animationList.value = "0";
490510
playAnimation(0);
491511
}
492512
}
493513

494514
// Play selected animation
495515
function playAnimation(index) {
496-
// Stop current animation if playing
497-
if (currentAnimationGroup) {
498-
currentAnimationGroup.stop();
516+
// Stop all animations first
517+
if (scene) {
518+
scene.animationGroups.forEach(group => group.stop());
499519
}
500520

501521
// Play selected animation
502522
if (index >= 0 && index < animationGroups.length) {
503523
currentAnimationGroup = animationGroups[index];
504-
currentAnimationGroup.start(true); // true for looping
505-
showStatus(`Playing animation: ${currentAnimationGroup.name}`);
524+
window.currentAnimationGroup = currentAnimationGroup; // Ensure global access
525+
if (currentAnimationGroup) {
526+
currentAnimationGroup.start(true); // true for looping
527+
showStatus(`Playing animation: ${currentAnimationGroup.name}`);
528+
// Update dropdown selection to match
529+
animationList.value = index.toString();
530+
}
506531
}
507532
}
508533

509534
// Recording sprite sheet functions
510535
function startRecording() {
536+
// Get the currently selected animation
537+
const selectedIndex = parseInt(animationList.value);
538+
539+
// Ensure we have a valid animation
540+
if (!animationGroups || animationGroups.length === 0) {
541+
showStatus("No animations available to record", true);
542+
return;
543+
}
544+
545+
// Force play the selected animation if it's not already playing
546+
if (!currentAnimationGroup || currentAnimationGroup !== animationGroups[selectedIndex]) {
547+
playAnimation(selectedIndex);
548+
}
549+
550+
// Double check we have a valid animation now
511551
if (!currentAnimationGroup) {
512-
showStatus("Please play an animation first before recording", true);
552+
showStatus("Failed to start animation for recording", true);
513553
return;
514554
}
515555

516-
// Get parameters from inputs
517-
totalFramesToCapture = parseInt(framesInput.value) || 16;
518-
if (totalFramesToCapture < 1) totalFramesToCapture = 16;
556+
// Get parameters from inputs with fallback values
557+
totalFramesToCapture = Math.max(1, parseInt(framesInput.value) || 16);
519558

520559
// Reset recording state
521560
recordedFrames = [];
522561
frameCount = 0;
523562
isRecording = true;
524563

525-
// Restart the animation for a clean recording and ensure we're at the beginning
564+
// Restart the animation from the beginning
526565
currentAnimationGroup.stop();
527-
currentAnimationGroup.reset(); // Reset to start position
528-
currentAnimationGroup.start(true); // Loop animation
566+
currentAnimationGroup.reset();
567+
currentAnimationGroup.start(true);
529568

530569
showStatus(`Recording sprite sheet: frame 0/${totalFramesToCapture}`);
531570

532571
// Disable record button during recording
533572
recordBtn.disabled = true;
534573
recordBtn.textContent = "Recording...";
535574

536-
// Start the recording loop with a slight delay to ensure animation is ready
575+
// Start the recording loop
537576
setTimeout(() => {
538577
recordingLoop();
539578
}, 100);

0 commit comments

Comments
 (0)