【发布时间】:2020-06-04 14:41:34
【问题描述】:
我按照这个 raywenderlich 教程使用 AR 和 Scene Kit 检测图像。在这个例子中,他们展示了在检测到的图像上显示视频。
https://www.raywenderlich.com/6957-building-a-museum-app-with-arkit-2
我想在检测到的图像上显示图像。请帮助我如何将 childNode 添加到 SCNNode 以便我可以在其上显示图像。
这是我尝试过的代码,它无法显示空白屏幕。
DispatchQueue.main.async {
let size = imageAnchor.referenceImage.physicalSize
let imageView = UIImageView(image: UIImage(named: "BG.png")!)
let imgMaterial = SCNMaterial()
imgMaterial.diffuse.contents = imageView
let imgPlane = SCNPlane(width: size.width, height: size.height)
imgPlane.materials = [imgMaterial]
let imgNode = SCNNode(geometry: imgPlane)
imgNode.eulerAngles.x = -.pi / 2
node.addChildNode(imgNode)
node.opacity = 1
}
请帮助在检测到的图像上显示图像。提前致谢。
我可以在检测到的图像上显示图像,但是该代码有什么问题会占用大量内存。
与图像视图相同,我使用以下代码在检测到的图像顶部显示 gif 播放。
let size = imageAnchor.referenceImage.physicalSize
let imgNameFromDoc = person["actionToTake"] as! String
let documentsPathURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
let imgpath = documentsPathURL?.appendingPathComponent("/Packages/\(self.selectedDatasetName)/3DScenes/\(imgNameFromDoc)")
let imageData = try! Data(contentsOf: URL(fileURLWithPath: imgpath!.path))
let imageURL = UIImage.gifImageWithData(imageData)
self.gifImgView = UIImageView(image: imageURL)
let imgMaterial = SCNMaterial()
imgMaterial.diffuse.contents = self.gifImgView
let imgPlane = SCNPlane(width: CGFloat(scaleActionSize(wid: Float(size.width), hei:Float(size.height))[0]), height: CGFloat(scaleActionSize(wid: Float(size.width), hei:Float(size.height))[1]))
imgPlane.materials = [imgMaterial]
let imgNode = SCNNode(geometry: imgPlane)
imgNode.eulerAngles.x = -.pi / 2
node.addChildNode(imgNode)
node.opacity = 1
在图像扩展的帮助下,我在检测到的图像顶部的图像视图上显示 GIF。 https://github.com/kiritmodi2702/GIF-Swift/blob/master/GIF-Swift/iOSDevCenters%2BGIF.swift
How to load GIF image in Swift?
我把iOSDevCenters+GIF.swift类拖到app里面,显示gif。
当我使用这个 gif 图像视图来显示 gif 和图像视图来显示图像时,在 iPad 上运行的 Xcode 中需要超过 800 MB 的内存。
有人可以帮我找出任何内存泄漏(尝试使用无法修复的工具)或此代码中的任何错误。
【问题讨论】:
标签: ios swift xcode scenekit augmented-reality