【问题标题】:Use an ARSCNView on devices that don't support ARKit在不支持 ARKit 的设备上使用 ARSCNView
【发布时间】:2017-09-08 12:00:37
【问题描述】:

是否可以使用ARSCNView,为支持它的设备配置ARWorldTrackingConfiguration,并为不支持它的设备(使用A8芯片及更低)配置它,但仍然有视频在后台渲染?

if ARWorldTrackingConfiguration.isSupported{
    let config=ARWorldTrackingConfiguration()
    config.planeDetection = .horizontal
    sceneView.session.run(config)
}else if AROrientationTrackingConfiguration.isSupported{
    let config=AROrientationTrackingConfiguration()
    sceneView.session.run(config)
}else{
    print("not supported")
    //what here?  <<<
}

【问题讨论】:

    标签: ios swift arkit arscnview


    【解决方案1】:

    您需要一个正在运行的ARSession 来将摄像头馈送至ARSCNView,要运行ARSession,您需要一个受支持的ARConfiguration,并且所有配置都需要A9。

    但是,如果您的低于 A9 的后备计划是拥有一个无法获得任何 ARKit 运动跟踪的 SceneKit 视图...您不需要 ARKit。只需使用常规的 SceneKit 视图 (SCNView)。要使摄像机源显示在您的 SceneKit 内容后面,请找到您想要的摄像机的 AVCaptureDevice,并将其传递给您视图中场景的 background.contents

    (使用捕获设备作为 SceneKit 背景是 iOS 11 中的新功能。文档中似乎没有(还没有?),但它被描述为 in the WWDC17 SceneKit session。)


    顺便说一句,没有任何设备支持方向跟踪但不支持世界跟踪,因此您问题中的多分支if 语句有点矫枉过正。

    【讨论】:

    • 感谢您的回复!我会试试你说的。
    • 顺便问一下,SCNView的背景内容,你建议如何通过相机?与AVCaptureVideoPreviewLayer?或者像我以前那样:在 GLKView 中显示框架?
    • 1.使用AVCaptureDevice.default(_:for:position:) 找到后置摄像头。 2. 将scene.background.contents 设置为刚刚得到的AVCaptureDevice 对象。 3. 没有第三步!
    • 我可能遗漏了一些东西。我有一个白屏,如果我更改backgroundColor 以清除它会变成黑色,但仍然没有相机预览。
    • 查看我的答案中的链接——不要设置视图的backgroundColor(这是从UIView 继承的属性并且只接受颜色),设置@ 的background 987654343@ 显示在视图中。这是一个SCNMaterialProperty,这意味着您可以将其contents 设置为任意数量的东西,包括颜色、图像和AVCaptureDevices。
    【解决方案2】:

    下面的代码解决了这个问题,可能是代码损坏

    let device = sceneView.device!
    let maskGeometry = ARSCNFaceGeometry(device: device)!
    mask = Mask(geometry: maskGeometry, maskType: maskType)
    

    替换为

        let device = MTLCreateSystemDefaultDevice()
        let maskGeometry = ARSCNFaceGeometry(device: device!)!
        mask = Mask(geometry: maskGeometry)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-19
      • 2013-07-02
      • 2018-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多