I'm using Apple's custom ARAnchor in a config.isCollaborationEnabled = true
environment.
When I call the following on DeviceA:
let boardAnchor = BoardAnchor(transform: last.worldTransform, size: CGSize(width: 10, height: 11))
arView.session.add(anchor: boardAnchor)
I can see the delegate func session(_ session: ARSession, didAdd anchors: [ARAnchor])
get called with the BoardAnchor on DeviceA.
However, DeviceB does not receive such a delegate call.
If however I add a non-subclassed ARAnchor on DeviceA, I can see the delegate called on DeviceB.
let namedAnchor = ARAnchor(name: "test", transform: last.worldTransform)
arView.session.add(anchor: namedAnchor)
So I'm really confused as to why the subclass doesn't work...any ideas?
class BoardAnchor: ARAnchor {
let size: CGSize
init(transform: float4x4, size: CGSize) {
self.size = size
super.init(name: "Board", transform: transform)
}
override class var supportsSecureCoding: Bool {
return true
}
required init?(coder aDecoder: NSCoder) {
self.size = aDecoder.decodeCGSize(forKey: "size")
super.init(coder: aDecoder)
}
// this is guaranteed to be called with something of the same class
required init(anchor: ARAnchor) {
let other = anchor as! BoardAnchor
self.size = other.size
super.init(anchor: other)
}
override func encode(with aCoder: NSCoder) {
super.encode(with: aCoder)
aCoder.encode(size, forKey: "size")
}
}
Delegate
func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
for anchor in anchors {
DLog("didAdd anchor: \(anchor)")
if anchor.name == "test" {
// Non-sublcass ARAnchor ok
}
if let board = anchor as? BoardAnchor {
// Never called
}
}
}
I think that other than simply noting the
config.isCollaborationEnabled = true
, you need to manually handle the data sent out and the connectivity and other peers.In addition, there is a different delegate method to get the collaborated anchors, if I remember correctly.
Please note the following: https://developer.apple.com/documentation/arkit/creating_a_collaborative_session
There is a sample project there that will probably answer most of your questions..