JSFiddle - React, Tailwind, and code Playground

by kirill321592

HTML

<script src="https://threejs.org/build/three.js"></script>
<script src="https://threejs.org/examples/js/geometries/ConvexGeometry.js"></script>
<script src="https://threejs.org/examples/js/QuickHull.js"></script>

CSS

body {
	  margin: 0;
}

JavaScript

var camera, scene, renderer;
var geometry, material, mesh;

init();
animate();

function init() {

    camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 100 );
    camera.position.z = 50;

    scene = new THREE.Scene();

		const radius = 20;
		const points = [];
		for (let i = 0; i < 100; i += 1) {
			const x = THREE.Math.randFloat(-1, 1);
			const y = THREE.Math.randFloat(-1, 1);
			const z = THREE.Math.randFloat(-1, 1);
			const normalizationFactor = 1 / Math.sqrt(x * x + y * y + z * z);

			points.push(new THREE.Vector3(
				x * normalizationFactor * radius,
				y * normalizationFactor * radius,
				z * normalizationFactor * radius,
			));
		}

		const geometry = new ConvexGeometry(points);
		const wireframe = new THREE.WireframeGeometry(geometry);
		const material = new THREE.LineBasicMaterial({
			color: 0xffffff,
			lineWidth: 1,
		});

		const line = new THREE.LineSegments(wireframe, material);
		console.log(geometry, wireframe, line);

		scene.add(line);

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

}

function animate() {

    requestAnimationFrame( animate );
    renderer.render( scene, camera );

}