Load animation file

Hello guys,
at the moment I´m trying to build an elevator.
I saw in the forum an post here a person want to do the same but the person got the full Json code into the js file, but is it possible to just load the file?


This is the code where the Json code is static into the js file

at the Project i use for other thinks the fetch variant to get information of json file is that possible to use it here too?

await fetch(wand_api[j]).then((response) => {return response.json(); });

this is how i use the fetch variante to get the infomation

I’m not sure this is exactly a Babylon question, but I think you want to load the JSON from a url and then parse it into a JSON object so that you can pass it to BABYLON.Animation.Parse? If so, I think what you wrote is close. You just need an additional JSON.parse to get the object.

If this is not what you mean, can you create a playground and add a link to the forum post you mentioned?

1 Like

It looks like you’re trying to load animations saved from the Animation Curve Editor? If so you can use ParseFromFileAsync to load them into an array like this for example:

const animations = await BABYLON.Animation.ParseFromFileAsync("animations", "./animations.json");

here is an playground, when you click on the sphere the animation will play.

I see from your PG that you tried the solution I proposed but you used the wrong GitHub URL and didn’t use await or then. Here it is working with the URL fixed as per the documentation here. Also you don’t need to call createScene in the playground, it’s already called for you. :slight_smile:

1 Like

yeah i saw that with the await later but í forget to post an new playground.
I never used the playground befor.
What did u change from the Github URL can I create that or ist that every time the same begining?

Thank you it is working now :smiley:

1 Like

No worries the documentation I linked shows what to change for the GitHub link. :slight_smile:

2 Likes