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?