JSFiddle - React, Tailwind, and code Playground

by Cody Bennett

CSS

body, html {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
}

JavaScript

import * as THREE from 'https://unpkg.com/three/build/three.module.js';
import { OrbitControls } from 'https://unpkg.com/three/examples/jsm/controls/OrbitControls.js';

let renderer, camera, controls, scene;
let geometry, material, mesh;

init();
animate();

function init() {
	renderer = new THREE.WebGLRenderer({ antialias: true });
	renderer.setSize(window.innerWidth, window.innerHeight);
	document.body.appendChild(renderer.domElement);

	camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.01, 1000);
	camera.position.z = 1;

	controls = new OrbitControls(camera, renderer.domElement);
  controls.enablePan = false;
  controls.enableZoom = false;

	scene = new THREE.Scene();

	geometry = new THREE.BoxGeometry(0.5, 0.5, 0.5);
	material = new THREE.MeshNormalMaterial();

	mesh = new THREE.Mesh(geometry, material);
  mesh.position.y = -0.5;

  scene.add(mesh);
}

function animate() {
	requestAnimationFrame(animate);
 
  mesh.translateZ(0.01);
  controls.target = mesh.position;
 
	controls.update();

	renderer.render(scene, camera);
}