Example #1
0
        static public int LoadLionData(PathWriter path, ColorRGBA[] colors, int[] path_idx)
        {
            // Parse the lion and then detect its bounding
            // box and arrange polygons orientations (make all polygons
            // oriented clockwise or counterclockwise)

            int npaths = 0;

            string[] splitOnNL = g_lion.Split('\n');
            foreach (string line in splitOnNL)
            {
                int newColor;
                if (line.Length > 0 &&
                    line[0] != 'M' &&
                    Int32.TryParse(line, NumberStyles.HexNumber, null, out newColor))
                {
                    // New color. Every new color creates new path in the path object.
                    path.CloseFigure();

                    colors[npaths]   = ColorRGBA.CreatRGB8Packed((int)newColor);
                    path_idx[npaths] = path.StartFigure();
                    npaths++;
                }
                else
                {
                    bool     startedPoly  = false;
                    string[] splitOnSpace = line.Split(' ');
                    for (int i = 0; i < splitOnSpace.Length; i++)
                    {
                        string[] splitOnComma = splitOnSpace[i].Split(',');
                        if (splitOnComma.Length > 1)
                        {
                            double x = 0.0;
                            double y = 0.0;
                            double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x);
                            double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y);

                            if (!startedPoly)
                            {
                                startedPoly = true;
                                path.CloseFigure();
                                path.MoveTo(x, y);
                            }
                            else
                            {
                                path.LineTo(x, y);
                            }
                        }
                    }
                }
            }

            //path.ArrangeOrientationsAll(ShapePath.FlagsAndCommand.FlagCW);

            VertexHelper.ArrangeOrientationsAll(path.Vxs, true);
            return(npaths);
        }