What's the difference between ARAnchor and Anc

2020-02-29 06:38发布

问题:

I'm currently doing some experiments with RealityKit.

I've been looking at some sample code, and I'm a bit confused about the differences between ARAnchor and AnchorEntity, and when to use one over the other.

So far I know that:

  • Both are anchors that describes a position in the real world.
  • AnchorEntity can also have other Entity's as children, so you can add model objects directly to the anchor. You can't do this with ARAnchor, you have to add model objects "manually" to the rootNode, and use the position of the anchor the place it correctly.
  • In the documentation it says that ARKit uses the added ARAnchor to optimize the tracking in the area around the anchor. The documentation for AnchorEntity does not specify this.

Right now I add a AnchorEntity to the session as a "root node", since it's simpler to use, so that I can simply add models as children directly to this anchor. But then I also add a ARAnchor, located at the same position, to the scene's anchors, to enhance tracking around this point. Is this nececary?

Q: Anyone can help me clarify the differences, and use cases of these two?

回答1:

RealityKit's AnchorEntity class greatly extends the capabilities of ARAnchors.

ARAnchor class in ARKit and AnchorEntity class in RealityKit were both made for the same divine purpose – to tether a 3D content to your real-world objects.

But these two classes slightly differ in hierarchical construction found in scenes. Here's an image depicting how it looks like:

Apple Developer documentation says:

In RealityKit framework you use an AnchorEntity instance as the root of an entity hierarchy, and 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.

Also the documentation says about AnchorEntity the following :

In addition to the components the anchor entity inherits from the Entity class, the anchor entity also conforms to the HasAnchoring protocol, giving it an AnchoringComponent instance.

AnchorEntity has three building blocks in it:

  • Transform component (transform matrix containing translate, rotate and scale)
  • Synchronization component (entity's synchro-data for networked applications)
  • Anchoring component (it's how 3D content can be anchored to the real world)

Look at this picture to find out more about entities. All entities have Synchronization component that helps organise collaborative sessions.

And AnchorEntity has seven specific type for different purposes:

  • .body
  • .camera
  • .face
  • .image
  • .object
  • .plane
  • .world

You can freely use both classes (ARAnchor and AnchorEntity) in your AR app.

For additional info on ARAnchor class, please look at THIS POST.