Added animation test

This commit is contained in:
2026-08-04 08:52:13 +08:00
parent a1b9f252b6
commit 2220d4031c
4 changed files with 32 additions and 4 deletions
+26 -4
View File
@@ -6,6 +6,7 @@ import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
const scene = new THREE.Scene();
const clock = new THREE.Clock(); // Required to calculate delta time
const sizes = {
width: window.innerWidth,
@@ -14,6 +15,7 @@ const sizes = {
let loadData = null;
let mixer;
fetch('model-index.json')
.then(response => response.json())
@@ -126,6 +128,20 @@ function loadModel(modelPath) {
loader.load(modelPath, (glb) => {
currentModel = glb.scene;
scene.add(glb.scene);
// Check if the file contains animations
if (glb.animations && glb.animations.length > 0) {
// Create the AnimationMixer and bind it to the model
mixer = new THREE.AnimationMixer(currentModel);
// Get the first animation clip and create a playable action
const animationClip = glb.animations[0];
const action = mixer.clipAction(animationClip);
// Play the animation
action.play();
}
loaderContainer.style.display = 'none'; // Hide Loading Throbber
setGuiEnabled(gui, true);
});
@@ -220,12 +236,18 @@ scene.environment = env_texture;
//UPDATE PER FRAME
renderer.setAnimationLoop( animate );
function animate( time ) {
controls.update();
renderer.render( scene, camera );
function animate() {
requestAnimationFrame(animate);
const delta = clock.getDelta();
if (mixer) {
mixer.update(delta);
}
controls.update();
renderer.render( scene, camera );
}
animate();
//Toggle GUI
function setGuiEnabled(guiInstance, isEnabled) {
guiInstance.controllersRecursive().forEach(controller => {
+6
View File
@@ -124,5 +124,11 @@
"variants": {
"default": "models/---------- Frog Zoo.glb"
}
},
{
"name": "Anim Test",
"variants": {
"default": "models/---------- anim test.glb"
}
}
]
Binary file not shown.
Binary file not shown.