Swift equivalent of ar_data_providers_create_with_data_providers and cp_time_to_cf_time_interval

This is an spinoff from forum post xrOS+Metal example code here

Am porting Warren Moore's example here

Have the most of the conversion to Swift complete but am stuck at a couple places

ar_data_providers_create_with_data_providers(...)

cp_time_to_cf_time_interval(...)

Any hints on how to track these down? Thanks!

Accepted Reply

Hi Muse, I have tracked it down to this block. Cheers.

extension LayerRenderer.Clock.Instant {
    func toTimeInterval() -> TimeInterval {
        let duration = LayerRenderer.Clock.Instant.epoch.duration(to: self)
        let secondsPart = Double(duration.components.seconds)
        let attosecondsPart = Double(duration.components.attoseconds) / 1e18
        return secondsPart + attosecondsPart
    }
}
  • @2time.net Works! You're a life saver -- or at least, a few hours of life saver.

Add a Comment

Replies

Hi Muse, I have tracked it down to this block. Cheers.

extension LayerRenderer.Clock.Instant {
    func toTimeInterval() -> TimeInterval {
        let duration = LayerRenderer.Clock.Instant.epoch.duration(to: self)
        let secondsPart = Double(duration.components.seconds)
        let attosecondsPart = Double(duration.components.attoseconds) / 1e18
        return secondsPart + attosecondsPart
    }
}
  • @2time.net Works! You're a life saver -- or at least, a few hours of life saver.

Add a Comment

As for

ar_data_providers_create_with_data_providers(...)

From modifications to warrenm example (see above)

am calling

 private func runWorldTrackingARSession() async {
        guard let arSession else { return err("arSession") }
        try? await arSession.run([worldTracking]) //WorldTrackingProvider
    }

passing through the arSession and worldTracking via

public func SpatialRenderer_InitAndRun(_ layerRenderer: LayerRenderer,
                                       _ arSession: ARKitSession,
                                       _ worldTracking: WorldTrackingProvider) {
    let renderThread = RenderThread(layerRenderer, arSession, worldTracking)
    renderThread.name = "Spatial Renderer Thread"
    renderThread.start()
}

called from

@main
struct FullyImmersiveMetalApp: App {
    @State var session = ARKitSession() //??
    @State var worldTracking = WorldTrackingProvider() //??
    init() {}
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        ImmersiveSpace(id: "ImmersiveSpace") {
            CompositorLayer(configuration: MetalLayerConfiguration()) { layerRenderer in
                SpatialRenderer_InitAndRun(layerRenderer, session, worldTracking)
            }
        }.immersionStyle(selection: .constant(.full), in: .full)
    }
}

All swift code compile but fails at runtime. Probably in another code block. YMMV

Full port of C++ to Swift is working. Code is here

Thanks to Warren Moore for C++ version.