예제 #1
0
        private static IntRect NodeBounds(MeshNode[] nodes, int from, int to)
        {
            if ((to - from) <= 0)
            {
                throw new ArgumentException();
            }
            Int3 vertex = nodes[from].GetVertex(0);
            Int2 num2   = new Int2(vertex.x, vertex.z);
            Int2 num3   = num2;

            for (int i = from; i < to; i++)
            {
                MeshNode node        = nodes[i];
                int      vertexCount = node.GetVertexCount();
                for (int j = 0; j < vertexCount; j++)
                {
                    Int3 num7 = node.GetVertex(j);
                    num2.x = Math.Min(num2.x, num7.x);
                    num2.y = Math.Min(num2.y, num7.z);
                    num3.x = Math.Max(num3.x, num7.x);
                    num3.y = Math.Max(num3.y, num7.z);
                }
            }
            return(new IntRect(num2.x, num2.y, num3.x, num3.y));
        }
예제 #2
0
        private static IntRect NodeBounds(MeshNode[] nodes, int from, int to)
        {
            if (to - from <= 0)
            {
                throw new ArgumentException();
            }
            Int3 vertex = nodes[from].GetVertex(0);
            Int2 @int   = new Int2(vertex.x, vertex.z);
            Int2 int2   = @int;

            for (int i = from; i < to; i++)
            {
                MeshNode meshNode    = nodes[i];
                int      vertexCount = meshNode.GetVertexCount();
                for (int j = 0; j < vertexCount; j++)
                {
                    Int3 vertex2 = meshNode.GetVertex(j);
                    @int.x = Math.Min(@int.x, vertex2.x);
                    @int.y = Math.Min(@int.y, vertex2.z);
                    int2.x = Math.Max(int2.x, vertex2.x);
                    int2.y = Math.Max(int2.y, vertex2.z);
                }
            }
            return(new IntRect(@int.x, @int.y, int2.x, int2.y));
        }
예제 #3
0
            public BBTreeBox(MeshNode node)
            {
                this.node = node;
                Int3 vertex = node.GetVertex(0);
                Int2 @int   = new Int2(vertex.x, vertex.z);
                Int2 int2   = @int;

                for (int i = 1; i < node.GetVertexCount(); i++)
                {
                    Int3 vertex2 = node.GetVertex(i);
                    @int.x = Math.Min(@int.x, vertex2.x);
                    @int.y = Math.Min(@int.y, vertex2.z);
                    int2.x = Math.Max(int2.x, vertex2.x);
                    int2.y = Math.Max(int2.y, vertex2.z);
                }
                this.rect = new IntRect(@int.x, @int.y, int2.x, int2.y);
                this.left = (this.right = -1);
            }
예제 #4
0
            public BBTreeBox(BBTree tree, MeshNode node)
            {
                this.node = node;
                Vector3 vector  = (Vector3)node.GetVertex(0);
                Vector2 vector2 = new Vector2(vector.x, vector.z);
                Vector2 vector3 = vector2;

                for (int i = 1; i < node.GetVertexCount(); i++)
                {
                    Vector3 vector4 = (Vector3)node.GetVertex(i);
                    vector2.x = Math.Min(vector2.x, vector4.x);
                    vector2.y = Math.Min(vector2.y, vector4.z);
                    vector3.x = Math.Max(vector3.x, vector4.x);
                    vector3.y = Math.Max(vector3.y, vector4.z);
                }
                this.rect = Rect.MinMaxRect(vector2.x, vector2.y, vector3.x, vector3.y);
                this.left = (this.right = -1);
            }
예제 #5
0
            public BBTreeBox(MeshNode node)
            {
                this.node = node;
                Int3 vertex = node.GetVertex(0);
                Int2 num2   = new Int2(vertex.x, vertex.z);
                Int2 num3   = num2;

                for (int i = 1; i < node.GetVertexCount(); i++)
                {
                    Int3 num5 = node.GetVertex(i);
                    num2.x = Math.Min(num2.x, num5.x);
                    num2.y = Math.Min(num2.y, num5.z);
                    num3.x = Math.Max(num3.x, num5.x);
                    num3.y = Math.Max(num3.y, num5.z);
                }
                this.rect = new IntRect(num2.x, num2.y, num3.x, num3.y);
                this.left = this.right = -1;
            }
예제 #6
0
        public BBTreeBox(BBTree tree, MeshNode node)
        {
            this.node = node;
            Vector3 first = (Vector3)node.GetVertex(0);
            Vector2 min   = new Vector2(first.x, first.z);
            Vector2 max   = min;

            for (int i = 1; i < node.GetVertexCount(); i++)
            {
                Vector3 p = (Vector3)node.GetVertex(i);
                min.x = Mathf.Min(min.x, p.x);
                min.y = Mathf.Min(min.y, p.z);

                max.x = Mathf.Max(max.x, p.x);
                max.y = Mathf.Max(max.y, p.z);
            }

            rect = Rect.MinMaxRect(min.x, min.y, max.x, max.y);
        }
예제 #7
0
            public BBTreeBox(MeshNode node)
            {
                this.node = node;
                var  first = node.GetVertex(0);
                var  min   = new Int2(first.x, first.z);
                Int2 max   = min;

                for (int i = 1; i < node.GetVertexCount(); i++)
                {
                    var p = node.GetVertex(i);
                    min.x = Math.Min(min.x, p.x);
                    min.y = Math.Min(min.y, p.z);

                    max.x = Math.Max(max.x, p.x);
                    max.y = Math.Max(max.y, p.z);
                }

                rect = new IntRect(min.x, min.y, max.x, max.y);
                left = right = -1;
            }
예제 #8
0
        public void Apply(bool forceNewCheck)
        {
            //TODO
            //This function assumes that connections from the n1,n2 nodes never need to be removed in the future (e.g because the nodes move or something)
            NNConstraint nn = NNConstraint.None;

            nn.distanceXZ = true;
            int graph = (int)startNode.GraphIndex;

            //Search all graphs but the one which start and end nodes are on
            nn.graphMask = ~(1 << graph);

            bool same = true;

            if (true)
            {
                var n1 = AstarPath.active.GetNearest(StartTransform.position, nn);
                same          &= n1.node == connectedNode1 && n1.node != null;
                connectedNode1 = n1.node as MeshNode;
                clamped1       = n1.position;
                if (connectedNode1 != null)
                {
                    Debug.DrawRay((Vector3)connectedNode1.position, Vector3.up * 5, Color.red);
                }
            }

            if (true)
            {
                var n2 = AstarPath.active.GetNearest(EndTransform.position, nn);
                same          &= n2.node == connectedNode2 && n2.node != null;
                connectedNode2 = n2.node as MeshNode;
                clamped2       = n2.position;
                if (connectedNode2 != null)
                {
                    Debug.DrawRay((Vector3)connectedNode2.position, Vector3.up * 5, Color.cyan);
                }
            }

            if (connectedNode2 == null || connectedNode1 == null)
            {
                return;
            }

            startNode.SetPosition((Int3)StartTransform.position);
            endNode.SetPosition((Int3)EndTransform.position);

            if (same && !forceNewCheck)
            {
                return;
            }

            RemoveConnections(startNode);
            RemoveConnections(endNode);

            uint cost = (uint)Mathf.RoundToInt(((Int3)(StartTransform.position - EndTransform.position)).costMagnitude * costFactor);

            startNode.AddConnection(endNode, cost);
            endNode.AddConnection(startNode, cost);

            Int3 dir = connectedNode2.position - connectedNode1.position;

            for (int a = 0; a < connectedNode1.GetVertexCount(); a++)
            {
                Int3 va1 = connectedNode1.GetVertex(a);
                Int3 va2 = connectedNode1.GetVertex((a + 1) % connectedNode1.GetVertexCount());

                if (Int3.DotLong((va2 - va1).Normal2D(), dir) > 0)
                {
                    continue;
                }

                for (int b = 0; b < connectedNode2.GetVertexCount(); b++)
                {
                    Int3 vb1 = connectedNode2.GetVertex(b);
                    Int3 vb2 = connectedNode2.GetVertex((b + 1) % connectedNode2.GetVertexCount());

                    if (Int3.DotLong((vb2 - vb1).Normal2D(), dir) < 0)
                    {
                        continue;
                    }


                    //Debug.DrawLine ((Vector3)va1, (Vector3)va2, Color.magenta);
                    //Debug.DrawLine ((Vector3)vb1, (Vector3)vb2, Color.cyan);
                    //Debug.Break ();

                    if (Int3.Angle((vb2 - vb1), (va2 - va1)) > (170.0 / 360.0f) * Mathf.PI * 2)
                    {
                        float t1 = 0;
                        float t2 = 1;

                        t2 = System.Math.Min(t2, VectorMath.ClosestPointOnLineFactor(va1, va2, vb1));
                        t1 = System.Math.Max(t1, VectorMath.ClosestPointOnLineFactor(va1, va2, vb2));

                        if (t2 < t1)
                        {
                            Debug.LogError("Wait wut!? " + t1 + " " + t2 + " " + va1 + " " + va2 + " " + vb1 + " " + vb2 + "\nTODO, fix this error");
                        }
                        else
                        {
                            Vector3 pa = (Vector3)(va2 - va1) * t1 + (Vector3)va1;
                            Vector3 pb = (Vector3)(va2 - va1) * t2 + (Vector3)va1;

                            startNode.portalA = pa;
                            startNode.portalB = pb;

                            endNode.portalA = pb;
                            endNode.portalB = pa;

                            //Add connections between nodes, or replace old connections if existing
                            connectedNode1.AddConnection(startNode, (uint)Mathf.RoundToInt(((Int3)(clamped1 - StartTransform.position)).costMagnitude * costFactor));
                            connectedNode2.AddConnection(endNode, (uint)Mathf.RoundToInt(((Int3)(clamped2 - EndTransform.position)).costMagnitude * costFactor));

                            startNode.AddConnection(connectedNode1, (uint)Mathf.RoundToInt(((Int3)(clamped1 - StartTransform.position)).costMagnitude * costFactor));
                            endNode.AddConnection(connectedNode2, (uint)Mathf.RoundToInt(((Int3)(clamped2 - EndTransform.position)).costMagnitude * costFactor));

                            return;
                        }
                    }
                }
            }
        }
예제 #9
0
			public BBTreeBox (MeshNode node) {
				this.node = node;
				var first = node.GetVertex(0);
				var min = new Int2(first.x,first.z);
				Int2 max = min;

				for (int i=1;i<node.GetVertexCount();i++) {
					var p = node.GetVertex(i);
					min.x = Math.Min (min.x,p.x);
					min.y = Math.Min (min.y,p.z);

					max.x = Math.Max (max.x,p.x);
					max.y = Math.Max (max.y,p.z);
				}

				rect = new IntRect (min.x,min.y,max.x,max.y);
				left = right = -1;
			}
예제 #10
0
 static void DrawDebugNode(MeshNode node, float yoffset, Color color)
 {
     Debug.DrawLine((Vector3)node.GetVertex(1) + Vector3.up * yoffset, (Vector3)node.GetVertex(2) + Vector3.up * yoffset, color);
     Debug.DrawLine((Vector3)node.GetVertex(0) + Vector3.up * yoffset, (Vector3)node.GetVertex(1) + Vector3.up * yoffset, color);
     Debug.DrawLine((Vector3)node.GetVertex(2) + Vector3.up * yoffset, (Vector3)node.GetVertex(0) + Vector3.up * yoffset, color);
 }
예제 #11
0
 public BBTreeBox(MeshNode node)
 {
     this.node = node;
     Int3 vertex = node.GetVertex(0);
     Int2 @int = new Int2(vertex.x, vertex.z);
     Int2 int2 = @int;
     for (int i = 1; i < node.GetVertexCount(); i++)
     {
         Int3 vertex2 = node.GetVertex(i);
         @int.x = Math.Min(@int.x, vertex2.x);
         @int.y = Math.Min(@int.y, vertex2.z);
         int2.x = Math.Max(int2.x, vertex2.x);
         int2.y = Math.Max(int2.y, vertex2.z);
     }
     this.rect = new IntRect(@int.x, @int.y, int2.x, int2.y);
     this.left = (this.right = -1);
 }
예제 #12
0
		public BBTreeBox (BBTree tree, MeshNode node) {
			this.node = node;
			Vector3 first = (Vector3)node.GetVertex(0);
			Vector2 min = new Vector2(first.x,first.z);
			Vector2 max = min;
			
			for (int i=1;i<node.GetVertexCount();i++) {
				Vector3 p = (Vector3)node.GetVertex(i);
				min.x = Mathf.Min (min.x,p.x);
				min.y = Mathf.Min (min.y,p.z);
				
				max.x = Mathf.Max (max.x,p.x);
				max.y = Mathf.Max (max.y,p.z);
			}
			
			rect = Rect.MinMaxRect (min.x,min.y,max.x,max.y);
		}
예제 #13
0
 private static void DrawDebugNode(MeshNode node, float yoffset, Color color)
 {
     UnityEngine.Debug.DrawLine(((Vector3)node.GetVertex(1)) + ((Vector3)(Vector3.up * yoffset)), ((Vector3)node.GetVertex(2)) + ((Vector3)(Vector3.up * yoffset)), color);
     UnityEngine.Debug.DrawLine(((Vector3)node.GetVertex(0)) + ((Vector3)(Vector3.up * yoffset)), ((Vector3)node.GetVertex(1)) + ((Vector3)(Vector3.up * yoffset)), color);
     UnityEngine.Debug.DrawLine(((Vector3)node.GetVertex(2)) + ((Vector3)(Vector3.up * yoffset)), ((Vector3)node.GetVertex(0)) + ((Vector3)(Vector3.up * yoffset)), color);
 }