A simple sphere with Three.js .

By | 19/05/2017

This tutorial is about how to add a simple wireframe sphere into your webpage using the javascript 3D library named three.js.
This 3D library and some demo and examples can be found here.
The tutorial for today is to let you know how to deal with a simple object.
First, you need to make a folder named project.
Into this folder create two folder named js and css.
Into the project create an index.html file and add this content:

Make a file named style.css into css folder and add this:

This wi
Into js folder create a file named index.js and add this source code:

This javascript file follows some steps to make the wireframe sphere:

  • make the scene;
  • set the camera;
  • create the renderer space;
  • add the renderer space to HTML document;
  • create sphere
  • add one material ;
  • make a wireframe from geometry variable;
  • create a wireframe object;
  • create a line like a wireframe object;
  • deal with line material;
  • add a line to the scene;
  • set the position of the camera;
  • create the render function to animate the content;
  • run all with a render function.

The result is something like this:

Some changes can be used in this example to see how is working.
You can remove the css folder and style file but you need to remove this line from index.html file:

The sphere variable can be added into javascript source code:

This will make some change into the render canvas.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.