Skip to content

Instantly share code, notes, and snippets.

@hashrock
Created September 6, 2017 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hashrock/00ea7e78332eb0f2034a1dec85cc1ec4 to your computer and use it in GitHub Desktop.
Save hashrock/00ea7e78332eb0f2034a1dec85cc1ec4 to your computer and use it in GitHub Desktop.
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/87/three.module.js";
export function init(){
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshLambertMaterial({color:'rgb(210,255,255)'});
var cube = new THREE.Mesh( geometry, material );
scene.add( cube );
var light = new THREE.PointLight( 0xff0055, 1, 100 );
light.position.set( 2, 2, 2 );
scene.add( light );
var light2 = new THREE.PointLight( 0x000055, 1, 100 );
light2.position.set( -2, -2, 2 );
scene.add( light2 );
camera.position.z = 5;
var animate = function () {
requestAnimationFrame( animate );
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render(scene, camera);
};
animate();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment