JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//cdn.rawgit.com/mrdoob/three.js/master/build/three.min.js"></script>
<canvas></canvas>
CSS
body {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
JavaScript
const $ = (s, o = document) => o.querySelector(s);
let width = 440,
height = 440,
canvas = $('canvas'),
renderer = new THREE.WebGLRenderer({
canvas: canvas,
context: canvas.getContext('webgl2'),
antialias: true,
alpha: true
});
let Ring3D = (innerRadius, outerRadius, heigth, Segments) => {
let extrudeSettings = {
depth: heigth,
bevelEnabled: false,
curveSegments: Segments
},
arcShape = new THREE.Shape();
arcShape.moveTo(outerRadius, 0);
arcShape.absarc(0, 0, outerRadius, 0, Math.PI * 2, false);
let holePath = new THREE.Path();
holePath.moveTo(innerRadius, 0);
holePath.absarc(0, 0, innerRadius, 0, Math.PI * 2, true);
arcShape.holes.push(holePath);
return new THREE.ExtrudeGeometry(arcShape, extrudeSettings);
}
renderer.setSize(width, height);
renderer.setPixelRatio(2);
renderer.shadowMap.enabled = true;
let scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 1000);
camera.position.z = 100;
camera.position.y = -160;
camera.rotation.x = THREE.Math.degToRad(60);
let planeGeometry = new THREE.PlaneGeometry(200, 200),
planeMaterial = new THREE.ShadowMaterial();
planeMaterial.opacity = .2;
let plane = new THREE.Mesh(planeGeometry, planeMaterial);
plane.position.y = 6;
plane.receiveShadow = true;
scene.add(plane);
let shape = Ring3D(12, 20, 6, 60),
material = new THREE.MeshLambertMaterial({
color: 0x8789A6
}),
object = new THREE.Mesh(shape, material);
object.castShadow = true;
object.receiveShadow = true;
scene.add(object);
let lightTop = new THREE.DirectionalLight(0xFFFFFF, .8);
lightTop.position.set(120, 120, 80);
lightTop.castShadow = true;
const d = 50;
lightTop.shadow.camera.left = - d;
lightTop.shadow.camera.right = d;
lightTop.shadow.camera.top = d;
lightTop.shadow.camera.bottom = - d;
scene.add(lightTop);
//const helper = new...