SlideShare a Scribd company logo
three.js
& leap motion
An introduction & overview of 3D graphics in the browser
• 3D primer
• What is three.js
• First steps with three.js
• What is a Leap Motion Controller
• Leap demo
• Washington Post special project review
Overview
This is not a tutorial.3D graphics in and of itself is a very complicated subject. This presentation is not a tutorial
but does attempt to cover (very briefly) the basics and help you understand where to get
started with three.js & how things fit together. With that said- the documentation around
three.js is very good and it’s fairly easy to find tutorials online.
A simple scene
consisting of a
light, cube, plane
and camera.
An Example
3D Scene
3D Primer
• The lights, cameras & objects are collectively called
a scene. In three.js it is a hierarchy & the scene is
the root of the tree.
• Objects or geometry such as cubes and planes (also
called primitives) are created by points in space
called vertices.
• A group of vertices and their edges create polygons.
• A group of polygons (objects) along with a material
create a mesh.
• The camera captures the picture and in the example
to the left we are looking through the camera.
• Lights allow us to cast shadows and render
highlights.
First Steps
with
three.js
• Follow the three.js “Getting Started” section in the docs.

https://threejs.org/docs/index.html#Manual/Introduction/Creating_a_scene
• Load a custom model instead of using geometry.
• Add a light & cast shadows.
three.js
example
.
├── index.html
├── js
│ ├── ext
│ │ ├── three.js
│ │ └── three.modules.js
│ └── main.js
└── run.py
directory structure
1 console.info("main.js loaded");
2
3 var scene = new THREE.Scene();
4 var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
5 console.info("scene & camera created");
6
7 var renderer = new THREE.WebGLRenderer();
8 renderer.setSize(window.innerWidth, window.innerHeight);
9 console.info("renderer created");
10
11 document.body.appendChild(renderer.domElement);
12 console.info("DOM modified");
13
14 var geometry = new THREE.BoxGeometry(1, 1, 1);
15 var material = new THREE.MeshBasicMaterial({color: 0x00ff00});
16 var cube = new THREE.Mesh(geometry, material);
17 scene.add(cube);
18 console.info("Cube created");
19
20 camera.position.z = 5;
21 console.info("Camera repositioned");
22
23 function render() {
24 // Animate the cube
25 cube.rotation.x += 0.01;
26 cube.rotation.y += 0.01;
27 requestAnimationFrame(render);
28 renderer.render(scene, camera);
29 }
30 console.info("Starting render")
31 render();
demo
Free “digger” model from
TurboSquid.
loading
custom
models
Model geometry must be
triangulated.
Note how there are now
diagonal lines and all of
the surfaces have
triangles.
Sidebar:
Use a 3D graphics program to
adjust your model’s geometry.
Any 3D program can adjust geometry. Blender
is free and can easily do this for us.
Loading
JSON
• Use the free utility from the three.js project to convert from
OBJ to JSON.

https://github.com/alteredq/three.js/blob/master/utils/exporters/convert_obj_three.py
• Use the built-in JSONLoader to load the object.
• Watch file sizes! If you are using a “real” web server
enable gzip compression!
1 var greenMat = new THREE.MeshBasicMaterial({color: 0x00ff00});
2
3 // Create a JSON loader
4 var loader = new THREE.JSONLoader();
5
6 // Load triangulated model as JSON
7 loader.load(
8 'models/digger_scaled_tri.json',
9 // onLoad callback
10 function (geometry) {
11 // Add geometry to a new mesh combining a material
12 var object = new THREE.Mesh(geometry, greenMat);
13 // Add our object to the scene
14 scene.add(object);
15 }
16 );
demo
lighting &
shadows
three.js has many types of
lights but we’ll focus on the
directional light.
• Directional lights shine from a specific direction
not a specific location.
• The documentation describes this as a light that
acts like the sun.
• Shadows are only calculated for objects that
exist within the light’s shadow camera’s field of
view.
• The shadow camera for a directional light is
orthographic (think 2D, e.g. top down).
• In the picture to the left the orange lines denote
the shadow camera’s field of view.
three.js uses shadow
mapping with the WebGL
renderer.
• Shadow mapping was introduced by Lance
Williams in 1978.
• Computation takes place on the GPU with
WebGL.
• Think of a shadow map like a texture map. They
are applied (mapped) to the surface of the
geometry during rendering.
• The size of the map directly affects the shadow
detail because the size of the map is the size of
the buffer and a larger map/buffer can hold more
information about the shadow.
• Shadows aren’t necessarily hard but they
require some tweaking and experimenting to get
right.
demo
The Leap Motion Controller lets you use your computer in a whole new way.
Reach out and swipe, grab, pinch, or punch your way through the digital world.
• Uses two wide angle IR cameras to detect hands in 3D space above the device.
• Tracks hands, fingers and wrists / arms and translates motion from real world
space to 3D environment coordinates.
• For developers it is plug & play and very accessible.
• It is a bit finicky and detecting / supporting custom gestures can be laborious.
Leap Motion Controller
demo
In 2015 I was contracted to help build a 3D interactive
experience exploring the restoration of the U.S. Capitol
Dome.
The interactive experience took place at the White House
Correspondents Dinner. The scope was narrowed down to
build a kiosk where visitors could approach one of two large
displays and interact with a 3D model of the dome using a
Leap Motion controller.
Washington Post
Special Project
3D
Model
three.js enabled the rapid
development & delivery of
the experience within a
browser.
Many issues could be ignored because we were operating as a kiosk
in a known environment:
• Device hardware specs were known (fast enough to ignore
optimizations)
• No external bandwidth requirements (all files are hosted & served
locally)
• Human explanations & help to explain how to interact with the
demo.
• No need to open up “heavier” tooling such as Unity.
Leap
Motion
Web
Browser
three.js
early prototype
Things didn’t go as planned
3 Weeks to Deliver
Interaction

Spent the majority of the time
figuring out gestures and hand
controls. Tried “gimbal” controls.
Settled on “joystick” controls.
“Hot Spots” & Polishing

Used ray casting for “fast enough”
collision detection between hands
and “hot spots”. Added dynamic
“demo” mode to pique interest.
Rendering & Lighting

Lost a good chunk of time to loading
a model of the entire capital.
Reverted to just the dome. Had
trouble with shadows & model size.
demo
THANK YOU!
@leetrout

More Related Content

PDF
ODP
Introduction to threejs
PPTX
Introduction to three.js
PDF
The next frontier: WebGL and WebVR
PDF
From Hello World to the Interactive Web with Three.js: Workshop at FutureJS 2014
PDF
WebGL and three.js
PPTX
WebGL and three.js - Web 3D Graphics
PDF
Three.js basics
Introduction to threejs
Introduction to three.js
The next frontier: WebGL and WebVR
From Hello World to the Interactive Web with Three.js: Workshop at FutureJS 2014
WebGL and three.js
WebGL and three.js - Web 3D Graphics
Three.js basics

What's hot (20)

PDF
Creating Applications with WebGL and Three.js
PDF
HTML5 game dev with three.js - HexGL
PDF
ENEI16 - WebGL with Three.js
PDF
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
PPTX
WebGL - 3D programming
PPTX
[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...
PDF
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
PDF
WebGL 3D player
PDF
Thomson Tom design_engineer_portfolio
PPTX
Developing Web Graphics with WebGL
PDF
Real-time collaborative drawing
KEY
Draw stuff at @jsnortheast
PDF
Leaving Flatland: Getting Started with WebGL- SXSW 2012
PDF
Augmented Reality in JavaScript
PDF
ITNetwork - 3D na webu
PDF
Ro 786 preview _tech art_
PDF
An Impromptu Introduction to HTML5 Canvas
PDF
OpenVisConf - WebGL for graphics and data visualization
PPTX
Introduction to open gl in android droidcon - slides
PDF
OL3-Cesium: 3D for OpenLayers maps
Creating Applications with WebGL and Three.js
HTML5 game dev with three.js - HexGL
ENEI16 - WebGL with Three.js
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
WebGL - 3D programming
[JS EXPERIENCE 2018] Jogos em JavaScript com WebGL - Juliana Negreiros, Codem...
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
WebGL 3D player
Thomson Tom design_engineer_portfolio
Developing Web Graphics with WebGL
Real-time collaborative drawing
Draw stuff at @jsnortheast
Leaving Flatland: Getting Started with WebGL- SXSW 2012
Augmented Reality in JavaScript
ITNetwork - 3D na webu
Ro 786 preview _tech art_
An Impromptu Introduction to HTML5 Canvas
OpenVisConf - WebGL for graphics and data visualization
Introduction to open gl in android droidcon - slides
OL3-Cesium: 3D for OpenLayers maps
Ad

Viewers also liked (9)

PPTX
老成之CreateJS與Flash
PPTX
Three.js 一場從2D變成3D的冒險
PDF
Build the Virtual Reality Web with A-Frame
PPTX
PDF
WebVR - MobileTechCon Berlin 2016
PDF
An Introduction to WebVR – or How to make your user sick in 60 seconds
PDF
My adventure with Elm
PDF
Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!
PPTX
WebVR Ecosystem and API Update
老成之CreateJS與Flash
Three.js 一場從2D變成3D的冒險
Build the Virtual Reality Web with A-Frame
WebVR - MobileTechCon Berlin 2016
An Introduction to WebVR – or How to make your user sick in 60 seconds
My adventure with Elm
Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!
WebVR Ecosystem and API Update
Ad

Similar to Introduction to three.js & Leap Motion (20)

PPTX
COMP340 TOPIC 4 THREE.JS.pptx
PPTX
is three.js better for developing web-based 3d games?
PPTX
Class[6][5th aug] [three js-loaders]
PDF
Begin three.js.key
PPTX
TampereJS June 2018 - Easy 3d drawing with three.js
PDF
Create Basic 3D Scenes Using Three.js
PDF
three.js WebGL library presentation
PPTX
Class[5][9th jul] [three js-meshes_geometries_and_primitives]
PPTX
Exploring-javafx-3d
PDF
Augmented reality in web rtc browser
DOC
Learn Java 3D
PDF
Introduction to 3D Mapping with X3D
PDF
Web3D - Semantic standards, WebGL, HCI
PPTX
GFX part 8 - Three.js introduction and usage
PDF
Getting started with Verold and Three.js
PDF
Introduction to data visualisation with D3
KEY
WebGL Camp 4 - A3 3D Engine
PDF
3D everywhere
PPT
Advanced Game Development with the Mobile 3D Graphics API
PDF
Bb 8 run - a star wars video game
COMP340 TOPIC 4 THREE.JS.pptx
is three.js better for developing web-based 3d games?
Class[6][5th aug] [three js-loaders]
Begin three.js.key
TampereJS June 2018 - Easy 3d drawing with three.js
Create Basic 3D Scenes Using Three.js
three.js WebGL library presentation
Class[5][9th jul] [three js-meshes_geometries_and_primitives]
Exploring-javafx-3d
Augmented reality in web rtc browser
Learn Java 3D
Introduction to 3D Mapping with X3D
Web3D - Semantic standards, WebGL, HCI
GFX part 8 - Three.js introduction and usage
Getting started with Verold and Three.js
Introduction to data visualisation with D3
WebGL Camp 4 - A3 3D Engine
3D everywhere
Advanced Game Development with the Mobile 3D Graphics API
Bb 8 run - a star wars video game

Recently uploaded (20)

PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
assetexplorer- product-overview - presentation
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
history of c programming in notes for students .pptx
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Understanding Forklifts - TECH EHS Solution
Operating system designcfffgfgggggggvggggggggg
Why Generative AI is the Future of Content, Code & Creativity?
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
assetexplorer- product-overview - presentation
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Computer Software and OS of computer science of grade 11.pptx
Digital Systems & Binary Numbers (comprehensive )
history of c programming in notes for students .pptx
Navsoft: AI-Powered Business Solutions & Custom Software Development
How to Choose the Right IT Partner for Your Business in Malaysia
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
wealthsignaloriginal-com-DS-text-... (1).pdf
Softaken Excel to vCard Converter Software.pdf
Odoo Companies in India – Driving Business Transformation.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Upgrade and Innovation Strategies for SAP ERP Customers
Which alternative to Crystal Reports is best for small or large businesses.pdf
Understanding Forklifts - TECH EHS Solution

Introduction to three.js & Leap Motion

  • 1. three.js & leap motion An introduction & overview of 3D graphics in the browser
  • 2. • 3D primer • What is three.js • First steps with three.js • What is a Leap Motion Controller • Leap demo • Washington Post special project review Overview
  • 3. This is not a tutorial.3D graphics in and of itself is a very complicated subject. This presentation is not a tutorial but does attempt to cover (very briefly) the basics and help you understand where to get started with three.js & how things fit together. With that said- the documentation around three.js is very good and it’s fairly easy to find tutorials online.
  • 4. A simple scene consisting of a light, cube, plane and camera. An Example 3D Scene 3D Primer • The lights, cameras & objects are collectively called a scene. In three.js it is a hierarchy & the scene is the root of the tree. • Objects or geometry such as cubes and planes (also called primitives) are created by points in space called vertices. • A group of vertices and their edges create polygons. • A group of polygons (objects) along with a material create a mesh. • The camera captures the picture and in the example to the left we are looking through the camera. • Lights allow us to cast shadows and render highlights.
  • 5. First Steps with three.js • Follow the three.js “Getting Started” section in the docs.
 https://threejs.org/docs/index.html#Manual/Introduction/Creating_a_scene • Load a custom model instead of using geometry. • Add a light & cast shadows.
  • 7. . ├── index.html ├── js │ ├── ext │ │ ├── three.js │ │ └── three.modules.js │ └── main.js └── run.py directory structure
  • 8. 1 console.info("main.js loaded"); 2 3 var scene = new THREE.Scene(); 4 var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); 5 console.info("scene & camera created"); 6 7 var renderer = new THREE.WebGLRenderer(); 8 renderer.setSize(window.innerWidth, window.innerHeight); 9 console.info("renderer created"); 10 11 document.body.appendChild(renderer.domElement); 12 console.info("DOM modified"); 13 14 var geometry = new THREE.BoxGeometry(1, 1, 1); 15 var material = new THREE.MeshBasicMaterial({color: 0x00ff00}); 16 var cube = new THREE.Mesh(geometry, material); 17 scene.add(cube); 18 console.info("Cube created"); 19 20 camera.position.z = 5; 21 console.info("Camera repositioned"); 22 23 function render() { 24 // Animate the cube 25 cube.rotation.x += 0.01; 26 cube.rotation.y += 0.01; 27 requestAnimationFrame(render); 28 renderer.render(scene, camera); 29 } 30 console.info("Starting render") 31 render();
  • 10. Free “digger” model from TurboSquid. loading custom models
  • 11. Model geometry must be triangulated. Note how there are now diagonal lines and all of the surfaces have triangles.
  • 12. Sidebar: Use a 3D graphics program to adjust your model’s geometry. Any 3D program can adjust geometry. Blender is free and can easily do this for us.
  • 13. Loading JSON • Use the free utility from the three.js project to convert from OBJ to JSON.
 https://github.com/alteredq/three.js/blob/master/utils/exporters/convert_obj_three.py • Use the built-in JSONLoader to load the object. • Watch file sizes! If you are using a “real” web server enable gzip compression!
  • 14. 1 var greenMat = new THREE.MeshBasicMaterial({color: 0x00ff00}); 2 3 // Create a JSON loader 4 var loader = new THREE.JSONLoader(); 5 6 // Load triangulated model as JSON 7 loader.load( 8 'models/digger_scaled_tri.json', 9 // onLoad callback 10 function (geometry) { 11 // Add geometry to a new mesh combining a material 12 var object = new THREE.Mesh(geometry, greenMat); 13 // Add our object to the scene 14 scene.add(object); 15 } 16 );
  • 15. demo
  • 17. three.js has many types of lights but we’ll focus on the directional light. • Directional lights shine from a specific direction not a specific location. • The documentation describes this as a light that acts like the sun. • Shadows are only calculated for objects that exist within the light’s shadow camera’s field of view. • The shadow camera for a directional light is orthographic (think 2D, e.g. top down). • In the picture to the left the orange lines denote the shadow camera’s field of view.
  • 18. three.js uses shadow mapping with the WebGL renderer. • Shadow mapping was introduced by Lance Williams in 1978. • Computation takes place on the GPU with WebGL. • Think of a shadow map like a texture map. They are applied (mapped) to the surface of the geometry during rendering. • The size of the map directly affects the shadow detail because the size of the map is the size of the buffer and a larger map/buffer can hold more information about the shadow. • Shadows aren’t necessarily hard but they require some tweaking and experimenting to get right.
  • 19. demo
  • 20. The Leap Motion Controller lets you use your computer in a whole new way. Reach out and swipe, grab, pinch, or punch your way through the digital world. • Uses two wide angle IR cameras to detect hands in 3D space above the device. • Tracks hands, fingers and wrists / arms and translates motion from real world space to 3D environment coordinates. • For developers it is plug & play and very accessible. • It is a bit finicky and detecting / supporting custom gestures can be laborious. Leap Motion Controller
  • 21. demo
  • 22. In 2015 I was contracted to help build a 3D interactive experience exploring the restoration of the U.S. Capitol Dome. The interactive experience took place at the White House Correspondents Dinner. The scope was narrowed down to build a kiosk where visitors could approach one of two large displays and interact with a 3D model of the dome using a Leap Motion controller. Washington Post Special Project
  • 23. 3D Model three.js enabled the rapid development & delivery of the experience within a browser. Many issues could be ignored because we were operating as a kiosk in a known environment: • Device hardware specs were known (fast enough to ignore optimizations) • No external bandwidth requirements (all files are hosted & served locally) • Human explanations & help to explain how to interact with the demo. • No need to open up “heavier” tooling such as Unity. Leap Motion Web Browser three.js
  • 25. Things didn’t go as planned
  • 26. 3 Weeks to Deliver Interaction
 Spent the majority of the time figuring out gestures and hand controls. Tried “gimbal” controls. Settled on “joystick” controls. “Hot Spots” & Polishing
 Used ray casting for “fast enough” collision detection between hands and “hot spots”. Added dynamic “demo” mode to pique interest. Rendering & Lighting
 Lost a good chunk of time to loading a model of the entire capital. Reverted to just the dome. Had trouble with shadows & model size.
  • 27. demo