【问题标题】:place SCNNode fixed in place without ARPlaneAnchor将 SCNNode 固定在没有 ARPlaneAnchor 的位置
【发布时间】:2019-05-04 12:30:46
【问题描述】:

我目前正在尝试将 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 的情况下使 cylinderLine SCNNode 固定到位?

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

【问题讨论】:

    标签: ios swift scenekit arkit


    【解决方案1】:

    你能展示你的 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)
          }
        }
    

    如果这有帮助,请告诉我;)

    【讨论】:

    • 嗨,我想在两个 SCNNode 对象之间绘制一条线
    • 我没有使用 nodeFor Anchor 方法来渲染线条,而是用于在 ARImageAnchor 之上渲染其他对象
    猜你喜欢
    • 2020-09-11
    • 1970-01-01
    • 1970-01-01
    • 2018-01-30
    • 1970-01-01
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    • 2014-03-31
    相关资源
    最近更新 更多