Search code examples
xamarin.iosarkit

How to use the SCNNode look Method in Xamarin iOS?


Im Programming a Xamarin iOS AR app. Im trying to display an arrow in my ARSCNView that points to a specific node.

The method I use to add the arrow:

 private void AddDirectionArrow()
    {
       
            var arrow = SCNScene.FromFile("arrow.dae");

            if (arrow is null)
            {
                throw new FileNotFoundException("Pfeil 3D Modell nicht gefunden");
            }

            this.ArrowNode = arrow.RootNode;
            this.ArrowNode.Position = new SCNVector3(0, 3, -8f);

            this.sceneView.PointOfView?.AddChildNode(this.ArrowNode);

            this.ArrowNode.Rotation = new SCNVector4(0, 0, 1, 0);
     }

This works fine.The arrow stays in front of the users device.

My class has 2 nodes as property:

private SCNNode ArrowNode;
private SCNNode NodeToPointTo;

The NodeToPointTo is set as followed:

this.NodeToPointTo = this.sceneView.GetNode(<SomeARAnchor>);

Works fine as well.

In the ARDelegate.cs method WillRenderScene I call this method to update the arrow:

  public override void OnUpdateScene(double timeInSeconds)
        {
            base.OnUpdateScene(timeInSeconds);

            if (this.NodeToPointTo is null)
            {
                return;
            }

            this.ArrowNode.Look(this.NodeToPointTo.WorldPosition, this.sceneView.PointOfView.WorldUp, this.ArrowNode.WorldFront);
        }

This is what I cant figure out.

Im calling the Look method that should point my arrow node to the node I want it to point to.

How do I call this method correctly so my arrow points to the node?

Here is the Apple Dokumentation since I couldn't find any for Xamarin.

And the desired outcome

Don't hesitate to ask if anything is unclear.

-Simon


Solution

  • According to this case which is about one SCNNode look at another SCNNode, you can try to use the SCNLookAtConstraint which is a constraint that orients a node to always point toward a specified other node.

    You can try the following code:

    private SCNNode ArrowNode;
    private SCNNode NodeToPointTo;
    ....
    SCNLookAtConstraint sCNLookAtConstraint = SCNLookAtConstraint.Create(NodeToPointTo);
    ArrowNode.Constraints = new SCNLookAtConstraint[] { sCNLookAtConstraint };