Lottie Texture
An extension library for loading and playing Lottie animation files in Babylon.js.
Introduction
This is an integration of lottie-web and Babylon.js.
It allows you to load a Lottie JSON file as a texture for Babylon.js.
What is Lottie?
Lottie is an iOS, Android, and React Native library that renders After Effects animations in real time, allowing apps to use animations as easily as they use static images.
install
pnpm add babylonjs-lottie @babylonjs/coreIt currently relies on the "@babylonjs/core" package and probably does not support the "babylonjs" package.
example
Load a Lottie JSON file
import {LottieTexture} from "babylon-lottie"
let lottieTexture = await LottieTexture.LoadFromUrlAsync("name", "/lottie.json", scene, {} /*option*/)Create a box and set its texture to the Lottie animation
let box = MeshBuilder.CreateBox("box")let mat = new PBRMaterial("pbr", scene)let lottieTexture = await LottieTexture.LoadFromUrlAsync("name", "/Aniki Hamster.json", scene, {} /*option*/)mat.albedoTexture = lottieTexturebox.material = matmat.unlit = trueLottieTexture exposes the lottieAnimation property.
You can use it to pause playback, get playback progress, and access other APIs.
let lottieTexture = await LottieTexture.LoadFromUrlAsync("name", "/lottie.json", scene, {} /*option*/)
lottieTexture.lottieAnimation.play()lottieTexture.lottieAnimation.pause()lottieTexture.lottieAnimation.currentFrame()//....Options
await LottieTexture.LoadFromUrlAsync("name", "/lottie.json", scene, { useAnimeSize: false, // If true then use the width and height set in the animation file autoPlay: true, width: 512, height: 512, loop: true,})