hypertidy/anglr

mesh_plot texture colour when partial coverage

mdsumner opened this issue · 1 comments

mesh_plot is currently only plotting a texture-approximate when present (and so only where the texture covers), this should rather update existing colours or the default mesh colouring.

BUT, this has to happen at mesh3d-creation time, because the colours get blasted there (or just ignored)

see #140 and #90

cc <- ceramic::cc_location(raster::extent(100, 120, -50, -10))
g <- as.mesh3d(raster::crop(gebco, raster::extent(70, 160, -70, 10)), 
               image_texture = cc, max_triangles = 80000)
mesh_plot(g)

image

just doing it manually and recording the path roughly before I lose it

cc <- ceramic::cc_location(raster::extent(100, 120, -50, -10))
g <- as.mesh3d(raster::crop(gebco, raster::extent(70, 160, -70, 10)), 
               image_texture = cc, max_triangles = 80000)
mesh_plot(g)
if (!is.null(x$ib)) {
  id <- x$ib
}
if (!is.null(x$it)) {
  id <- x$it
}
x <- g
x$meshColor <- "faces"
b <- raster::brick(x$material$texture)
b <- raster::setExtent(b, raster::extent(0, 1, 0, 1))
rgb0 <- raster::extract(b, t(x$texcoords[1:2, ]))

red <- sqrt(colMeans(matrix(rgb0[id,   1] ^2, dim(id)[1L]), na.rm = TRUE))
green <- sqrt(colMeans(matrix(rgb0[id, 2] ^2, dim(id)[1L]), na.rm = TRUE))
blue <- sqrt(colMeans(matrix(rgb0[id,  3] ^2, dim(id)[1L]), na.rm = TRUE))
#      x$material$color <- rgb(red, green, blue, maxColorValue = 255)
x$material$color <- colourvalues::convert_colour(cbind(red, green, blue))


g2 <- as.mesh3d(raster::crop(gebco, raster::extent(70, 160, -70, 10)), max_triangles = 80000)
g2$material$color <- colourvalues::colour_values(g2$vb[3, g2$it[1, ]])
g2$material$color[!x$material$color ==  "#000000"] <- 
  x$material$color[!x$material$color == "#000000"]

mesh_plot(g2)

image

and proving it works in 3D

plot3d(g2)

image