如何在不使用相机的情况下使用ARKit iOS 11和一些自定义背景视图放置3D模型?

时间:2017-07-26 08:22:10

标签: ios11 xcode9-beta arkit

我正在使用增强现实iOS应用程序,我使用的是iOS 11测试版的ARKIT。我正在使用ARSCNView(SceneKit)来渲染我的.scn对象。我已经按照apple给出的示例来创建ARSession(https://developer.apple.com/sample-code/wwdc/2017/PlacingObjects.zip)。是否可以使用自定义背景而不是相机来放置3D模型?

用户可以选择背景颜色还是可以提供自定义2D照片作为背景?

2 个答案:

答案 0 :(得分:2)

您的视图有scene属性,您可以将background设置为颜色或图像:

 view.scene.background.contents = UIColor.red

 let myImage: UIImage = ... 
 view.scene.background.contents = myImage

答案 1 :(得分:0)

我使用UIKit的摇动动作回调来改变背景内容。正如@yaali所说,CameraContents用于存储相机内容。请注意,如果相机尚未启动,我们无法获取background.contents,例如viewWillAppear。我想ARKitAVCaptureVideoPreviewLayer设置为ARSCNView.scene.background.cocntents

    override func motionBegan(_ motion: UIEventSubtype, with event: UIEvent?) {
        if CameraContents == nil {
            CameraContents = sceneView.scene.background.contents;
            return
        }
        if cameraBackGround == true {
            sceneView.scene.background.contents = "Background_sky.png"
        }else{
            sceneView.scene.background.contents = CameraContents
        }
        cameraBackGround = !cameraBackGround

    }
相关问题