Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 场景套件中的颜色线?_Ios_Scenekit - Fatal编程技术网

Ios 场景套件中的颜色线?

Ios 场景套件中的颜色线?,ios,scenekit,Ios,Scenekit,我使用以下代码在两个节点之间画一条线: 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 positi

我使用以下代码在两个节点之间画一条线:

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)) + ...
但由于几何体没有法线,
漫反射
始终乘以0


您可能希望使用
SCNLightingModelConstant
照明模型,或者使用
发射
材质属性,而不是
漫反射

难道您还没有指定颜色吗?在你发布的代码中,我看到了一些关于
橙色的东西。它看起来不起作用。线条始终是黑色的我尝试使用发射属性而不是漫反射,但它仍然是黑色的。好吧,所以我认为使用光常数是可行的,尽管很难看到线条的颜色,因为它非常薄。。。我这样做了:line.firstMaterial?.lightingModelName=scnlightingmodelsconstant