ARKit (Part 2) — Core Classes Overview
Core Classes Overview ARAnchor ARAnchor represents the position and orientation of an object in 3D space. It is commonly referred to as a 3D anchor point for an object — somewhat similar to the Anchor property of CALayer in the UIKit framework. ARCamera ARCamera is the bridge between the virtual scene and the real world. In ARKit, it is the camera that captures real-world images; in SceneKit, it is the camera in the 3D virtual world. (In typical first-person 3D games, the main character is essentially a 3D camera — what we see on screen is what that camera captures.) You generally do not need to create a camera manually. When an AR view is initialized, a camera is created by default. This camera corresponds to the position of the device's physical camera, and is also the origin of the 3D world (x=0, y=0, z=0). ARError The class in the ARKit framework that describes errors. Errors can originate from an unsupported device, or from the ARSession disconnecting when the camera stays in the background. ARFrame A wrapper class for camera video frames, containing position tracking information, environmental parameters, and the video frame itself. The hit test result class, primarily used for interaction between the real world and 3D virtual objects in AR. For example, moving or dragging a 3D virtual object in the camera view can use this class to obtain results captured by ARKit. ARLightEstimate provides lighting effects to make AR scenes appear more realistic. ARDirectionalLightEstimate is a subclass of ARLightEstimate. ARPlaneAnchor is a subclass of ARAnchor and can be understood as a planar anchor. ARKit can automatically detect planes and will add an anchor to the scene by default. To visualize a detected plane in the real world, you need to use an SCNNode to render the anchor. An anchor is just a position. ARPointCloud is a point cloud renderer, primarily used for rendering scenes. A supplementary view whose main function is to render 3D content from SceneKit onto the real-time camera image to create an AR experience. ARSCNView inherits from SCNView in the SceneKit framework, and SCNView inherits from UIView in UIKit. This class primarily does the following: - Takes the real-time feed from the device camera and renders it as the background of the 3D scene. - ARKit's 3D coordinate system can be matched to SceneKit's 3D coordinate system. Objects rendered in this view are automatically matched to ARKit's world coordinates. - Automatically moves the virtual SceneKit camera to match the 3D coordinates tracked by ARKit in the real world, so we don't need to write code to associate movement events with SceneKit's 3D graphics. Since ARKit automatically aligns SceneKit space with the real world, placing a virtual object at a real-world position only requires setting an appropriate SceneKit coordinate. We don't need to use the ARAnchor class to track the coordinates of objects we add to the scene, but we do need to implement ARSCNViewDelegate methods to add SceneKit content on any anchor that ARKit automatically detects. Note: the ability to render 3D objects is provided by the parent class SCNView, while capturing the 3D real-world scene and performing the corresponding coordinate conversion is implemented by ARSCNView (i.e., ARKit). ARSession is a bridge between the underlying layer and the AR view. In fact, all delegate methods in ARSCNView are provided by ARSession. Every AR scene built with ARKit requires an ARSession object. It is responsible for controlling the camera, collecting all sensor data from the device (including reading data from the device's motion sensors, controlling the device camera, and analyzing images captured by the camera) to establish the connection between the user's real-world location and the AR content space. The ARSCNView instance already contains an ARSession instance — you just need to configure it at startup (using or its subclass ). ARSession provides two main ways to retrieve camera position data: one is by implementing the ARSession delegate method , and the other is by accessing the ARSession property . In recent ARKit updates, has been renamed to . The subclass has also been renamed to . This class tracks device movement across 6 degrees of freedom (6DOF) — 3 rotation axes (roll: rotation around the axis perpendicular to the screen; yaw: rotation around the device's upward axis; pitch: the device's forward tilt angle) and 3 translation axes (movement along x, y, z). This allows us to walk around virtual objects and even move them. If this is not needed and the user will not change position during the AR experience, can be used to initialize the ARSession instead. References: ARKit ARKit from Beginner to Expert