试着用我的RealityKit项目作为屏幕上应用程序(VR)的基础,而不是把它投射到现实世界(AR)后面的摄像头上。
有人知道如何使用RealityKit相机选项异步加载.nonAR项目,所以它在应用程序中进行项目,而不是利用后面的摄像头?
我是在Swift代码还是Reality Composer项目中创建位置信息?
发布于 2020-08-27 09:45:17
下面是如何在RealityKit的.loadModelAsync()实例方法的帮助下异步加载.loadModelAsync()VR模型并组合其AnyCancellable类型。
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")
}
}
)
}
}但是,如果您想在3D环境中移动,则不要使用.nonAR相机模式,请使用:
arView.environment.background = .color(.black)https://stackoverflow.com/questions/63600132
复制相似问题