Slide 1

Slide 1 text

Modeling the Physical
 World with Three.js Berlin.js · June 21, 2018

Slide 2

Slide 2 text

Patrick Dubroy @dubroy lyft.com/level5

Slide 3

Slide 3 text

• Opened Dec. 1 • 18 engineers now - Goal of 35 in 2018 - Space for ~100 in 2019 • HD Mapping & localization • Frontend: viz + internal tools • We are hiring!

Slide 4

Slide 4 text

Three.js • Raw WebGL is very low-level • Three.js provides: - Scene graph API - Math library (Vector3, Matrix4, Quaternion, etc.) - Other helpers for audio, animation, etc.

Slide 5

Slide 5 text

My first three.js app body { margin: 0; } canvas { width: 100%; height: 100% } // Our Javascript will go here. Hello Three.js

Slide 6

Slide 6 text

const {innerWidth, innerHeight} = window; const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera( 75, innerWidth / innerHeight, 0.1, 1000); const renderer = new THREE.WebGLRenderer(); renderer.setSize(innerWidth, innerHeight); document.body.appendChild(renderer.domElement); Creating a scene

Slide 7

Slide 7 text

const geometry = new THREE.BoxGeometry(1, 1, 1); const material = new THREE.MeshBasicMaterial({ color: 0x648fff }); const cube = new THREE.Mesh(geometry, material); scene.add(cube); camera.position.z = 5; Creating an object

Slide 8

Slide 8 text

function animate() { requestAnimationFrame(animate); cube.rotation.x += 0.01; cube.rotation.y += 0.01; renderer.render(scene, camera); } animate(); Rendering the scene ▶

Slide 9

Slide 9 text

const {innerWidth, innerHeight} = window; const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera( 75, innerWidth / innerHeight, 0.1, 1000); const renderer = new THREE.WebGLRenderer(); renderer.setSize(innerWidth, innerHeight); document.body.appendChild(renderer.domElement); Creating a scene

Slide 10

Slide 10 text

Coordinates

Slide 11

Slide 11 text

(0, 0) X Y Viewport Coordinates 2D

Slide 12

Slide 12 text

(0, 0) X Y Viewport (0, 0, 0) X Y Viewport Z Coordinates 2D 3D

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Near plane Far plane

Slide 15

Slide 15 text

Near plane Far plane

Slide 16

Slide 16 text

const {innerWidth, innerHeight} = window; const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera( 75, innerWidth / innerHeight, 0.1, 1000); const renderer = new THREE.WebGLRenderer(); renderer.setSize(innerWidth, innerHeight); document.body.appendChild(renderer.domElement); Creating a scene Field of view (degrees) Aspect ratio Distance to
 near plane Distance to
 far plane

Slide 17

Slide 17 text

const geometry = new THREE.BoxGeometry(1, 1, 1); const material = new THREE.MeshBasicMaterial({ color: 0x648fff }); const cube = new THREE.Mesh(geometry, material); scene.add(cube); camera.position.z = 5; Creating an object

Slide 18

Slide 18 text

Demo: Map Visualization ▶

Slide 19

Slide 19 text

function createLineWithPointsAndColor( points: THREE.Vector3[], color: number) { const geometry = new THREE.Geometry(); for (const p of points) { geometry.vertices.push(p); } const material = new THREE.LineBasicMaterial({ color }); return new THREE.Line(geometry, material); } Rendering Lanes

Slide 20

Slide 20 text

Understanding
 the scene graph

Slide 21

Slide 21 text

… …

Slide 22

Slide 22 text

Transformations … …

Slide 23

Slide 23 text

(.39, 0, -.6) Transformations • Each object defines its own coordinate system or frame • An object’s pose is its position and rotation relative to its parent - obj.rotation / obj.position … … (1.2, 0, 1.9)

Slide 24

Slide 24 text

• Each object defines its own coordinate system or frame • An object’s pose is its position and rotation relative to its parent - obj.rotation / obj.position Transformations … … (.39, 0, -.6) (1.2, 0, 1.9) (-.39, 0, .6) (-1.2, 0, -1.9)

Slide 25

Slide 25 text

• Each object defines its own coordinate system or frame • An object’s pose is its position and rotation relative to its parent - obj.rotation / obj.position Transformations … … (.39, 0, -.6) (1.2, 0, 1.9) (-.39, 0, .6) (-1.2, 0, -1.9)

Slide 26

Slide 26 text

• Each object defines its own coordinate system or frame • An object’s pose is its position and rotation relative to its parent - obj.rotation / obj.position - obj.matrix Transformations … … (.39, 0, -.6) (1.2, 0, 1.9) (-.39, 0, .6) (-1.2, 0, -1.9)

Slide 27

Slide 27 text

… … vec.applyMatrix4(lidar.matrix); const m = new THREE.Matrix4() .getInverse(camera.matrix); vec.applyMatrix4(m);

Slide 28

Slide 28 text

Demo: Colored Point Cloud ▶

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

More:
 threejs.org Cartographer point cloud viewer We are hiring frontend engineers in Munich: lyft.com/level5 Thanks!