0

I am trying to build an app with Xamarin while using ARKit in combination with Scenekit. The ARSession is configured to track horizontal planes, and when such a plane is found. I want to draw a custom chart on such a plane. The object looks fine and is in the right place, but it keeps rotating weirdly. As I walk around the object while testing, its orientation changes to face me, which it shouldn't do. This occurs for less than a second and then it changes back to its original orientation.

This method triggers when a plane is found in my delegate:

public override void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor) {

    if (anchor.GetType() != typeof(ARPlaneAnchor) || ChartIsPlaced) {
        return;
    }

    var planeAnchor = (ARPlaneAnchor) anchor;
    var chart = new ARChart(createTestData());
    chart = (ARChart) chart.DrawOnPlane(node);
    renderer.PointOfView.Light = chart.AddLightSource();

    node.AddChildNode(chart);
    ChartIsPlaced = true;
}

Whenever ARKit registers enough points to 'see' an anchor plane, a 3D chart is added as a child of this plane node.

Nearly every iOS sample I've seen that's made with Xcode doesn't have this problem, but I can't seem to translate it to C# correctly.

I suspect this has something to do with the way SceneKit handles the nodes and its children. Maybe the ARAnchor node changes and my object (which is a child of the anchor node) changes as well.

Why is it rotating? How can this behavior be controlled?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • Have you checked official sample https://developer.xamarin.com/samples/monotouch/ios11/ARKitSample/? – ColeX Oct 24 '17 at 07:39
  • @ColeXia I have. It has an unused method that seems to create a new anchor based on existing anchors. I experimented with it before, but I don't get how I can use this anchor – MikeCornelissen Oct 24 '17 at 08:40
  • refer to https://stackoverflow.com/questions/44401173/how-do-i-programmatically-move-an-aranchor – ColeX Oct 24 '17 at 09:22
  • @ColeXia Thanks for the reference. It seems that the code in the answer should do the exact same as mine. I add my node to the parent anchor node in exactly the same way. The function `func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor)` should be the same as `public override void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)`. If I'm wrong there, I'd love to know what the difference is. – MikeCornelissen Oct 25 '17 at 12:36

0 Answers0