Exemplo n.º 1
0
 private void PathStart(string name, string coords, bool relative)
 {
     if (buffer != null)
     {
         WriteBufferTo(paths);
     }
     buffer = new SplineDefinition(name, Spline.Type.Bezier);
     if (relative)
     {
         buffer.position = paths.Last().GetLastPoint().position;
     }
     Vector2[] vectors = ParseVector2(coords);
     foreach (Vector3 vector in vectors)
     {
         if (relative)
         {
             buffer.position += vector;
         }
         else
         {
             buffer.position = vector;
         }
         buffer.CreateLinear();
     }
 }
Exemplo n.º 2
0
        private string EncodePath(SplineDefinition definition, Axis ax)
        {
            string text = "M";

            for (int i = 0; i < definition.pointCount; i++)
            {
                SplinePoint p        = definition.points[i];
                Vector3     tangent  = MapPoint(p.tangent, ax);
                Vector3     position = MapPoint(p.position, ax);
                if (i == 0)
                {
                    text += position.x + "," + position.y;
                }
                else
                {
                    SplinePoint lp       = definition.points[i - 1];
                    Vector3     tangent2 = MapPoint(lp.tangent2, ax);
                    text += "C" + tangent2.x + "," + tangent2.y + "," + tangent.x + "," + tangent.y + "," + position.x + "," + position.y;
                }
            }
            if (definition.closed)
            {
                text += "z";
            }
            return(text);
        }
Exemplo n.º 3
0
        public CSV(string filePath, List <ColumnType> customColumns = null)
        {
            if (!File.Exists(filePath))
            {
                return;
            }
            string a = Path.GetExtension(filePath).ToLower();

            fileName = Path.GetFileNameWithoutExtension(filePath);
            if (a != ".csv")
            {
                UnityEngine.Debug.LogError("CSV Parsing ERROR: Wrong format. Please use SVG or XML");
                return;
            }
            string[] lines = File.ReadAllLines(filePath);
            if (customColumns == null)
            {
                columns.Add(ColumnType.Position);
                columns.Add(ColumnType.Tangent);
                columns.Add(ColumnType.Tangent2);
                columns.Add(ColumnType.Normal);
                columns.Add(ColumnType.Size);
                columns.Add(ColumnType.Color);
            }
            else
            {
                columns = new List <ColumnType>(customColumns);
            }
            buffer = new SplineDefinition(fileName, Spline.Type.Hermite);
            Read(lines);
        }
Exemplo n.º 4
0
        private string EncodePath(SplineDefinition definition, Axis ax)
        {
            string text = "M";

            for (int i = 0; i < definition.pointCount; i++)
            {
                SplinePoint splinePoint = definition.points[i];
                Vector3     vector      = MapPoint(splinePoint.tangent, ax);
                Vector3     vector2     = MapPoint(splinePoint.position, ax);
                string      text2;
                if (i == 0)
                {
                    text2 = text;
                    text  = text2 + vector2.x + "," + vector2.y;
                    continue;
                }
                SplinePoint splinePoint2 = definition.points[i - 1];
                Vector3     vector3      = MapPoint(splinePoint2.tangent2, ax);
                text2 = text;
                text  = text2 + "C" + vector3.x + "," + vector3.y + "," + vector.x + "," + vector.y + "," + vector2.x + "," + vector2.y;
            }
            if (definition.closed)
            {
                text += "z";
            }
            return(text);
        }
Exemplo n.º 5
0
        int ReadEllipse(XmlNode ellipseNode)
        {
            float  x = 0f, y = 0f, rx = 0f, ry = 0f;
            string attribute = GetAttributeContent(ellipseNode, "cx");

            if (attribute == "ERROR")
            {
                return(0);
            }
            float.TryParse(attribute, out x);
            attribute = GetAttributeContent(ellipseNode, "cy");
            if (attribute == "ERROR")
            {
                return(0);
            }
            float.TryParse(attribute, out y);
            attribute = GetAttributeContent(ellipseNode, "r");
            string shapeName = "circle";

            if (attribute == "ERROR") //It might be an ellipse
            {
                shapeName = "ellipse";
                attribute = GetAttributeContent(ellipseNode, "rx");
                if (attribute == "ERROR")
                {
                    return(0);
                }
                float.TryParse(attribute, out rx);
                attribute = GetAttributeContent(ellipseNode, "ry");
                if (attribute == "ERROR")
                {
                    return(0);
                }
            }
            else   //Nope, it's a circle
            {
                float.TryParse(attribute, out rx);
                ry = rx;
            }
            float.TryParse(attribute, out ry);
            Ellipse ellipse = new Ellipse();

            ellipse.offset  = new Vector2(x, -y);
            ellipse.axis    = SplinePrimitive.Axis.nZ;
            ellipse.xRadius = rx;
            ellipse.yRadius = ry;

            string elementName = GetAttributeContent(ellipseNode, "id");

            if (elementName == "ERROR")
            {
                elementName = fileName + "_" + shapeName + (ellipses.Count + 1);
            }
            buffer = new SplineDefinition(elementName, ellipse.GetSpline());
            int addedTransforms = ParseTransformation(ellipseNode);

            WriteBufferTo(ellipses);
            return(addedTransforms);
        }
Exemplo n.º 6
0
        private string EncodePolygon(SplineDefinition definition, Axis ax)
        {
            string text = "";

            for (int i = 0; i < definition.pointCount; i++)
            {
                Vector3 position = MapPoint(definition.points[i].position, ax);
                if (text != "")
                {
                    text += ",";
                }
                text += position.x + "," + position.y;
            }
            return(text);
        }
Exemplo n.º 7
0
        private int ReadLine(XmlNode lineNode)
        {
            float  result           = 0f;
            float  result2          = 0f;
            float  result3          = 0f;
            float  result4          = 0f;
            string attributeContent = GetAttributeContent(lineNode, "x1");

            if (attributeContent == "ERROR")
            {
                return(0);
            }
            float.TryParse(attributeContent, out result);
            attributeContent = GetAttributeContent(lineNode, "y1");
            if (attributeContent == "ERROR")
            {
                return(0);
            }
            float.TryParse(attributeContent, out result2);
            attributeContent = GetAttributeContent(lineNode, "x2");
            if (attributeContent == "ERROR")
            {
                return(0);
            }
            float.TryParse(attributeContent, out result3);
            attributeContent = GetAttributeContent(lineNode, "y2");
            if (attributeContent == "ERROR")
            {
                return(0);
            }
            float.TryParse(attributeContent, out result4);
            string text = GetAttributeContent(lineNode, "id");

            if (text == "ERROR")
            {
                text = fileName + "_line" + (ellipses.Count + 1);
            }
            buffer          = new SplineDefinition(text, Spline.Type.Linear);
            buffer.position = new Vector2(result, 0f - result2);
            buffer.CreateLinear();
            buffer.position = new Vector2(result3, 0f - result4);
            buffer.CreateLinear();
            int result5 = ParseTransformation(lineNode);

            WriteBufferTo(lines);
            return(result5);
        }
Exemplo n.º 8
0
        private string EncodePolygon(SplineDefinition definition, Axis ax)
        {
            string text = string.Empty;

            for (int i = 0; i < definition.pointCount; i++)
            {
                SplinePoint splinePoint = definition.points[i];
                Vector3     vector      = MapPoint(splinePoint.position, ax);
                if (text != string.Empty)
                {
                    text += ",";
                }
                string text2 = text;
                text = text2 + vector.x + "," + vector.y;
            }
            return(text);
        }
Exemplo n.º 9
0
        private int ReadLine(XmlNode lineNode)
        {
            float  startX = 0f, startY = 0f, endX = 0f, endY = 0f;
            string attribute = GetAttributeContent(lineNode, "x1");

            if (attribute == "ERROR")
            {
                return(0);
            }
            float.TryParse(attribute, out startX);
            attribute = GetAttributeContent(lineNode, "y1");
            if (attribute == "ERROR")
            {
                return(0);
            }
            float.TryParse(attribute, out startY);
            attribute = GetAttributeContent(lineNode, "x2");
            if (attribute == "ERROR")
            {
                return(0);
            }
            float.TryParse(attribute, out endX);
            attribute = GetAttributeContent(lineNode, "y2");
            if (attribute == "ERROR")
            {
                return(0);
            }
            float.TryParse(attribute, out endY);
            string elementName = GetAttributeContent(lineNode, "id");

            if (elementName == "ERROR")
            {
                elementName = fileName + "_line" + (ellipses.Count + 1);
            }
            buffer          = new SplineDefinition(elementName, Spline.Type.Linear);
            buffer.position = new Vector2(startX, -startY);
            buffer.CreateLinear();
            buffer.position = new Vector2(endX, -endY);
            buffer.CreateLinear();
            int addedTransforms = ParseTransformation(lineNode);

            WriteBufferTo(lines);
            return(addedTransforms);
        }
Exemplo n.º 10
0
        public CSV(SplineComputer computer)
        {
            Spline spline = new Spline(computer.type, computer.sampleRate);

            spline.points = computer.GetPoints();
            if (spline.type != Spline.Type.Bezier && spline.type != Spline.Type.Linear)
            {
                spline.CatToBezierTangents();
            }
            if (computer.isClosed)
            {
                spline.Close();
            }
            buffer   = new SplineDefinition(computer.name, spline);
            fileName = computer.name;
            columns.Add(ColumnType.Position);
            columns.Add(ColumnType.Tangent);
            columns.Add(ColumnType.Tangent2);
        }
Exemplo n.º 11
0
        public void Init(SplineDefinition data)
        {
            Spline.SetUnselectedColour(System.Drawing.Color.White);
            Spline.Init(data.Points);
            Vector3[] editPoints = (Vector3[])data.Points.Clone();

            if (data.HasToward)
            {
                towardLanes = new Render2DPlane[data.Toward.LaneSize0];

                for (int i = 0; i != data.Toward.LaneSize0; i++)
                {
                    Render2DPlane lane = new Render2DPlane();
                    lane.Init(ref editPoints, data.Toward.Lanes[i], data.Toward.Flags);
                    towardLanes[i] = lane;
                }

                Toward    = data.Toward;
                HasToward = data.HasToward;
            }

            editPoints = (Vector3[])data.Points.Clone();

            if (data.HasBackward)
            {
                backwardLanes = new Render2DPlane[data.Backward.LaneSize0];

                for (int i = 0; i != data.Backward.LaneSize0; i++)
                {
                    Render2DPlane lane = new Render2DPlane();
                    lane.Init(ref editPoints, data.Backward.Lanes[i], data.Backward.Flags);
                    backwardLanes[i] = lane;
                }

                Backward    = data.Backward;
                HasBackward = data.HasBackward;
            }

            BBox        = BoundingBox.CreateFromPoints(editPoints);
            IndexOffset = data.IndexOffset;
        }
Exemplo n.º 12
0
        public void Init(SplineDefinition data)
        {
            Spline.SetUnselectedColour(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
            Spline.Init(data.points);
            Vector3[] editPoints = (Vector3[])data.points.Clone();

            if (data.hasToward)
            {
                towardLanes = new Render2DPlane[data.toward.LaneSize0];

                for (int i = 0; i != data.toward.LaneSize0; i++)
                {
                    Render2DPlane lane = new Render2DPlane();
                    lane.Init(ref editPoints, data.toward.Lanes[i], data.toward.Flags);
                    towardLanes[i] = lane;
                }

                Toward    = data.toward;
                HasToward = data.hasToward;
            }

            editPoints = (Vector3[])data.points.Clone();

            if (data.hasBackward)
            {
                backwardLanes = new Render2DPlane[data.backward.LaneSize0];

                for (int i = 0; i != data.backward.LaneSize0; i++)
                {
                    Render2DPlane lane = new Render2DPlane();
                    lane.Init(ref editPoints, data.backward.Lanes[i], data.backward.Flags);
                    backwardLanes[i] = lane;
                }

                Backward    = data.backward;
                HasBackward = data.hasBackward;
            }

            BBox = BoundingBox.FromPoints(editPoints);
        }
Exemplo n.º 13
0
 private void PathStart(string name, string coords, bool relative)
 {
     if (buffer != null)
     {
         WriteBufferTo(paths);
     }
     buffer = new SplineDefinition(name, Spline.Type.Bezier);
     Vector2[] array  = ParseVector2(coords);
     Vector2[] array2 = array;
     foreach (Vector3 vector in array2)
     {
         if (relative)
         {
             buffer.position += vector;
         }
         else
         {
             buffer.position = vector;
         }
         buffer.CreateLinear();
     }
 }
Exemplo n.º 14
0
        private int ReadPolygon(XmlNode polyNode, bool closed)
        {
            string attributeContent = GetAttributeContent(polyNode, "points");

            if (attributeContent == "ERROR")
            {
                return(0);
            }
            List <float> list = ParseFloatArray(attributeContent);

            if (list.Count % 2 != 0)
            {
                UnityEngine.Debug.LogWarning("There is an error with one of the polygon shapes.");
                return(0);
            }
            string text = GetAttributeContent(polyNode, "id");

            if (text == "ERROR")
            {
                text = fileName + ((!closed) ? "_polyline" : "_polygon ") + (polygons.Count + 1);
            }
            buffer = new SplineDefinition(text, Spline.Type.Linear);
            int num = list.Count / 2;

            for (int i = 0; i < num; i++)
            {
                buffer.position = new Vector2(list[2 * i], 0f - list[1 + 2 * i]);
                buffer.CreateLinear();
            }
            if (closed)
            {
                buffer.CreateClosingPoint();
                buffer.closed = true;
            }
            int result = ParseTransformation(polyNode);

            WriteBufferTo(polygons);
            return(result);
        }
Exemplo n.º 15
0
        private int ReadPolygon(XmlNode polyNode, bool closed)
        {
            string contents = GetAttributeContent(polyNode, "points");

            if (contents == "ERROR")
            {
                return(0);
            }
            List <float> coords = ParseFloatArray(contents);

            if (coords.Count % 2 != 0)
            {
                Debug.LogWarning("There is an error with one of the polygon shapes.");
                return(0);
            }
            string elementName = GetAttributeContent(polyNode, "id");

            if (elementName == "ERROR")
            {
                elementName = fileName + (closed ? "_polygon " : "_polyline") + (polygons.Count + 1);
            }
            buffer = new SplineDefinition(elementName, Spline.Type.Linear);
            int count = coords.Count / 2;

            for (int i = 0; i < count; i++)
            {
                buffer.position = new Vector2(coords[0 + 2 * i], -coords[1 + 2 * i]);
                buffer.CreateLinear();
            }
            if (closed)
            {
                buffer.CreateClosingPoint();
                buffer.closed = true;
            }
            int addedTransforms = ParseTransformation(polyNode);

            WriteBufferTo(polygons);
            return(addedTransforms);
        }
Exemplo n.º 16
0
        private int ReadEllipse(XmlNode ellipseNode)
        {
            float  result           = 0f;
            float  result2          = 0f;
            float  result3          = 0f;
            float  result4          = 0f;
            string attributeContent = GetAttributeContent(ellipseNode, "cx");

            if (attributeContent == "ERROR")
            {
                return(0);
            }
            float.TryParse(attributeContent, out result);
            attributeContent = GetAttributeContent(ellipseNode, "cy");
            if (attributeContent == "ERROR")
            {
                return(0);
            }
            float.TryParse(attributeContent, out result2);
            attributeContent = GetAttributeContent(ellipseNode, "r");
            string text = "circle";

            if (attributeContent == "ERROR")
            {
                text             = "ellipse";
                attributeContent = GetAttributeContent(ellipseNode, "rx");
                if (attributeContent == "ERROR")
                {
                    return(0);
                }
                float.TryParse(attributeContent, out result3);
                attributeContent = GetAttributeContent(ellipseNode, "ry");
                if (attributeContent == "ERROR")
                {
                    return(0);
                }
            }
            else
            {
                float.TryParse(attributeContent, out result3);
                result4 = result3;
            }
            float.TryParse(attributeContent, out result4);
            Ellipse ellipse = new Ellipse();

            ellipse.offset  = new Vector2(result, 0f - result2);
            ellipse.axis    = SplinePrimitive.Axis.nZ;
            ellipse.xRadius = result3;
            ellipse.yRadius = result4;
            string text2 = GetAttributeContent(ellipseNode, "id");

            if (text2 == "ERROR")
            {
                text2 = fileName + "_" + text + (ellipses.Count + 1);
            }
            buffer = new SplineDefinition(text2, ellipse.GetSpline());
            int result5 = ParseTransformation(ellipseNode);

            WriteBufferTo(ellipses);
            return(result5);
        }
Exemplo n.º 17
0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Text.RegularExpressions;

namespace Dreamteck.Splines.IO
{
    public class CSV : SplineParser
    {
        public enum ColumnType { Position, Tangent, Tangent2, Normal, Size, Color }
        public List<ColumnType> columns = new List<ColumnType>();

        private System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");
        private System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Any;

        public CSV(SplineComputer computer)
        {
            Spline spline = new Spline(computer.type, computer.sampleRate);
            spline.points = computer.GetPoints();
            if (spline.type != Spline.Type.Bezier && spline.type != Spline.Type.Linear) spline.CatToBezierTangents();
            if (computer.isClosed) spline.Close();
            buffer = new SplineDefinition(computer.name, spline);
            fileName = computer.name;
            columns.Add(ColumnType.Position);
            columns.Add(ColumnType.Tangent);
            columns.Add(ColumnType.Tangent2);
        }

        public CSV(string filePath, List<ColumnType> customColumns = null)
        {
            if (File.Exists(filePath))
            {
                string ext = Path.GetExtension(filePath).ToLower();
                fileName = Path.GetFileNameWithoutExtension(filePath);
                if (ext != ".csv")
                {
                    Debug.LogError("CSV Parsing ERROR: Wrong format. Please use SVG or XML");
                    return;
                }
                string[] lines = File.ReadAllLines(filePath);
                if (customColumns == null)
                {
                    columns.Add(ColumnType.Position);
                    columns.Add(ColumnType.Tangent);
                    columns.Add(ColumnType.Tangent2);
                    columns.Add(ColumnType.Normal);
                    columns.Add(ColumnType.Size);
                    columns.Add(ColumnType.Color);
                } else columns = new List<ColumnType>(customColumns);
                buffer = new SplineDefinition(fileName, Spline.Type.CatmullRom);
                Read(lines);
            }
        }

        void Read(string[] lines)
        {
            int expectedElementCount = 0;
            foreach (ColumnType col in columns)
            {
                switch (col)
                {
                    case ColumnType.Position: expectedElementCount +=3; break;
                    case ColumnType.Tangent: expectedElementCount += 3; break;
                    case ColumnType.Tangent2: expectedElementCount += 3; break;
                    case ColumnType.Normal: expectedElementCount += 3; break;
                    case ColumnType.Size: expectedElementCount ++; break;
                    case ColumnType.Color: expectedElementCount += 4; break;
                }
            }
            for (int i = 1; i < lines.Length; i++)
            {
                lines[i] = Regex.Replace(lines[i], @"\s+", "");
                string[] elements = lines[i].Split(',');
                if(elements.Length != expectedElementCount)
                {
                    Debug.LogError("Unexpected element count on row " + i + ". Expected " + expectedElementCount +  " found " + elements.Length + " Please make sure that all values exist and the column order is correct.");
                    continue;
                }
                float[] values = new float[elements.Length];
                for (int j = 0; j < elements.Length; j++)
                {
                    float.TryParse(elements[j], style, culture, out values[j]);
                }
                int currentValue = 0;
                foreach (ColumnType col in columns)
                {
                    switch (col)
                    {
                        case ColumnType.Position: buffer.position = new Vector3(values[currentValue++], values[currentValue++], values[currentValue++]); break;
                        case ColumnType.Tangent: buffer.tangent = new Vector3(values[currentValue++], values[currentValue++], values[currentValue++]); break;
                        case ColumnType.Tangent2: buffer.tangent2 = new Vector3(values[currentValue++], values[currentValue++], values[currentValue++]); break;
                        case ColumnType.Normal: buffer.normal = new Vector3(values[currentValue++], values[currentValue++], values[currentValue++]); break;
                        case ColumnType.Size: buffer.size = values[currentValue++]; break;
                        case ColumnType.Color: buffer.color = new Color(values[currentValue++], values[currentValue++], values[currentValue++], values[currentValue++]); break;
                    }
                }
                buffer.CreateSmooth();
            }
        }

        public SplineComputer CreateSplineComputer(Vector3 position, Quaternion rotation)
        {
            return buffer.CreateSplineComputer(position, rotation);
        }

        public Spline CreateSpline()
        {
            return buffer.CreateSpline();
        }


        public void FlatX()
        {
            for (int i = 0; i < buffer.pointCount; i++)
            {
                SplinePoint p = buffer.points[i];
                p.position.x = 0f;
                p.tangent.x = 0f;
                p.tangent2.x = 0f;
                p.normal = Vector3.right;
                buffer.points[i] = p;
            }
        }

        public void FlatY()
        {
            for (int i = 0; i < buffer.pointCount; i++)
            {
                SplinePoint p = buffer.points[i];
                p.position.y = 0f;
                p.tangent.y = 0f;
                p.tangent2.y = 0f;
                p.normal = Vector3.up;
                buffer.points[i] = p;
            }
        }

        public void FlatZ()
        {
            for (int i = 0; i < buffer.pointCount; i++)
            {
                SplinePoint p = buffer.points[i];
                p.position.z = 0f;
                p.tangent.z = 0f;
                p.tangent2.z = 0f;
                p.normal = Vector3.back;
                buffer.points[i] = p;
            }
        }

        void AddTitle(ref string[] content, string title)
        {
            if (!string.IsNullOrEmpty(content[0])) content[0] += ",";
            content[0] += title;
        }

        void AddVector3Title(ref string[] content, string prefix)
        {
            AddTitle(ref content, prefix + "X," + prefix + "Y," + prefix + "Z");
        }

        void AddColorTitle(ref string[] content, string prefix)
        {
            AddTitle(ref content, prefix + "R," + prefix + "G," + prefix + "B" + prefix + "A");
        }

        void AddVector3(ref string[] content, int index, Vector3 vector)
        {
            AddFloat(ref content, index, vector.x);
            AddFloat(ref content, index, vector.y);
            AddFloat(ref content, index, vector.z);
        }

        void AddColor(ref string[] content, int index, Color color)
        {
            AddFloat(ref content, index, color.r);
            AddFloat(ref content, index, color.g);
            AddFloat(ref content, index, color.b);
            AddFloat(ref content, index, color.a);
        }

        void AddFloat(ref string[] content, int index, float value)
        {
            if (!string.IsNullOrEmpty(content[index])) content[index] += ",";
            content[index] += value.ToString();
        }

        public void Write(string filePath)
        {
            if (!Directory.Exists(Path.GetDirectoryName(filePath)))  throw new DirectoryNotFoundException("The file is being saved to a non-existing directory.");
            List<SplinePoint> csvPoints = buffer.points;
            string[] content = new string[csvPoints.Count+1];
            //Add the column titles
            foreach(ColumnType col in columns)
            {
                switch (col)
                {
                    case ColumnType.Position: AddVector3Title(ref content, "Position"); break;
                    case ColumnType.Tangent: AddVector3Title(ref content, "Tangent"); break;
                    case ColumnType.Tangent2: AddVector3Title(ref content, "Tangent2"); break;
                    case ColumnType.Normal: AddVector3Title(ref content, "Normal"); break;
                    case ColumnType.Size: AddTitle(ref content, "Size"); break;
                    case ColumnType.Color: AddColorTitle(ref content, "Color"); break;
                }
            }
            //Add the content for each column
            foreach (ColumnType col in columns)
            {
                for (int i = 1; i <= csvPoints.Count; i++)
                {
                    int index = i - 1;
                    switch (col)
                    {
                        case ColumnType.Position: AddVector3(ref content, i, csvPoints[index].position); break;
                        case ColumnType.Tangent: AddVector3(ref content, i, csvPoints[index].tangent); break;
                        case ColumnType.Tangent2: AddVector3(ref content, i, csvPoints[index].tangent2); break;
                        case ColumnType.Normal: AddVector3(ref content, i, csvPoints[index].normal); break;
                        case ColumnType.Size: AddFloat(ref content, i, csvPoints[index].size); break;
                        case ColumnType.Color: AddColor(ref content, i, csvPoints[index].color); break;
                    }
                }
            }
            File.WriteAllLines(filePath, content);
        }
    }
}
Exemplo n.º 18
0
        private int ReadRectangle(XmlNode rectNode)
        {
            float  result           = 0f;
            float  result2          = 0f;
            float  result3          = 0f;
            float  result4          = 0f;
            float  result5          = -1f;
            float  result6          = -1f;
            string attributeContent = GetAttributeContent(rectNode, "x");

            if (attributeContent == "ERROR")
            {
                return(0);
            }
            float.TryParse(attributeContent, out result);
            attributeContent = GetAttributeContent(rectNode, "y");
            if (attributeContent == "ERROR")
            {
                return(0);
            }
            float.TryParse(attributeContent, out result2);
            attributeContent = GetAttributeContent(rectNode, "width");
            if (attributeContent == "ERROR")
            {
                return(0);
            }
            float.TryParse(attributeContent, out result3);
            attributeContent = GetAttributeContent(rectNode, "height");
            if (attributeContent == "ERROR")
            {
                return(0);
            }
            float.TryParse(attributeContent, out result4);
            attributeContent = GetAttributeContent(rectNode, "rx");
            if (attributeContent != "ERROR")
            {
                float.TryParse(attributeContent, out result5);
            }
            attributeContent = GetAttributeContent(rectNode, "ry");
            if (attributeContent != "ERROR")
            {
                float.TryParse(attributeContent, out result6);
            }
            else
            {
                result6 = result5;
            }
            string text = GetAttributeContent(rectNode, "id");

            if (result5 == -1f && result6 == -1f)
            {
                Rectangle rectangle = new Rectangle();
                rectangle.offset = new Vector2(result + result3 / 2f, 0f - result2 - result4 / 2f);
                rectangle.axis   = SplinePrimitive.Axis.nZ;
                rectangle.size   = new Vector2(result3, result4);
                if (text == "ERROR")
                {
                    text = fileName + "_rectangle" + (rectangles.Count + 1);
                }
                buffer = new SplineDefinition(text, rectangle.GetSpline());
            }
            else
            {
                RoundedRectangle roundedRectangle = new RoundedRectangle();
                roundedRectangle.offset  = new Vector2(result + result3 / 2f, 0f - result2 - result4 / 2f);
                roundedRectangle.axis    = SplinePrimitive.Axis.nZ;
                roundedRectangle.size    = new Vector2(result3, result4);
                roundedRectangle.xRadius = result5;
                roundedRectangle.yRadius = result6;
                if (text == "ERROR")
                {
                    text = fileName + "_roundedRectangle" + (rectangles.Count + 1);
                }
                buffer = new SplineDefinition(text, roundedRectangle.GetSpline());
            }
            int result7 = ParseTransformation(rectNode);

            WriteBufferTo(rectangles);
            return(result7);
        }
Exemplo n.º 19
0
        private int ReadRectangle(XmlNode rectNode)
        {
            float  x = 0f, y = 0f, w = 0f, h = 0f, rx = -1f, ry = -1f;
            string attribute = GetAttributeContent(rectNode, "x");

            if (attribute == "ERROR")
            {
                return(0);
            }
            float.TryParse(attribute, out x);
            attribute = GetAttributeContent(rectNode, "y");
            if (attribute == "ERROR")
            {
                return(0);
            }
            float.TryParse(attribute, out y);
            attribute = GetAttributeContent(rectNode, "width");
            if (attribute == "ERROR")
            {
                return(0);
            }
            float.TryParse(attribute, out w);
            attribute = GetAttributeContent(rectNode, "height");
            if (attribute == "ERROR")
            {
                return(0);
            }
            float.TryParse(attribute, out h);
            attribute = GetAttributeContent(rectNode, "rx");
            if (attribute != "ERROR")
            {
                float.TryParse(attribute, out rx);
            }
            attribute = GetAttributeContent(rectNode, "ry");
            if (attribute != "ERROR")
            {
                float.TryParse(attribute, out ry);
            }
            else
            {
                ry = rx;
            }
            string elementName = GetAttributeContent(rectNode, "id");

            if (rx == -1f && ry == -1f)
            {
                Rectangle rect = new Rectangle();
                rect.offset = new Vector2(x + w / 2f, -y - h / 2f);
                rect.size   = new Vector2(w, h);
                if (elementName == "ERROR")
                {
                    elementName = fileName + "_rectangle" + (rectangles.Count + 1);
                }
                buffer = new SplineDefinition(elementName, rect.CreateSpline());
            }
            else
            {
                RoundedRectangle rect = new RoundedRectangle();
                rect.offset  = new Vector2(x + w / 2f, -y - h / 2f);
                rect.size    = new Vector2(w, h);
                rect.xRadius = rx;
                rect.yRadius = ry;
                if (elementName == "ERROR")
                {
                    elementName = fileName + "_roundedRectangle" + (rectangles.Count + 1);
                }
                buffer = new SplineDefinition(elementName, rect.CreateSpline());
            }
            int addedTransforms = ParseTransformation(rectNode);

            WriteBufferTo(rectangles);
            return(addedTransforms);
        }