49
Lab 5: Vuforia + Unity CS410/510: Virtual Reality Ehsan Aryafar [email protected] Sam Shippey [email protected] 1

Lab 5: Vuforia + Unity - web.cecs.pdx.edu

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Lab 5: Vuforia + Unity

CS410/510: Virtual RealityEhsan Aryafar [email protected] Shippey [email protected]

1

Page 2: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Review from last week● Vuforia: What/why● Go to https://developer.vuforia.com/● Sign up for an account● Upload an image under “target manager”● When choosing an image, select for:

○ Strong lines○ Good lighting○ <2Mb size

2

2

Page 3: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Review from last week● Key AR concepts

○ Marker-based AR vs Markerless AR○ A really rough view of how object detection works○ Know what SLAM means and why it’s important

3

3

Page 4: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Review from last week● Key AR concepts

○ Marker-based AR vs Markerless AR■ Marker-based AR finds a “marker”, usually an image or pattern,

within a scene. Everything is defined in reference to that marker.■ Markerless AR tries to understand an environment, and works from

there by adding things to the scene.○ A really rough view of how object detection works○ Know what SLAM means and why it’s important

4

4

Page 5: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Review from last week● Key AR concepts

○ Marker-based AR vs Markerless AR■ Marker-based AR finds a “marker”, usually an image or pattern,

within a scene. Everything is defined in reference to that marker.■ Markerless AR tries to understand an environment, and works from

there by adding things to the scene.○ A really rough view of how object detection works

■ Classification, bounding boxes, etc. Limited on phones, but works better than you would think.

○ Know what SLAM means and why it’s important

5

5

Page 6: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Review from last week● Key AR concepts

○ Marker-based AR vs Markerless AR■ Marker-based AR finds a “marker”, usually an image or pattern,

within a scene. Everything is defined in reference to that marker.■ Markerless AR tries to understand an environment, and works from

there by adding things to the scene.○ Know what SLAM means and why it’s important

■ Simultaneous Localization And Mapping. Depth maps, orientation, etc.

○ A really rough view of how object detection works

6

6

Page 7: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Review from last week● Key AR concepts

○ Marker-based AR vs Markerless AR■ Marker-based AR finds a “marker”, usually an image or pattern,

within a scene. Everything is defined in reference to that marker.■ Markerless AR tries to understand an environment, and works from

there by adding things to the scene.○ Know what SLAM means and why it’s important

■ Simultaneous Localization And Mapping. Depth maps, orientation, etc.

○ A really rough view of how object detection works■ Classification, bounding boxes, etc. Limited on phones, but works

better than you would think.7

7

Page 8: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

● Limits to environmental understanding

Addendum to last week

8

8

Page 9: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

● Limits to environmental understanding○ Object recognition and SLAM are hard

Addendum to last week

9

9

Page 10: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

● Limits to environmental understanding○ Object recognition and SLAM are hard○ Phones have limited hardware and poor thermals

Addendum to last week

10

10

Page 11: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

● Limits to environmental understanding○ Object recognition and SLAM are hard○ Phones have limited hardware and poor thermals○ Functionality for cutting edge software isn’t always particularly

user-friendly.

Addendum to last week

11

11

Page 12: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

● Although neural approaches to object detection, SLAM, and other AR related tasks such as human segmentation are still hard, they’re now doable, even on phones.

● Even over the web.

Addendum to last week

12

12

Page 13: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Addendum to last week● Some examples from Tensorflow’s javascript API:

○ https://github.com/tensorflow/tfjs-models/tree/master/face-landmarks-detection

○ https://github.com/tensorflow/tfjs-models/tree/master/posenet

13Facemesh Posenet

13

Page 14: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Onto Unity!● Open the Unityhub and we’ll get to work building a super

basic AR application.

14

14

Page 15: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Editor settings● If you plan to build and

deploy this, make sure your platform’s build support is checked in the editor you installed.

● To check, go to Installs in the UnityHub.

15

15

Page 16: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

What to do if this doesn’t build● This might or might not build for you● Why this happens

○ As previously discussed, iOS doesn’t necessarily play nice with Windows or Linux to the point where cross compilation is impossible.

○ Sometimes Android is annoying.○ Oftentimes Unity is annoying.

● What to do○ Rejoice! Vuforia can simulate some of this.○ If you really, really want to deploy quickly, we have other

technologies.16

16

Page 17: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Getting started● Create project

17

17

Page 18: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Getting started● Setup editor to work correctly● We want to be able to see:

18

18

Page 19: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Getting started● Setup editor to work correctly● We want to be able to see:

○ Package manager: Window->Package manager

The package manager lets us add packages, which are distinct from Assets in that they somehow extend not just your project’s functionality, but Unity’s as well, both the editor and the engine.

19

19

Page 20: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Getting started● Setup editor to work

correctly● We want to be able to see:

○ Package manager○ Game windows

These should be visible by default, but it’s easier if both the preview and the scene view are both turned on. 20

20

Page 21: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Adding Vuforia support● In the package manager,

find “Vuforia Engine AR”

21

21

Page 22: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Adding Vuforia support● In the package manager,

find “Vuforia Engine AR” ● Click “Install”

22

22

Page 23: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Adding Vuforia support● In the package manager,

find “Vuforia Engine AR” ● Click “Install”● Wait

23

23

Page 24: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Vuforia Camera● AR Cameras are different!● Even with marker-based AR, we still have to do 6dof

tracking.● Vuforia implements its own camera for this reason exactly.● Remember: It matters remarkably little where this camera

is. All positions are computed relative to the marker rather than the camera.

24

24

Page 25: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Vuforia Camera● Add by going to

“GameObjects”● -> Vuforia Engine● -> AR Camera● Delete the main camera.● Position somewhere you’ll

remember it.● Should look basically the

same as the default scene. 25

25

Page 26: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Adding the Vuforia marker● Time to add the markers we made last week through

Vuforia’s developer portal.

26

26

Page 27: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Adding the Vuforia marker● Time to add the markers we made last week through

Vuforia’s developer portal.● Go to the Vuforia developer portal

27

27

Page 28: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Adding the Vuforia marker● Time to add the markers we made last week through

Vuforia’s developer portal.● Go to the Vuforia developer portal● Target manager

28

28

Page 29: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Adding the Vuforia marker● Time to add the markers we made last week through

Vuforia’s developer portal.● Go to the Vuforia developer portal● Target manager● Find the target you created in lab 4

29

29

Page 30: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Adding the Vuforia marker● Time to add the markers we made last week through

Vuforia’s developer portal.● Go to the Vuforia developer portal● Target manager● Find the target you created in lab 4● Download it as a .unitypackage.

30

30

Page 31: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Adding the Vuforia Marker● Back in the Unity editor, go to● GameObject● -> Vuforia Engine● -> Image

31

31

Page 32: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Adding the Vuforia Marker● You should now have an image in the scene!

32

32

Page 33: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Adding the Vuforia Marker● You should now have an image in the scene!● Note: It may be extremely tiny because of the scale. Make

sure it’s there by zooming in.

33

33

Page 34: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Adding the Vuforia Marker● You should now have an image in the scene!● Note: It may be extremely tiny because of the scale. Make

sure it’s there by zooming in.● Time to add our image. Go to● Assets● -> Right click● -> Import package…● -> Custom package…● Find the .unitypackage you downloaded earlier

34

34

Page 35: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Adding the Vuforia Marker● Now, we want to configure the image we

have to match our database.● Click the image on the scene (Or

click+drag to select it)

35

35

Page 36: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Adding the Vuforia Marker● Now, we want to configure the image we

have to match our database.● Click the image on the scene (Or

click+drag to select it)● Examine the object in the inspector.

36

36

Page 37: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Adding the Vuforia Marker● Now, we want to configure the image we

have to match our database.● Click the image on the scene (Or

click+drag to select it)● Examine the object in the inspector.● Change the “database” and “image

target” attributes to point to what you want them to.

37

37

Page 38: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

The actual app part● You now have a kind of working app!● Add some assets, as children of the image target.

38

38

Page 39: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

The actual app part● You now have a kind of working app!● Add some assets, as children of the image target.● I’m uncreative, so I’ve put a cube here.

39

39

Page 40: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

The actual app part● You can now work as if this was a more or less normal

app in Unity.● This part is the part you’re familiar with

40

40

Page 41: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Deployment, further reading● Deployment is intentionally left out of the close

instructions as otherwise it would exclude most of the iOS users.

● As such, as part of the homework, Android users are encouraged (but not required) to work out how to deploy to Android.

● This isn’t required because the sheer volume of software needed to do it makes it borderline unfair.

41

41

Page 42: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Deployment, further reading● Guide for mobile deployment

○ https://learn.unity.com/tutorial/building-for-mobile#5c7f8528edbc2a002053b4a1

● Tips for mobile deployment○ Make sure the phone is connected in the right way according to

the software. My phone is set, by default, to act something like a USB stick. This doesn’t go so great for sending apps to it. Make sure USB Debugging is enabled under developer settings, etc.

○ If your phone gets a bit hot testing, that’s unfortunately kind of normal.

42

42

Page 43: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Deployment, further reading● Deployment is intentionally left out of the close

instructions as otherwise it would exclude most of the iOS users.

● The homework○ Add some more things to your app! Assets, physics, etc. Knock

yourself out.○ Package it up and send it to us.

43

43

Page 44: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Deployment, further reading

44

● Guide for mobile deployment○ https://learn.unity.com/tutorial/building-for-

mobile#5c7f8528edbc2a002053b4a1● Tips for mobile Unity usage

○ Unity has support for mobile input, you can read about that here: https://learn.unity.com/tutorial/touch-input-for-mobile-scripting

○ You might want to minimize the number and complexity of elements on the screen, particularly in regard to physics.

44

Page 45: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Deployment, further reading● Deployment is intentionally left out of the close

instructions as otherwise it would exclude most of the iOS users.

● The homework○ Add some more things to your app! Assets, physics, etc. Knock

yourself out.○ Package it up and send it to us.○ How to do that: Find where it’s installed (Right click Assets->Open

in Containing Folder…), go up a level, package the folder your project is in in a zip, tarball, 500mb git repository, etc.

45

45

Page 46: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Deployment, further reading● Guide for mobile deployment

○ https://learn.unity.com/tutorial/building-for-mobile#5c7f8528edbc2a002053b4a1

● Tips for mobile deployment○ Make sure the phone is connected in the right way according to

the software. My phone is set, by default, to act something like a USB stick. This doesn’t go so great for sending apps to it. Make sure USB Debugging is enabled under developer settings, etc.

46

46

Page 47: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Further reading● Vuforia is easy to use, but certainly not the only AR

platform!● If you’d like to experiment more with Marker based AR,

consider using Three.JS + AR.JS, AWS Sumerian, or any one of around a dozen constantly shifting proprietary solutions.

47

47

Page 48: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Further reading● Vuforia is easy to use, but certainly not the only AR

platform!● If you’d like to experiment more with Marker based AR,

consider using Three.JS + AR.JS, A-Frame, AWS Sumerian, or any one of around a dozen constantly shifting proprietary solutions.

● If you’d like to experiment with markerless AR, try the same set of things, plus Unity’s AR Foundation.

48

48

Page 49: Lab 5: Vuforia + Unity - web.cecs.pdx.edu

Let’s experiment● I’ll sit around here to answer more questions if you want to

continue adding things while we’re here.● Feel free to leave and bug me on Slack later, or stick

around and try to debug things with this OR with your project now.

49

49