Persist object orientations in ARKit ARWorldMap
Apple Documentation for ARWorldMap
shows that the properties for an ARWorldMap
class are:
When you archive a world map, these are the only information that get saved. Any information about the nodes added to the anchors during the session (e.g. changing node scale and orientation) are not saved along with the world map during the archiving.
I remember watching a WWDC session where they demoed a multiplayer AR game called SwiftShot where players hit different objects with balls. They provided the source code and I noticed they used a custom ARAnchor
subclass called BoardAnchor
which they used to store additional information in the anchor class such as the size of the game board.
See: SwiftShot: Creating a Game for Augmented Reality.
You can use the same approach to store, for example, the scale and orientation of a node, so that when you unarchive the world map and it get's relocalized, you can use ARSCNViewDelegate
's renderer(_:didAdd:for:)
to resize and scale the node based on the information stored in your custom ARAnchor
.
Persistance with an ARWorldMap created with ARKit through Unity
Saving ARWorldMap is not a rocket science. If this feature is supported in ARKit extension for Unity, ARWorldMap will be saved in any AR app the same way as expected. The main difference is that Unity builds for iOS are written in slow Objective-C, not in faster Swift for UIKit, and not in the fastest Swift for SwiftUI. In iOS for storing ARWorldMap you must use NSKeyedArchiver
, and for retrieving ARWorldMap data you must use NSKeyedUnarchiver
.
func writeWorldMap(_ worldMap: ARWorldMap, to url: URL) throws {
let data = try NSKeyedArchiver.archivedData(withRootObject: worldMap,
requiringSecureCoding: true)
try data.write(to: url)
}
ARWorldMap stores world coordinate grid, position and orientation of your device, reference snapshots of a surrounding environment and ARAnchors. It's hard to say what you mean saying ...as effective as Azure...
but ARWorldMap data is the most effective offline way to store and retrieve persistence data in iOS AR apps.
Related Topics
Swift 3, Xcode 8 Instantiate View Controller Is Not Working
Early Return from a Void-Func in Swift
How to Add a Double Tap Gesture Recognizer in Swift
Vapor Toolbox Broken After Upgrading Swift
How to Succinctly Get the First 5 Characters of a String in Swift
Swift Protocol Generic as Function Return Type
Differences Between "Static Var" and "Var" in Swift
Getting Path for Resource in Command Line Tool
Pause an Skaction in Spritekit with Swift
How to Take Screen Shot Programmatically (Swift, Spritekit)
What Is an Example of Drawing Custom Nodes with Vertices in Swift Scenekit
Resize a Sklabelnode Font Size to Fit
Checking When a Date Has Passed - Swift
Reusing Security Scoped Bookmark
Changing Value in Nested Dictionary in Swift
How to Read and Write Data to a Text File in Swift Using Playground