Skip to content

Commit 157c941

Browse files
Mugen87RuthySheffi
authored andcommitted
LottieLoader: Deprecated loader, inline library usage. (mrdoob#30896)
1 parent be3483d commit 157c941

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

examples/jsm/loaders/LottieLoader.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ import lottie from '../libs/lottie_canvas.module.js';
3333
*/
3434
class LottieLoader extends Loader {
3535

36+
/**
37+
* Constructs a new Lottie loader.
38+
*
39+
* @deprecated The loader has been deprecated and will be removed with r186. Use lottie-web instead and create your animated texture manually.
40+
* @param {LoadingManager} [manager] - The loading manager.
41+
*/
42+
constructor( manager ) {
43+
44+
super( manager );
45+
46+
console.warn( 'THREE.LottieLoader: The loader has been deprecated and will be removed with r186. Use lottie-web instead and create your animated texture manually.' );
47+
48+
}
49+
3650
/**
3751
* Sets the texture quality.
3852
*

examples/tags.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"webgl_loader_ifc": [ "external" ],
5151
"webgl_loader_ldraw": [ "lego" ],
5252
"webgl_loader_pdb": [ "molecules", "css2d" ],
53+
"webgl_loader_texture_lottie": [ "external" ],
5354
"webgl_loader_texture_ultrahdr": [ "hdr", "jpg", "ultrahdr" ],
5455
"webgl_loader_ttf": [ "text", "font" ],
5556
"webgl_lod": [ "level", "details" ],

examples/webgl_loader_texture_lottie.html

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import { RoundedBoxGeometry } from 'three/addons/geometries/RoundedBoxGeometry.js';
3030
import { LottieLoader } from 'three/addons/loaders/LottieLoader.js';
3131

32+
import lottie from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';
33+
3234
let renderer, scene, camera;
3335
let mesh;
3436

@@ -42,11 +44,40 @@
4244
scene = new THREE.Scene();
4345
scene.background = new THREE.Color( 0x111111 );
4446

45-
const loader = new LottieLoader();
46-
loader.setQuality( 2 );
47-
loader.load( 'textures/lottie/24017-lottie-logo-animation.json', function ( texture ) {
47+
// lottie
48+
49+
const loader = new THREE.FileLoader();
50+
loader.setResponseType( 'json' );
51+
loader.load( 'textures/lottie/24017-lottie-logo-animation.json', function ( data ) {
52+
53+
const container = document.createElement( 'div' );
54+
container.style.width = data.w + 'px';
55+
container.style.height = data.h + 'px';
56+
document.body.appendChild( container );
57+
58+
const animation = lottie.loadAnimation( {
59+
container: container,
60+
animType: 'canvas',
61+
loop: true,
62+
autoplay: true,
63+
animationData: data,
64+
rendererSettings: { dpr: 1 }
65+
} );
66+
67+
const texture = new THREE.CanvasTexture( animation.container );
68+
texture.minFilter = THREE.NearestFilter;
69+
texture.generateMipmaps = false;
70+
texture.colorSpace = THREE.SRGBColorSpace;
71+
72+
animation.addEventListener( 'enterFrame', function () {
73+
74+
texture.needsUpdate = true;
75+
76+
} );
77+
78+
container.style.display = 'none'; // must be done after loadAnimation() otherwise canvas has 0 dimensions
4879

49-
setupControls( texture.animation );
80+
setupControls( animation );
5081

5182
// texture = new THREE.TextureLoader().load( 'textures/uv_grid_directx.jpg' );
5283
// texture.colorSpace = THREE.SRGBColorSpace;

0 commit comments

Comments
 (0)