/* * 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); }
/* * writeNavigationMeshToFile method will serialize the data for a navigation mesh and write it all do a file * Parameters: none * Return: none */ void writeNavigationMeshToFile() { AIPolygon[] polygons = surfacePolygonHolders.getPolygons(); /*AIPolygonHolderData dataHolder = new AIPolygonHolderData (); * dataHolder.polygonData = new AIPolygonData[polygons.Length]; * for (int count = 0; count < polygons.Length; count++) { * float[,] vertices = new float[polygons [count].getVerticesCount (), 3]; * for (int count2 = 0; count2 < polygons[count].getVerticesCount(); count2++) { * Vector3 vertex = polygons [count].getVectorAtIndex (count2); * vertices [count2, 0] = vertex.x; * vertices [count2, 1] = vertex.y; * vertices [count2, 2] = vertex.z; * } * dataHolder.polygonData [count] = new AIPolygonData (); * dataHolder.polygonData [count].vertices = vertices; * dataHolder.polygonData [count].neighborCount = polygons [count].getNeighborsHeld (); * dataHolder.polygonData [count].neighbors = polygons [count].getNeighbors (); * dataHolder.polygonData [count].gotGoal = polygons [count].getHasGoal (); * dataHolder.polygonData [count].gotAgent = polygons [count].getHasAgent (); * dataHolder.polygonData [count].id = polygons [count].getID (); * } * * string filePath = Application.dataPath + "/" + Path.GetFileNameWithoutExtension (EditorApplication.currentScene) + "UserNavMesh.dat"; * Stream writer = File.Create (filePath); * BinaryFormatter serializer = new BinaryFormatter (); * serializer.Serialize (writer, dataHolder); * Debug.Log ("NavMesh exported as '" + filePath + "'"); * writer.Close ();*/ string data = ""; data += polygons.Length + "\n"; int debugCounter = 0; for (int counter = 0; counter < polygons.Length; counter++) { float[,] vertices = new float[polygons [counter].getVerticesCount(), 3]; data += polygons [counter].getVerticesCount() + "\n"; for (int count3 = 0; count3 < polygons[counter].getVerticesCount(); count3++) { Vector3 vertex = polygons [counter].getVectorAtIndex(count3); data += vertex.x + "\n" + vertex.y + "\n" + vertex.z + "\n"; } data += polygons [counter].getNeighborsHeld() + "\n"; int[] neighbors = polygons [counter].getNeighbors(); for (int count3 = 0; count3 < neighbors.Length; count3++) { data += neighbors [count3] + "\n"; } //data += "\n"; data += polygons [counter].getID() + "\n"; } using (StreamWriter sw = new StreamWriter(Application.dataPath + "/" + Path.GetFileNameWithoutExtension(EditorApplication.currentScene) + "UserNavMesh.obj")) { sw.Write(data); Debug.Log(data); } }