Coloring Graphics3D as a Function of Spatial Coordinates

I would like to plot a Graphics3D object colored based on the value of some spatial function. For example to plot a triangle colored by the function cf I might start with:

testCorners = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
testTriangle = Triangle[testCorners];
cf [{x_, y_, z_}] = ColorData["NeonColors"][z];


I hope that there is a couple of lines, probably involving Graphics3D that will plot this triangle (or other, more complicated surfaces) colored with the function I have specified (or other more complicated functions of x, y, and z).

I can do fun stuff like color vertices and have Mathematica linearly interpolate over the faces.

Graphics3D[
Append[PolyhedronData["Dodecahedron", "GraphicsComplex"],
VertexColors -> ColorData["NeonColors"] /@ RandomReal[{0, 1}, 20]]]


It may be possible to use a similar method by transforming the surface into a GraphicsComplex object and then setting VertexTextureCoordinates appropriately and supplying a Texture to Graphics3D, but that seems quite complicated...

gc = PolyhedronData["Dodecahedron", "GraphicsComplex"];
minmax = MinMax @ N @ gc[[1, All, -1]]

Graphics3D[Append[gc,
VertexColors -> (ColorData[{"NeonColors", minmax}] /@ gc[[1, All, -1]])]]


Alternatively, use your cf with rescaled arguments:

Graphics3D[Append[gc,
VertexColors -> (cf /@ Transpose[Rescale /@ Transpose[First @ N @ gc]])]


same picture

Update: "but suppose I had a color function which was radially symmetric like Norm. The dodecahedron would be uniformly colored, even though the centers of each face should have a lower value."

texture = RadialGradientImage["NeonColors"];

Graphics3D[Normal[gc] /. Polygon[x_] :>
{Texture @ texture,
Polygon[x, VertexTextureCoordinates -> Rescale[CirclePoints @ Length @ x]]}]


Further examples:

SeedRandom[1]
polyhedra = RandomSample[PolyhedronData["Archimedean"], 12];

Graphics3D[Normal[PolyhedronData[#, "GraphicsComplex"]] /.
Polygon[x_] :> {Texture @ texture,
Polygon[x,
VertexTextureCoordinates -> Rescale[CirclePoints @ Length @ x]]},
Lighting -> "Neutral"] & /@  polyhedra // Multicolumn[#, 4] &


• This is useful but suppose I had a color function which was radially symmetric like Norm. The dodecahedron would be uniformly colored, even though the centers of each face should have a lower value. Commented Oct 5, 2020 at 20:53
• @alessandro, please see the update.
– kglr
Commented Oct 5, 2020 at 21:46
• That looks spectacular, let me play with it for a second and I'll get back to you. Commented Oct 5, 2020 at 21:53
• This doesn't let me specify an arbitrary function. It just maps the same image on to each face. An texture for each face could be made I suppose though... Commented Oct 5, 2020 at 23:42