JSFiddle - React, Tailwind, and code Playground
JavaScript
import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.125.2/build/three.module.js';
let camera, scene, renderer;
let group;
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
camera.position.set( 0, 2, 2 );
scene = new THREE.Scene();
camera.lookAt( scene.position );
group = new THREE.Group();
scene.add( group );
const geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
const material = new THREE.MeshNormalMaterial();
const mesh = new THREE.Mesh( geometry, material );
mesh.position.x = 1;
group.add( mesh );
scene.add( new THREE.AxesHelper() );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
}
function animate() {
requestAnimationFrame( animate );
group.rotation.y += 0.01;
renderer.render( scene, camera );
}