如何使使用ARKit ARSKViewDelegate JPG图片?

问题描述 投票:3回答:2

我想呈现JPG图片作为2D矩形漂浮在太空中。使用SpriteKit例子 - 我怎么从ARSKViewDelegate返回JPG图片?

演示返回SKLabelNode - 有一个Node类,这将是适合,我会从网络上,也许UIImage取一个JPG图片?

func view(_ view: ARSKView, nodeFor anchor: ARAnchor) -> SKNode? {
    // Create and configure a node for the anchor added to the view's session.
    let labelNode = SKLabelNode(text: "👾")
    labelNode.horizontalAlignmentMode = .center
    labelNode.verticalAlignmentMode = .center
    return labelNode;
}
ios swift sprite-kit arkit
2个回答
2
投票

您可以使用SCNPlane和分配UIImage为平面的内容。

let imagePlane = SCNPlane(width: sceneView.bounds.width/6000, height: sceneView.bounds.height/6000)
imagePlane.firstMaterial?.diffuse.contents = //<-- UIImage here
imagePlane.firstMaterial?.lightingModel = .constant
let planeNode = SCNNode(geometry: imagePlane)

更新:现在我注意到您使用SpriteKit。我共享的代码是使用SceneKit。


1
投票

貌似我可以从一个SKSpriteNode使用SKTexture。与唯一的问题是我在大约降低AR性能日志警告看到。 [Technique] World tracking performance is being affected by resource constraints [1]

let url = URL(string: imageURL)
let data = try? Data(contentsOf: url!) //make sure your image in this url does exist, otherwise unwrap in a if let check
let theImage = UIImage(data: data!)
let Texture = SKTexture(image: theImage!)
return SKSpriteNode(texture: Texture)
© www.soinside.com 2019 - 2024. All rights reserved.