Created
August 24, 2020 16:34
-
-
Save pjbelo/4c0928468ee5a012076d04a947158cdd to your computer and use it in GitHub Desktop.
my3DProject.js
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
// my3DProject.js | |
var camera, scene, renderer; | |
var geometry, material, box; | |
init(); | |
animate(); | |
function init() { | |
scene = new THREE.Scene(); | |
geometry = new THREE.BoxGeometry(); | |
material = new THREE.MeshNormalMaterial(); | |
box = new THREE.Mesh( geometry, material ); | |
scene.add( box ); | |
var fov = 70; | |
var aspect = window.innerWidth / window.innerHeight; | |
var near = 0.10; | |
var far = 100; | |
camera = new THREE.PerspectiveCamera(fov, aspect, near, far); | |
camera.position.z = 4; | |
renderer = new THREE.WebGLRenderer( { antialias: true } ); | |
renderer.setSize( window.innerWidth, window.innerHeight ); | |
document.body.appendChild( renderer.domElement ); | |
} | |
function animate() { | |
requestAnimationFrame( animate ); | |
autoRotate(); | |
renderer.render( scene, camera ); | |
} | |
function autoRotate() { | |
box.rotation.x += 0.01; | |
box.rotation.y += 0.02; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment