【问题标题】:(ARKit 2 Room Scanner) How to use UIBezierPath & featurePoints to create a node with the geometry of your surroundings with ARKit 2 & ARWorldMap(ARKit 2 Room Scanner)如何使用 UIBezierPath 和 featurePoints 通过 ARKit 2 和 ARWorldMap 创建具有周围几何形状的节点
【发布时间】: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


    【解决方案1】:

    ARWorldMap 可以存储特征点,但更有趣的是,它还可以保存 ARPlaneAnchors,它们本质上是已经为你准备好的网格。结果不会是完美的,但更接近您想要实现的目标并且更容易。我之前做过这方面的工作,并在 Twitter 上展示了一段视频,以在公园中展示视觉 ARWorldMap,每次在该位置启动应用程序时,它都会得到扩展(改进)。 ARKit 可以从特征点检测平面,数学已经为您完成,所以使用它而不是尝试将特征点链接在一起。 https://twitter.com/londonrom/status/1010150386848628736

    【讨论】:

    • 非常有趣,你在最前沿,我会告诉你这么多。我看了链接!超酷!。我仍然会看看是否仍然可以创建一个单一的网格。如果不是,我很可能会将其标记为答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-08
    • 2018-11-15
    • 1970-01-01
    • 1970-01-01
    • 2020-04-01
    • 2017-12-11
    • 2019-04-24
    相关资源
    最近更新 更多