我正在使用增强现实iOS应用程序,我使用的是iOS 11测试版的ARKIT。我正在使用ARSCNView(SceneKit)来渲染我的.scn对象。我已经按照apple给出的示例来创建ARSession(https://developer.apple.com/sample-code/wwdc/2017/PlacingObjects.zip)。是否可以使用自定义背景而不是相机来放置3D模型?
用户可以选择背景颜色还是可以提供自定义2D照片作为背景?
答案 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
。我想ARKit
将AVCaptureVideoPreviewLayer
设置为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
}