public bool NextEdge(out RawEdge edge)
        {
            if (RawEdges.Count == 0)
            {
                edge = null;
                return(false);
            }

            edge = RawEdges.Dequeue();
            return(true);
        }
        public JSONGraphFileReader(string json)
        {
            RawNodes         = new Queue <RawNode>();
            RawEdges         = new Queue <RawEdge>();
            RawDefaultValues = new Queue <RawDefaultValue>();

            // Load graph
            ParsedJSON = (Dictionary <string, object>)fastJSON.JSON.Parse(json);
            Nodes      = (Dictionary <string, object>)ParsedJSON["processes"];
            Edges      = (List <object>)ParsedJSON["connections"];

            foreach (string componentName in Nodes.Keys)
            {
                Details = (Dictionary <string, object>)Nodes[componentName];

                RawNode node = new RawNode()
                {
                    Name = componentName,
                    QualifiedComponentName = Details["component"] as string,
                };
                RawNodes.Enqueue(node);

                if (Details.ContainsKey("metadata"))
                {
                    metadata = (Dictionary <string, object>)Details["metadata"];

                    if (metadata.ContainsKey("x") && metadata.ContainsKey("y"))
                    {
                        float x = 0, y = 0;

                        object X = metadata["x"];
                        switch (X.GetType().Name)
                        {
                        case "Double":
                            x = (float)(double)X;
                            break;

                        case "Int64":
                            x = (float)(Int64)X;
                            break;

                        default:
                            throw new Exception("Uknown number type found: " + X.GetType().Name);
                        }

                        object Y = metadata["y"];
                        switch (Y.GetType().Name)
                        {
                        case "Double":
                            y = (float)(double)Y;
                            break;

                        case "Int64":
                            y = (float)(Int64)Y;
                            break;

                        default:
                            throw new Exception("Uknown number type found: " + Y.GetType().Name);
                        }

                        node.metadataPosition = new Vector3(x, y);
                    }
                }
            }

            for (int i = 0; i < Edges.Count; i++)
            {
                Details = (Dictionary <string, object>)Edges[i];

                tgt = (Dictionary <string, object>)Details["tgt"];
                if (Details.ContainsKey("src"))
                {
                    Dictionary <string, object> src = (Dictionary <string, object>)Details["src"];

                    RawEdge edge = new RawEdge()
                    {
                        srcProcess = src["process"] as string,
                        srcPort    = src["port"] as string,
                        tgtProcess = tgt["process"] as string,
                        tgtPort    = tgt["port"] as string,
                    };

                    RawEdges.Enqueue(edge);
                }
                else if (Details.ContainsKey("data"))
                {
                    RawDefaultValue defaultValue = new RawDefaultValue()
                    {
                        Data       = Details["data"],
                        tgtProcess = tgt["process"] as string,
                        tgtPort    = tgt["port"] as string,
                    };

                    RawDefaultValues.Enqueue(defaultValue);
                }
            }
        }
            public static Geometry LoadFromJson(Stream s)
            {
                Geometry geo = new Geometry();

                using (var reader = new StreamReader(s))
                {
                    var txt = reader.ReadToEnd();

                    var raw = JsonConvert.DeserializeObject <GeometryRaw>(txt);

                    RawVertex[] verts = new RawVertex[raw.vertexAttrEdge.Length];
                    RawEdge[]   edges = new RawEdge[raw.edgeAttrFace.Length];
                    RawFace[]   faces = new RawFace[raw.faceAttrEdge.Length];

                    geo.HasVertices = raw.vertexPositions != null;
                    geo.HasUVs      = raw.vertexUVs != null;
                    geo.HasNormals  = raw.vertexNormals != null;
                    geo.HasTangents = raw.vertexTangents != null;

                    if (geo.HasVertices)
                    {
                        for (int i = 0, j = 0; i < verts.Length; ++i)
                        {
                            verts[i].Position = new OpenTK.Vector3(raw.vertexPositions[j++], raw.vertexPositions[j++], raw.vertexPositions[j++]);
                        }
                    }
                    if (geo.HasUVs)
                    {
                        for (int i = 0, j = 0; i < verts.Length; ++i)
                        {
                            verts[i].UV = new OpenTK.Vector2(raw.vertexUVs[j++], raw.vertexUVs[j++]);
                        }
                    }
                    if (geo.HasNormals)
                    {
                        for (int i = 0, j = 0; i < verts.Length; ++i)
                        {
                            verts[i].Normal = new OpenTK.Vector3(raw.vertexNormals[j++], raw.vertexNormals[j++], raw.vertexNormals[j++]);
                        }
                    }
                    if (geo.HasTangents)
                    {
                        for (int i = 0, j = 0; i < verts.Length; ++i)
                        {
                            verts[i].Tangent = new OpenTK.Vector3(raw.vertexTangents[j++], raw.vertexTangents[j++], raw.vertexTangents[j++]);
                        }
                    }

                    for (int i = 0; i < verts.Length; ++i)
                    {
                        verts[i].Edge = raw.vertexAttrEdge[i];
                    }
                    for (int i = 0; i < edges.Length; ++i)
                    {
                        edges[i].Next     = raw.edgeAttrNext[i];
                        edges[i].Head     = raw.edgeAttrHead[i];
                        edges[i].Opposite = raw.edgeAttrOpposite[i];
                        edges[i].Face     = raw.edgeAttrFace[i];
                    }
                    for (int i = 0; i < faces.Length; ++i)
                    {
                        faces[i].Edge = raw.faceAttrEdge[i];
                    }

                    geo.vertices = verts.ToList();
                    geo.edges    = edges.ToList();
                    geo.faces    = faces.ToList();
                }

                geo.UpdateBoundingBox();
                geo.UpdateHasBoundary();

                return(geo);
            }