JSFiddle - React, Tailwind, and code Playground

by Immo Blaese

HTML

<script src="//cdn.rawgit.com/mrdoob/three.js/master/build/three.min.js"></script>

CSS

body {
	  margin: 0;
}

JavaScript

var camera, scene, renderer;
var geometry, material, container;
var radius = 0.3;

init();
initSpheresGrid();
animate();

function init() {

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

    scene = new THREE.Scene();
    
    var light = new THREE.DirectionalLight( 0xffffff );
		light.position.set( 0, 1, 1 ).normalize();
		scene.add(light);
    
    
    container = new THREE.Object3D();
    scene.add(container);

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

    var mesh = new THREE.Mesh( geometry, material );
   // container.add( mesh );

	 // add wireframe layer
  	var wireMaterial  = new THREE.MeshPhongMaterial({wireframe: true, color: 0xdddddd, transparent: false});
  	var wireFrame = new THREE.Mesh(new THREE.SphereGeometry(radius-0.01, 50, 50), wireMaterial);
    container.add( wireFrame );

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

}


function initSpheresGrid () {
		
    var phi, theta, gridPosition, sphere;
		var sphereMaterial = new THREE.MeshBasicMaterial({color:0x00ff00});
    var sphereGeometry = new THREE.SphereGeometry(0.002);

		var latitude = 0; // x 
		var longitude = 0; // y

    while (longitude < 360) {
    
    	phi = (latitude/180) * Math.PI;
			theta = (longitude/180) * Math.PI;
   
      gridPosition = {

					x:radius * Math.cos(theta) * Math.sin(phi ),
					y:radius * Math.sin(theta) * Math.sin(phi ),
					z:radius * Math.cos(phi)

			};
      
      sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
  		sphere.position.set(gridPosition.x, gridPosition.y, gridPosition.z);
    	container.add( sphere );
    
  		latitude += 10;
      if (latitude > 360) {
      	latitude = 0;
      	longitude += 10;
      }
  	
    }

}

function animate() {

   ...