0

I am having trouble with the R package,rgl (version 0.95.1441), in particular, I cannot reproduce the code from the Examples section of the documentation of the scene3d rgl function:

http://www.inside-r.org/packages/cran/rgl/docs/plot3d.rglscene

I am using R of version 3.2.4 and R studio 0.99.892 under Windows 8.

open3d()
z <- 2 * volcano        # Exaggerate the relief
x <- 10 * (1:nrow(z))   # 10 meter spacing (S to N)
y <- 10 * (1:ncol(z))   # 10 meter spacing (E to W)
persp3d(x, y, z, col = "green3", aspect = "iso")

s <- scene3d()
# Make it bigger
s$par3d$windowRect <- 1.5*s$par3d$windowRect
# and draw it again
plot3d(s)

I am able to produce a 3D image after calling the persp3d function and I was able to save the rglscene object into variable s. However, after executing the last string of the present listing, an extremely narrow window has appeared and it's not possible to see whether it contains anything or not. How I can fix it?

lmo
  • 37,904
  • 9
  • 56
  • 69
Denis
  • 315
  • 4
  • 11

1 Answers1

2

There's no par3d component in s. It is part of s$rootSubscene. (That's not how it is documented, but that's how it is.)

If you want to double the size of your scene, you need to change two things: the windowRect and the viewport. So this works for me:

open3d()
z <- 2 * volcano        # Exaggerate the relief
x <- 10 * (1:nrow(z))   # 10 meter spacing (S to N)
y <- 10 * (1:ncol(z))   # 10 meter spacing (E to W)
persp3d(x, y, z, col = "green3", aspect = "iso")

s <- scene3d()
# Make it bigger
par3d <- s$rootSubscene$par3d
par3d$windowRect <- 1.5*par3d$windowRect
par3d$viewport <- 1.5*par3d$viewport
s$rootSubscene$par3d <- par3d

# and draw it again
plot3d(s)
user2554330
  • 37,248
  • 4
  • 43
  • 90
  • @user2554330Thank you so much! – Denis Apr 15 '16 at 01:02
  • Besides, one from the reasons of my troubles was multiple editing `s` variable. The code works for me correctly only when i explicitly deleted the variable before it creating (i many times played with code, so i created the mentioned variable many times as well). For example: `... rm(s) s <- scene3d() ...` instead of simple overwriting by `... s <- scene3d() ...` I don't understand why, but for me it was an important aspect. – Denis Apr 15 '16 at 09:12