JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My first three.js app</title>
<style>
body { margin: 0; }
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r123/three.js"></script>
<script>
let time = 0;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
const geometry = new THREE.BoxGeometry(2, 2, 2);
const material = new THREE.MeshPhongMaterial( { color: 0xffffff } );
const cubes = new THREE.Object3D();
for (var c = 0; c < 10; c++) {
const cube = new THREE.Mesh( geometry, material );
cube.position.x = Math.random() * 40 - 20;
cube.position.y = Math.random() * 20 - 10;
cube.position.z = Math.random() * 20 - 10;
cubes.add( cube )
}
scene.add( cubes );
const cubeRenderTarget = new THREE.WebGLCubeRenderTarget( 128, { format: THREE.RGBFormat, generateMipmaps: true, minFilter: THREE.LinearMipmapLinearFilter } );
// Create cube camera
const cubeCamera = new THREE.CubeCamera( 1, 100000, cubeRenderTarget );
scene.add( cubeCamera );
const chromeMaterial = new THREE.MeshLambertMaterial( { color: 0xcccccc, envMap: cubeRenderTarget.texture } );
chromeMaterial.reflectivity = 0.8;
const geometry2 = new THREE.SphereBufferGeometry( 8, 32, 32 );
const sphere = new THREE.Mesh( geometry2, chromeMaterial );
sphere.position.z = -6;
scene.add( sphere );
const light = new THREE.PointLight( 0xffffff, 1, 200 );
light.position.set( 0, 0, 4 );
scene.add( light );
camera.position.z = 10;
function animate() {
requestAnimationFrame( animate );
...