Bug visualization rglwidget()
SbastianGarzon opened this issue · 3 comments
- rgl Version: latest development version
- R Version: 4.2.2
- Platform: Ubuntu 22.04
I'm having problems visualizing surfaces with the rglwidget() while using Rayshader (Quarto document)
Here is a reproducible error:
library(tidyverse)
library(rayshader)
library(rgl)
set.seed(2)
elevation_matrix <- matrix(rnorm(25) , nrow = 10,ncol = 10)
elevation_matrix %>%
height_shade(texture = topo.colors(256)) %>%
plot_3d(elevation_matrix,baseshape = "rectangle")
rglwidget()
rgl output:
rglwidget output (HTML):
Same error in another (more complex) Rayshader viz.
I see the issue in your first example. Hopefully easy to fix.
This is definitely a bug in rgl
. It's triggered by the fact that the back of the surface is culled, but I don't see a way to avoid that (other than editing the source to rayshader::plot_3d
). I'll track down the cause and patch it soon.
I found it. The problem was that scene3d()
(used by rglwidget()
) removed the normals for the objects when it saw the object was unlit. That meant that they needed to be recalculated to determine front and back in order to cull the back, but the recalculation was incorrect because of the indexing used by rayshader::plot_3d()
.
I'll stop the removal, and not allow two-sided indexed rendering without normals. Look for rgl 1.0.10 sometime later today.