ios - 将 SCNNode 固定在没有 ARPlaneAnchor 的位置
问题描述
我目前正在尝试在使用ARImageTrackingConfiguration时将 SCNNode固定到位,这不是平面检测,但似乎无法正常工作,因为 SCNNode 在相机移动时正在移动
以下是代码:
/// show cylinder line
func showCylinderLine(point a: SCNVector3, point b: SCNVector3, object: VirtualObject) {
let length = Vector3Helper.distanceBetweenPoints(a: a, b: b)
let cyclinderLine = GeometryHelper.drawCyclinderBetweenPoints(a: a, b: b, length: length, radius: 0.001, radialSegments: 10)
cyclinderLine.name = "line"
cyclinderLine.geometry?.firstMaterial?.diffuse.contents = UIColor.red
self.sceneView.scene.rootNode.addChildNode(cyclinderLine)
cyclinderLine.look(at: b, up: self.sceneView.scene.rootNode.worldUp, localFront: cyclinderLine.worldUp)
}
是否可以在没有 ARPlaneAnchor 的情况下将 cylinderLine SCNNode 固定到位?
(注意:我曾在 nodeForAnchor 委托方法上尝试过 ARAnchor,但它仍在随着相机的移动而移动)
解决方案
你能展示你的 nodeForAnchors 方法吗?那是节点被“固定”到图像的地方,所以我猜某处有错误。这是该委托的一个示例应用程序:
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
let node = SCNNode()
if let _ = anchor as? ARImageAnchor {
if let objectScene = SCNScene(named: "ARassets.scnassets/object.scn") {
//creates a new node that is connected to the image. This is what makes your object "fixed"
let objectNode = objectScene.rootNode.childNodes.first!
objectNode.position = SCNVector3Zero
objectNode.position.y = 0.15
node.addChildNode(planeNode)
}
}
让我知道这是否有帮助;)
推荐阅读
- python - 使用时间和numpy时使用Python API在外部C函数中出现Dymola Segfault
- ruby-on-rails - 在 URL 中自动使用模型属性生成路由
- reactjs - 将 props 传递给 material-ui 样式
- php - 使用 PHP 表单插入数据时忽略空输入
- angular - 用来自另一个界面的数据填充选择
- css - 如何使我的搜索框图标与我的搜索框输入对齐?
- javascript - 添加/删除类会导致输入内容消失
- sql - SQl 查询以查找用户尚未预测但其他用户可能已经预测的多个固定装置
- reactjs - 如果我没有在后台打开我的应用程序,深层链接将不起作用
- javascript - URL 解析 NodeJS 已弃用。如何解析相对网址?