1
votes

I'm currently trying to put an SCNNode fixed in place while use ARImageTrackingConfiguration which is no plane detection but it seems like not working properly because the SCNNode is moving while camera moves

below are the code:

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

is it possible to make the cylinderLine SCNNode fixed in place without ARPlaneAnchor ?

(Note: I had tried ARAnchor on nodeForAnchor delegate methods and it is still moving as camera moves)

1

1 Answers

0
votes

Can you show your nodeForAnchors method? That is where nodes are "fixed" to the image so i am guessing an error is there somewhere. Here is one example application of that 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)
      }
    }

Let me know if this helps ;)