Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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]

enter image description here

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

enter image description here

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?

share|improve this question
up vote 7 down vote accepted

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]]],

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] :=
         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["", Map[POVtriangle, triangles], "Lines"]

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

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 ""

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]]. sphereplot

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.