Shapes

Share on Twitter Share on Facebook Share on LinkedIn

Shapes

Description

There are a number of built in shapes (Geometries) you may wish to make use of.

Including Sphere, Box, Plane, Cylinder, Tube, Torus, Pyramid and Cone.


Video

No video yet


Code

using ARKit;
using SceneKit;
using System;
using UIKit;

namespace XamarinArkitSample
{
    public partial class ViewController : UIViewController
    {
        private readonly ARSCNView sceneView;

        public ViewController(IntPtr handle) : base(handle)
        {
            this.sceneView = new ARSCNView
            {
                AutoenablesDefaultLighting = true
            };

            this.View.AddSubview(this.sceneView);
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            this.sceneView.Frame = this.View.Frame;
        }

        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            this.sceneView.Session.Run(new ARWorldTrackingConfiguration
            {
                AutoFocusEnabled = true,
                PlaneDetection = ARPlaneDetection.Horizontal,
                LightEstimationEnabled = true,
                WorldAlignment = ARWorldAlignment.GravityAndHeading,
                FrameSemantics = ARFrameSemantics.PersonSegmentationWithDepth,
            }, ARSessionRunOptions.ResetTracking | ARSessionRunOptions.RemoveExistingAnchors);

            var size = 0.05f;

            var material = new SCNMaterial();
            material.Diffuse.Contents = UIColor.Red;

            var boxNode = new SCNNode();
            boxNode.Geometry = SCNBox.Create(size, size, size, 0);
            boxNode.Geometry.Materials = new SCNMaterial[] { material };
            boxNode.Position = new SCNVector3(0, 0, 0);

            var sphereNode = new SCNNode();
            sphereNode.Geometry = SCNSphere.Create(size/2);
            sphereNode.Geometry.Materials = new SCNMaterial[] { material };
            sphereNode.Position = new SCNVector3(0.1f, 0, 0);

            var torusNode = new SCNNode();
            torusNode.Geometry = SCNTorus.Create(size / 2, size/6);
            torusNode.Geometry.Materials = new SCNMaterial[] { material };
            torusNode.Position = new SCNVector3(0.2f, 0, 0);

            var tubeNode = new SCNNode();
            tubeNode.Geometry = SCNTube.Create(size/2, (size/2), size*2);
            tubeNode.Geometry.Materials = new SCNMaterial[] { material };
            tubeNode.Position = new SCNVector3(0.3f, 0, 0);

            var coneNode = new SCNNode();
            coneNode.Geometry = SCNCone.Create(0.01f, (size / 2), size * 2);
            coneNode.Geometry.Materials = new SCNMaterial[] { material };
            coneNode.Position = new SCNVector3(0.4f, 0, 0);

            var cylinderNode = new SCNNode();
            cylinderNode.Geometry = SCNCylinder.Create(size/2,size);
            cylinderNode.Geometry.Materials = new SCNMaterial[] { material };
            cylinderNode.Position = new SCNVector3(0.5f, 0, 0);

            var pyramidNode = new SCNNode();
            pyramidNode.Geometry = SCNPyramid.Create(size,size,size);
            pyramidNode.Geometry.Materials = new SCNMaterial[] { material };
            pyramidNode.Position = new SCNVector3(0.6f, 0, 0);

            var planeNode = new SCNNode();
            planeNode.Geometry = SCNPlane.Create(size,size);
            planeNode.Geometry.Materials = new SCNMaterial[] { material };
            planeNode.Position = new SCNVector3(0.7f, 0, 0);

            this.sceneView.Scene.RootNode.AddChildNode(boxNode);
            this.sceneView.Scene.RootNode.AddChildNode(sphereNode);
            this.sceneView.Scene.RootNode.AddChildNode(torusNode);
            this.sceneView.Scene.RootNode.AddChildNode(tubeNode);
            this.sceneView.Scene.RootNode.AddChildNode(coneNode);
            this.sceneView.Scene.RootNode.AddChildNode(cylinderNode);
            this.sceneView.Scene.RootNode.AddChildNode(pyramidNode);
            this.sceneView.Scene.RootNode.AddChildNode(planeNode);
        }

        public override void ViewDidDisappear(bool animated)
        {
            base.ViewDidDisappear(animated);

            this.sceneView.Session.Pause();
        }

        public override void DidReceiveMemoryWarning()
        {
            base.DidReceiveMemoryWarning();
        }
    }
}

Next Step : Place text in scene

After you have mastered this you should try Place text in scene