private func lineFrom(vector vector1: SCNVector3, toVector vector2: SCNVector3) -> SCNGeometry {

        let indices: [Int32] = [0,1]
        let source = SCNGeometrySource(vertices: [vector1, vector2])
        let element = SCNGeometryElement(indices: indices, primitiveType: .line)
        return SCNGeometry(sources: [source], elements: [element])
    }


@objc private func tapped(rec: UITapGestureRecognizer) {

    let hitTransform = SCNMatrix4(hit.worldTransform)

                let hitPoint = SCNVector3Make(hitTransform.m41 , hitTransform.m42, hitTransform.m43)

                if points.start == nil{
                    print("start touch")
                    points.start = hitPoint
                    print(points.start!.x, points.start!.y, points.start!.z)

                }

        else{
                    points.end = hitPoint
                    print(points.end!.x, points.end!.y, points.end!.z

                    line.geometry = lineFrom(vector: points.start!, toVector: points.end!)

                    line.geometry?.firstMaterial?.diffuse.contents = UIColor.red
                    line.geometry?.firstMaterial?.isDoubleSided = true

                    sceneView.scene.rootNode.addChildNode(line)
                    func renderer(_ renderer: SCNSceneRenderer, willRenderScene scene: SCNScene, atTime time: TimeInterval) {
                        glLineWidth(80)
                     }
                    canPlacePoint = false
                }
            }
        }
}


我触摸两个点以保存位置,然后尝试画一条连接两个点的线。尽管画了线,但触摸点的位置不正确。
 我还使用了glLineWidth(),因为我想更改绘制线的粗细,但不会改变。我该怎么办?

最佳答案

SCeneKit比起OpenGl更喜欢使用Metal,在Metal中无法绘制粗线。此外,现在不建议使用OpenGl。您需要使用三角形绘制粗线。

关于ios - 如何更改画线的粗细?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50149132/

10-08 21:25