JSFiddle - React, Tailwind, and code Playground
by crays
HTML
<script src="https://cdn.jsdelivr.net/npm/three@0.121.1/build/three.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bodymovin/5.7.3/lottie.min.js"></script>
CSS
body {
margin: 0;
}
JavaScript
let camera, scene, renderer;
let mesh;
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
camera.position.z = 5;
scene = new THREE.Scene();
scene.background = new THREE.Color( 0xffffff );
const canvas = document.createElement( 'canvas' );
canvas.width = 1024;
canvas.height = 1024;
const context = canvas.getContext( '2d' );
const animation = bodymovin.loadAnimation( {
container: document.getElementById( 'bm' ),
renderer: 'canvas',
rendererSettings: {
context: context
},
loop: true,
autplay: true,
path: 'https://assets5.lottiefiles.com/packages/lf20_mb9ka7yz.json'
//animationData: json
} );
const texture = new THREE.CanvasTexture( canvas );
const geometry = new THREE.PlaneGeometry();
const material = new THREE.MeshBasicMaterial( { map: texture } );
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
}
function animate() {
requestAnimationFrame( animate );
mesh.material.map.needsUpdate = true;
renderer.render( scene, camera );
}