/*internal*/ public static IEnumerable <Mesh> GetPreviewMeshes ( this IEnumerable <DB.GeometryObject> geometries, MeshingParameters meshingParameters ) { foreach (var geometry in geometries) { if (geometry.Visibility != DB.Visibility.Visible) { continue; } switch (geometry) { case DB.GeometryInstance instance: { var xform = instance.Transform.ToTransform(); foreach (var g in instance.SymbolGeometry.GetPreviewMeshes(meshingParameters)) { g?.Transform(xform); yield return(g); } break; } case DB.Mesh mesh: { if (mesh.NumTriangles <= 0) { continue; } var f = Geometry.Raw.RawDecoder.ToRhino(mesh); UnitConverter.Scale(f, UnitConverter.ToRhinoUnits); yield return(f); break; } case DB.Face face: { var faceMesh = face.Triangulate(meshingParameters.LevelOfDetail()); var f = Geometry.Raw.RawDecoder.ToRhino(faceMesh); UnitConverter.Scale(f, UnitConverter.ToRhinoUnits); yield return(f); break; } case DB.Solid solid: { if (solid.Faces.IsEmpty) { continue; } var solidFaces = solid.Faces.OfType <DB.Face>(); bool useMultipleMaterials = solidFaces.HasMultipleMaterials(); var facesMeshes = useMultipleMaterials ? null : new List <Mesh>(solid.Faces.Size); foreach (var face in solidFaces) { var faceMesh = face.Triangulate(meshingParameters.LevelOfDetail()); var f = Geometry.Raw.RawDecoder.ToRhino(faceMesh); UnitConverter.Scale(f, UnitConverter.ToRhinoUnits); if (facesMeshes is null) { yield return(f); } else if (f is object) { facesMeshes.Add(f); } } if (facesMeshes is object) { if (facesMeshes.Count > 0) { var mesh = new Mesh(); mesh.Append(facesMeshes); yield return(mesh); } else { yield return(null); } } break; } } } }
/// <summary> /// Extracts a sequence of <see cref="Mesh"/> from a sequence of <see cref="DB.GeometryObject"/>. /// </summary> /// <remarks> /// Empty <see cref="DB.Mesh"/> and empty <see cref="DB.Solid"/> will be skipped, /// so output <see cref="IEnumerable{T}"/> may be shorter than the input. /// Output is warranted to be free of nulls, an empty <see cref="Mesh"/> is returned in case of error. /// </remarks> /// <param name="geometries"></param> /// <param name="meshingParameters"></param> /// <returns>An <see cref="IEnumerable{Mesh}"/></returns> /// <seealso cref="GetPreviewMaterials(IEnumerable{DB.GeometryObject}, DB.Document, DB.Material)"/> internal static IEnumerable <Mesh> GetPreviewMeshes ( this IEnumerable <DB.GeometryObject> geometries, DB.Document doc, MeshingParameters meshingParameters ) { foreach (var geometry in geometries) { if (geometry.Visibility != DB.Visibility.Visible) { continue; } switch (geometry) { case DB.GeometryInstance instance: { var xform = instance.Transform.ToTransform(); foreach (var g in instance.SymbolGeometry.GetPreviewMeshes(doc, meshingParameters)) { g.Transform(xform); yield return(g); } break; } case DB.Mesh mesh: { if (mesh.NumTriangles <= 0) { continue; } if (SkipGeometryObject(geometry, doc)) { continue; } var f = Geometry.Raw.RawDecoder.ToRhino(mesh); UnitConverter.Scale(f, UnitConverter.ToRhinoUnits); yield return(f ?? new Rhino.Geometry.Mesh()); break; } case DB.Face face: { if (SkipGeometryObject(geometry, doc)) { continue; } var faceMesh = face.Triangulate(meshingParameters.LevelOfDetail()); var f = Geometry.Raw.RawDecoder.ToRhino(faceMesh); UnitConverter.Scale(f, UnitConverter.ToRhinoUnits); yield return(f ?? new Rhino.Geometry.Mesh()); break; } case DB.Solid solid: { if (solid.Faces.IsEmpty) { continue; } if (SkipGeometryObject(geometry, doc)) { continue; } var solidFaces = solid.Faces.OfType <DB.Face>(); foreach (var face in solidFaces) { var faceMesh = face.Triangulate(meshingParameters.LevelOfDetail()); var f = Geometry.Raw.RawDecoder.ToRhino(faceMesh); UnitConverter.Scale(f, UnitConverter.ToRhinoUnits); yield return(f ?? new Rhino.Geometry.Mesh()); } break; } } } }