如何将图像添加到 Swift 中的 ARSCNScene?

How to add an image to an ARSCNScene in Swift?

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

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

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

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

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

写:

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

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