Last active
July 26, 2019 16:24
-
-
Save anacampesan/415c00b74b97174d4563292c3d815b90 to your computer and use it in GitHub Desktop.
Three JS Snippets
This file contains 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
// Scene | |
const container = document.querySelector('#scene-container'); | |
var scene = new THREE.Scene(); | |
scene.background = new THREE.Color('blue'); | |
//scene.add(stuff) | |
// Renderer | |
const renderer = new THREE.WebGLRenderer({alpha: true}); | |
renderer.setSize(container.clientWidth, container.clientHeight); | |
renderer.setPixelRatio(window.devicePixelRatio); | |
container.appendChild(renderer.domElement); | |
renderer.render(scene, camera); | |
// Camera | |
const fov = 35; | |
const aspect = container.clientWidth / container.clientHeight; | |
const near = 0.1; | |
const far = 100; | |
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far); | |
camera.position.set(0, 0, 10); | |
// Light | |
const light = new THREE.DirectionalLight('white', 5.0); | |
light.position.set(0, 9, 0); | |
// Shapes (Geometry, Material -> Mesh) | |
const cube = new THREE.BoxBufferGeometry(dims); | |
const material = new THREE.MeshStandardMaterial({color: 'white'}); | |
const mesh = new THREE.Mesh(cube, material); | |
mesh.position.set(0, 0, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment