Exemple #1
0
    //Updated
    private void DrawNodeNet(ref bool elementClicked)
    {
        //Nodes
        for (int i = 0; i < creator.NNodes; i++)
        {
            DrawNode(creator.GetNode(i), ref elementClicked);
            DrawNodeID(i);
        }
        //Stretches
        for (int i = 0; i < creator.NStretches; i++)
        {
            Stretch   st     = creator.GetStretch(i);
            Vector3[] points = st.GetPoints();

            DrawHandler(st, ref elementClicked);

            DrawStretch(points);
            if (creator.displayNet)
            {
                DrawBezier(points, netDisplaySettings, st.IsIntersection());
            }
            DrawDeleteButton(st);
            if (netDisplaySettings.showArrows)
            {
                DrawArrow(st);
            }
            if (netDisplaySettings.showVertices)
            {
                DrawVertices(st);
            }
        }
    }
Exemple #2
0
 public Stretch GetNStretch(int n)
 {
     if (nodes.Count < 2)
     {
         Debug.LogError("This path has not a single stretch");
     }
     if (n > nodes.Count - 1)
     {
         Debug.LogError("This path doesnt have a " + n + " stretch");
         return(null);
     }
     return(net.GetStretch(nodes[n], nodes[n + 1]));
 }
Exemple #3
0
    public Path(List <Node> nodes, NodeNetCreator net)
    {
        this.nodes = nodes;
        this.net   = net;
        forward    = new List <bool>(nodes.Count - 1);
        for (int i = 0; i < nodes.Count - 1; i++)
        {
            Node a = nodes[i];
            Node b = nodes[i + 1];

            Stretch st = net.GetStretch(a, b);
            forward.Add(st.AnchorA == a);
        }
    }
Exemple #4
0
 private static void UpdateDistances(NodeNetCreator net, DijkstraNode current)
 {
     foreach (var dn in dNodes)
     {
         Stretch st = net.GetStretch(current.node, dn.node);
         if (st != null && !dn.visited)
         {
             float possibleNewDistance = current.distance + st.GetLength();
             if (possibleNewDistance < dn.distance)
             {
                 dn.distance = possibleNewDistance;
                 dn.parent   = current;
             }
         }
     }
     current.visited = true;
 }
Exemple #5
0
    public XmlSerialization(NodeNetCreator net)
    {
        string      path = EditorUtility.SaveFilePanel("Save Nodenet xml", Application.dataPath, "NewNodenet", "xml");
        XmlDocument doc  = new XmlDocument();
        XmlElement  root;
        XmlNode     netNode;

        if (File.Exists(path))
        {
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);

            doc.Load(fs);

            root = doc.DocumentElement;
            root.RemoveAll();

            netNode = doc.ChildNodes[1];

            fs.Close();
        }
        else
        {
            XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
            doc.AppendChild(xmlDeclaration);

            netNode = doc.CreateElement(string.Empty, "net", string.Empty);
            doc.AppendChild(netNode);
        }

        XmlElement nodesNode = doc.CreateElement(string.Empty, "nodes", string.Empty);

        netNode.AppendChild(nodesNode);

        //Nodes
        for (int n = 0; n < net.NNodes; n++)
        {
            Node       node     = net.GetNode(n);
            Vector3    nodePos  = node.Pos;
            XmlElement nodeNode = doc.CreateElement(string.Empty, "node", string.Empty);
            {
                nodeNode.SetAttribute("x", nodePos.x.ToString());
                nodeNode.SetAttribute("y", nodePos.y.ToString());
                nodeNode.SetAttribute("z", nodePos.z.ToString());
            }
            nodesNode.AppendChild(nodeNode);
        }



        XmlElement stretchesNode = doc.CreateElement(string.Empty, "stretches", string.Empty);

        netNode.AppendChild(stretchesNode);

        //Stretches
        for (int s = 0; s < net.NStretches; s++)
        {
            Stretch st           = net.GetStretch(s);
            int     anchorAIndex = st.anchorAIndex;
            int     anchorBIndex = st.anchorBIndex;

            XmlElement stretchNode = doc.CreateElement(string.Empty, "stretch", string.Empty);
            {
                stretchNode.SetAttribute("a", anchorAIndex.ToString());
                stretchNode.SetAttribute("b", anchorBIndex.ToString());

                Vector3    controlA     = st.ControlA;
                XmlElement controlANode = doc.CreateElement(string.Empty, "controlA", string.Empty);
                {
                    controlANode.SetAttribute("x", controlA.x.ToString());
                    controlANode.SetAttribute("y", controlA.y.ToString());
                    controlANode.SetAttribute("z", controlA.z.ToString());
                }
                Vector3    controlB     = st.ControlB;
                XmlElement controlBNode = doc.CreateElement(string.Empty, "controlB", string.Empty);
                {
                    controlBNode.SetAttribute("x", controlB.x.ToString());
                    controlBNode.SetAttribute("y", controlB.y.ToString());
                    controlBNode.SetAttribute("z", controlB.z.ToString());
                }

                stretchNode.AppendChild(controlANode);
                stretchNode.AppendChild(controlBNode);

                stretchesNode.AppendChild(stretchNode);
            }
        }

        doc.Save(path);
        AssetDatabase.Refresh();
    }