Immersive Media Design
AR Book Map Part 4
Getting the AR part to work
This week I focused on getting my Mapbox globe in Unity to work in AR. What might have been a straightforward process turned into a long and frustrating saga from which I only emerged with excessive assistance from RJ. Thanks, RJ!! And thanks to all the people posting and solving problems on github.
I am going to document my process here, so I don’t forget.
This is where I was last week. I had figured out how to import the Mapbox SDK and how to connect my customized map through the tileset and style links.
In order to make the map work in an AR app built through Xcode, I decided to start my file from scratch. These were the steps.
The Straightforward Steps
- Open new Unity file.
- Change the platform to iOS.
- Go to Assets → Import Package and import the Mapbox SDK that I previously downloaded and saved to my desktop.
- Open the Mapbox globe example in my scene.
- Go to Window →Package Manager and add the AR Foundation and ARKit XR Plugin packages.
- Add AR Session Origin and AR Session to scene.
- Set AR Camera to MainCamera tag. Delete original camera.
- Place the Map object into an empty GameObject and scale down the game object to 0.0005 for X, Y, and Z. (Note from RJ: If you try to scale the globe as is, it gets set to a scale of 1 which is HUUUUGE for our little AR camera. It can’t see it at that scale.)
- Change the Player Settings (set the bundle identifier, set the camera usage description, make sure target minimum iOS version says 13.0, set the architecture to ARM64)
- Build & Run
- Open and build in Xcode
- Andddd build fails.
The Error
The error I continually received when trying to compile in Xcode had to do with locating folders within my unity file. Despite all the folders being located where they should be, some glitch was causing them to not be findable.
RJ’s first possible solution consisted of changing the some of the code in Xcode.
Xcode code changes
- Line 1 in MapboxMetricsClient.m
#import “MapboxMobileEvents.h”
2. Lines 11–14 in MapboxMobileEvents.h
#import “MMEConstants.h”
#import “MMEEvent.h”
#import “MMETypes.h”
#import “MMEEventsManager.h”
When that didn’t fully solve my build problem, we continued to search the internet forums for help, and finally came across this link which gave these directions:
Xcode modifications
- Open the Xcode project and go to the Build Settings tab and search for Header Search Paths. Double click on the Header Search Paths row and press the + button to add a line and paste this into it
$(SRCROOT)/Libraries/Mapbox/Core/Plugins/iOS/MapboxMobileEvents/include/
- Manually link the libz library to the project. That can be done by going to the Build Phases tab and expanding Link Binary With Libraries. Click the + button and search for libz.tbd and press Add.
And that was the trick! With those modifications to my Unity build, I was able to export the application to my phone, and open it to see a globe. I then tried the same export and build process with the Unity file that includes my Mapbox styles (pictured below) and it worked! I still need to play around with the size of the globe and the position of the AR camera (right now, the camera is in the center of the globe, so in order to see the globe you have to open the app, and then step a few feet away and look back at where you had been standing when you opened it.
Next Steps:
- Make the Mapbox data interactive.
- Design a popup.