【问题标题】:How to add an image to an ARSCNScene in Swift?如何在 Swift 中将图像添加到 ARSCNScene?
【发布时间】:2018-03-18 21:44:13
【问题描述】:

我在开发我正在开发的 Swift 游乐场时偶然发现了障碍。我想将图像添加到我的 ARSCNScene (ARKit + SceneKit)。不是作为背景,而是作为具有位置和所有的实际节点。有谁知道这是否可能?我在网上找不到任何东西。谢谢!

【问题讨论】:

  • 使用图片作为SCNPlane的素材

标签: swift scenekit arkit swift-playground


【解决方案1】:

您可以轻松地将 UIImage 作为漫反射材质添加到您的 SCNPlane。示例:

    let image = UIImage(named: "yourImageName")
    let node = SCNNode(geometry: SCNPlane(width: 1, height: 1))
    node.geometry?.firstMaterial?.diffuse.contents = image

此外,您可以根据需要修改您的节点。希望对您有所帮助!

【讨论】:

    【解决方案2】:

    我想我也找到了解决这个问题的方法,因为我遇到了同样的问题

    写:

    node.geometry?.firstmaterial?.diffuse.contents = #imageLiteral(resourceName: “yourimagename”)
    

    请注意,您必须先将图像添加到资产中(当然作为图像集)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-20
      相关资源
      最近更新 更多