public static string Flood_Fill(Vector3 furthest_from_face, face current_face, Stack <edge> horizon_edge_list, Stack <face> visited_faces) { UnityEngine.Debug.Log("Flooding... " + current_face); string path = ""; face next_face; face last_face; if (visited_faces.Count > 0) { last_face = visited_faces.Peek(); // Testing if face is a conflict (not visible or already visited) // There is some conflict, either the current face has already been visited or it is not visible from the point if (visited_faces.Contains(current_face)) { return("C"); } if (!current_face.Is_Visible_from_Point(furthest_from_face)) { // Adding the relevant edge to the edge list horizon_edge_list.Push(current_face.edges.Find(element1 => element1.connected_faces.Exists(element2 => element2 == last_face))); UnityEngine.Debug.Log("INTREST: " + horizon_edge_list.Peek().connected_faces.Exists(element2 => visited_faces.Contains(element2))); return("H"); } } else { if (!current_face.Is_Visible_from_Point(furthest_from_face)) { return("H"); } } visited_faces.Push(current_face); path += 'V'; foreach (edge e in current_face.edges) { next_face = e.connected_faces.Find(element => element != current_face); path += '['; path += Flood_Fill(furthest_from_face, next_face, horizon_edge_list, visited_faces); path += ']'; } return(path); }
public static string Flood_Fill_and_Make(Vector3 furthest_from_face, face current_face, Stack <edge> horizon_edge_list, Stack <face> visited_faces, List <face> daughter_faces) { UnityEngine.Debug.Log("Flooding... " + current_face); if (visited_faces.Count > 0) { // Testing if face is a conflict (not visible or already visited) // There is some conflict, either the current face has already been visited or it is not visible from the point if (visited_faces.Contains(current_face)) { return("C"); } if (!current_face.Is_Visible_from_Point(furthest_from_face)) { face last_face = visited_faces.Peek(); edge horizon_edge = current_face.edges.Find(element1 => element1.connected_faces.Exists(element2 => element2 == last_face)); UnityEngine.Debug.Log("last face: " + last_face); UnityEngine.Debug.Log("current face: " + current_face); // Adding the relevant edge to the edge list horizon_edge_list.Push(horizon_edge); List <Vector3> new_face_corners = new List <Vector3>(horizon_edge.vertices); new_face_corners.Add(furthest_from_face); //new stuff - generate and filter var possible_faces = from c1 in new_face_corners from c2 in new_face_corners from c3 in new_face_corners where c1 != c2 && c1 != c3 && c2 != c3 select new face(c1, c2, c3); var front_facing_faces = from t in possible_faces where Distance_from_Plane(t.corners[0], t.corners[1] - t.corners[0], t.corners[2] - t.corners[0], Array.Find(last_face.corners, corner => !Array.Exists(t.corners, c => c == corner)), false) < 0 select t; var new_face = front_facing_faces.First(); // Modify horizon edges so they point to new face horizon_edge.connected_faces.Remove(last_face); horizon_edge.Connect_to_Face(new_face); daughter_faces.Add(new_face); UnityEngine.Debug.Log("ITEM: "); return("H"); } } else { if (!current_face.Is_Visible_from_Point(furthest_from_face)) { return("H"); } } string path = ""; UnityEngine.Debug.Log("Visit: "); path += 'V'; foreach (edge e in current_face.edges) { visited_faces.Push(current_face); //testing if (e.connected_faces.Count < 2 || !e.connected_faces.Contains(current_face)) { UnityEngine.Debug.Log("WARNING, MAKING ONE WAY TRIP: " + !e.connected_faces.Contains(current_face)); } UnityEngine.Debug.Log("Flag: " + !e.connected_faces.Contains(current_face)); UnityEngine.Debug.Log("current face: " + current_face); UnityEngine.Debug.Log("top of stack: " + visited_faces.Peek()); UnityEngine.Debug.Log("traversing edge: " + e); //testing face next_face = e.connected_faces.Find(element => element != current_face); UnityEngine.Debug.Log("next face: " + next_face); path += '['; path += Flood_Fill_and_Make(furthest_from_face, next_face, horizon_edge_list, visited_faces, daughter_faces); path += ']'; } return(path); }