我想使用SceneKit显示实时球面图像。我正在使用SCNMaterial的漫反射内容来显示它,但是实时显示时有些延迟。以下代码是我尝试实现的代码。如果遇到这种情况,请指导。
@IBOutlet weak var sceneView: SCNView!
let scene = SCNScene()
sceneView.scene = scene
sceneView.backgroundColor = UIColor.black
let material = SCNMaterial()
material.diffuse.mipFilter = .linear
material.diffuse.magnificationFilter = .linear
material.diffuse.contentsTransform = SCNMatrix4MakeScale(-1, 1, 1)
material.diffuse.wrapS = .repeat
material.cullMode = .front
let sphere = SCNSphere(radius: 8)
sphere.segmentCount = 300
httpConnection.startLiveView { (data) in
DispatchQueue.main.async {
let image = UIImage(data: data!)
material.diffuse.contents = image
}
}
sphere.firstMaterial = material
let sphereNode = SCNNode()
sphereNode.geometry = sphere
scene.rootNode.addChildNode(sphereNode)
在httpConnection.startLiveView
块中,我正在获取实时取景的图像数据。