/* * mergePolygonHolder will merge two AIPolygonHolder objects. This will create a new AIPolygonHolder * place the polygons from each AIPolygonHolder to the new AIPolygonHolder then merge the Polygons * in the new AIPolygonHolder * Parameter: (AIPolygonHolder)holderToMerge is the AIPolygonHolder that will be merged with this object * Return: (AIPolygonHolder) * the new AIPolygonHolder that is the two merged AIPolygonHolders */ public AIPolygonHolder mergePolygonHolder(AIPolygonHolder holderToMerge) { copyAndSrink(polygonArray); holderToMerge.copyAndSrink(holderToMerge.getPolygons()); AIPolygon[] tempArray = mergeTwoArrays(polygonArray, holderToMerge.getPolygons()); //makes a new AIPolygonHolder with the capacity of both AIPolygonHolders being Merged AIPolygonHolder newHolder = new AIPolygonHolder(tempArray.Length); //makes a new AIPolygonHolder with the capacity of both AIPolygonHolders being Merged for (int count = 0; count < tempArray.Length; count++) { newHolder.addPolygon(tempArray [count].getVertices()); } newHolder.merge(); // merged the polygons in the new AIPolygonHolders return(newHolder); }
/* * writeAfterDataToFile method will write all the data from the navigation mesh and the search agent to the * end of the file * parameters: none * return: none */ /*void writeAfterDataToFile () * { * string filePath = "data.txt"; * StreamReader inputStream = new StreamReader(filePath); * string tempString = ""; * tempString += inputStream.ReadToEnd(); * tempString += "\n"; * inputStream.Close (); * tempString += Application.loadedLevelName + "\t"; * if (AINavigationMeshAgent.loadNavigationMesh == true) * tempString += "load Navigation Mesh\t"; * else * tempString += "build Navigation Mesh\t"; * tempString += AINavigationMeshData.timeTaken + "\t"; * tempString += AINavigationMeshData.initialPolygonCount + "\t"; * tempString += AINavigationMeshData.obstacleCount + "\t"; * tempString += AINavigationMeshData.finalPolygonCount + "\t"; * tempString += AISearchAgentData.searchType + "\t"; * tempString += AISearchAgentData.timeTaken + "\t"; * tempString += AISearchAgentData.nodesVisited + "\t"; * tempString += AISearchAgentData.maxQueueSize + "\t"; * tempString += AISearchAgentData.finalPathLength + "\t"; * tempString += AISearchAgentData.finalPathCost + "\t"; * StreamWriter writer = new StreamWriter (filePath); * writer.Write (tempString); * writer.Close (); * * * * }*/ /* * doAISearchMethods will make a search agent to start searching though the navigation mesh * Parameter: none * Return: none */ /*void doAISearchMethods() * { * * AINavigationMeshAgent.polygonLengthMin = surfacePolygonHolders [positionToStart].getMinPolygonLength (); * AINavigationMeshAgent.polygonLengthAvg = surfacePolygonHolders [positionToStart].getAveragePolygonLength (); * if (positionToStart != -1) * tempSearch = new AISearch (searchType, goalPosition, surfacePolygonHolders [positionToStart].getPolygons ()); * if (tempSearch != null) { * Vector3[] vertices = tempSearch.getWayPoints (); * if (vertices != null) * for (int count = 0; count < vertices.Length; count++) * Instantiate (sphere, vertices [count], new Quaternion (0f, 0f, 0f, 0f)); * } * }*/ /* getObjectsArray gets all the triangle polygons that compose all objects in a Unity map, * and loads them into the triangleArray. Then creates new AIObjects from those triangles and loads * them into objectsArray to be used for nav mesh construction. * Parameters: none * Return: none */ /*void getObjectsArray () * { * Vector3[] WorldPositionArray = new Vector3[3]; * for (int count = 0; count < staticObjects.Length; count++) { * staticObjectMesh [count] = staticObjects [count].GetComponent<MeshFilter> ().mesh; * vectorArray = staticObjectMesh[count].vertices; * triangleArray = staticObjectMesh[count].GetTriangles (0); * objectsArray[count] = new AIObjects(triangleArray.Length/3, staticObjects[count]); * for (int count1 = 0, count2 = 1, count3 = 2; count1 < triangleArray.Length; count1 += 3, count2 += 3, count3 += 3) { * WorldPositionArray [0] = staticObjects [count].transform.TransformPoint (vectorArray [triangleArray [count1]]); * WorldPositionArray [1] = staticObjects [count].transform.TransformPoint (vectorArray [triangleArray [count2]]); * WorldPositionArray [2] = staticObjects [count].transform.TransformPoint (vectorArray [triangleArray [count3]]); * objectsArray[count].addPolygon(WorldPositionArray); * } * } * }*/ /* getSurgavePolygonHolders gets all the triangle polygons that compose all objects in a Unity map, * and loads them into the triangleArray. Then creates new AIObjects from those triangles out of the walkable * polygons and loads them into surfacePolygonHolders to be used for nav mesh construction. * Parameters: none * Return: none */ void getSurfacePolygonHolders() { Vector3[] WorldPositionArray = new Vector3[3]; NavMeshTriangulation triangulatedNavMesh = NavMesh.CalculateTriangulation(); //Mesh mesh = new Mesh (); //mesh.vertices = triangulatedNavMesh.vertices; //mesh.triangles = triangulatedNavMesh.indices; vectorArray = triangulatedNavMesh.vertices; triangleArray = triangulatedNavMesh.indices; surfacePolygonHolders = new AIPolygonHolder(triangleArray.Length / 3); for (int count1 = 0, count2 = 1, count3 = 2; count1 < triangleArray.Length; count1 += 3, count2 += 3, count3 += 3) { WorldPositionArray [0] = vectorArray [triangleArray [count1]]; WorldPositionArray [1] = vectorArray [triangleArray [count2]]; WorldPositionArray [2] = vectorArray [triangleArray [count3]]; //if (checkVertex (WorldPositionArray) == false) { surfacePolygonHolders.addPolygon(WorldPositionArray); //} } }