dmurdoch / rgl

rgl is a 3D visualization system based on OpenGL. It provides a medium to high level interface for use in R, currently modelled on classic R graphics, with extensions to allow for interaction.
https://dmurdoch.github.io/rgl/
GNU General Public License v2.0
84 stars 20 forks source link

`bbox3d` does not respect `xlen` #415

Closed katrinabrock closed 4 months ago

katrinabrock commented 4 months ago

Reprex:

desired_tick_count <- 1
x <- rnorm(100)
y <- rnorm(100)
z <- rnorm(100)

dev.new()
open3d()
points3d(x, y, z)
bbox3d(
  xlen=2, ylen=2, zlen=2,
  xlab='X', ylab='Y', zlab = 'Z',
  color = c("#333377", "black"), emission = "#333377",
  specular = "#3333FF", shininess = 5, alpha = 0.8
)

Expected result: a plot with about 1 tick mark on each axes. ("about" because this is a suggestion for pretty.) Actual result: a plot with 4-6 tick marks per axis. image

I suspected this may simply be due to pretty not taking our suggestion, but putting the data into pretty directly, it returns 3 items. So still, I would expect 3 tick marks per axis, not 4-6.

> print(pretty(x))
[1] -3 -2 -1  0  1  2  3
> print(pretty(x, desired_tick_count))
[1] -5  0  5

Note: I first saw this issue when helping someone who was using windows so I don't think it's a platform specific issue.

I haven't yet attempted to repro with the latest version from github. I will give that a try and perhaps also dig in the sourcecode.

There's also a possibility that I am misunderstanding what this argument is supposed to do. In that case, I would be happy to propose an edit do the document to make it more clear.

UPDATE: Also confirmed the same behavior when installing from github (41b9e90).

dmurdoch commented 4 months ago

Currently there's no difference between Github and CRAN: 1.3.1 was just uploaded a few days ago. So this looks like a current issue.

dmurdoch commented 4 months ago

I tried your code. It works properly in R, but the bug is present in WebGL (produced by rglwidget()). So the code to look at is the Javascript code in inst/htmlwidgets/lib/rglClass. From a quick glance, it appears to have 5 hardcoded for the xlen setting, so this should be pretty easy to fix.

dmurdoch commented 4 months ago

Thanks for the report! It's fixed now.

katrinabrock commented 4 months ago

Thanks for the quick work! It's working for me (installed from github).