Ios 使用Swift在ARKit中显示白色图像材质

Ios 使用Swift在ARKit中显示白色图像材质,ios,swift,scenekit,augmented-reality,arkit,Ios,Swift,Scenekit,Augmented Reality,Arkit,我已经用SCNGeometryElement创建了节点,并应用图像内容材质显示白色,应用颜色内容工作正常。我有附加代码 func getsquareDrawnLineFrom(pos1: SCNVector3, pos2: SCNVector3, pos3: SCNVector3) -> SCNNode { let square = SquareplanlineFrom

我已经用SCNGeometryElement创建了节点,并应用图像内容材质显示白色,应用颜色内容工作正常。我有附加代码

func getsquareDrawnLineFrom(pos1: SCNVector3,
                            pos2: SCNVector3,
                            pos3: SCNVector3) -> SCNNode {

    let square = SquareplanlineFrom(vector1: pos1, vector2: pos2, vector3: pos3)
    let material = SCNMaterial()
    // material.diffuse.contents = UIColor.red
    material.diffuse.contents = UIImage(named: "grid")
    square.materials = [material]
    let square1 = SCNNode(geometry: square)
    square1.name = "tringle"
    return square1
}

// get line geometry between three vectors
func SquareplanlineFrom(vector1: SCNVector3,
                        vector2: SCNVector3, 
                        vector3: SCNVector3) -> SCNGeometry {

    let indices: [Int32] = [0, 1, 2]
    let source = SCNGeometrySource(vertices: [vector1, vector2, vector3])
    let element = SCNGeometryElement(indices: indices, primitiveType: .triangles)

    return SCNGeometry(sources: [source], elements: [element])
}

要在自定义几何体上放置纹理,您需要实现两个更重要的类型属性:

SCNGeometrySource.Semantic.texcoord
SCNGeometrySource.Semantic.normal
它让纹理找出UV坐标和多边形法线方向,这样纹理就可以在多边形曲面上占据一定的空间

查看post和GitHub上的post,了解如何实现它

尽管如此,当您使用常规SceneKit基本体(如SCNSphere、SCNBox、SCNPlane等)或导入的三维模型(采用DAE、OBJ或USDZ文件格式)时,您不会考虑这些类型属性的实现,因为前面提到的几何体已经包含它们