Spiff
Spiff

Reputation: 913

RealityKit – What's the difference between Anchor and Entity translation?

For an anchor with a single child, is there any difference between repositioning the anchor and repositioning the child entity?

let material = SimpleMaterial(color: .gray, isMetallic: false)
let entity = ModelEntity(mesh: .generateBox(size: 0.3), materials: [material])

// position anchor
let anchor = AnchorEntity(world: SIMD3<Float>(x: 0, y: 0.5, z: 0))
anchor.addChild(entity)
arView.scene.addAnchor(anchor)

// vs. position child
let material = SimpleMaterial(color: .gray, isMetallic: false)
let entity = ModelEntity(mesh: .generateBox(size: 0.3), materials: [material])
entity.position = SIMD3<Float>(x: 0, y: 0.5, z: 0)

let anchor = AnchorEntity(world: .zero)
anchor.addChild(entity)
arView.scene.addAnchor(anchor)

Upvotes: 3

Views: 828

Answers (1)

Andy Jazz
Andy Jazz

Reputation: 58583

In RealityKit, both AnchorEntity and ModelEntity are subclasses of their parental Entity class, which means that both of these subclasses have a Transform component. This implies that both objects can be moved, rotated and scaled.

The difference between ModelEntity and AnchorEntity is that an anchor is a special object that is automatically tracked in RealityKit. Model or several models need to be attached to the anchor, to prevent models from drifting. Thus, you can move the anchor itself (together with the models attached to it) and each model individually, if you need to.


Answering your question:

For an anchor with a single child, is there any difference between repositioning the anchor and repositioning the child entity?

In that particular case there's no difference. The only thing you need to think of is THIS.

Upvotes: 4

Related Questions