簡體   English   中英

使用 Swift 在 ARKit 中顯示白色圖像材料

[英]Display white image material in ARKit with Swift

我已經用 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 坐標和多邊形法線方向,因此紋理可以在多邊形表面上占據一定的空間。

查看 GitHub 上的這篇文章和這篇文章,了解如何實現它

雖然,當您使用常規 SceneKit 原語(例如 SCNSphere、SCNBox、SCNPlane 等)或導入的 3D 模型(DAE、OBJ 或 USDZ 文件格式)時,您不會考慮這些類型屬性的實現,因為上述幾何體已經包含他們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM