# Mathematica's “POV” export format ignores ColorFunction

I was playing with xslittlegrass's Pov-Ray package and more generally with the POV-conversion function ExportString[#, "POV"] &, and noticed that ExportString[#, "POV"] & seems to ignore colors given to objects using ColorFunction.

For example:

ParametricPlot3D[{Cos[ϕ] Sin[θ], Sin[ϕ] Sin[θ], Cos[θ]}, {ϕ, 0, 2 π}, {θ, 0, π},
PlotPoints -> 100, Mesh -> None,
ColorFunction -> Function[{x, y, z, ϕ, θ}, Hue[Sin[6 ϕ] Sin[6 θ]]],
ColorFunctionScaling -> False]

However, applying ExportString[#, "POV"] & to the previous graphics object yields a POV-Ray script which, when rendered, consists entirely of white triangles:

So it seems that the surface coloration provided by the ColorFunction specified in the plot does not get converted to the POV output at all.

Is there some way to correctly export the plot colors provided by ColorFunction?

-

Like you, I found no colours in the output *.pov file. Mathematica recognises the pov extension, but Export["povtest.pov",pplot3D] outputs all triangle objects with white colour: pigment {color rgb <1, 1, 1>}.

I took the brute-force approach and decomposed the 3D plot into vertices, triangles, and colours.

Define the 3D plot.

pplot3D = ParametricPlot3D[
{Cos[p] Sin[t], Sin[p] Sin[t], Cos[t]},
{p, 0, 2 \[Pi]}, {t, 0, \[Pi]},
PlotPoints->150, Mesh->None,
ColorFunction->Function[{x, y, z, p, t}, Hue[Sin[6 p] Sin[6 t]]],
ColorFunctionScaling->False];

Find the vertices, triangles, and vertex colours.

vertices = pplot3D[[1, 1]];
triangles = pplot3D[[1, 2, 1, 1, 2, 1, 1, 1]];
colours = Chop[Map[ColorConvert[#, "RGB"]&, pplot3D[[1, 3, 2]]]];

Define an auxillary function forming a string from triples of real numbers, avoiding exponents. The order of the three components {x,y,z} is switched to match the POVRay convention of {x,z,y}.

AccString[x_List] :=
StringDrop[ StringJoin[
Map[ToString[AccountingForm[#, NumberSigns->{"-", ""}]]<>","&,
x[[{1,3,2}]]]], -1]

Define a function to write POVRay triangle objects.

POVtriangle[ind_List] :=
StringJoin[{
"triangle{<",
AccString[vertices[[ind[[1]]]]], ">,<",
AccString[vertices[[ind[[2]]]]], ">,<",
AccString[vertices[[ind[[3]]]]], "> pigment{colour rgb <",
AccString[Mean[Apply[List, colours[[ind]], 1]]], ">}}"}]

Export the triangles to a POVRay include file.

Export["povtest.inc", Map[POVtriangle, triangles], "Lines"]

Create the file povtest.pov file with the camera and lights, and include povtest.inc.

camera { location <0, 10, -50>  angle 3
up y*image_height right x*image_width look_at <0, 0, 0> }
light_source { <0, 20,  -500> colour rgb 2 * <1,1,1> shadowless }
light_source { <0, 20,  500> colour rgb 2 * <1,1,1> shadowless }
#include "povtest.inc"

The vertex normals are found in pplot3D[[1,4,2]], and may be used to form POVRay smooth triangles. Other options are found in pplot3D[[2]].

-