({{, (RefLink[MeshCellShapeFunction, paclet:ref/MeshCellShapeFunction]) 
is an option and property for (RefLink[MeshRegion, paclet:ref/MeshRegion]), (RefLink[BoundaryMeshRegion, paclet:ref/BoundaryMeshRegion]), and related functions that specifies functions to use to generate primitives for rendering mesh cells.}})

OpenersNotesSection(Spacer1)Details

The following settings can be used:

Mesh cells with no explicit mesh cell shape function are taken to use the automatic shape.

The wrapper (RefLink[Property, paclet:ref/Property])[cellspec,MeshCellShapeFunction->func] can be used when creating mesh regions in functions such as (RefLink[MeshRegion, paclet:ref/MeshRegion]), (RefLink[BoundaryMeshRegion, paclet:ref/BoundaryMeshRegion]), etc.

The cell specification cellspec follows the standard form described for (RefLink[MeshRegion, paclet:ref/MeshRegion]) and (RefLink[BoundaryMeshRegion, paclet:ref/BoundaryMeshRegion]).

A general shape function func specifies that the cell of the form h[{(Subscript[i, 1]),…,(Subscript[i, n])}] should be rendered with the primitive provided by func[coords,index,cell], where coords are coordinates of points with index (Subscript[i, 1]),…,(Subscript[i, n]), and index is the mesh cell index.

OpenersPrimaryExamplesSection(Spacer1)Examples  (11)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Specify a mesh cell function for all zero-dimensional cells:

MeshRegion[{{0,0,0},{2,0,0},{2,2,0},{0,2,0},{1,1,2}},Pyramid[{1,2,3,4,5}],MeshCellShapeFunction->{0->(Sphere[#,0.1]&)}]

Specify a mesh cell function for all 1D cells:

MeshRegion[{{0,0,0},{2,0,0},{2,2,0},{0,2,0},{1,1,2}},Pyramid[{1,2,3,4,5}],MeshCellShapeFunction->{1->(Tube[#1,.1]&)}]

OpenersExampleSection1(Spacer1)Scope  (9)

(RefLink[MeshCellShapeFunction, paclet:ref/MeshCellShapeFunction]) works with regions in 0D:

MeshRegion[{{0},{1}},Point[{{1},{2}}], MeshCellShapeFunction->{0->(Disk[#,.02]&)}]

Regions in 1D:

MeshRegion[{{0},{5}},Line[{{1,2}}],MeshCellShapeFunction->{1->(Arrow[#]&)}]

Regions in 2D:

BoundaryMeshRegion[{{0,0},{1,0},{0,1}},Line[{1,2,3,1}],MeshCellShapeFunction->{0->(Disk[#1,.02]&)}]

Regions in 3D:

MeshRegion[{{0,0,0},{1,0,0},{0,1,0},{0,0,1}},Tetrahedron[{1,2,3,4}],MeshCellShapeFunction->{0->(Sphere[#1,.02]&)}]

Specify mesh cell functions for all 1D cells and all 0D cells:

MeshRegion[{{0,0,0},{2,0,0},{2,2,0},{0,2,0},{1,1,2}},Pyramid[{1,2,3,4,5}],MeshCellShapeFunction->{0->(Sphere[#,0.2]&),1->(Tube[#1,.1]&)}]

Individual cells can be drawn using their cell index:

MeshRegion[{{1,1,0},{0,0,0},{0,1,0},{1,0,1},{1,0,0},{1,1,1},{0,1,1},{0,0,1}},Polygon[{{1,5,2,3}, {2,8,4,5},{2,3,7,8},{1,6,7,3},{1,5,4,6},{4,8,7,6}}],MeshCellShapeFunction->{{1,6}->({CapForm["Butt"],Tube[#1,.05]}&)}]

Or by the cell itself:

MeshRegion[{{1,1,0},{0,0,0},{0,1,0},{1,0,1},{1,0,0},{1,1,1},{0,1,1},{0,0,1}},Polygon[{{1,5,2,3}, {2,8,4,5},{2,3,7,8},{1,6,7,3},{1,5,4,6},{4,8,7,6}}],MeshCellShapeFunction->{Line[{8,4}]->({CapForm["Butt"],Tube[#1,.05]}&)}]

Draw all cells of a given dimension:

MeshRegion[{{0,0,0},{2,0,0},{2,2,0},{0,2,0},{1,1,2}},Pyramid[{1,2,3,4,5}],MeshCellShapeFunction->{0->(Sphere[#,0.2]&),1->(Tube[#1,.1]&)}]

Specify a list of cell indices to style:

MeshRegion[{{0,0,0},{2,0,0},{2,2,0},{0,2,0},{1,1,2}},Pyramid[{1,2,3,4,5}],MeshCellShapeFunction->{{{0,1},{0,2}}->(Sphere[#,0.1]&)}]

Style cells whose indices match a pattern:

MeshRegion[{{0,0,0},{2,0,0},{2,2,0},{0,2,0},{1,1,2}},Pyramid[{1,2,3,4,5}],MeshCellShapeFunction->{{1,_?EvenQ}->(Tube[#,.1]&)}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[MeshCellStyle, paclet:ref/MeshCellStyle])  ▪  (RefLink[MeshCellLabel, paclet:ref/MeshCellLabel])  ▪  (RefLink[MeshCellHighlight, paclet:ref/MeshCellHighlight])  ▪  (RefLink[MeshCellMarker, paclet:ref/MeshCellMarker])  ▪  (RefLink[MeshRegion, paclet:ref/MeshRegion])  ▪  (RefLink[BoundaryMeshRegion, paclet:ref/BoundaryMeshRegion])  ▪  (RefLink[PropertyValue, paclet:ref/PropertyValue])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Mesh-Based Geometric Regions, paclet:guide/MeshRegions])}, {▪(RefLinkPlain[Properties, paclet:guide/Properties])}})}})