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()因为我想改变绘制线条粗细的厚度,但它不会改变。我该怎么办?
答案 0 :(得分:0)
SCeneKit首选使用Metal而不是OpenGl,并且在Metal中无法绘制粗线。此外,现在不建议使用OpenGl。您需要使用三角形来绘制粗线。
答案 1 :(得分:0)
两个值得尝试的想法: