Skip to content

Instantly share code, notes, and snippets.

@adegard
Created June 16, 2021 19:20
Show Gist options
  • Save adegard/8a49fbfefc6ae7bdfa328a1259b048e9 to your computer and use it in GitHub Desktop.
Save adegard/8a49fbfefc6ae7bdfa328a1259b048e9 to your computer and use it in GitHub Desktop.
Three.js - Fundamentals
/*bug-in-github-api-content-can-not-be-empty*/
<canvas id="c"></canvas>
// 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();
{"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