Created
May 1, 2018 19:48
-
-
Save Dexdot/cd0111694c48a6c79a512a3cb10ad2f5 to your computer and use it in GitHub Desktop.
Three.js base setup
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
| import * as THREE from 'three'; | |
| const OrbitControls = require('three-orbit-controls')(THREE); | |
| let camera, | |
| controls, | |
| scene, | |
| renderer, | |
| mesh, | |
| time = 0; | |
| const animate = () => { | |
| time++; | |
| renderer.render(scene, camera); | |
| requestAnimationFrame(animate); | |
| }; | |
| const init = () => { | |
| scene = new THREE.Scene(); | |
| scene.background = new THREE.Color(0x000000); | |
| renderer = new THREE.WebGLRenderer(); | |
| renderer.setPixelRatio = window.devicePixelRatio; | |
| renderer.setSize(window.innerWidth, window.innerWidth); | |
| const container = document.getElementById('container'); | |
| container.appendChild(renderer.domElement); | |
| camera = new THREE.PerspectiveCamera( | |
| 90, | |
| window.innerWidth / window.innerHeight, | |
| 1, | |
| 3000 | |
| ); | |
| camera.position.z = 200; | |
| controls = new OrbitControls(camera, renderer.domElement); | |
| window.addEventListener('resize', () => { | |
| renderer.setSize(window.innerWidth, window.innerHeight); | |
| camera.aspect = window.innerWidth / window.innerHeight; | |
| camera.updateProjectionMatrix(); | |
| }); | |
| animate(); | |
| }; | |
| init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment