Skip to content

Instantly share code, notes, and snippets.

@videlais
Created January 15, 2017 21:28
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 videlais/6fb98f1a41227a2e6188b223ea486a87 to your computer and use it in GitHub Desktop.
Save videlais/6fb98f1a41227a2e6188b223ea486a87 to your computer and use it in GitHub Desktop.
var camera, scene, renderer, geometry, material, mesh;
var texture, lightsource, controls;
function init() {
// Load a texture
texture = new THREE.TextureLoader().load( "checkered.png" );
// Create a scene
scene = new THREE.Scene();
// Create a geometry
// Create a box (cube) of 10 width, length, and height
geometry = new THREE.BoxGeometry( 10, 10, 10 );
// Create a MeshPhongMaterial with a loaded texture
material = new THREE.MeshPhongMaterial( { map: texture} );
// Combine the geometry and material into a mesh
mesh = new THREE.Mesh( geometry, material );
// Add the mesh to the scene
scene.add( mesh );
// Create an AmbientLight with the color white (0xffffff)
lightsource = new THREE.AmbientLight( 0xffffff);
// Add the light to the scene
scene.add( lightsource );
// Create a camera
// Set a Field of View (FOV) of 75 degrees
// Set an Apsect Ratio of the inner width divided by the inner height of the window
// Set the 'Near' distance at which the camera will start rendering scene objects to 2
// Set the 'Far' (draw distance) at which objects will not be rendered to 1000
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 2, 1000 );
// Move the camera 'out' by 30
camera.position.z = 30;
// Create a WebGL Renderer
renderer = new THREE.WebGLRenderer();
// Set the size of the renderer to the inner width and inner height of the window
renderer.setSize( window.innerWidth, window.innerHeight );
// Add in the created DOM element to the body of the document
document.body.appendChild( renderer.domElement );
// Add OrbitControls
controls = new THREE.OrbitControls( camera, renderer.domElement );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment