minimal three.js

with orbitControls, XZgrid, info

by Rebecca Chen

HTML

<div id="info">minimal three.js</div>
<script src="https://threejs.org/build/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js">
</script>

CSS

#info {
  position: absolute;
  top: 0px;
  width: 100%;
  padding: 10px;
  text-align: center;
  color: #ffff00
}

body {
  overflow: hidden;
}

JavaScript

var camera, scene, renderer;

init();
animate();

function init() {

  scene = new THREE.Scene();

  renderer = new THREE.WebGLRenderer();
  renderer.setSize(window.innerWidth, window.innerHeight);
  renderer.setClearColor(0x888888);
  document.body.appendChild(renderer.domElement);

  camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 1000);
  camera.position.z = 500;
  let controls = new THREE.OrbitControls(camera, renderer.domElement);

  ////////////////////////////////////////////////////////////////
  var gridXZ = new THREE.GridHelper(200, 20, 'red', 'white');
  //scene.add(gridXZ);
  
  var ground = new THREE.Mesh (new THREE.PlaneGeometry (200,200), new THREE.MeshNormalMaterial());
  scene.add (ground);
  ground.rotation.x = -Math.PI/2;

	var platform1 = new THREE.Mesh (new THREE.BoxGeometry (80,30,60), new THREE.MeshNormalMaterial());
  scene.add (platform1);
	platform1.position.set (-60, 15, -70);

	var platform2 = new THREE.Mesh (new THREE.BoxGeometry (60,20,200), new THREE.MeshNormalMaterial());
  scene.add (platform2);
	platform2.position.set (70, 10, 0);
}

function animate() {

  requestAnimationFrame(animate);
  render();

}

function render() {

  renderer.render(scene, camera);

}