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/es-module-shims@1.3.6/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.set( 0, 0.5, 1 );
camera.lookAt( 0, 0, 0 );
const scene = new THREE.Scene();
const geometry = new THREE.PlaneGeometry( 1.5, 0.5, 1, 42 );
const material = new THREE.MeshNormalMaterial();
geometry.rotateX( -0.5 * Math.PI );
const p = geometry.attributes.position;
for( let i = 0; i < p.count; i++ ) {
p.array[3 * i + 1] += Math.sqrt ( 1 - 4.0 * p.array[3 * i + 2] ** 2 ) - 1;
}
geometry.computeVertexNormals();
const mesh = new THREE.Mesh( geometry, material );
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 ) {
mesh.rotation.y = time / 1000;
renderer.render( scene, camera );
}