JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//cdn.rawgit.com/mrdoob/three.js/master/build/three.min.js"></script>
JavaScript
var camera, scene, renderer;
var geometry, material, mesh;
const axis = new THREE.Vector3(0,1,0);
const cameraDisplacement = new THREE.Vector3(0,0,1);
const group = new THREE.Group();
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.01, 10);
camera.position.z = 2;
scene = new THREE.Scene();
geometry = new THREE.IcosahedronGeometry(1, 16);
const count = geometry.attributes.position.count;
for (let i = 0; i < count; i++) {
const x = geometry.attributes.position.getX(i);
if (x >= 0.7){
geometry.attributes.position.setX(i, 1.4 - x);
}
}
geometry.computeVertexNormals();
geometry.attributes.position.needsUpdate = true;
geometry.attributes.normal.needsUpdate = true;
material = new THREE.MeshStandardMaterial({
flatShading: true
});
light = new THREE.PointLight("white", 1, 0, 2);
light.shadow.enabled = true;
light.shadow.mapSize.width = 4096;
light.shadow.mapSize.height = 4096;
light.shadow.bias = -0.0002;
light.castShadow = true;
mesh = new THREE.Mesh(geometry, material);
mesh.position.set(-20, 0, 0);
mesh.rotation.set(0,-1.5,0);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
group.add(light);
scene.add(group);
renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
}
function animate() {
requestAnimationFrame(animate);
mesh.position.applyAxisAngle(axis, 0.001);
group.position.copy(mesh.position);
group.position.multiplyScalar(-1);
/* mesh.rotation.x += 0.01 */
renderer.render(scene, camera);
}