Skip to content

Commit 6c77f06

Browse files
committed
Examples: Improve lottie example
1 parent d891d2c commit 6c77f06

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

examples/webgl_loader_texture_lottie.html

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
import * as THREE from 'three';
2828
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
2929
import { RoundedBoxGeometry } from 'three/addons/geometries/RoundedBoxGeometry.js';
30+
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
3031

31-
import lottie from 'https://cdn.jsdelivr.net/npm/lottie-web@5.12.2/+esm';
32+
import lottie from 'https://cdn.jsdelivr.net/npm/lottie-web@5.13.0/+esm';
3233

33-
let renderer, scene, camera;
34+
let renderer, scene, camera, controls;
3435
let mesh;
3536

3637
init();
@@ -50,8 +51,9 @@
5051
loader.load( 'textures/lottie/24017-lottie-logo-animation.json', function ( data ) {
5152

5253
const container = document.createElement( 'div' );
53-
container.style.width = data.w + 'px';
54-
container.style.height = data.h + 'px';
54+
const dpr = window.devicePixelRatio;
55+
container.style.width = data.w * dpr + 'px';
56+
container.style.height = data.h * dpr + 'px';
5557
document.body.appendChild( container );
5658

5759
const animation = lottie.loadAnimation( {
@@ -60,7 +62,7 @@
6062
loop: true,
6163
autoplay: true,
6264
animationData: data,
63-
rendererSettings: { dpr: 1 }
65+
rendererSettings: { dpr: dpr }
6466
} );
6567

6668
const texture = new THREE.CanvasTexture( animation.container );
@@ -99,6 +101,9 @@
99101

100102
scene.environment = pmremGenerator.fromScene( environment ).texture;
101103

104+
controls = new OrbitControls( camera, renderer.domElement );
105+
controls.autoRotate = true;
106+
102107
//
103108

104109
window.addEventListener( 'resize', onWindowResize );
@@ -155,11 +160,7 @@
155160

156161
function animate() {
157162

158-
if ( mesh ) {
159-
160-
mesh.rotation.y -= 0.001;
161-
162-
}
163+
controls.update();
163164

164165
renderer.render( scene, camera );
165166

0 commit comments

Comments
 (0)