2019-09-23 14:52:06 +02:00
|
|
|
// Computes the aspect ratio of the window.
|
|
|
|
let aspectRatio = window.innerWidth / window.innerHeight;
|
2019-09-23 12:04:36 +02:00
|
|
|
|
2019-09-23 14:52:06 +02:00
|
|
|
// Creates a camera and sets its parameters and position.
|
|
|
|
let camera = new THREE.PerspectiveCamera(70, aspectRatio, 0.01, 10);
|
|
|
|
camera.position.z = 1;
|
2019-09-23 12:04:36 +02:00
|
|
|
|
2019-09-23 14:52:06 +02:00
|
|
|
// Creates the scene that contains our objects.
|
|
|
|
let scene = new THREE.Scene();
|
2019-09-23 12:04:36 +02:00
|
|
|
|
2019-09-23 14:52:06 +02:00
|
|
|
// Creates a geometry (vertices and faces) corresponding to a cube.
|
|
|
|
let geometry = new THREE.BoxGeometry(0.2, 0.2, 0.2);
|
2019-09-23 12:04:36 +02:00
|
|
|
|
2019-09-23 14:52:06 +02:00
|
|
|
// Creates a material that paints the faces depending on their normal.
|
|
|
|
let material = new THREE.MeshNormalMaterial();
|
2019-09-23 12:04:36 +02:00
|
|
|
|
2019-09-23 14:52:06 +02:00
|
|
|
// Creates a mesh that associates the geometry with the material.
|
|
|
|
let mesh = new THREE.Mesh(geometry, material);
|
2019-09-23 12:04:36 +02:00
|
|
|
|
2019-09-23 14:52:06 +02:00
|
|
|
// Adds the mesh to the scene.
|
|
|
|
scene.add(mesh);
|
2019-09-23 12:04:36 +02:00
|
|
|
|
2019-09-23 14:52:06 +02:00
|
|
|
// Creates the renderer and append its canvas to the DOM.
|
|
|
|
renderer = new THREE.WebGLRenderer({ antialias: true });
|
|
|
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
|
|
document.body.appendChild(renderer.domElement);
|
2019-09-23 12:04:36 +02:00
|
|
|
|
2019-09-23 14:52:06 +02:00
|
|
|
// Renders the scene with the camera.
|
|
|
|
renderer.render(scene, camera);
|