A few WebGL and Three.js code experiments, inspired by the « Intro to WebGL with Three.js » slides of David Scott Lyons.
- Setting up renderer, camera, scene and ambient light (required for textures)
- Box and sphere meshes
- Dashed lines WebGL engine is a rasterizer – it supports drawing dots and lines, not only triangles
- Mixing HTML with WebGL canvas: transparent overlay composition works quite fast!
- Animating the scene, every 15ms
- Camera orbit controls loading as an ES6 module was a bit tricky
- Correctly setting aspect ratio and canvas dimension with CSS
(using.clientWidth/Height
CSS properties – see WebGL Anti-patterns #2) - Texturing the sphere with a color map (the earth)
- Using PRPL HTTP2 server to serve assets (script, libraries and textures)
- Importing libraries as ES6 modules
Run the HTTP local server:
cd codelabs/intro-to-webgl
npm start
and then open your browser at localhost:8080
.
Assuming you have Git and Node installed:
git clone [email protected]:olange/learning-webgl.git
cd learning-webgl
cd codelabs/intro-to-webgl
npm install