【问题标题】:Display white image material in ARKit with Swift使用 Swift 在 ARKit 中显示白色图像素材
【发布时间】:2019-06-24 11:26:01
【问题描述】:

我已经使用 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])
}

【问题讨论】:

    标签: ios swift scenekit augmented-reality arkit


    【解决方案1】:

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

    SCNGeometrySource.Semantic.texcoord
    SCNGeometrySource.Semantic.normal
    

    它让纹理找出什么是 UV 坐标和多边形法线方向,因此纹理可以在多边形表面上占据一定的空间。

    查看 GitHub 上的 this 帖子和 this 帖子,了解如何实现它

    虽然,当您使用常规 SceneKit 基元(例如 SCNSphere、SCNBox、SCNPlane 等)或导入的 3D 模型(DAE、OBJ 或 USDZ 文件格式)时,您不会考虑实现这些类型属性,因为前面提到的几何图形已经包含它们。

    【讨论】:

      猜你喜欢
      • 2018-07-18
      • 1970-01-01
      • 2014-04-21
      • 1970-01-01
      • 2020-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多