A Pen by Gerben Neven on CodePen.
Created
October 25, 2018 08:14
-
-
Save gerbyzation/86021e0df1a8ca0e236075d6db153e7c to your computer and use it in GitHub Desktop.
S1-00_Basic-structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Global variables | |
var scene, camera, renderer; | |
var geometry, material, mesh; | |
function init(){ | |
// Create an empty scene -------------------------- | |
scene = new THREE.Scene(); | |
// Create a basic perspective camera -------------- | |
camera = new THREE.PerspectiveCamera(35, window.innerWidth/window.innerHeight, 300, 10000 ); | |
// Create a renderer with Antialiasing ------------ | |
renderer = new THREE.WebGLRenderer({antialias:true}); | |
// Configure renderer clear color | |
renderer.setClearColor("#000000"); | |
// Configure renderer size | |
renderer.setSize( window.innerWidth, window.innerHeight ); | |
// Append Renderer to DOM | |
document.body.appendChild( renderer.domElement ); | |
} | |
function geometry(){ | |
// Create a Cube Mesh with basic material --------- | |
geometry = new THREE.BoxGeometry(100, 100, 100); | |
material = new THREE.MeshBasicMaterial( { color: "#433F81" } ); | |
mesh = new THREE.Mesh( geometry, material ); | |
mesh.position.z = -1000; | |
// Add mesh to scene | |
scene.add( mesh ); | |
} | |
// Render Loop | |
var render = function () { | |
requestAnimationFrame( render ); | |
//mesh.rotation.x += 0.01; //Continuously rotate the mesh | |
//mesh.rotation.y += 0.01; | |
renderer.setClearColor("#000000"); | |
// Render the scene | |
renderer.render(scene, camera); | |
}; | |
init(); | |
geometry(); | |
render(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/97/three.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { margin: 0; } | |
canvas { width: 100%; height: 100% } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment