Updated
BoundaryMesh
is not needed, faster than the previous version
mesh = MengerMesh[4, 3];
idx = {1, 2, 2, 3, 3, 4, 4, 1, 5, 6, 6, 7, 7, 8, 8, 5, 1, 5, 2, 6, 3, 7, 4, 8};
outlines = MeshPrimitives[mesh, 3][[All, 1, idx]] //
RightComposition[
ArrayReshape[#, {Times @@ Dimensions@#/6, 2, 3}] &,
Map[Sort],
Tally,
Cases[{x_, 1} :> x],
Developer`ToPackedArray,
Line
]; // AbsoluteTiming
Graphics3D[{
{EdgeForm[], mesh},
{Black, Tube[outlines, Scaled[1/1000]]}
}, Boxed -> False, ImageSize -> 800, Lighting -> "Classic"]
{3.31279, Null}
Using method in Extract 2D quad mesh from 3D hexahedral mesh, add some optimization
Clear[boundaryMeshOutlines];
boundaryMeshOutlines[bmr_BoundaryMeshRegion, tol_ : 0.] :=
Module[{enormal, graph, edges, vl, adj, corneredges},
enormal = Region`Mesh`MeshCellNormals[bmr, 2];
graph = MeshConnectivityGraph[bmr, {1, 2}];
edges = MeshCellIndex[bmr, 1];
vl = VertexList[graph];
adj = Lookup[AssociationThread[vl, Extract[vl,
List/@ AdjacencyMatrix[graph]["AdjacencyLists"]]], edges][[All, All, 2]];
corneredges = Pick[edges, UnitStep[(Dot @@ enormal[[#]] & /@ adj) - 1 + tol], 0];
MeshPrimitives[bmr, corneredges, "Multicells" -> True]
];
bmesh = BoundaryMesh[MengerMesh[3, 3]];
outlines = boundaryMeshOutlines[bmesh]; // AbsoluteTiming
Graphics3D[{
{EdgeForm[], bmesh},
{Black, Tube[#, Scaled[1/800]] & /@ outlines}
}, Boxed -> False, ImageSize -> 600]
{0.30785, Null}
It also works for this Construct a polyhedron from the coordinates of its vertices and calculate the area of each face
q={{-10.,-7.5,-6.25},{-10.,-7.5,6.25},{-10.,0.,-10.},{-10.,0.,10.},{-10.,7.5,-6.25},{-10.,7.5,6.25},{-1.66667,-11.6667,-8.33333},{-1.66667,-11.6667,8.33333},{2.5,-13.75,0.},{-2.5,0.,-13.75},{1.66667,-8.33333,-11.6667},{-2.5,0.,13.75},{1.66667,-8.33333,11.6667},{-1.66667,11.6667,-8.33333},{1.66667,8.33333,-11.6667},{-1.66667,11.6667,8.33333},{1.66667,8.33333,11.6667},{2.5,13.75,0.},{10.,-10.,0.},{10.,-6.25,-7.5},{10.,-6.25,7.5},{10.,6.25,-7.5},{10.,6.25,7.5},{10.,10.,0.}};
bdm=BoundaryMesh@DelaunayMesh[q];
Graphics3D[{
{EdgeForm[], bdm},
{Black,
Tube[#, Scaled[1/800]] & /@ boundaryMeshOutlines[bdm, 10^-5.]}
}, Boxed -> False, ImageSize -> 600]