首页 文章

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

提问于
浏览
1

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

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

2 回答

  • 2

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

    view.scene.background.contents = UIColor.red
    
     let myImage: UIImage = ... 
     view.scene.background.contents = myImage
    
  • 0

    我使用UIKit的震动回调来更改背景内容。 As @yaali said,CameraContents用于存储摄像机内容。请注意,如果相机尚未启动,例如在viewWillAppear上,我们将无法获得background.contents。我猜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
    
        }
    

相关问题