ios - 如何在两个地理位置之间创建 SCNPlane(如下图所示)?
问题描述
我正在为 AR 导航使用“Mapbox”框架,我需要在两个地理位置之间添加 SCNPlane,如下图所示
// 代码 - 添加 SCNNode 和 SCNPlane
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
// 1
guard let planeAnchor = anchor as? ARPlaneAnchor else { return }
// 2
let width = CGFloat(planeAnchor.extent.x )
let height = CGFloat(planeAnchor.extent.z)
let plane = SCNPlane(width: width, height: height)
// 3
plane.materials.first?.diffuse.contents = UIColor.lightText
// 4
let planeNode = SCNNode(geometry: plane)
// 5
let x = CGFloat(planeAnchor.center.x)
let y = CGFloat(planeAnchor.center.y)
let z = CGFloat(planeAnchor.center.z)
planeNode.position = SCNVector3(x,y,z)
planeNode.eulerAngles.x = -.pi / 2
// 6
node.addChildNode(planeNode)
}
// 更新这里的节点
func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
// 1
guard let planeAnchor = anchor as? ARPlaneAnchor,
let planeNode = node.childNodes.first,
let plane = planeNode.geometry as? SCNPlane
else { return }
// 2
let width = CGFloat(planeAnchor.extent.x + 100)
let height = CGFloat(planeAnchor.extent.z )
plane.width = width
plane.height = height
// 3
let x = CGFloat(planeAnchor.center.x)
let y = CGFloat(planeAnchor.center.y)
let z = CGFloat(planeAnchor.center.z)
planeNode.position = SCNVector3(x, y, z)
}
在这里,我使用 ARPlaneAnchor 来检测平面并使用 didAdd /didUpdate 代表添加/更新 SCNNode,但我需要在不使用 ARPlaneAnchor 的情况下在两个地理位置之间绘制 SCNPlane。
提前致谢,
解决方案
推荐阅读
- postgresql - spark是否支持以下级联查询?
- microsoft-graph-api - 团队/组的邮件昵称 - 允许的字符或正则表达式
- angular - 垫表不显示任何数据,显示白条
- tensorflow - Tensorflow model.fit 在 while 循环中崩溃
- php - 使用 Symfony 5 中的 FOSRestBundle 转换单个属性以进行响应
- javascript - Javascript:在这种情况下如何避免嵌套 foreach?
- apache-flink - 将 func_type='pandas' 添加到 PyFlink UDF 会引发 ArrowTypeError('Did not pass numpy.dtype object'))
- rx-java - Micronaut 中反应式控制器方法的返回类型应该是什么?
- java - 实例化泛型类的正确方法
- javascript - 在 ServiceNow 中使用 ES5(仅使用 CDN 库)签署 HTTP 请求