JSFiddle - React, Tailwind, and code Playground
HTML
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three/build/three.module.js"
}
}
</script>
JavaScript
import * as THREE from 'three';
// init
const camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
camera.position.z = 1;
camera.rotation.x = -7 * Math.PI/180;
const scene = new THREE.Scene();
const geometry = new THREE.BoxGeometry( 0.2, 2.5, 0.5, 1, 15, 1 );
const material = new THREE.MeshNormalMaterial( { wireframe: true } );
const mesh = new THREE.Mesh( geometry, material );
mesh.rotation.y = Math.PI / 4;
scene.add( mesh );
const renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animation );
document.body.appendChild( renderer.domElement );
// animation
function animation( time ) {
camera.position.y = Math.sin( time / 1000 );
renderer.render( scene, camera );
}