Created
June 16, 2021 19:20
-
-
Save adegard/8a49fbfefc6ae7bdfa328a1259b048e9 to your computer and use it in GitHub Desktop.
Three.js - Fundamentals
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
/*bug-in-github-api-content-can-not-be-empty*/ |
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
<canvas id="c"></canvas> | |
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
// Three.js - Fundamentals | |
// from https://threejsfundamentals.org/threejs/threejs-fundamentals.html | |
import * as THREE from 'https://threejsfundamentals.org/threejs/resources/threejs/r127/build/three.module.js'; | |
function main() { | |
const canvas = document.querySelector('#c'); | |
const renderer = new THREE.WebGLRenderer({canvas}); | |
const fov = 75; | |
const aspect = 2; // the canvas default | |
const near = 0.1; | |
const far = 5; | |
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far); | |
camera.position.z = 2; | |
const scene = new THREE.Scene(); | |
const boxWidth = 1; | |
const boxHeight = 1; | |
const boxDepth = 1; | |
const geometry = new THREE.BoxGeometry(boxWidth, boxHeight, boxDepth); | |
const material = new THREE.MeshBasicMaterial({color: 0x44aa88}); // greenish blue | |
const cube = new THREE.Mesh(geometry, material); | |
scene.add(cube); | |
renderer.render(scene, camera); | |
} | |
main(); |
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
{"name":"Three.js - Fundamentals","settings":{},"filenames":["index.html","index.css","index.js"]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment