How to place 3D model using ARKit iOS 11 with some custom background view without using camera?

六月ゝ 毕业季﹏ 提交于 2019-12-23 02:36:05

问题


I am working on an Augmented Reality iOS app for which i am using ARKIT of iOS 11 beta. I am using ARSCNView(SceneKit) to render my .scn object. I have followed the sample given by apple in order to create an ARSession(https://developer.apple.com/sample-code/wwdc/2017/PlacingObjects.zip). Is it possible to place the 3D model with custom background instead of camera?

Like user can select the background color or can provide custom 2D photos as background?


回答1:


Your view has a scene property where you can set the background to a color or an image:

 view.scene.background.contents = UIColor.red

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



回答2:


I use shake motion callback of UIKit to change background contents. As @yaali said, CameraContents is used to store camera contents. Notice that we can't get background.contents if the camera has not launched, for example on viewWillAppear. I guess ARKit set the AVCaptureVideoPreviewLayer to 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

    }


来源:https://stackoverflow.com/questions/45321275/how-to-place-3d-model-using-arkit-ios-11-with-some-custom-background-view-withou

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!