我正在构建一个想要在目标增强图像上显示多行文本的应用程序。该程序对于少于7行的文本可以正常工作,但是当超过7行时会崩溃。我还注意到,如果一行太长,则会出现相同的错误“由于执行过程中的错误而中止了命令缓冲区的执行。忽略(由于导致先前的或过多的GPU错误)”。
let text = SCNText(string: "this is the first line \n hello this is the second line \n hello this is the third line \n hello this is the fourth line \n hello this is the fifth line \n hello this is the sixth line \n hello this is the seventh line \n hello this is the eigth lines\n " , extrusionDepth: 0.1)
//setting the basic properties of text
text.font = UIFont.systemFont(ofSize: 1)
text.flatness = 0.005
text.isWrapped = true
let textNode = SCNNode(geometry: text)
let fontScale: Float = 0.01
textNode.scale = SCNVector3(fontScale, fontScale, fontScale)
//将文本设置为在图片上方居中并面向相机
textNode.eulerAngles.x = -.pi/2
centerNode(node: textNode)
//self.sceneView.scene.rootNode.addChildNode(planeNode)
// the text will be centered right above the image
node.addChildNode(textNode)
// create a plane node as the background of the text
let textWidth = text.boundingBox.max.x - text.boundingBox.min.x
let textHeight = text.boundingBox.max.y - text.boundingBox.min.y
let plane = SCNPlane(width: CGFloat(textWidth), height: CGFloat(textHeight))
plane.firstMaterial?.transparency = 0.5
plane.firstMaterial?.diffuse.contents = UIColor.black
let planeNode = SCNNode(geometry: plane)
planeNode.position = SCNVector3(textWidth/2,1.5*textHeight,-0.0001)
textNode.addChildNode(planeNode)
“由于执行过程中的错误,命令缓冲区的执行被中止。被忽略(由于导致先前/过多的GPU错误)”
答案 0 :(得分:1)
当我的文字过于复杂时,我遇到了这个问题。我通过增加flatness
中的SCNText
减少了多边形的总数,并能够渲染更多文本。
text.flatness = 0.6 // default value
text.flatness = 0.0005 // more polygons, higher complexity
text.flatness = 1.0 // lower polyon, lower complexity (uglier text)
尝试降低复杂性。照明,多边形总数,材料复杂性等。