SlideShare a Scribd company logo
© 2018 Solteq. All rights reserved.
Easy 3d drawing with three.js
TampereJS June 2018
© 2018 Solteq. All rights reserved.
Jere Kuusela
• Software Developer at Solteq
• jere.kuusela@iki.fi
• jere.kuusela@solteq.com
• First talk ever!
© 2018 Solteq. All rights reserved.
WebGL
• JavaScript API to implement 3d graphics in modern browsers
• Wide support
• Uses HTML <canvas> element
• Uses hardware-acceleration
• Low level -> 
• Multiple higher level libraries
• three.js
• PhiloGL
• GLGE
• J3D
• …
© 2018 Solteq. All rights reserved.© 2018 Solteq. All rights reserved.
Demo 1
© 2018 Solteq. All rights reserved.
Recap of Demo 1
• Scene: Container for objects which you want to draw
• Objects: Actual objects which usually need both geometry and material
• Camera: Location and direction where you are looking at the scene
• Renderer: Uses WebGL to draw pixels based on the scene and the camera
© 2018 Solteq. All rights reserved.
Closer look at objects
• Base class for points, lines, meshes, cameras, scenes, lights …
• Every object can have children
• For example a camera can be attached to a geometry
• Most objects should have a parent
• You can only render one object (usually the scene) and its children
• Object’s location is relative to its parent <- IMPORTANT!
• Allows easily moving complex objects
© 2018 Solteq. All rights reserved.© 2018 Solteq. All rights reserved.
Demo 2
© 2018 Solteq. All rights reserved.
Recap of Demo 2
• A car built from a cone, 4 cylinders (tires) and a camera
• Cars were attached to a proxy object which was used to move them around
• No need to update locations of cars and tires manually
• An image was added as a floor for visual purposes
• The scene only directly included the floor and the proxy object!
• Camera can be toggled by simply changing which camera is used in render function
© 2018 Solteq. All rights reserved.
Controlling camera manually?
• No first class support for moving a camera with mouse
• But lots of examples which contain reusable code: https://threejs.org/examples/
• https://threejs.org/examples/#misc_controls_orbit
• https://threejs.org/examples/#misc_controls_trackball
• Have to download the required JS file manually
• But only a few lines of codes required to get it working
© 2018 Solteq. All rights reserved.
Lights and shadows
• Multiple choices: ambient, directional, spotlight, point, …
• This is where the easy ends
• Lots of things which can go wrong -> nothing appears on the screen 
• Use helpers to visualize lights and shadows when debugging
© 2018 Solteq. All rights reserved.© 2018 Solteq. All rights reserved.
Demo 3
© 2018 Solteq. All rights reserved.
Recap of Demo 3
• Imported camera controls JS-file
• One line of code to get it working properly
• Added a light to cars (copypaste from three.js documentation)
• But no light shows up
• Helper objects appear so can see that the light is there
© 2018 Solteq. All rights reserved.
Lights and shadows, again
• Lights require:
• Proper material (MeshStandardMaterial instead of MeshBasicMaterial)
• Ambient light unless you want the world be pitch black
• Spotlight must have the target location set and added to scene
• Shadows require:
• Light must be set to cast shadow
• Light shadow camera must have proper near and far
• Renderer must have shadowmap enabled
• Floor must be set to receive shadow
• Any other objects must be set to cast shadow
© 2018 Solteq. All rights reserved.© 2018 Solteq. All rights reserved.
Demo 4
© 2018 Solteq. All rights reserved.
Recap of Demo 4
• Changed floor material
• Added ambient light
• Fixed location of lights, added target location
• Also added another light to cars with help of clone()
• Fixed shadow near and far settings
• Added shadowmap to renderer
• Added receive shadows to floor
• Added static towers to cast shadows

More Related Content

Similar to TampereJS June 2018 - Easy 3d drawing with three.js

20 x Tips to better Optimize your Flash content
20 x Tips to better Optimize your Flash content20 x Tips to better Optimize your Flash content
20 x Tips to better Optimize your Flash content
Elad Elrom
 
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
DevGAMM Conference
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN Stack
Troy Miles
 
[Unity Forum 2019] Mobile Graphics Optimization Guides
[Unity Forum 2019] Mobile Graphics Optimization Guides[Unity Forum 2019] Mobile Graphics Optimization Guides
[Unity Forum 2019] Mobile Graphics Optimization Guides
Owen Wu
 
[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...
[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...
[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...
Kobkrit Viriyayudhakorn
 
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
Unite2017Tokyo
 
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
Unity Technologies Japan K.K.
 
Compliant S1000D illustrations 2018 - Part 1
Compliant S1000D illustrations 2018 - Part 1Compliant S1000D illustrations 2018 - Part 1
Compliant S1000D illustrations 2018 - Part 1
Larson Software Technology
 
Computer Vision based Automated Spare Part Finder App.pptx
Computer Vision based  Automated Spare Part Finder App.pptxComputer Vision based  Automated Spare Part Finder App.pptx
Computer Vision based Automated Spare Part Finder App.pptx
ssusercd48d1
 
Software AG Application Modularity - OSGi and JPMS (Jigsaw)
Software AG Application Modularity - OSGi and JPMS (Jigsaw)Software AG Application Modularity - OSGi and JPMS (Jigsaw)
Software AG Application Modularity - OSGi and JPMS (Jigsaw)
mfrancis
 
Manasa
ManasaManasa
Unity - Internals: memory and performance
Unity - Internals: memory and performanceUnity - Internals: memory and performance
Unity - Internals: memory and performance
Codemotion
 
Steganography: a tool for community driven development in TerraTech
Steganography: a tool for community driven development in TerraTechSteganography: a tool for community driven development in TerraTech
Steganography: a tool for community driven development in TerraTech
Russ Clarke
 
Engineering Portfolio
Engineering PortfolioEngineering Portfolio
Engineering Portfolio
FrankIattarelli
 
Point Clouds from Rolling Shutter Cameras
Point Clouds from Rolling Shutter CamerasPoint Clouds from Rolling Shutter Cameras
Point Clouds from Rolling Shutter Cameras
Christoph Strecha
 
[TGDF 2020] Mobile Graphics Best Practices for Artist
[TGDF 2020] Mobile Graphics Best Practices for Artist[TGDF 2020] Mobile Graphics Best Practices for Artist
[TGDF 2020] Mobile Graphics Best Practices for Artist
Owen Wu
 
Developing VR Experiences with Unity
Developing VR Experiences with UnityDeveloping VR Experiences with Unity
Developing VR Experiences with Unity
Mark Billinghurst
 
Advanced angular
Advanced angularAdvanced angular
Advanced angular
Sumit Kumar Rakshit
 
Building CI from scratch
Building CI from scratchBuilding CI from scratch
Building CI from scratch
Artem Nikitin
 
Ng Sydney Dynamic Templates Talk - 18 April 2018
Ng Sydney Dynamic Templates Talk - 18 April 2018Ng Sydney Dynamic Templates Talk - 18 April 2018
Ng Sydney Dynamic Templates Talk - 18 April 2018
Roger Kermode
 

Similar to TampereJS June 2018 - Easy 3d drawing with three.js (20)

20 x Tips to better Optimize your Flash content
20 x Tips to better Optimize your Flash content20 x Tips to better Optimize your Flash content
20 x Tips to better Optimize your Flash content
 
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN Stack
 
[Unity Forum 2019] Mobile Graphics Optimization Guides
[Unity Forum 2019] Mobile Graphics Optimization Guides[Unity Forum 2019] Mobile Graphics Optimization Guides
[Unity Forum 2019] Mobile Graphics Optimization Guides
 
[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...
[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...
[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...
 
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
 
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
 
Compliant S1000D illustrations 2018 - Part 1
Compliant S1000D illustrations 2018 - Part 1Compliant S1000D illustrations 2018 - Part 1
Compliant S1000D illustrations 2018 - Part 1
 
Computer Vision based Automated Spare Part Finder App.pptx
Computer Vision based  Automated Spare Part Finder App.pptxComputer Vision based  Automated Spare Part Finder App.pptx
Computer Vision based Automated Spare Part Finder App.pptx
 
Software AG Application Modularity - OSGi and JPMS (Jigsaw)
Software AG Application Modularity - OSGi and JPMS (Jigsaw)Software AG Application Modularity - OSGi and JPMS (Jigsaw)
Software AG Application Modularity - OSGi and JPMS (Jigsaw)
 
Manasa
ManasaManasa
Manasa
 
Unity - Internals: memory and performance
Unity - Internals: memory and performanceUnity - Internals: memory and performance
Unity - Internals: memory and performance
 
Steganography: a tool for community driven development in TerraTech
Steganography: a tool for community driven development in TerraTechSteganography: a tool for community driven development in TerraTech
Steganography: a tool for community driven development in TerraTech
 
Engineering Portfolio
Engineering PortfolioEngineering Portfolio
Engineering Portfolio
 
Point Clouds from Rolling Shutter Cameras
Point Clouds from Rolling Shutter CamerasPoint Clouds from Rolling Shutter Cameras
Point Clouds from Rolling Shutter Cameras
 
[TGDF 2020] Mobile Graphics Best Practices for Artist
[TGDF 2020] Mobile Graphics Best Practices for Artist[TGDF 2020] Mobile Graphics Best Practices for Artist
[TGDF 2020] Mobile Graphics Best Practices for Artist
 
Developing VR Experiences with Unity
Developing VR Experiences with UnityDeveloping VR Experiences with Unity
Developing VR Experiences with Unity
 
Advanced angular
Advanced angularAdvanced angular
Advanced angular
 
Building CI from scratch
Building CI from scratchBuilding CI from scratch
Building CI from scratch
 
Ng Sydney Dynamic Templates Talk - 18 April 2018
Ng Sydney Dynamic Templates Talk - 18 April 2018Ng Sydney Dynamic Templates Talk - 18 April 2018
Ng Sydney Dynamic Templates Talk - 18 April 2018
 

Recently uploaded

J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
devvsandy
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 

Recently uploaded (20)

J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 

TampereJS June 2018 - Easy 3d drawing with three.js

  • 1. © 2018 Solteq. All rights reserved. Easy 3d drawing with three.js TampereJS June 2018
  • 2. © 2018 Solteq. All rights reserved. Jere Kuusela • Software Developer at Solteq • jere.kuusela@iki.fi • jere.kuusela@solteq.com • First talk ever!
  • 3. © 2018 Solteq. All rights reserved. WebGL • JavaScript API to implement 3d graphics in modern browsers • Wide support • Uses HTML <canvas> element • Uses hardware-acceleration • Low level ->  • Multiple higher level libraries • three.js • PhiloGL • GLGE • J3D • …
  • 4. © 2018 Solteq. All rights reserved.© 2018 Solteq. All rights reserved. Demo 1
  • 5. © 2018 Solteq. All rights reserved. Recap of Demo 1 • Scene: Container for objects which you want to draw • Objects: Actual objects which usually need both geometry and material • Camera: Location and direction where you are looking at the scene • Renderer: Uses WebGL to draw pixels based on the scene and the camera
  • 6. © 2018 Solteq. All rights reserved. Closer look at objects • Base class for points, lines, meshes, cameras, scenes, lights … • Every object can have children • For example a camera can be attached to a geometry • Most objects should have a parent • You can only render one object (usually the scene) and its children • Object’s location is relative to its parent <- IMPORTANT! • Allows easily moving complex objects
  • 7. © 2018 Solteq. All rights reserved.© 2018 Solteq. All rights reserved. Demo 2
  • 8. © 2018 Solteq. All rights reserved. Recap of Demo 2 • A car built from a cone, 4 cylinders (tires) and a camera • Cars were attached to a proxy object which was used to move them around • No need to update locations of cars and tires manually • An image was added as a floor for visual purposes • The scene only directly included the floor and the proxy object! • Camera can be toggled by simply changing which camera is used in render function
  • 9. © 2018 Solteq. All rights reserved. Controlling camera manually? • No first class support for moving a camera with mouse • But lots of examples which contain reusable code: https://threejs.org/examples/ • https://threejs.org/examples/#misc_controls_orbit • https://threejs.org/examples/#misc_controls_trackball • Have to download the required JS file manually • But only a few lines of codes required to get it working
  • 10. © 2018 Solteq. All rights reserved. Lights and shadows • Multiple choices: ambient, directional, spotlight, point, … • This is where the easy ends • Lots of things which can go wrong -> nothing appears on the screen  • Use helpers to visualize lights and shadows when debugging
  • 11. © 2018 Solteq. All rights reserved.© 2018 Solteq. All rights reserved. Demo 3
  • 12. © 2018 Solteq. All rights reserved. Recap of Demo 3 • Imported camera controls JS-file • One line of code to get it working properly • Added a light to cars (copypaste from three.js documentation) • But no light shows up • Helper objects appear so can see that the light is there
  • 13. © 2018 Solteq. All rights reserved. Lights and shadows, again • Lights require: • Proper material (MeshStandardMaterial instead of MeshBasicMaterial) • Ambient light unless you want the world be pitch black • Spotlight must have the target location set and added to scene • Shadows require: • Light must be set to cast shadow • Light shadow camera must have proper near and far • Renderer must have shadowmap enabled • Floor must be set to receive shadow • Any other objects must be set to cast shadow
  • 14. © 2018 Solteq. All rights reserved.© 2018 Solteq. All rights reserved. Demo 4
  • 15. © 2018 Solteq. All rights reserved. Recap of Demo 4 • Changed floor material • Added ambient light • Fixed location of lights, added target location • Also added another light to cars with help of clone() • Fixed shadow near and far settings • Added shadowmap to renderer • Added receive shadows to floor • Added static towers to cast shadows