ios - (ARKit 2 Room Scanner)如何使用 UIBezierPath 和 featurePoints 来创建一个带有 ARKit 2 和 ARWorldMap 周围几何图形的节点
问题描述
我正在使用 ARKit 2 和ARWorldMapData我创建了一个 AR 世界,它可以通过此处的链接使用地图数据等识别您的周围环境。现在我试图弄清楚如何获取所有特征点然后连接以创建我的环境/ARWorldMap的网格(我认为以前从未尝试过使用 ARKit 2)。尽管我确信您可以通过将特征点与 UIBezierPath 连接来实现它。这样您就可以使用路径创建的形状作为节点几何图形。
经过测试,下面的代码不会在屏幕上产生任何东西,或者至少我看不到它。所以现在这就是问题所在。虽然我确信这可能还有更多问题。
我几乎只是在这里使用了这个问题中的示例来查看它是否可以远程工作。
代码:
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
guard !(anchor is ARPlaneAnchor) else { return }
let testNode = bezierNode.clone()
DispatchQueue.main.async {
node.addChildNode(testNode)
}
}
func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {
// take the current frame/views features points and create an array out of them
guard let currentFrame = self.sceneView.session.currentFrame,
let featurePointsArray = currentFrame.rawFeaturePoints?.points else { return }
// Create STROKE BezierPath
let strokeBezierPath = UIBezierPath()
strokeBezierPath.lineWidth = 0.1
// Start the BezierPath at the first feature points on the screen
strokeBezierPath.move(to: CGPoint(x: CGFloat(featurePointsArray.first!.x), y: CGFloat(featurePointsArray.first!.y)))
// iterate through all feature pints and add then to the path
featurePointsArray.forEach { (pointLocation) in
strokeBezierPath.addLine(to: CGPoint(x: CGFloat(pointLocation.x), y: CGFloat(pointLocation.y)))
}
// Close the Stroke BezierPath
strokeBezierPath.close()
// Do fancy work, not sure what this does
let cgPath = strokeBezierPath.cgPath.copy(
strokingWithWidth: strokeBezierPath.lineWidth,
lineCap: strokeBezierPath.lineCapStyle,
lineJoin: strokeBezierPath.lineJoinStyle,
miterLimit: strokeBezierPath.miterLimit)
// Create the actually bezierpath that were going to use to create the nodes geometry
let bezierPath = UIBezierPath(cgPath: cgPath)
let shape = SCNShape(path: bezierPath, extrusionDepth: 0.1)
shape.firstMaterial?.diffuse.contents = UIColor.blue
let node = SCNNode(geometry: shape)
// Add newly created node to the reference that gets passed to the didAdd delegate
bezierNode = node
// Then anchor gets added when we touch the screen with a tap gesture temporary that call the didAdd delegate
}
所以它几乎可以占用这样的房间并填充墙壁/点以创建网格:
结果看起来像这样,但显然是真人大小,并且从实际站在房间的角度来看:
如果那里有任何天才可以帮助重构我的代码,有比这更好的代码,或者可能知道如何真正实现它。这将是惊人的!. 谢谢
解决方案
ARWorldMap 可以存储特征点,但更有趣的是,它还可以保存 ARPlaneAnchors,它们本质上是已经为你准备好的网格。结果不会是完美的,但更接近您想要实现的目标并且更容易。我之前做过这方面的工作,并在 Twitter 上展示了一段视频,以在公园中展示视觉 ARWorldMap,每次在该位置启动应用程序时,它都会得到扩展(改进)。ARKit 可以从特征点检测平面,数学已经为您完成,所以使用它而不是尝试将特征点链接在一起。 https://twitter.com/londonrom/status/1010150386848628736
推荐阅读
- javascript - 如何将表单与一个输入链接提交与两个链接
- html - 带箭头的垂直线
- android - Android (Chrome) 上带有初始屏幕的 PWA 无法在应用名称中显示特殊字符
- java - StorageService 在 GluonHQ 框架上出现错误 - 我该如何解决?
- wpf - WPF DockPanel MinHeight 用法
- javascript - JavaScript:连续调用多个异步函数的更好方法?
- firebase - Decoding managed protocol buffer datastore/firestore export by google with protoc
- reactjs - 如何在 React Redux 中全局设置 `forwardRef: true`?
- javascript - 为什么axios拦截器中不能设置cookies
- c# - 如果单击图像或文本,则仅单击自定义选项卡项