Skip to content

Instantly share code, notes, and snippets.

@mathdoodle
Created July 31, 2015 13:01
Show Gist options
  • Save mathdoodle/5f2d6cf9bb1d49605b49 to your computer and use it in GitHub Desktop.
Save mathdoodle/5f2d6cf9bb1d49605b49 to your computer and use it in GitHub Desktop.
Phong
{
"uuid": "dd7ba6a1-11e6-4d1c-9edb-982a9554db3f",
"description": "Phong",
"dependencies": {
"davinci-threejs": "0.71.4"
},
"operatorOverloading": true
}
<!doctype html>
<html>
<head>
<style>
/* STYLE-MARKER */
</style>
<!-- SCRIPTS-MARKER -->
</head>
<body>
<script>
// CODE-MARKER
</script>
</body>
</html>
var scene = new THREE.Scene();
var camera: THREE.PerspectiveCamera;
var renderer = new THREE.WebGLRenderer();
var mesh: THREE.Mesh;
init();
animate();
/**
* Initializes the scene.
*/
function init() {
var aspect = window.innerWidth / window.innerHeight;
camera = new THREE.PerspectiveCamera(75, aspect, 1, 1000);
camera.position.z = 200;
scene.add(camera);
var geometry = new THREE.BoxGeometry(100, 100, 100);
var material = new THREE.MeshPhongMaterial({
ambient: 0x555555,
color: 0x555555,
specular: 0xffffff,
shininess: 50,
shading: THREE.SmoothShading
});
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
var light1 = new THREE.PointLight(0xff0040, 2, 0);
light1.position.set(200, 100, 300);
scene.add(light1);
var light2 = new THREE.PointLight(0x0040ff, 2, 0);
light2.position.set(-200, 100, 300);
scene.add(light2);
//renderer.setClearColor(0xFFFFFF, 1.0);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.style.margin = '0px';
document.body.style.overflow = 'hidden';
document.body.appendChild(renderer.domElement);
}
/**
* Animates the scene.
*/
function animate() {
requestAnimationFrame(animate);
mesh.rotation.x = Date.now() * 0.0005;
mesh.rotation.y = Date.now() * 0.001;
renderer.render(scene, camera);
}
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