Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 虚拟现实技术 尝试使用我的RealyTyKIT项目作为屏幕应用程序(VR)的基础,而不是投影到真实世界(AR)外的后置摄像头。_Swift_Virtual Reality_Realitykit_Reality Composer - Fatal编程技术网

Swift 虚拟现实技术 尝试使用我的RealyTyKIT项目作为屏幕应用程序(VR)的基础,而不是投影到真实世界(AR)外的后置摄像头。

Swift 虚拟现实技术 尝试使用我的RealyTyKIT项目作为屏幕应用程序(VR)的基础,而不是投影到真实世界(AR)外的后置摄像头。,swift,virtual-reality,realitykit,reality-composer,Swift,Virtual Reality,Realitykit,Reality Composer,有人知道如何使用.nonAR摄像头选项异步加载RealityKit项目,从而使其在应用程序中投影,而不是利用后向摄像头吗 我是在Swift代码还是Reality Composer项目中创建位置信息?以下是如何借助RealityKit的.loadModelAsync()实例方法和Combine的anyCancelable类型异步加载.usdz虚拟现实模型 import UIKit import RealityKit import Combine class VRViewController: U

有人知道如何使用
.nonAR
摄像头选项异步加载RealityKit项目,从而使其在应用程序中投影,而不是利用后向摄像头吗


我是在Swift代码还是Reality Composer项目中创建位置信息?

以下是如何借助RealityKit的
.loadModelAsync()
实例方法和Combine的
anyCancelable
类型异步加载
.usdz
虚拟现实模型

import UIKit
import RealityKit
import Combine

class VRViewController: UIViewController {
    
    @IBOutlet var arView: ARView!
    var anyCancellable: AnyCancellable? = nil
    let anchorEntity = AnchorEntity(world: [0, 0,-2])
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        arView.backgroundColor = .black
        arView.cameraMode = .nonAR

        anyCancellable = ModelEntity.loadModelAsync(named: "horse").sink(
                        
            receiveCompletion: { _ in
                self.anyCancellable?.cancel()
            },
            
            receiveValue: { [self] (object: Entity) in
                if let model = object as? ModelEntity {
                    self.anchorEntity.addChild(model)
                    self.arView.scene.anchors.append(self.anchorEntity)
                } else {
                    print("Can't load a model due to some issues")
                }
            }
        )
    }
}
但是,如果要在三维环境中移动,请不要使用
.nonAR
相机模式,而是使用:

arView.environment.background = .color(.black)