djeustice Posted February 12, 2018 Share Posted February 12, 2018 I received a model of a tractor / crane arm. It is boned and animated. I exported this crane arm out of 3DS Max as a glTF. When I import it into BabylonJS, the animation begins playing immediately. I would like import the crane arm and not have the animation play immediately. I have a "Play" button and I'd like the animation to start from frame 0 when clicked. I'd like the animation to stop and return back to frame 0 when the button is clicked again. Is creating a Play / Stop animation button fairly basic (loader.beginAnimation())? Do I have to work with skeletons? Below is my code: var loader = BABYLON.SceneLoader.ImportMesh("", "models/", "CraneArm.gltf", scene, function (newMeshes) { }); document.getElementById("AddOars").addEventListener("click",function () { }); Quote Link to comment Share on other sites More sharing options...
Guest Posted February 12, 2018 Share Posted February 12, 2018 Beautiful model Just go through all your meshes and call scene.stopAnimation(mesh) Quote Link to comment Share on other sites More sharing options...
djeustice Posted February 13, 2018 Author Share Posted February 13, 2018 Wonderful thank you! I'll try this out and report back my results. Quote Link to comment Share on other sites More sharing options...
djeustice Posted February 15, 2018 Author Share Posted February 15, 2018 The animation button works now! This is the code I ended up with: var isAnimating = false; var meshesForAnimation = null; BABYLON.SceneLoader.ImportMesh("", "test/", "Crane.gltf", scene, function (newMeshes) { for (i = 0; i < newMeshes.length; i++) { scene.stopAnimation(newMeshes); isAnimating = false; } meshesForAnimation = newMeshes; }); document.getElementById("Button").addEventListener("click",function () { if(!meshesForAnimation){ return; } if (!isAnimating) { for (i = 0; i < meshesForAnimation.length; i++) { scene.beginAnimation(meshesForAnimation, 0, 300, true); } isAnimating = true; } else { for (i = 0; i < meshesForAnimation.length; i++) { scene.stopAnimation(meshesForAnimation, 0, 300, true); } isAnimating = false; } }); Thanks for pointing me in the right direction! Quote Link to comment Share on other sites More sharing options...
Guest Posted February 15, 2018 Share Posted February 15, 2018 i really like the model Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.