I'm trying to understand and use ARKit. But there is one thing that I cannot fully understand.
Apple said about ARAnchor:
A real-world position and orientation that can be used for placing objects in an AR scene.
But that's not enough. So my questions are:
- What is
ARAnchor
exactly? - What are the differences between anchors and feature points?
- Is
ARAnchor
just part of feature points? - And how does ARKit determines its anchors?
Updated: January 19, 2020.
ARAnchor
Simply put,
ARAnchor
is an invisible null-object that can hold a 3D content (at anchor's position) in World Space. Think ofARAnchor
just like it's a local axis for your 3D object. Every 3D object has a pivot point, right? So this pivot point must meet anARAnchor
.If you do not use anchors in
ARKit
/RealityKit
app, your virtual objects can drift away from where they were placed and this can impact your app's realism and user experience. Thus, anchors are crucial elements in AR scene.According to ARKit documentation 2017:
ARAnchor
is a parent class for all other types of anchors existing in ARKit framework, hence all these subclasses inherit fromARAnchor
class but cannot use it directly in your code. I should also say thatARAnchor
andFeature Points
have nothing in common.Feature Points
are rather for debugging.Here's an image with visual representation of plane anchor. But keep in mind: by default, you can neither see a detected plane nor its corresponding ARPlaneAnchor.
In ARKit you can automatically add
ARAnchors
to your scene using different scenarios:ARPlaneAnchor
planeDetection
instance property isON
, ARKit is able to add ARPlaneAnchors to the session.ARImageAnchor (conforms to
ARTrackable
protocol)detectionImages
instance property. In ARKit 2.0 you can totally track up to 25 images, in ARKit 3.0 – up to 100 images, respectively. But, in both cases, not more than just 4 images simultaneously.ARBodyAnchor (conforms to
ARTrackable
protocol)ARBodyTrackingConfiguration()
. You'll get ARBodyAnchor in aRoot Joint
of 3D Skeleton.ARFaceAnchor (conforms to
ARTrackable
protocol)ARObjectAnchor
AREnvironmentProbeAnchor
ARParticipantAnchor
true
value forisCollaborationEnabled
instance property andMultipeer Connectivity
framework.Hit-Testing method
Ray-Casting method
Feature points
ARCamera's transform
Any arbitrary world position
And below is a code's snippet how to implement anchors inside renderer method:
AnchorEntity
RealityKit framework was released in 2019. It has a new class named
AnchorEntity
. You can use AnchorEntity as the root point of an entity hierarchy, and you can add it to the anchors collection for a scene instance. This enables ARKit to place the anchor entity, along with all of its hierarchical descendants, into the real world.According to RealityKit documentation 2019:
Let's look at a code snippet:
AnchorEntity
stores three components:Here are seven AnchorEntity's cases available in current version of RealityKit: