add animation mixer for glb files

This commit is contained in:
Yash Suresh Chandra
2024-07-03 22:21:06 +05:30
committed by GitHub
parent 3b4e715939
commit 4f2b918a34
+11 -1
View File
@@ -51,9 +51,11 @@ window.onresize = function () {
};
const clock = new THREE.Clock();
var lastTimestamp = "";
var needUpdate = false;
let mixer;
function frameUpdate() {
@@ -62,6 +64,10 @@ function frameUpdate() {
if (timestamp == lastTimestamp){
if (needUpdate){
controls.update();
if (mixer !== undefined) {
const delta = clock.getDelta();
mixer.update(delta);
}
renderer.render( scene, camera );
}
requestAnimationFrame( frameUpdate );
@@ -138,6 +144,10 @@ async function main(filepath="") {
model.scale.set( 5, 5, 5 );
scene.add( model );
mixer = new THREE.AnimationMixer(model);
gltf.animations.forEach((clip) => {
mixer.clipAction(clip).play();
});
}, onProgress, onError );
@@ -159,4 +169,4 @@ async function main(filepath="") {
}
//main("C:/Users/reall/Softwares/ComfyUI_windows_portable/ComfyUI/output/MeshTest/Mesh_01.obj");
main();
main();