ios - 在 ARKit 水平面上绘制填充多边形
问题描述
我将如何在 ARKit 世界中检测到的水平面上绘制用户触摸的填充多边形连接点。
我继续通过将生命值保持在数组上来做到这一点......
let position = SCNVector3.positionFrom(matrix: result.worldTransform)
let sphere = SphereNode(position: position)
nodes.append(position)
...然后尝试绘制贝塞尔路径
let bezierPath = UIBezierPath()
bezierPath.lineWidth = 0.1
for index in 0..<nodes.count {
let node = nodes[index] as SphereNode
if (index == 0) {
let point = CGPoint(x: CGFloat(node.position.x), y: CGFloat(node.position.z))
bezeierPath.move(to: point)
} else {
let point = CGPoint(x: CGFloat(node.position.x), y: CGFloat(node.position.z))
bezeierPath.addLine(to: point)
}
}
bezeierPath.close()
bezeierPath.fill()
bezeierPath.stroke()
let shape = SCNShape(path: bezeierPath, extrusionDepth: 0.03)
shape.firstMaterial?.diffuse.contents = UIColor.red
let node = SCNNode.init(geometry: shape)
sceneView.scene.rootNode.addChildNode(node)
但这并没有在正确的位置绘制多边形。它以垂直角度将其绘制在相机后面。
解决方案
像和的2D 几何形状本质SCNPlane
上是垂直的,因为它们在 xy 平面上工作。在您的示例中,您使用 z 3D 坐标作为 y 2X 坐标。SCNText
SCNShape
尝试设置node.eulerAngles.x
为-.pi / 2
(如果不起作用,请尝试不使用-
),您的节点将是水平的而不是垂直的。
推荐阅读
- php - DocuSign 嵌入式签名的隐式身份验证
- python - Python Tkinter - 将滚动条从框架画布的东边界延伸到西边界
- reactjs - 如何正确导出模块,以便 vscode 可以在建议 [ctrl+space] 中显示我的模块?
- bash - Makefiles 中的配方以破折号为前缀
- java - 尝试将 UUID 属性(外键)转换为实体对象的异常(已解决)
- mysql - 按相关表列排序表的最快方法
- c# - Linq-to-SQL dbContext 数据
- javascript - 将配置的 log4js 实例传递给类
- tensorflow - 将 TensorFlow 模型转换为可以提供的格式
- docusignapi - 将 Docusign 集成到 Web 应用程序中