Changing Colors usEd by wireframe when shade = TRUE

When shade = TRUE the colors used are set in the function shade.colors.palette. The default definition of this function is
function (irr, ref, height, saturation = 0.9) 
{
    hsv(h = height, s = 1 - saturation * (1 - (1 - ref)^0.5), 
        v = irr)
}
It maps the height which is scaled to [0,1], to the hue in a hue-saturation-value color representation. To use height to select from a palette created by, say, terrain.colors we can use something like this:
p <- local({
    len <- 100
    col <- rgb2hsv(col2rgb(terrain.colors(len)))[1,]
    function (irr, ref, height, saturation = 0.9) {
        h <- col[1 + ceiling((len -1) * height)]
        hsv(h = h, s = 1 - saturation * (1 - (1 - ref)^0.5), 
            v = irr)
    }
})
wireframe(volcano, shade = TRUE, shade.colors.palette = p)
Another approach would be so use the surface drawing facilities of the misc3d package. For example:
library(misc3d)
wireframe(volcano, 
          panel.3d.wireframe = function(x,y,z,
                                        rot.mat, distance, col.region, ...) {
              z <- t(matrix(z, nrow = length(y)))
              drawScene(surfaceTriangles(x,y,z), distance = distance,
                        add = TRUE, scale = FALSE,engine = "grid",
                        R.mat = rot.mat)
})


Luke Tierney 2008-10-09