Last active
June 18, 2020 12:11
-
-
Save duhaime/d9cd23df3e36c5045de3b96cc3662d70 to your computer and use it in GitHub Desktop.
minimal three.js scene
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset='UTF-8'> | |
<style>* {margin: 0; padding: 0; height: 100%; width: 100%;}</style> | |
</head> | |
<body> | |
<script src='https://cdnjs.cloudflare.com/ajax/libs/three.js/110/three.min.js'></script> | |
<script> | |
var scene = new THREE.Scene(); | |
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); | |
camera.position.z = 5; | |
var renderer = new THREE.WebGLRenderer({antialias: true}); | |
renderer.setSize( window.innerWidth, window.innerHeight ); | |
document.body.appendChild( renderer.domElement ); | |
// geom | |
var geometry = new THREE.BoxGeometry( 1, 1, 1 ); | |
var material = new THREE.MeshPhongMaterial({ color: 0xffff00 }) | |
var cube = new THREE.Mesh( geometry, material ); | |
scene.add( cube ); | |
// light | |
var light = new THREE.PointLight( 0xffffff, .7, 0 ); | |
light.position.set(1, 1, 100 ); | |
scene.add(light) | |
// main | |
function animate() { | |
requestAnimationFrame( animate ); | |
renderer.render( scene, camera ); | |
cube.rotation.y += 0.01; | |
cube.rotation.z += 0.01; | |
} | |
animate(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment