|
29 | 29 | import { RoundedBoxGeometry } from 'three/addons/geometries/RoundedBoxGeometry.js'; |
30 | 30 | import { LottieLoader } from 'three/addons/loaders/LottieLoader.js'; |
31 | 31 |
|
| 32 | + import lottie from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'; |
| 33 | + |
32 | 34 | let renderer, scene, camera; |
33 | 35 | let mesh; |
34 | 36 |
|
|
42 | 44 | scene = new THREE.Scene(); |
43 | 45 | scene.background = new THREE.Color( 0x111111 ); |
44 | 46 |
|
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 |
48 | 79 |
|
49 | | - setupControls( texture.animation ); |
| 80 | + setupControls( animation ); |
50 | 81 |
|
51 | 82 | // texture = new THREE.TextureLoader().load( 'textures/uv_grid_directx.jpg' ); |
52 | 83 | // texture.colorSpace = THREE.SRGBColorSpace; |
|
0 commit comments