场景套件中的颜色线?
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)
}
我希望在调用此函数时能够传入颜色,以便它相应地改变颜色...
如何指定画线的颜色?
我将代码编辑为适合我的代码。我使用了发射 属性 而不是漫反射,并且我使用了恒定光...
a material 的 lightingModelName
默认为 SCNLightingModelBlinn
。使用此光照模型,漫反射 material 属性 的用法如下:
color = ... + diffuse * max(0, dot(N, L)) + ...
但由于您的几何体没有法线,diffuse
总是乘以 0。
您可能想要使用 SCNLightingModelConstant
光照模型或使用 emission
material 属性 而不是 diffuse
。
我正在使用以下代码在两个节点之间画一条线:
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)
}
我希望在调用此函数时能够传入颜色,以便它相应地改变颜色...
如何指定画线的颜色?
我将代码编辑为适合我的代码。我使用了发射 属性 而不是漫反射,并且我使用了恒定光...
a material 的 lightingModelName
默认为 SCNLightingModelBlinn
。使用此光照模型,漫反射 material 属性 的用法如下:
color = ... + diffuse * max(0, dot(N, L)) + ...
但由于您的几何体没有法线,diffuse
总是乘以 0。
您可能想要使用 SCNLightingModelConstant
光照模型或使用 emission
material 属性 而不是 diffuse
。