场景工具包中的颜色线?

4
我正在使用以下代码在两个节点之间绘制一条线:
```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
它似乎不起作用。该行始终是黑色的。 - zumzum
1个回答

6
一个材质的lightingModelName默认为SCNLightingModelBlinn。使用这种照明模型,漫反射材质属性的用途如下:
color = ... + diffuse * max(0, dot(N, L)) + ...

但是,由于您的几何体没有法线,diffuse 始终乘以 0。

您可能希望使用 SCNLightingModelConstant 光照模型或使用 emission 材质属性代替 diffuse


我尝试使用发射属性而不是漫反射,但仍然是黑色的。 - zumzum
1
好的,我认为使用光常数可以解决问题,尽管很难看清线的颜色,因为它非常细... 我做了这个:line.firstMaterial?.lightingModelName = SCNLightingModelConstant - zumzum

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接