1
votes

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?

2
You need to include some more information. What are you doing? Are you using SceneKit, what do you mean with "camera"?jlsiewert
@orangenkopf Sorry for the vague question. I have edited my question. I am using "SceneKit" and the sample "PlacingObjects" provided by apple.yaali
So you don't want to have the camera stream as a scene background but something different? But than you don't have AR anymore? You can change the background of the scene to an image or a color: scene.background.contents = UIColor.red. I don't know if that works for ARKit too though.jlsiewert
@orangenkopf This is what exactly i needed!! I want to give user an option to place the object either using camera(AR) or with custom background. Thats why i need it. Thank you!!yaali
Have you tried it and it works? Or does ARKit overrides the scene's background in some way?jlsiewert

2 Answers

2
votes

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
0
votes

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

    }