public override void _Ready()
    {
        maze = new Maze(ShapeGeometry.MakePolygon(6, 21, (float)Math.PI / 2),
                        new Vector2(-21, -21), new Vector2(21, 21));
        //maze = new Maze(ShapeGeometry.MakeStar(12, 21, (float)Math.PI / 2), new Vector2(-21, -21), new Vector2(21, 21));

        //Draw cells to single mesh and apply to screen
        var surfTool = MeshCreation.CreateSurfaceTool();

        var walls = maze.GetWalls();

        foreach (var wall in walls)
        {
            if (!wall.KnockedDown)
            {
                MeshCreation.AddWall(surfTool, new Vector3(wall.GetPoint1X(), 0.0f, wall.GetPoint1Y()),
                                     new Vector3(wall.GetPoint2X(), 0.0f, wall.GetPoint2Y()), 0.1f, 2.0f);
            }
        }

        this.AddChild(MeshCreation.CreateMeshInstanceFromMesh(MeshCreation.CreateMeshFromSurfaceTool(surfTool)));

        //Put players at start
        KinematicBody player       = (KinematicBody)this.GetParent().GetNode("player");
        var           startingCell = maze.GetStartingCell();

        player.SetTranslation(new Vector3(startingCell.X, 0.0f, startingCell.Y));

        //Put flag at end
        Spatial flag       = (Spatial)this.GetParent().GetNode("Flag");
        var     endingCell = maze.GetEndingCell();

        flag.SetTranslation(new Vector3(endingCell.X, 0.0f, endingCell.Y));
    }
    // Creates a wire mesh and places the spheres to make sure the tile is aligned.
    private void CreateMeshForTile(Tile tile, float sphereScale)
    {
        //Get tile center point
        decimal      tileCenterX = 0;
        decimal      tileCenterY = 0;
        decimal      tileCenterZ = 0;
        List <Point> points      = tile.boundary;

        //Calculate the average center point and polygon side length.
        foreach (Point point in points)
        {
            tileCenterX += point.x / points.Count;
            tileCenterY += point.y / points.Count;
            tileCenterZ += point.z / points.Count;
        }
        //Create the center point
        var tileCenterPoint = new Vector3((float)tileCenterX, (float)tileCenterY, (float)tileCenterZ);

        if (points.Count == 5)
        {
            tileCenterPoint = tileCenterPoint + (tileCenterPoint.Normalized() * 6);
        }
        GD.Print(tileCenterPoint);

        //Create surface tool
        var material = new SpatialMaterial();

        //material.SetEmission(new Color(1.0f, 0.0f, 0.0f));
        //material.SetEmissionEnergy(0.5f);
        material.SetAlbedo(new Color(0.0f, 0.0f, 0.0f));
        //material.SetMetallic(0.5f);
        material.SetCullMode(SpatialMaterial.CullMode.Back);
        var surfaceTool = MeshCreation.CreateSurfaceTool(material);

        //Make triangles for polygon
        for (var index = 0; index < points.Count; index++)
        {
            var     point = new Vector3((float)points[index].x, (float)points[index].y, (float)points[index].z);
            Vector3 nextPoint;
            if (index < points.Count - 1)
            {
                nextPoint = new Vector3((float)points[index + 1].x, (float)points[index + 1].y, (float)points[index + 1].z);
            }
            else
            {
                nextPoint = new Vector3((float)points[0].x, (float)points[0].y, (float)points[0].z);
            }
            if (points.Count == 5)
            {
                point     = point + (point.Normalized() * 6);
                nextPoint = nextPoint + (nextPoint.Normalized() * 6);
            }
            MeshCreation.AddTriangle(surfaceTool, point, nextPoint, tileCenterPoint, true);
        }
        //Add to scene
        var meshInstance = MeshCreation.CreateMeshInstanceFromMesh(MeshCreation.CreateMeshFromSurfaceTool(surfaceTool));

        this.AddChild(meshInstance);


        /*
         * var surfTool = new SurfaceTool();
         * var mesh = new ArrayMesh();
         * var material = new SpatialMaterial();
         * material.SetEmission(new Color(1.0f, 0.0f, 0.0f));
         * material.SetAlbedo(new Color(1.0f, 0.0f, 0.0f));
         * surfTool.Begin(Mesh.PrimitiveType.TriangleStrip);
         * //LineLoop - Nothing
         * //Lines - Nothing
         * //LineStrip - Nothing
         * //Points - Nothing
         * //TriangleFan - Nothing
         * //Triangles - Nothing
         * //TriangleStrip - Nothing
         * surfTool.SetMaterial(material);
         * decimal tileCenterX = 0;
         * decimal tileCenterY = 0;
         * decimal tileCenterZ = 0;
         * decimal polygonRadius = 0;
         *
         * List<Point> points = tile.boundary;
         * var lastPoint = points[points.Count - 1];
         * Vector3 lastPointVector = new Vector3((float)lastPoint.x, (float)lastPoint.y, (float)lastPoint.z);
         * decimal polygonSideLength = 0;
         * foreach (Point point in points) {
         *  surfTool.AddUv(new Vector2(0, 0));
         *  surfTool.AddVertex(new Vector3((float)point.x, (float)point.y, (float)point.z));
         *
         *  tileCenterX += point.x / points.Count;
         *  tileCenterY += point.y / points.Count;
         *  tileCenterZ += point.z / points.Count;
         *  Vector3 currentVector = new Vector3((float)point.x, (float)point.y, (float)point.z);
         *  polygonSideLength += (decimal)currentVector.DistanceTo(lastPointVector);
         *  lastPointVector = currentVector;
         * }
         * polygonSideLength = polygonSideLength / points.Count;
         *
         * var tileCenterPoint = new Vector3((float)tileCenterX, (float)tileCenterY, (float)tileCenterZ);
         * var firstPoint = new Vector3((float)points[0].x, (float)points[0].y, (float)points[0].z);
         *
         * foreach (Point point in points)
         * {
         *  var vector = new Vector3((float) point.x, (float)point.y, (float)point.z);
         *  polygonRadius += (decimal)vector.DistanceTo(tileCenterPoint);
         * }
         * polygonRadius = polygonRadius / points.Count;
         *
         * var polygonRotation = firstPoint.AngleTo(tileCenterPoint);
         *
         *
         * var sphereCenterPoint = new Vector3(0f, 0f, 0f);
         *
         * MeshInstance sphere = (MeshInstance)blueSphereMeshScene.Instance();
         * sphere.SetTranslation(tileCenterPoint);
         * sphere.SetScale(new Vector3(sphereScale, sphereScale, sphereScale));
         * this.AddChild(sphere);
         *
         * MeshInstance sphere2 = (MeshInstance)greenSphereMeshScene.Instance();
         * sphere2.SetTranslation(firstPoint);
         * sphere2.SetScale(new Vector3(sphereScale, sphereScale, sphereScale));
         * this.AddChild(sphere2);
         *
         * MeshInstance sphere3 = (MeshInstance)greenSphereMeshScene.Instance();
         * sphere3.SetTranslation((firstPoint - tileCenterPoint) / 2 + tileCenterPoint);
         * sphere3.SetScale(new Vector3(sphereScale, sphereScale, sphereScale));
         * this.AddChild(sphere3);
         *
         * surfTool.GenerateNormals();
         * surfTool.Index();
         * surfTool.Commit(mesh);
         * var meshInstance = new MeshInstance();
         * meshInstance.SetMesh(mesh);
         * meshInstance.CreateTrimeshCollision();
         * this.AddChild(meshInstance);
         */
    }