Example #1
0
        /// <summary> Creates a path from the supplied 3D points </summary>
        ///<param name="points"> List or array of points to create the path from. </param>
        ///<param name="isClosed"> Should the end point connect back to the start point? </param>
        ///<param name="space"> Determines if the path is in 3d space, or clamped to the xy/xz plane </param>
        public BezierPath(NodeNetCreator nodeNetCreator, IEnumerable <Vector3> points, bool isClosed = false, PathSpace space = PathSpace.xz)
        {
            this.nodeNetCreator = nodeNetCreator;

            Vector3[] pointsArray = points.ToArray();

            if (pointsArray.Length < 2)
            {
                Debug.LogError("Path requires at least 2 anchor points.");
            }
            else
            {
                controlMode = ControlMode.Automatic;

                if (pointsRefs == null)
                {
                    pointsRefs = new List <int>();
                }

                CreatePoint(pointsArray[0]);
                CreatePoint(Vector3.zero);
                CreatePoint(Vector3.zero);
                CreatePoint(pointsArray[1]);

                perAnchorNormalsAngle = new List <float>(new float[] { 0, 0 });

                for (int i = 2; i < pointsArray.Length; i++)
                {
                    AddSegmentToEnd(pointsArray[i]);
                    perAnchorNormalsAngle.Add(0);
                }
            }

            Space    = space;
            IsClosed = isClosed;

            nodeNetCreator.OnPointDeleted += RetargetPointRefs;
        }
Example #2
0
    public Path(Stretch st, Vector3 carForward, Vector3 carPos, NodeNetCreator net)
    {
        this.net = net;
        Vector3 carToA = (st.AnchorA.Pos - carPos).normalized;
        Vector3 carToB = (st.AnchorB.Pos - carPos).normalized;

        Node first  = null;
        Node second = null;

        if (Vector3.Dot(carForward, carToA) > Vector3.Dot(carForward, carToB))
        {
            first  = st.AnchorB;
            second = st.AnchorA;
        }
        else
        {
            first  = st.AnchorA;
            second = st.AnchorB;
        }

        nodes.Add(first);
        AddNode(second);
    }
Example #3
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();
    }
Example #4
0
    public XmlDeserialization(/*string path, */ NodeNetCreator net)
    {
        string path = EditorUtility.OpenFilePanel("Open Nodenet xml", Application.dataPath, "xml");

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

            doc.Load(fs);

            //"net" node
            XmlNode netNode = doc.ChildNodes[1];

            XmlNode nodesNode = netNode.FirstChild;

            XmlNode stretchesNode = netNode.LastChild;

            int nNodes     = nodesNode.ChildNodes.Count;
            int nStretches = stretchesNode.ChildNodes.Count;

            net.DeleteAllNodes();

            List <Stretch> stretches = new List <Stretch>(nStretches);

            //Nodes
            for (int n = 0; n < nNodes; n++)
            {
                XmlNode node = nodesNode.ChildNodes[n];

                float x = float.Parse(node.Attributes["x"].Value);
                float y = float.Parse(node.Attributes["y"].Value);
                float z = float.Parse(node.Attributes["z"].Value);

                net.CreateNode(new Vector3(x, y, z));
            }

            //Stretches
            for (int s = 0; s < nStretches; s++)
            {
                XmlNode stretch = stretchesNode.ChildNodes[s];

                int anchorA = int.Parse(stretch.Attributes["a"].Value);
                int anchorB = int.Parse(stretch.Attributes["b"].Value);

                Vector3 controlARelativePos;
                Vector3 controlBRelativePos;

                //ControlA
                {
                    XmlNode controlA = stretch.ChildNodes[0];

                    float x = float.Parse(controlA.Attributes["x"].Value);
                    float y = float.Parse(controlA.Attributes["y"].Value);
                    float z = float.Parse(controlA.Attributes["z"].Value);

                    controlARelativePos = new Vector3(x, y, z);
                }
                //ControlB
                {
                    XmlNode controlB = stretch.ChildNodes[1];

                    float x = float.Parse(controlB.Attributes["x"].Value);
                    float y = float.Parse(controlB.Attributes["y"].Value);
                    float z = float.Parse(controlB.Attributes["z"].Value);

                    controlBRelativePos = new Vector3(x, y, z);
                }

                stretches.Add(new Stretch(anchorA, anchorB, controlARelativePos, controlBRelativePos));
            }

            net.stretches = stretches;

            fs.Close();
        }
    }
Example #5
0
 public Route(NodeNetCreator nodeNetCreator, List <Node> nodes, bool isClosed = false)
 {
     this.nodeNetCreator = nodeNetCreator;
     this.nodes          = nodes;
     this.isClosed       = false;
 }
Example #6
0
 public Route(NodeNetCreator nodeNetCreator, bool isClosed = false)
 {
     this.nodeNetCreator = nodeNetCreator;
     nodes         = new List <Node>();
     this.isClosed = isClosed;
 }
Example #7
0
 /// <summary> Creates a path from the supplied 2D points </summary>
 ///<param name="points"> List or array of 2d points to create the path from. </param>
 ///<param name="isClosed"> Should the end point connect back to the start point? </param>
 ///<param name="pathSpace"> Determines if the path is in 3d space, or clamped to the xy/xz plane </param>
 public BezierPath(NodeNetCreator nodeNetCreator, IEnumerable <Vector2> points, PathSpace space = PathSpace.xyz, bool isClosed = false) :
     this(nodeNetCreator, points.Select(p => new Vector3(p.x, p.y)), isClosed, space)
 {
 }
Example #8
0
 /// <summary> Creates a path from the positions of the supplied transforms </summary>
 ///<param name="transforms"> List or array of transforms to create the path from. </param>
 ///<param name="isClosed"> Should the end point connect back to the start point? </param>
 ///<param name="space"> Determines if the path is in 3d space, or clamped to the xy/xz plane </param>
 public BezierPath(NodeNetCreator nodeNetCreator, IEnumerable <Transform> transforms, bool isClosed = false, PathSpace space = PathSpace.xy) :
     this(nodeNetCreator, transforms.Select(t => t.position), isClosed, space)
 {
 }
Example #9
0
 /// <summary> Creates a path from the positions of the supplied 2D points </summary>
 ///<param name="transforms"> List or array of transforms to create the path from. </param>
 ///<param name="isClosed"> Should the end point connect back to the start point? </param>
 ///<param name="space"> Determines if the path is in 3d space, or clamped to the xy/xz plane </param>
 public BezierPath(NodeNetCreator nodeNetCreator, IEnumerable <Vector2> transforms, bool isClosed = false, PathSpace space = PathSpace.xy) :
     this(nodeNetCreator, transforms.Select(p => new Vector3(p.x, p.y)), isClosed, space)
 {
 }
Example #10
0
 public void NotifyDelete()
 {
     NodeNetCreator.NotifyNodeDeleted(id);
     Debug.Log(id);
 }
 private void OnEnable()
 {
     node    = (Node)target;
     creator = node.transform.GetComponentInParent <NodeNetCreator>();
 }
Example #12
0
 public Path(Node initialNode, NodeNetCreator net)
 {
     this.net = net;
     nodes.Add(initialNode);
     forward = new List <bool>();
 }
Example #13
0
 private void Awake()
 {
     mainNet = this;
 }