public void AddGraphObstacles(Simulator sim, NavGraph graph) { if (this.obstacles.get_Count() > 0 && this.lastSim != null && this.lastSim != sim) { this.RemoveObstacles(); } this.lastSim = sim; INavmesh navmesh = graph as INavmesh; if (navmesh == null) { return; } int[] uses = new int[20]; navmesh.GetNodes(delegate(GraphNode _node) { TriangleMeshNode triangleMeshNode = _node as TriangleMeshNode; uses[0] = (uses[1] = (uses[2] = 0)); if (triangleMeshNode != null) { for (int i = 0; i < triangleMeshNode.connections.Length; i++) { TriangleMeshNode triangleMeshNode2 = triangleMeshNode.connections[i] as TriangleMeshNode; if (triangleMeshNode2 != null) { int num = triangleMeshNode.SharedEdge(triangleMeshNode2); if (num != -1) { uses[num] = 1; } } } for (int j = 0; j < 3; j++) { if (uses[j] == 0) { VInt3 vertex = triangleMeshNode.GetVertex(j); VInt3 vertex2 = triangleMeshNode.GetVertex((j + 1) % triangleMeshNode.GetVertexCount()); this.obstacles.Add(sim.AddObstacle(vertex, vertex2, this.wallHeight)); } } } return(true); }); }
private void DrawTriangles() { // draw all graph nodes GL.Begin(GL.TRIANGLES); Vector3 offsetUp = new Vector3(0f, 0.1f, 0f); for (int graphIndex = 0; graphIndex < AstarPath.active.graphs.Length; ++graphIndex) { NavGraph graph = AstarPath.active.graphs[graphIndex]; INavmesh ng = graph as INavmesh; if (null != ng) { ng.GetNodes(delegate(GraphNode _node) { // if we are only displaying one region, and this is not that region if (desplaySpecifiedRegion != DisplayAllRegions && desplaySpecifiedRegion != _node.Area) { return(true); } Color theColor = graph.NodeColor(_node, AstarPath.active.debugPathData); theColor.a = navMeshAlpha; TriangleMeshNode node = _node as TriangleMeshNode; if (!node.Walkable) { theColor = Color.black; } GL.Color(theColor); Vector3 vert0 = (Vector3)node.GetVertex(0); Vector3 vert1 = (Vector3)node.GetVertex(1); Vector3 vert2 = (Vector3)node.GetVertex(2); GL.Vertex(vert0 + offsetUp); GL.Vertex(vert1 + offsetUp); GL.Vertex(vert2 + offsetUp); return(true); }); } } GL.End(); }
private static float CalculateY(Vector3 pf, TriangleMeshNode node) { Vector3 vector; Vector3 vector2; Vector3 vector3; node.GetPoints(out vector, out vector2, out vector3); float num = ((vector2.z - vector3.z) * (vector.x - vector3.x)) + ((vector3.x - vector2.x) * (vector.z - vector3.z)); float num2 = 1f / num; float num3 = ((vector2.z - vector3.z) * (pf.x - vector3.x)) + ((vector3.x - vector2.x) * (pf.z - vector3.z)); num3 *= num2; float num4 = ((vector3.z - vector.z) * (pf.x - vector3.x)) + ((vector.x - vector3.x) * (pf.z - vector3.z)); num4 *= num2; float num5 = (1f - num3) - num4; return(((num3 * vector.y) + (num4 * vector2.y)) + (num5 * vector3.y)); }
private static float CalculateY(Vector3 pf, TriangleMeshNode node) { Vector3 vector; Vector3 vector2; Vector3 vector3; node.GetPoints(ref vector, ref vector2, ref vector3); float num = (vector2.z - vector3.z) * (vector.x - vector3.x) + (vector3.x - vector2.x) * (vector.z - vector3.z); float num2 = 1f / num; float num3 = (vector2.z - vector3.z) * (pf.x - vector3.x) + (vector3.x - vector2.x) * (pf.z - vector3.z); num3 *= num2; float num4 = (vector3.z - vector.z) * (pf.x - vector3.x) + (vector.x - vector3.x) * (pf.z - vector3.z); num4 *= num2; float num5 = 1f - num3 - num4; return(num3 * vector.y + num4 * vector2.y + num5 * vector3.y); }
private bool NodeHas2VerticesTouchingEdge(TriangleMeshNode node, Vector3 axisFilter, Int3 valueInt3) { isTouching = true; node.GetVertices(out v0, out v1, out v2); if (axisFilter.x != 0) { isTouching = isTouching && (Mathf.Abs(v0.x - valueInt3.x) <= maxGap_Int3 ? 1 : 0) + (Mathf.Abs(v1.x - valueInt3.x) <= maxGap_Int3 ? 1 : 0) + (Mathf.Abs(v2.x - valueInt3.x) <= maxGap_Int3 ? 1 : 0) >= 1; } if (axisFilter.y != 0) { isTouching = isTouching && (Mathf.Abs(v0.y - valueInt3.y) <= maxGap_Int3 ? 1 : 0) + (Mathf.Abs(v1.y - valueInt3.y) <= maxGap_Int3 ? 1 : 0) + (Mathf.Abs(v2.y - valueInt3.y) <= maxGap_Int3 ? 1 : 0) >= 1; } if (axisFilter.z != 0) { isTouching = isTouching && (Mathf.Abs(v0.z - valueInt3.z) <= maxGap_Int3 ? 1 : 0) + (Mathf.Abs(v1.z - valueInt3.z) <= maxGap_Int3 ? 1 : 0) + (Mathf.Abs(v2.z - valueInt3.z) <= maxGap_Int3 ? 1 : 0) >= 1; } return(isTouching); }
public static bool GetGroundY(VInt3 pos, out VInt groundY) { if (AstarPath.active == null) { groundY = pos.y; return(false); } groundY = pos.y; acotrName = "null"; TriangleMeshNode locatedByRasterizer = AstarPath.active.astarData.GetLocatedByRasterizer(pos); if (locatedByRasterizer == null) { return(false); } float num = CalculateY_Clamped((Vector3)pos, locatedByRasterizer); groundY = (VInt)num; return(true); }
private static float CalculateY_Clamped(Vector3 pf, TriangleMeshNode node) { Vector3 vector; Vector3 vector2; Vector3 vector3; node.GetPoints(out vector, out vector2, out vector3); float num = (vector2.z - vector3.z) * (vector.x - vector3.x) + (vector3.x - vector2.x) * (vector.z - vector3.z); float num2 = 1f / num; float num3 = (vector2.z - vector3.z) * (pf.x - vector3.x) + (vector3.x - vector2.x) * (pf.z - vector3.z); num3 *= num2; num3 = Mathf.Clamp01(num3); float num4 = (vector3.z - vector.z) * (pf.x - vector3.x) + (vector.x - vector3.x) * (pf.z - vector3.z); num4 *= num2; num4 = Mathf.Clamp01(num4); float num5 = Mathf.Clamp01(1f - num3 - num4); return(num3 * vector.y + num4 * vector2.y + num5 * vector3.y); }
public static bool GetGroundY(VInt3 pos, out VInt groundY) { if (!AstarPath.active) { groundY = pos.y; return(false); } groundY = pos.y; PathfindingUtility.acotrName = "null"; AstarData astarData = AstarPath.active.astarData; TriangleMeshNode locatedByRasterizer = astarData.GetLocatedByRasterizer(pos); if (locatedByRasterizer == null) { return(false); } float f = PathfindingUtility.CalculateY_Clamped((Vector3)pos, locatedByRasterizer); groundY = (VInt)f; return(true); }
public static bool GetGroundY(ActorRoot actor, out VInt groundY) { if ((AstarPath.active == null) || (actor == null)) { groundY = (actor == null) ? 0 : actor.groundY; return(false); } groundY = actor.groundY; acotrName = (actor == null) ? string.Empty : actor.name; VInt3 location = actor.location; TriangleMeshNode locatedByRasterizer = AstarPath.active.astarData.GetLocatedByRasterizer(location); if (locatedByRasterizer == null) { return(false); } float num2 = CalculateY_Clamped((Vector3)location, locatedByRasterizer); groundY = (VInt)num2; return(true); }
public static bool GetGroundY(Actor actor, out Int1 groundY) { if (!AstarPath.active || actor == null) { groundY = ((actor == null) ? 0 :(int)actor.ActorTransform.position.y); return(false); } groundY = (int)actor.ActorTransform.position.y; PathfindingUtility.acotrName = ((actor == null) ? string.Empty : actor.ActorId.ToString()); Int3 location = (Int3)actor.ActorTransform.position; AstarData astarData = AstarPath.active.astarData; TriangleMeshNode locatedByRasterizer = astarData.GetLocatedByRasterizer(location); if (locatedByRasterizer == null) { return(false); } float f = PathfindingUtility.CalculateY_Clamped((Vector3)location, locatedByRasterizer); groundY = (Int1)f; return(true); }
private static Int3 InternalMove(Int3 srcLoc, Int3 delta, ref Int1 groundY, Actor actor) { if (!AstarPath.active) { return(Int3.zero); } //if (delta.x == 0 && delta.z == 0) //{ // return delta; //} Int3 vInt = srcLoc + delta; int startEdge = -1; int actorCamp = (int)actor.CampId; AstarData data = AstarPath.active.astarData; TriangleMeshNode triangleMeshNode = data.GetLocatedByRasterizer(srcLoc); if (triangleMeshNode == null) { TriangleMeshNode triangleMeshNode2 = data.IntersectByRasterizer(srcLoc, vInt, out startEdge); if (triangleMeshNode2 == null) { return(Int3.zero); } triangleMeshNode = triangleMeshNode2; } Int3 lhs; PathfindingUtility.MoveFromNode(triangleMeshNode, startEdge, srcLoc, vInt, out lhs); PathfindingUtility.checkedNodes.Clear(); groundY = lhs.y; if (!PathfindingUtility.MoveAxisY) { lhs.y = srcLoc.y; } return(lhs - srcLoc); }
public static bool GetGroundY(ActorRoot actor, out VInt groundY) { if (!AstarPath.active || actor == null) { groundY = ((actor != null) ? actor.groundY : 0); return(false); } groundY = actor.groundY; PathfindingUtility.acotrName = ((actor != null) ? actor.name : string.Empty); VInt3 location = actor.location; AstarData astarData = AstarPath.active.astarData; TriangleMeshNode locatedByRasterizer = astarData.GetLocatedByRasterizer(location); if (locatedByRasterizer == null) { return(false); } float f = PathfindingUtility.CalculateY_Clamped((Vector3)location, locatedByRasterizer); groundY = (VInt)f; return(true); }
public static List <Vector3> GetRandomPointsOnNavmesh(Vector3 origin, int count, float maxRadius, float minRadius = 0.0f) { List <TriangleMeshNode> validNodes = GetAllNodesInRadius(origin, maxRadius); // remove nodes in smaller radius if (minRadius > 0.0f) { List <TriangleMeshNode> invalidNodes = GetAllNodesInRadius(origin, minRadius); for (int i = 0; i < invalidNodes.Count; i++) { validNodes.Remove(invalidNodes[i]); } } List <Vector3> points = new List <Vector3>(); if (validNodes.Count == 0) { //EB.Debug.LogError("No valid navmesh nodes found!"); return(points); } for (int i = 0; i < count; i++) { TriangleMeshNode randomNode = validNodes[UnityEngine.Random.Range(0, validNodes.Count)]; Vector3 randomPoint = RandomPointInTrangle((Vector3)randomNode.GetVertex(0), (Vector3)randomNode.GetVertex(1), (Vector3)randomNode.GetVertex(2)); float dist = (randomPoint - origin).magnitude; if (dist <= maxRadius && dist > minRadius) { points.Add(randomPoint); } else { points.Add(origin + (randomPoint - origin).normalized * (minRadius + maxRadius) / 2.0f); } } return(points); }
public static bool ValidateTarget(VInt3 loc, VInt3 target, out VInt3 newTarget, out int nodeIndex) { newTarget = target; nodeIndex = -1; if (!AstarPath.active) { return(false); } AstarData astarData = AstarPath.active.astarData; TriangleMeshNode locatedByRasterizer = astarData.GetLocatedByRasterizer(target); if (locatedByRasterizer != null) { return(true); } int num = -1; TriangleMeshNode triangleMeshNode = astarData.IntersectByRasterizer(target, loc, out num); if (triangleMeshNode == null) { return(false); } VInt3[] staticVerts = PathfindingUtility._staticVerts; triangleMeshNode.GetPoints(out staticVerts[0], out staticVerts[1], out staticVerts[2]); bool flag = false; VInt3 vInt = Polygon.IntersectionPoint(ref target, ref loc, ref staticVerts[num], ref staticVerts[(num + 1) % 3], out flag); if (!flag) { return(false); } if (!PathfindingUtility.MakePointInTriangle(ref vInt, triangleMeshNode, -4, 4, -4, 4, VInt3.zero)) { return(false); } newTarget = vInt; return(true); }
// see if an infinite virtical ray intersects the plane of the triangle node public static bool VirticalRayPlaneIntersection(Vector2 rayFrom, TriangleMeshNode node, ref Vector3 intersectionPoint) { Vector3 vertZero = (Vector3)node.GetVertex(0); Vector3 vertOne = (Vector3)node.GetVertex(1); Vector3 vertTwo = (Vector3)node.GetVertex(2); Vector3 nodeNormal = Vector3.Cross(vertOne - vertZero, vertTwo - vertZero).normalized; Plane plane = new Plane(nodeNormal, (Vector3)node.position); // create a plane from the triangle normal and a position on the triangle plane // make sure our ray starts below the triangle, so a virtical up ray will hit it float minTriangleY = Mathf.Min(vertZero.y, Mathf.Min(vertOne.y, vertTwo.y)) - 1f; Vector3 rayFrom3d = new Vector3(rayFrom.x, minTriangleY, rayFrom.y); Ray ray = new Ray(rayFrom3d, Vector3.up); float dist = 0f; if (plane.Raycast(ray, out dist)) { intersectionPoint = rayFrom3d + Vector3.up * dist; return(true); } return(false); }
private static bool CheckNearestNodeIntersection(TriangleMeshNode node, VInt3 srcLoc, VInt3 destLoc, ref int edge) { if (!node.ContainsPoint(destLoc)) { int num = 0; VInt3[] numArray = _staticVerts; node.GetPoints(out numArray[0], out numArray[1], out numArray[2]); float maxValue = float.MaxValue; int num3 = -1; Vector3 vector = (Vector3)srcLoc; Vector3 vector2 = (Vector3)destLoc; for (int i = 0; i < 3; i++) { if (Polygon.Intersects(numArray[i], numArray[(i + 1) % 3], srcLoc, destLoc)) { bool flag; num++; Vector3 b = Polygon.IntersectionPoint((Vector3)numArray[i], (Vector3)numArray[(i + 1) % 3], vector, vector2, out flag); DebugHelper.Assert(flag); float num5 = vector.XZSqrMagnitude(ref b); if (num5 < maxValue) { maxValue = num5; num3 = i; } } } if ((num != 2) || (num3 == -1)) { object[] args = new object[] { srcLoc, destLoc, node.NodeIndex, acotrName }; string str = string.Format("Nav: Can't move, src:{0}, dest:{1}, node:{2}, actor:{3}", args); return(false); } edge = num3; } return(true); }
private static VInt3 InternalMove(VInt3 srcLoc, VInt3 delta, ref VInt groundY, ActorRoot actor) { VInt3 num4; if (AstarPath.active == null) { return(VInt3.zero); } if ((delta.x == 0) && (delta.z == 0)) { return(delta); } VInt3 end = srcLoc + delta; int edge = -1; int actorCamp = (int)actor.TheActorMeta.ActorCamp; AstarData data = AstarPath.active.GetData(actorCamp); TriangleMeshNode locatedByRasterizer = data.GetLocatedByRasterizer(srcLoc); if (locatedByRasterizer == null) { TriangleMeshNode node2 = data.IntersectByRasterizer(srcLoc, end, out edge); if (node2 == null) { return(VInt3.zero); } locatedByRasterizer = node2; } MoveFromNode(locatedByRasterizer, edge, srcLoc, end, out num4); checkedNodes.Clear(); groundY = num4.y; if (!MoveAxisY) { num4.y = srcLoc.y; } return(num4 - srcLoc); }
private static void CalculateY(ref VInt3 point, TriangleMeshNode node) { float num = CalculateY((Vector3)point, node); point.y = Mathf.RoundToInt(num * 1000f); }
private static void MoveFromNode(TriangleMeshNode node, int startEdge, VInt3 srcLoc, VInt3 destLoc, MoveDirectionState state, out VInt3 result) { result = srcLoc; while (node != null) { int num; int num10; int count = 2; if (node.IsVertex(srcLoc, out num)) { int vertexIndex = node.GetVertexIndex(num); List <TMNodeInfo> nodeInfos = null; GetAllNodesByVert(ref nodeInfos, node, vertexIndex); TriangleMeshNode node2 = null; int vi = -1; for (int i = 0; i < nodeInfos.Count; i++) { TMNodeInfo info = nodeInfos[i]; if ((!checkedNodes.Contains(info.node) && !Polygon.LeftNotColinear(info.v0, info.v2, destLoc)) && Polygon.Left(info.v0, info.v1, destLoc)) { node2 = info.node; vi = info.vi; break; } } if (node2 != null) { node = node2; startEdge = (vi + 1) % 3; count = 1; } else { int num6 = -1; VFactor factor = new VFactor { nom = -2L, den = 1L }; for (int j = 0; j < nodeInfos.Count; j++) { TMNodeInfo info2 = nodeInfos[j]; if (!checkedNodes.Contains(info2.node)) { int num8; VFactor factor2 = info2.GetCosineAngle(destLoc, state, out num8); if (factor2 > factor) { factor = factor2; num6 = num8; node2 = info2.node; } } } if (node2 != null) { MoveAlongEdge(node2, num6, srcLoc, destLoc, state, out result, true); break; } } } int edge = -1; if (startEdge == -1) { edge = node.EdgeIntersect(srcLoc, destLoc); } else { edge = node.EdgeIntersect(srcLoc, destLoc, startEdge, count); } if (edge == -1) { if (node.ContainsPoint(destLoc)) { result = destLoc; if (MoveAxisY) { CalculateY(ref result, node); } } else { edge = node.GetColinearEdge(srcLoc, destLoc); if (edge != -1) { MoveAlongEdge(node, edge, srcLoc, destLoc, state, out result, true); } } break; } TriangleMeshNode neighborByEdge = node.GetNeighborByEdge(edge, out num10); if (neighborByEdge != null) { node = neighborByEdge; startEdge = num10 + 1; count = 2; } else { MoveAlongEdge(node, edge, srcLoc, destLoc, state, out result, true); break; } } }
private static void GetAllNodesByVert(ref List <PathfindingUtility.TMNodeInfo> nodeInfos, TriangleMeshNode startNode, int vertIndex) { if (nodeInfos == null) { nodeInfos = new List <PathfindingUtility.TMNodeInfo>(); } for (int i = 0; i < nodeInfos.get_Count(); i++) { if (nodeInfos.get_Item(i).node == startNode) { return; } } int num; if (startNode.v0 == vertIndex) { num = 0; } else if (startNode.v1 == vertIndex) { num = 1; } else { if (startNode.v2 != vertIndex) { return; } num = 2; } PathfindingUtility.TMNodeInfo tMNodeInfo = default(PathfindingUtility.TMNodeInfo); tMNodeInfo.vi = num; tMNodeInfo.node = startNode; tMNodeInfo.v0 = startNode.GetVertex(num % 3); tMNodeInfo.v1 = startNode.GetVertex((num + 1) % 3); tMNodeInfo.v2 = startNode.GetVertex((num + 2) % 3); nodeInfos.Add(tMNodeInfo); if (startNode.connections != null) { for (int j = 0; j < startNode.connections.Length; j++) { TriangleMeshNode triangleMeshNode = startNode.connections[j] as TriangleMeshNode; if (triangleMeshNode != null && triangleMeshNode.GraphIndex == startNode.GraphIndex) { PathfindingUtility.GetAllNodesByVert(ref nodeInfos, triangleMeshNode, vertIndex); } } } }
private static void MoveAlongEdge(TriangleMeshNode node, int edge, VInt3 srcLoc, VInt3 destLoc, MoveDirectionState state, out VInt3 result, bool checkAnotherEdge = true) { bool flag; DebugHelper.Assert((edge >= 0) && (edge <= 2)); VInt3 vertex = node.GetVertex(edge); VInt3 num2 = node.GetVertex((edge + 1) % 3); VInt3 a = destLoc - srcLoc; a.y = 0; VInt3 lhs = num2 - vertex; lhs.y = 0; lhs.NormalizeTo(0x3e8); int num5 = 0; if (state != null) { num5 = a.magnitude2D * 0x3e8; VInt3 num6 = !state.enabled ? a : state.firstAdjDir; if (VInt3.Dot(ref lhs, ref num6) < 0) { num5 = -num5; num6 = -lhs; } else { num6 = lhs; } if (!state.enabled) { state.enabled = true; state.firstAdjDir = VInt3.Lerp(a, num6, 1, 3); state.firstDir = state.curDir; state.adjDir = num6; } else if (VInt3.Dot(ref state.adjDir, ref num6) >= 0) { state.adjDir = num6; } else { num5 = 0; } state.applied = true; } else { num5 = (lhs.x * a.x) + (lhs.z * a.z); } VInt3 rhs = Polygon.IntersectionPoint(ref vertex, ref num2, ref srcLoc, ref destLoc, out flag); if (!flag) { if (!Polygon.IsColinear(vertex, num2, srcLoc) || !Polygon.IsColinear(vertex, num2, destLoc)) { result = srcLoc; return; } if (num5 >= 0) { int num8 = (lhs.x * (num2.x - vertex.x)) + (lhs.z * (num2.z - vertex.z)); int num9 = (lhs.x * (destLoc.x - vertex.x)) + (lhs.z * (destLoc.z - vertex.z)); rhs = (num8 <= num9) ? num2 : destLoc; DebugHelper.Assert((num8 >= 0) && (num9 >= 0)); } else { int num10 = (-lhs.x * (vertex.x - num2.x)) - (lhs.z * (vertex.z - num2.z)); int num11 = (-lhs.x * (destLoc.x - num2.x)) - (lhs.z * (destLoc.z - num2.z)); rhs = (Mathf.Abs(num10) <= Mathf.Abs(num11)) ? vertex : destLoc; DebugHelper.Assert((num10 >= 0) && (num11 >= 0)); } } int num12 = -IntMath.Sqrt(vertex.XZSqrMagnitude(rhs) * 0xf4240L); int num13 = IntMath.Sqrt(num2.XZSqrMagnitude(rhs) * 0xf4240L); if ((num5 >= num12) && (num5 <= num13)) { result = IntMath.Divide(lhs, (long)num5, 0xf4240L) + rhs; if (!node.ContainsPoint(result)) { int num16; int num17; int num18; int num19; Vector3 vector = (Vector3)(num2 - vertex); vector.y = 0f; vector.Normalize(); VInt3 num14 = num2 - vertex; num14.y = 0; num14 *= 0x2710; long magnitude = num14.magnitude; VFactor factor = new VFactor { nom = num5, den = magnitude * 0x3e8L }; getMinMax(out num16, out num18, (long)num14.x, ref factor); getMinMax(out num17, out num19, (long)num14.z, ref factor); if (!MakePointInTriangle(ref result, node, num16, num18, num17, num19, srcLoc) && !MakePointInTriangle(ref result, node, num16 - 4, num18 + 4, num17 - 4, num19 + 4, srcLoc)) { result = srcLoc; } } if (MoveAxisY) { CalculateY(ref result, node); } } else { int num20; int num21; VInt3 num22; int num24; if (num5 < num12) { num20 = num5 - num12; num21 = (edge + 2) % 3; num22 = vertex; } else { num20 = num5 - num13; num21 = (edge + 1) % 3; num22 = num2; } VInt3 num23 = (VInt3)((lhs * num20) / 1000000f); TriangleMeshNode neighborByEdge = node.GetNeighborByEdge(num21, out num24); if (neighborByEdge != null) { checkedNodes.Add(node); MoveFromNode(neighborByEdge, num24, num22, num23 + num22, state, out result); } else { if (checkAnotherEdge) { VInt3 num27 = node.GetVertex((edge + 2) % 3) - num22; if (VInt3.Dot(num27.NormalizeTo(0x3e8), num23) > 0) { checkedNodes.Add(node); MoveAlongEdge(node, num21, num22, num23 + num22, state, out result, false); return; } } result = num22; } } }
private static void MoveFromNode(TriangleMeshNode node, int startEdge, VInt3 srcLoc, VInt3 destLoc, MoveDirectionState state, out VInt3 result) { result = srcLoc; while (node != null) { int count = 2; int i; if (node.IsVertex(srcLoc, out i)) { int vertexIndex = node.GetVertexIndex(i); List <PathfindingUtility.TMNodeInfo> list = null; PathfindingUtility.GetAllNodesByVert(ref list, node, vertexIndex); TriangleMeshNode triangleMeshNode = null; int num = -1; for (int j = 0; j < list.get_Count(); j++) { PathfindingUtility.TMNodeInfo tMNodeInfo = list.get_Item(j); if (!PathfindingUtility.checkedNodes.Contains(tMNodeInfo.node) && !Polygon.LeftNotColinear(tMNodeInfo.v0, tMNodeInfo.v2, destLoc) && Polygon.Left(tMNodeInfo.v0, tMNodeInfo.v1, destLoc)) { triangleMeshNode = tMNodeInfo.node; num = tMNodeInfo.vi; break; } } if (triangleMeshNode != null) { node = triangleMeshNode; startEdge = (num + 1) % 3; count = 1; } else { int edge = -1; VFactor b = new VFactor { nom = -2L, den = 1L }; for (int k = 0; k < list.get_Count(); k++) { PathfindingUtility.TMNodeInfo tMNodeInfo2 = list.get_Item(k); if (!PathfindingUtility.checkedNodes.Contains(tMNodeInfo2.node)) { int num2; VFactor cosineAngle = tMNodeInfo2.GetCosineAngle(destLoc, state, out num2); if (cosineAngle > b) { b = cosineAngle; edge = num2; triangleMeshNode = tMNodeInfo2.node; } } } if (triangleMeshNode != null) { PathfindingUtility.MoveAlongEdge(triangleMeshNode, edge, srcLoc, destLoc, state, out result, true); break; } } } int num3; if (startEdge == -1) { num3 = node.EdgeIntersect(srcLoc, destLoc); } else { num3 = node.EdgeIntersect(srcLoc, destLoc, startEdge, count); } if (num3 == -1) { if (node.ContainsPoint(destLoc)) { result = destLoc; if (PathfindingUtility.MoveAxisY) { PathfindingUtility.CalculateY(ref result, node); } } else { num3 = node.GetColinearEdge(srcLoc, destLoc); if (num3 != -1) { PathfindingUtility.MoveAlongEdge(node, num3, srcLoc, destLoc, state, out result, true); } } break; } int num4; TriangleMeshNode neighborByEdge = node.GetNeighborByEdge(num3, out num4); if (neighborByEdge == null) { PathfindingUtility.MoveAlongEdge(node, num3, srcLoc, destLoc, state, out result, true); break; } node = neighborByEdge; startEdge = num4 + 1; } }
private static void MoveAlongEdge(TriangleMeshNode node, int edge, VInt3 srcLoc, VInt3 destLoc, MoveDirectionState state, out VInt3 result, bool checkAnotherEdge = true) { DebugHelper.Assert(edge >= 0 && edge <= 2); VInt3 vertex = node.GetVertex(edge); VInt3 vertex2 = node.GetVertex((edge + 1) % 3); VInt3 vInt = destLoc - srcLoc; vInt.y = 0; VInt3 vInt2 = vertex2 - vertex; vInt2.y = 0; vInt2.NormalizeTo(1000); int num; if (state != null) { num = vInt.magnitude2D * 1000; VInt3 vInt3 = state.enabled ? state.firstAdjDir : vInt; if (VInt3.Dot(ref vInt2, ref vInt3) < 0) { num = -num; vInt3 = -vInt2; } else { vInt3 = vInt2; } if (!state.enabled) { state.enabled = true; state.firstAdjDir = VInt3.Lerp(vInt, vInt3, 1, 3); state.firstDir = state.curDir; state.adjDir = vInt3; } else if (VInt3.Dot(ref state.adjDir, ref vInt3) >= 0) { state.adjDir = vInt3; } else { num = 0; } state.applied = true; } else { num = vInt2.x * vInt.x + vInt2.z * vInt.z; } bool flag; VInt3 rhs = Polygon.IntersectionPoint(ref vertex, ref vertex2, ref srcLoc, ref destLoc, out flag); if (!flag) { if (!Polygon.IsColinear(vertex, vertex2, srcLoc) || !Polygon.IsColinear(vertex, vertex2, destLoc)) { result = srcLoc; return; } if (num >= 0) { int num2 = vInt2.x * (vertex2.x - vertex.x) + vInt2.z * (vertex2.z - vertex.z); int num3 = vInt2.x * (destLoc.x - vertex.x) + vInt2.z * (destLoc.z - vertex.z); rhs = ((num2 > num3) ? destLoc : vertex2); DebugHelper.Assert(num2 >= 0 && num3 >= 0); } else { int num4 = -vInt2.x * (vertex.x - vertex2.x) - vInt2.z * (vertex.z - vertex2.z); int num5 = -vInt2.x * (destLoc.x - vertex2.x) - vInt2.z * (destLoc.z - vertex2.z); rhs = ((Mathf.Abs(num4) > Mathf.Abs(num5)) ? destLoc : vertex); DebugHelper.Assert(num4 >= 0 && num5 >= 0); } } int num6 = -IntMath.Sqrt(vertex.XZSqrMagnitude(rhs) * 1000000L); int num7 = IntMath.Sqrt(vertex2.XZSqrMagnitude(rhs) * 1000000L); if (num >= num6 && num <= num7) { result = IntMath.Divide(vInt2, (long)num, 1000000L) + rhs; if (!node.ContainsPoint(result)) { Vector3 vector = (Vector3)(vertex2 - vertex); vector.y = 0f; vector.Normalize(); VInt3 lhs = vertex2 - vertex; lhs.y = 0; lhs *= 10000; long num8 = (long)lhs.magnitude; VFactor vFactor = default(VFactor); vFactor.nom = (long)num; vFactor.den = num8 * 1000L; int num9; int num10; PathfindingUtility.getMinMax(out num9, out num10, (long)lhs.x, ref vFactor); int num11; int num12; PathfindingUtility.getMinMax(out num11, out num12, (long)lhs.z, ref vFactor); if (!PathfindingUtility.MakePointInTriangle(ref result, node, num9, num10, num11, num12, srcLoc) && !PathfindingUtility.MakePointInTriangle(ref result, node, num9 - 4, num10 + 4, num11 - 4, num12 + 4, srcLoc)) { result = srcLoc; } } if (PathfindingUtility.MoveAxisY) { PathfindingUtility.CalculateY(ref result, node); } } else { int rhs2; int edge2; VInt3 vInt4; if (num < num6) { rhs2 = num - num6; edge2 = (edge + 2) % 3; vInt4 = vertex; } else { rhs2 = num - num7; edge2 = (edge + 1) % 3; vInt4 = vertex2; } VInt3 vInt5 = vInt2 * rhs2 / 1000000f; int startEdge; TriangleMeshNode neighborByEdge = node.GetNeighborByEdge(edge2, out startEdge); if (neighborByEdge != null) { PathfindingUtility.checkedNodes.Add(node); PathfindingUtility.MoveFromNode(neighborByEdge, startEdge, vInt4, vInt5 + vInt4, state, out result); } else { if (checkAnotherEdge) { VInt3 vertex3 = node.GetVertex((edge + 2) % 3); VInt3 lhs2 = (vertex3 - vInt4).NormalizeTo(1000); if (VInt3.Dot(lhs2, vInt5) > 0) { PathfindingUtility.checkedNodes.Add(node); PathfindingUtility.MoveAlongEdge(node, edge2, vInt4, vInt5 + vInt4, state, out result, false); return; } } result = vInt4; } } }
public void AddGraphObstacles(Simulator sim, INavmesh ng) { if (this.obstacles.Count > 0 && this.lastSim != null && this.lastSim != sim) { Debug.LogError("Simulator has changed but some old obstacles are still added for the previous simulator. Deleting previous obstacles."); this.RemoveObstacles(); } this.lastSim = sim; int[] uses = new int[20]; Dictionary <int, int> outline = new Dictionary <int, int>(); Dictionary <int, Int3> vertexPositions = new Dictionary <int, Int3>(); HashSet <int> hasInEdge = new HashSet <int>(); ng.GetNodes(delegate(GraphNode _node) { TriangleMeshNode triangleMeshNode = _node as TriangleMeshNode; uses[0] = (uses[1] = (uses[2] = 0)); if (triangleMeshNode != null) { for (int j = 0; j < triangleMeshNode.connections.Length; j++) { TriangleMeshNode triangleMeshNode2 = triangleMeshNode.connections[j] as TriangleMeshNode; if (triangleMeshNode2 != null) { int num3 = triangleMeshNode.SharedEdge(triangleMeshNode2); if (num3 != -1) { uses[num3] = 1; } } } for (int k = 0; k < 3; k++) { if (uses[k] == 0) { int i2 = k; int i3 = (k + 1) % triangleMeshNode.GetVertexCount(); outline[triangleMeshNode.GetVertexIndex(i2)] = triangleMeshNode.GetVertexIndex(i3); hasInEdge.Add(triangleMeshNode.GetVertexIndex(i3)); vertexPositions[triangleMeshNode.GetVertexIndex(i2)] = triangleMeshNode.GetVertex(i2); vertexPositions[triangleMeshNode.GetVertexIndex(i3)] = triangleMeshNode.GetVertex(i3); } } } return(true); }); for (int i = 0; i < 2; i++) { bool flag = i == 1; foreach (int num in new List <int>(outline.Keys)) { if (flag || !hasInEdge.Contains(num)) { int key = num; List <Vector3> list = new List <Vector3>(); list.Add((Vector3)vertexPositions[key]); while (outline.ContainsKey(key)) { int num2 = outline[key]; outline.Remove(key); Vector3 item = (Vector3)vertexPositions[num2]; list.Add(item); if (num2 == num) { break; } key = num2; } if (list.Count > 1) { sim.AddObstacle(list.ToArray(), this.wallHeight, flag); } } } } }
void SerializeUnityNavMesh(NavMeshTriangulation unityNavMesh, ref RecastGraph recast) { if (active == null || active.data == null) { return; } var vertMap = ObjectPoolSimple <Dictionary <int, int> > .Claim(); var totalVoxelWidth = (int)(recast.forcedBoundsSize.x / recast.cellSize + 0.5f); var totalVoxelDepth = (int)(recast.forcedBoundsSize.z / recast.cellSize + 0.5f); var tileSizeX = recast.editorTileSize; var tileSizeZ = recast.editorTileSize; var tileXCount = (totalVoxelWidth + tileSizeX - 1) / tileSizeX; var tileZCount = (totalVoxelDepth + tileSizeZ - 1) / tileSizeZ; var tileWorldSize = recast.TileWorldSizeX; var bucket = ArrayPool <List <int> > .Claim((tileXCount + 1) *(tileZCount + 1)); for (int i = 0; i < unityNavMesh.vertices.Length; i++) { var v = unityNavMesh.vertices[i]; var tileIndex = vertexOnTile( v, recast.forcedBoundsCenter, recast.forcedBoundsSize, tileWorldSize, tileXCount, tileZCount); tileIndex = 0; if (bucket[tileIndex] == null) { bucket[tileIndex] = ListPool <int> .Claim(); } bucket[tileIndex].Add(i); } foreach (var b in bucket) { if (b == null) { continue; } for (int i = 0; i < b.Count; i++) { for (int j = 0; j < i; j++) { if (b[i] >= unityNavMesh.vertices.Length || b[j] >= unityNavMesh.vertices.Length) { continue; } if (Vector3.Distance(unityNavMesh.vertices[b[i]], unityNavMesh.vertices[b[j]]) < 1e-3) { vertMap[b[i]] = b[j]; break; } } } } ArrayPool <List <int> > .Release(ref bucket, true); // only one tile recast.transform = recast.CalculateTransform(); recast.tileXCount = 1; recast.tileZCount = 1; recast.tileSizeX = totalVoxelWidth + 1; recast.tileSizeZ = totalVoxelDepth + 1; recast.ResetTiles(recast.tileXCount * recast.tileZCount); TriangleMeshNode.SetNavmeshHolder((int)recast.graphIndex, recast); var graphUpdateLock = active.PausePathfinding(); for (int z = 0; z < recast.tileZCount; z++) { for (int x = 0; x < recast.tileXCount; x++) { var tileOffset = recast.forcedBoundsCenter - recast.forcedBoundsSize * 0.5f + new Vector3( x * tileWorldSize, 0, z * tileWorldSize ); var trisClaim = ArrayPool <int> .Claim(unityNavMesh.indices.Length); var tris = Memory.ShrinkArray(trisClaim, unityNavMesh.indices.Length); ArrayPool <int> .Release(ref trisClaim, true); for (int i = 0; i < tris.Length; i++) { var tri = unityNavMesh.indices[i]; if (vertMap.ContainsKey(tri)) { tri = vertMap[tri]; } tris[i] = tri; } var vertsClaim = ArrayPool <Int3> .Claim(unityNavMesh.vertices.Length); var verts = Memory.ShrinkArray(vertsClaim, unityNavMesh.vertices.Length); ArrayPool <Int3> .Release(ref vertsClaim, true); for (int i = 0; i < verts.Length; i++) { var vertInWorld = unityNavMesh.vertices[i]; var vertInTile = vertInWorld - tileOffset; verts[i] = new Int3(vertInTile); } recast.ReplaceTile(x, z, 1, 1, verts, tris); } } graphUpdateLock.Release(); ObjectPoolSimple <Dictionary <int, int> > .Release(ref vertMap); }
private static void MoveAlongEdge(TriangleMeshNode node, int edge, VInt3 srcLoc, VInt3 destLoc, out VInt3 result) { bool flag; DebugHelper.Assert((edge >= 0) && (edge <= 2)); VInt3 vertex = node.GetVertex(edge); VInt3 num2 = node.GetVertex((edge + 1) % 3); VInt3 num3 = destLoc - srcLoc; num3.y = 0; VInt3 a = num2 - vertex; a.y = 0; a.NormalizeTo(0x3e8); int num5 = (a.x * num3.x) + (a.z * num3.z); VInt3 rhs = Polygon.IntersectionPoint(ref vertex, ref num2, ref srcLoc, ref destLoc, out flag); if (!flag) { if (!Polygon.IsColinear(vertex, num2, srcLoc) || !Polygon.IsColinear(vertex, num2, destLoc)) { result = srcLoc; return; } if (num5 >= 0) { int num7 = (a.x * (num2.x - vertex.x)) + (a.z * (num2.z - vertex.z)); int num8 = (a.x * (destLoc.x - vertex.x)) + (a.z * (destLoc.z - vertex.z)); rhs = (num7 <= num8) ? num2 : destLoc; DebugHelper.Assert((num7 >= 0) && (num8 >= 0)); } else { int num9 = (-a.x * (vertex.x - num2.x)) - (a.z * (vertex.z - num2.z)); int num10 = (-a.x * (destLoc.x - num2.x)) - (a.z * (destLoc.z - num2.z)); rhs = (Mathf.Abs(num9) <= Mathf.Abs(num10)) ? vertex : destLoc; DebugHelper.Assert((num9 >= 0) && (num10 >= 0)); } } int num11 = -IntMath.Sqrt(vertex.XZSqrMagnitude(rhs) * 0xf4240L); int num12 = IntMath.Sqrt(num2.XZSqrMagnitude(rhs) * 0xf4240L); if ((num5 >= num11) && (num5 <= num12)) { result = IntMath.Divide(a, (long)num5, 0xf4240L) + srcLoc; if (!node.ContainsPoint(result)) { int num15; int num16; int num17; int num18; Vector3 vector = (Vector3)(num2 - vertex); vector.y = 0f; vector.Normalize(); VInt3 num13 = num2 - vertex; num13.y = 0; num13 *= 0x2710; long magnitude = num13.magnitude; VFactor factor = new VFactor { nom = num5, den = magnitude * 0x3e8L }; getMinMax(out num15, out num17, (long)num13.x, ref factor); getMinMax(out num16, out num18, (long)num13.z, ref factor); if (!MakePointInTriangle(ref result, node, num15, num17, num16, num18, srcLoc) && !MakePointInTriangle(ref result, node, num15 - 4, num17 + 4, num16 - 4, num18 + 4, srcLoc)) { result = srcLoc; } } if (MoveAxisY) { CalculateY(ref result, node); } } else { int num19; int num20; VInt3 num21; int num22; if (num5 < num11) { num19 = num5 - num11; num20 = (edge + 2) % 3; num21 = vertex; } else { num19 = num5 - num12; num20 = (edge + 1) % 3; num21 = num2; } TriangleMeshNode neighborByEdge = node.GetNeighborByEdge(num20, out num22); if (neighborByEdge != null) { VInt3 num23 = ((VInt3)((a * num19) / 1000000f)) + num21; checkedNodes.Add(node); MoveFromNode(neighborByEdge, num22, num21, num23, out result); } else { result = num21; } } }
private static RecastGraph buildGraph(River river) { RecastGraph recastGraph = LevelNavigation.addGraph(); int graphIndex = AstarPath.active.astarData.GetGraphIndex(recastGraph); TriangleMeshNode.SetNavmeshHolder(graphIndex, recastGraph); recastGraph.forcedBoundsCenter = river.readSingleVector3(); recastGraph.forcedBoundsSize = river.readSingleVector3(); recastGraph.tileXCount = (int)river.readByte(); recastGraph.tileZCount = (int)river.readByte(); RecastGraph.NavmeshTile[] array = new RecastGraph.NavmeshTile[recastGraph.tileXCount * recastGraph.tileZCount]; recastGraph.SetTiles(array); for (int i = 0; i < recastGraph.tileZCount; i++) { for (int j = 0; j < recastGraph.tileXCount; j++) { RecastGraph.NavmeshTile navmeshTile = new RecastGraph.NavmeshTile(); navmeshTile.x = j; navmeshTile.z = i; navmeshTile.w = 1; navmeshTile.d = 1; navmeshTile.bbTree = new BBTree(navmeshTile); int num = j + i * recastGraph.tileXCount; array[num] = navmeshTile; navmeshTile.tris = new int[(int)river.readUInt16()]; for (int k = 0; k < navmeshTile.tris.Length; k++) { navmeshTile.tris[k] = (int)river.readUInt16(); } navmeshTile.verts = new Int3[(int)river.readUInt16()]; for (int l = 0; l < navmeshTile.verts.Length; l++) { navmeshTile.verts[l] = new Int3(river.readInt32(), river.readInt32(), river.readInt32()); } navmeshTile.nodes = new TriangleMeshNode[navmeshTile.tris.Length / 3]; num <<= 12; for (int m = 0; m < navmeshTile.nodes.Length; m++) { navmeshTile.nodes[m] = new TriangleMeshNode(AstarPath.active); TriangleMeshNode triangleMeshNode = navmeshTile.nodes[m]; triangleMeshNode.GraphIndex = (uint)graphIndex; triangleMeshNode.Penalty = 0u; triangleMeshNode.Walkable = true; triangleMeshNode.v0 = (navmeshTile.tris[m * 3] | num); triangleMeshNode.v1 = (navmeshTile.tris[m * 3 + 1] | num); triangleMeshNode.v2 = (navmeshTile.tris[m * 3 + 2] | num); triangleMeshNode.UpdatePositionFromVertices(); navmeshTile.bbTree.Insert(triangleMeshNode); } recastGraph.CreateNodeConnections(navmeshTile.nodes); } } for (int n = 0; n < recastGraph.tileZCount; n++) { for (int num2 = 0; num2 < recastGraph.tileXCount; num2++) { RecastGraph.NavmeshTile tile = array[num2 + n * recastGraph.tileXCount]; recastGraph.ConnectTileWithNeighbours(tile); } } return(recastGraph); }
// Token: 0x0600001A RID: 26 RVA: 0x00002B84 File Offset: 0x00000F84 public GraphNode ClampAlongNavmesh(Vector3 startPos, GraphNode _startNode, Vector3 endPos, out Vector3 clampedPos) { TriangleMeshNode triangleMeshNode = (TriangleMeshNode)_startNode; clampedPos = endPos; Stack <TriangleMeshNode> stack = this.tmpStack; List <TriangleMeshNode> list = this.tmpClosed; stack.Clear(); list.Clear(); float num = float.PositiveInfinity; TriangleMeshNode result = null; Vector3 vector = (startPos + endPos) / 2f; float num2 = AstarMath.MagnitudeXZ(startPos, endPos) / 2f; Vector3 vector2 = startPos; stack.Push(triangleMeshNode); list.Add(triangleMeshNode); INavmesh navmesh = AstarData.GetGraph(triangleMeshNode) as INavmesh; if (navmesh == null) { return(triangleMeshNode); } while (stack.Count > 0) { TriangleMeshNode triangleMeshNode2 = stack.Pop(); int tileIndex = ((RecastGraph)navmesh).GetTileIndex(triangleMeshNode2.GetVertexIndex(0)); Int3[] verts = ((RecastGraph)navmesh).GetTiles()[tileIndex].verts; int vertexArrayIndex = triangleMeshNode2.GetVertexArrayIndex(triangleMeshNode2.v0); int vertexArrayIndex2 = triangleMeshNode2.GetVertexArrayIndex(triangleMeshNode2.v1); int vertexArrayIndex3 = triangleMeshNode2.GetVertexArrayIndex(triangleMeshNode2.v2); if (NavMeshGraph.ContainsPoint(vertexArrayIndex, vertexArrayIndex2, vertexArrayIndex3, endPos, verts)) { result = triangleMeshNode2; vector2 = endPos; break; } int i = 0; int i2 = 2; while (i < 3) { int vertexIndex = triangleMeshNode2.GetVertexIndex(i2); int vertexIndex2 = triangleMeshNode2.GetVertexIndex(i); bool flag = true; TriangleMeshNode triangleMeshNode3 = null; for (int j = 0; j < triangleMeshNode2.connections.Length; j++) { triangleMeshNode3 = (triangleMeshNode2.connections[j] as TriangleMeshNode); if (triangleMeshNode3 != null) { int k = 0; int i3 = 2; while (k < 3) { int vertexIndex3 = triangleMeshNode3.GetVertexIndex(i3); int vertexIndex4 = triangleMeshNode3.GetVertexIndex(k); if ((vertexIndex3 == vertexIndex && vertexIndex4 == vertexIndex2) || (vertexIndex3 == vertexIndex2 && vertexIndex4 == vertexIndex)) { flag = false; break; } i3 = k++; } if (!flag) { break; } } } if (flag) { Vector3 vector3 = AstarMath.NearestPointStrictXZ((Vector3)verts[vertexIndex], (Vector3)verts[vertexIndex2], endPos); float num3 = AstarMath.MagnitudeXZ(vector3, endPos); if (num3 < num) { vector2 = vector3; num = num3; result = triangleMeshNode2; } } else if (!list.Contains(triangleMeshNode3)) { list.Add(triangleMeshNode3); Vector3 vector3 = AstarMath.NearestPointStrictXZ((Vector3)verts[vertexIndex], (Vector3)verts[vertexIndex2], vector); float num3 = AstarMath.MagnitudeXZ(vector3, vector); if (num3 <= num2) { stack.Push(triangleMeshNode3); } } i2 = i++; } } clampedPos = vector2; return(result); }
/** Adds obstacles for a graph */ public void AddGraphObstacles(Pathfinding.RVO.Simulator sim, NavGraph graph) { if (obstacles.Count > 0 && lastSim != null && lastSim != sim) { Debug.LogError("Simulator has changed but some old obstacles are still added for the previous simulator. Deleting previous obstacles."); RemoveObstacles(); } //Remember which simulator these obstacles were added to lastSim = sim; INavmesh ng = graph as INavmesh; if (ng == null) { return; } //Assume less than 20 vertices per node (actually assumes 3, but I will change that some day) int[] uses = new int[20]; ng.GetNodes(delegate(GraphNode _node) { TriangleMeshNode node = _node as TriangleMeshNode; uses[0] = uses[1] = uses[2] = 0; if (node != null) { //Find out which edges are shared with other nodes for (int j = 0; j < node.connections.Length; j++) { TriangleMeshNode other = node.connections[j] as TriangleMeshNode; // Not necessarily a TriangleMeshNode if (other != null) { int a = node.SharedEdge(other); if (a != -1) { uses[a] = 1; } } } //Loop through all edges on the node for (int j = 0; j < 3; j++) { //The edge is not shared with any other node //I.e it is an exterior edge on the mesh if (uses[j] == 0) { //The two vertices of the edge Vector3 v1 = (Vector3)node.GetVertex(j); Vector3 v2 = (Vector3)node.GetVertex((j + 1) % node.GetVertexCount()); //I think node vertices always should be clockwise, but it's good to be certain /*if (!Polygon.IsClockwise (v1,v2,(Vector3)node.GetVertex((j+2) % node.GetVertexCount()))) { * Vector3 tmp = v2; * v2 = v1; * v1 = tmp; * }*/ #if ASTARDEBUG Debug.DrawLine(v1, v2, Color.red); Debug.DrawRay(v1, Vector3.up * wallHeight, Color.red); #endif //Find out the height of the wall/obstacle we are about to add float height = System.Math.Abs(v1.y - v2.y); height = System.Math.Max(height, 5); //Add the edge as a line obstacle obstacles.Add(sim.AddObstacle(v1, v2, wallHeight)); } } } return(true); }); }
public static VInt3 FindValidTarget(ActorRoot actor, VInt3 start, VInt3 end, out bool bResult) { int actorCamp = (int)actor.TheActorMeta.ActorCamp; TriangleMeshNode triangleMeshNode = null; bResult = false; if (!AstarPath.active) { return(end); } AstarData data = AstarPath.active.GetData(actorCamp); if (data == null) { return(end); } int num; int num2; data.rasterizer.GetCellPosClamped(out num, out num2, start); int num3; int num4; data.rasterizer.GetCellPosClamped(out num3, out num4, end); bool flag = num < num3; bool flag2 = num2 < num4; int num5 = flag ? (num3 - num) : (num - num3); int num6 = flag2 ? (num4 - num2) : (num2 - num4); for (int i = 0; i <= num5; i++) { for (int j = 0; j <= num6; j++) { int num7 = num + i * (flag ? 1 : -1); int num8 = num2 + j * (flag2 ? 1 : -1); List <object> objs = data.rasterizer.GetObjs(num7, num8); if (objs != null) { int count = objs.get_Count(); if (count != 0) { VInt3 vInt; if (count > 2) { if (data.rasterizer.IntersectionSegment(num7, num8, start, end) && data.CheckSegmentIntersects(start, end, num7, num8, out vInt, out triangleMeshNode)) { if (triangleMeshNode != null) { VInt3 offset = vInt; bResult = PathfindingUtility.MakePointInTriangle(ref vInt, triangleMeshNode, -4, 4, -4, 4, offset); } return(vInt); } } else if (data.CheckSegmentIntersects(start, end, num7, num8, out vInt, out triangleMeshNode)) { if (triangleMeshNode != null) { VInt3 offset2 = vInt; bResult = PathfindingUtility.MakePointInTriangle(ref vInt, triangleMeshNode, -4, 4, -4, 4, offset2); } return(vInt); } } } } } return(end); }