【发布时间】:2018-12-30 19:04:19
【问题描述】:
我正在使用 ARKit 2 和 ARWorldMapData 我创建了一个 AR 世界,它可以使用来自 link here 的地图数据等来识别您的周围环境。现在我正试图弄清楚如何获取所有特征点然后连接以创建我的周围环境/ARWorldMap 的网格(我认为以前从未尝试过 ARKit 2)。虽然我确信你可以通过将特征点与 UIBezierPath 连接来实现它。这样您就可以使用路径创建的形状作为节点几何体。
经过测试,下面的代码不会在屏幕上产生任何东西,或者至少我看不到它。所以现在这就是问题所在。虽然我确信这可能还有更多问题。
我几乎只是使用这个问题中的示例here 来查看它是否可以远程工作。
代码:
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
}
所以它几乎可以占据这样的房间并填充墙壁/点以创建网格:
结果看起来像这样,但从实际站在房间的角度来看,显然是真人大小:
如果有任何天才可以帮助重构我的代码,有比这更好的代码,或者知道如何真正实现它。那将是惊人的!。谢谢
【问题讨论】:
标签: ios swift xcode scenekit arkit