1

Say I have this:

var a = getSphere(0.05, .white)
var b = getSphere(0.04, UIColor.brown)
var c = getSphere(0.03, UIColor.cyan)
    
var aa = AnchorEntity()
var bb = AnchorEntity()
var cc = AnchorEntity()
aa.transform.translation.y = -0.5
aa.addChild(bb)
bb.addChild(cc)
aa.addChild(a)
bb.addChild(b)
cc.addChild(c)
scene.anchors.append(aa)

The aa anchor & its object will be at y -0.5 properly, but bb and cc anchors/objects will still be positioned at 0,0,0....

This feels extremely buggy. Like... why would child object ignore its parent transform?

Can any1 shed a light how to "fix" this ?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Dariusz
  • 960
  • 13
  • 36

1 Answers1

1

You don't need so many nested AnchorEntities. RealityKit's scene can contain any hierarchical structure of nested ModelEntities (also known as Parent-Child pairs). Nevertheless, in order to automatically track a position and orientation of every 3D element in this structure – just ONE anchor is needed (that's a regular way of working with anchors in any AR framework).

let container = Entity()
let modelA = ModelEntity()
let modelB = ModelEntity()

container.addChild(modelA)
modelB.setParent(modelA)

container.position.x = -1.2
modelA.position.x = 0.5          // adjust transform independently
modelB.position.y = 1

let anchor = AnchorEntity()      // object being tracked
anchor.addChild(container)
arView.scene.addAnchor(anchor)
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • 1
    Yep I ended up doing that. But the strange thing is that AnchorEntity ignores parent transform! That should NOT happen in a hierarchy based structure. – Dariusz Jun 20 '21 at 16:37
  • It looks quite logical. How can the app track anchor inside tracked anchor and inside tracked anchor?! – Andy Jazz Jun 20 '21 at 23:43
  • 1
    That actually makes perfect sense... Thanks! I didn't quite grasp the idea of anchor... :- ) So if I place anchor in scene, would it drift away like normal object do while I move around & tracking tweaks/change ? Or it will be glued better than object? – Dariusz Jun 22 '21 at 00:06
  • AnchorEntity (and ARAnchor) will be glued considerably better than any other Entity, however it may drift...https://stackoverflow.com/questions/52893075/what-is-aranchor-exactly/52899502#52899502 – Andy Jazz Jun 22 '21 at 00:12
  • Uuu quite awesome, are the constructors : AnchorEntity(.world(transform: mtx)) and AnchorEntity(raycastResult: myRaycastResult) perform the same way in terms of tracking quality ? – Dariusz Jun 22 '21 at 00:20