我正在尝试在iOS中探索Google VR(虚拟现实)SDK。
参考:https://github.com/googlevr/gvr-ios-sdk
所以在Obj-C中有示例,我在Swift中进行了转换。出现问题,我无法预览VR视频(如SS1所示),黑屏显示为SS2。
我也尝试调试,发现
Google代码
GVRRendererViewController *viewController = self.childViewControllers[0];
GVRSceneRenderer *sceneRenderer = (GVRSceneRenderer *)viewController.rendererView.renderer;
GVRVideoRenderer *videoRenderer = [sceneRenderer.renderList objectAtIndex:0];
我的代码
if let vc = self.children.first as? GVRRendererViewController {
self.vrManager!.setupGVR(vc)
}
func setupGVR(_ gvrRendererVC: GVRRendererViewController) {
let sceneRenderer = gvrRendererVC.rendererView.renderer as! GVRSceneRenderer
if sceneRenderer.renderList.count() > 0,
let videoRenderer = sceneRenderer.renderList.object(at: 0) as? GVRVideoRenderer {
videoRenderer.player = self.avPlayer
}
}
在这里,我sceneRenderer.renderList
为空。在他们的SDK中很好。
让我知道是什么错误。
答案 0 :(得分:0)
func setupGVR(_ gvrRendererVC: GVRRendererViewController) {
guard let sceneRenderer = gvrRendererVC.rendererView.renderer as? GVRSceneRenderer else {
return
}
if sceneRenderer.renderList.isEmpty {
let videoRenderer = GVRVideoRenderer()
videoRenderer.player = self.avPlayer
videoRenderer.setSphericalMeshOfRadius(50.0,
latitudes: 12,
longitudes: 24,
verticalFov: 180,
horizontalFov: 360,
meshType: .stereoTopBottom)
sceneRenderer.renderList.add(videoRenderer)
} else {
if let videoRenderer = sceneRenderer.renderList.object(at: 0) as? GVRVideoRenderer {
videoRenderer.player = self.avPlayer
}
}
}