ios - 将 SCNNode 固定到位,无需 ARPlaneAnchor

标签 ios swift scenekit arkit

我目前正在尝试将 SCNNode 固定到位,同时使用 ARImageTrackingConfiguration,它没有平面检测,但似乎无法正常工作,因为 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 的情况下将圆柱体线 SCNNode 固定到位?

(注意:我在nodeForAnchor委托(delegate)方法上尝试过ARAnchor,它仍然随着相机移动而移动)

最佳答案

你能展示一下你的nodeForAnchors方法吗? 这就是节点“固定”到图像的地方,所以我猜测某处存在错误。以下是该委托(delegate)的一个示例应用程序:

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)
      }
    }

请告诉我这是否有帮助;)

关于ios - 将 SCNNode 固定到位,无需 ARPlaneAnchor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53589929/

相关文章:

ios - 使用 SceneKit 在 ARKit 中拖动 SCNNode

ios - 从通知中心删除 "remote notifications"

ios - 如何访问 objective-c 文件中的 swift 类

html - 33% + 33% + 34% 与 iOS 上的 100% 宽度不同

iOS:根据 View 位置动态更改 UILabel 对齐方式

ios - 在 SpriteKit 中,当播放声音时,它会与加速度计混淆

swift 4 将图像文字添加到字符串

ios - 如何以编程方式将 .scn 从 Documents 文件夹转换为 SCNNode?

ios - JoyStick 仅在 Camera Controls = true 时移动 Xcode、SWIFT、SpriteKit、SceneKit

ios - 响应按钮事件更新图像