我正在使用以下代码在两个节点之间绘制一条线:
```html
```html
我正在使用以下代码在两个节点之间绘制一条线:
```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)
}
我希望能够在调用此函数时传入一种颜色,以便相应地更改颜色...
如何指定绘制线条的颜色?
我编辑了代码以使其适用于我。我使用了发射属性而不是漫反射,并且使用了恒定光源...
orangeColor
。 - rickster