/// <summary> /// Gets all <see cref="Face"/> objects referenced by this <see cref="Model"/>, recursively. /// </summary> /// <param name="bsp">This <see cref="BSP"/>.</param> /// <param name="model">The <see cref="Model"/> to get all <see cref="Face"/> objects from. Depending on <see cref="BSP.version"/> this may need to traverse through <see cref="BSP.leaves"/>.</param> /// <returns>A <see cref="List{T}"/><<see cref="Face"/>> containing all <see cref="Face"/> objects descended from <paramref name="model"/>.</returns> public static List <Face> GetFacesInModel(this BSP bsp, Model model) { List <Face> result = null; if (model.FirstFaceIndex >= 0) { if (result == null) { result = new List <Face>(); } for (int i = 0; i < model.NumFaces; i++) { result.Add(bsp.faces[model.FirstFaceIndex + i]); } } else { bool[] faceUsed = new bool[bsp.faces.Count]; List <Leaf> leaves = bsp.GetLeavesInModel(model); foreach (Leaf leaf in leaves) { if (leaf.FirstMarkFaceIndex >= 0) { if (result == null) { result = new List <Face>(); } for (int i = 0; i < leaf.NumMarkFaceIndices; i++) { int currentFace = (int)bsp.markSurfaces[leaf.FirstMarkFaceIndex + i]; if (!faceUsed[currentFace]) { faceUsed[currentFace] = true; result.Add(bsp.faces[currentFace]); } } } } } return(result); }