[英]Color line in scene kit?
我使用以下代碼在兩個節點之間繪制一條線:
class func lineBetweenNodeA(nodeA: SCNNode, nodeB: SCNNode) -> SCNNode {
let positions: [Float32] = [nodeA.position.x, nodeA.position.y, nodeA.position.z, nodeB.position.x, nodeB.position.y, nodeB.position.z]
let positionData = NSData(bytes: positions, length: sizeof(Float32)*positions.count)
let indices: [Int32] = [0, 1]
let indexData = NSData(bytes: indices, length: sizeof(Int32) * indices.count)
let source = SCNGeometrySource(data: positionData, semantic: SCNGeometrySourceSemanticVertex, vectorCount: indices.count, floatComponents: true, componentsPerVector: 3, bytesPerComponent: sizeof(Float32), dataOffset: 0, dataStride: sizeof(Float32) * 3)
let element = SCNGeometryElement(data: indexData, primitiveType: SCNGeometryPrimitiveType.Line, primitiveCount: indices.count, bytesPerIndex: sizeof(Int32))
let line = SCNGeometry(sources: [source], elements: [element])
line.firstMaterial?.lightingModelName = SCNLightingModelConstant
line.firstMaterial?.emission.contents = UIColor.orangeColor()
return SCNNode(geometry: line)
}
我希望能夠在調用此函數時傳遞顏色,以便相應地更改顏色...
如何指定繪制線條的顏色?
我編輯了代碼以適合我。 我使用發射屬性而不是漫反射,我使用恆定光...
材質的lightingModelName
默認為SCNLightingModelBlinn
。 使用此照明模型,漫反射材質屬性使用如下:
color = ... + diffuse * max(0, dot(N, L)) + ...
但由於幾何體沒有法線,因此diffuse
總是乘以0。
您可能希望使用SCNLightingModelConstant
光照模型或使用emission
材質屬性而不是diffuse
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.