Hi Vision Pro Engineer,
Thanks for your reply, and apologies for my late reply.
We tried points 1, 2, and 3 of your recommendations and have since moved our logic into the following DeviceTracker class.
Using your recommendations, we appear to be able to remove the frame counter properties. But, the following arbitrary yValue > 0.3 condition needs to remain. Otherwise, we are still getting negative values, see image.
import ARKit
import Combine
import OSLog
import RealityKit
import SwiftUI
@Observable
public final class DeviceTracker {
private let session = ARKitSession()
private let worldInfo = WorldTrackingProvider()
private var sceneUpdateSubscription: EventSubscription?
private let logger = Logger(subsystem: SUBSYSTEM, category: "DeviceTransformTracker")
public var deviceTransform: simd_float4x4? = nil
public init() {
// Defer the task until self is fully initialized
Task.detached(priority: .userInitiated) { [session, worldInfo, logger] in
do {
try await session.run([worldInfo])
} catch {
logger.error("\(#function) \(#line) Failed to start ARKitSession: \(error.localizedDescription)")
}
}
}
public func subscribe(content: RealityViewContent) {
sceneUpdateSubscription = content.subscribe(to: SceneEvents.Update.self) { [weak self] _ in
guard let self = self else { return }
guard self.worldInfo.state == .running else {
logger.warning("\(#function) \(#line) worldInfo.state not running")
return
}
guard let deviceAnchor = self.worldInfo.queryDeviceAnchor(atTimestamp: CACurrentMediaTime()) else {
logger.warning("\(#function) \(#line) missing deviceAnchor for CACurrentMediaTime() \(String(describing: CACurrentMediaTime()))")
return
}
guard deviceAnchor.isTracked else {
logger.warning("\(#function) \(#line) deviceAnchor not yet tracked")
return
}
let yValue = deviceAnchor.originFromAnchorTransform.columns.3.y
logger.warning("\(#function) \(#line) y value = \(deviceAnchor.originFromAnchorTransform.columns.3.y)")
if yValue > 0.3 {
self.deviceTransform = deviceAnchor.originFromAnchorTransform
}
}
}
public func cancel() {
sceneUpdateSubscription?.cancel()
}
}