尝试在 SCNRender 对象的每个调用渲染上从 MTLTexture 创建 CVPixelBufferRef:
CVPixelBufferLockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
let bytesPerRow = 4 * Int(textureSizeX)
let region = MTLRegionMake2D(0, 0, Int(textureSizeX), Int(textureSizeY))
var tmpBuffer = CVPixelBufferGetBaseAddress(pixelBuffer!);
offscreenTexture.getBytes(tmpBuffer!, bytesPerRow: bytesPerRow, from: region, mipmapLevel: 0)
CVPixelBufferUnlockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
然后转换为 UIImage 显示在屏幕上
let ciImage = CIImage.init(cvPixelBuffer: pixelBuffer!)
let temporaryContext = CIContext(options: nil)
let tempImage = temporaryContext.createCGImage(ciImage, from: CGRect(x: 0, y: 0, width: textureSizeX, height: textureSizeY))
let uiImage = UIImage.init(cgImage: tempImage!)
但图像不显示