This creates a new subscene, or selects one by
id value, or adds objects to one.
1 2 3 4 5 6 7 8 9 10
newSubscene3d(viewport = "replace", projection = "replace", model = "replace", parent = currentSubscene3d(), copyLights = TRUE, copyShapes = FALSE, copyBBoxDeco = copyShapes, copyBackground = FALSE, newviewport, ignoreExtent) currentSubscene3d(dev = rgl.cur()) useSubscene3d(subscene) addToSubscene3d(ids, subscene = currentSubscene3d()) delFromSubscene3d(ids, subscene = currentSubscene3d()) gc3d(protect = NULL)
How should the new subscene be embedded? Possible values are
The parent subscene (defaults to the current subscene).
Whether lights, shapes, bounding box decorations and background should be copied to the new subscene.
Optionally specify the new subscene's viewport (in pixels).
Whether to ignore the subscene's bounding box when calculating the parent bounding
box. Defaults to
Which rgl device to query for the current subscene.
Which subscene to use or modify.
A vector of integer object ids to add to the subscene.
Object ids to protect from this garbage collection.
The rgl package allows multiple windows to be open; each one corresponds to a “scene”. Within each scene there are one or more “subscenes”. Each subscene corresponds to a rectangular region in the window, and may have its own projection and transformation.
There is always a current subscene: most graphic operations make changes there, e.g. by adding an object to it.
The scene “owns” objects;
put their ids into or remove them from the list being displayed within a particular subscene.
gc3d function deletes objects from the scene if they are not visible in any
subscene, unless they are protected by having their id included in
model parameters each have three possible settings:
c("inherit", "modify", "replace").
"inherit" means that the corresponding value
from the parent subscene will be used.
"replace" means that the new subscene will
have its own value of the value, independent of its parent.
"modify" means that the
child value will be applied first, and then the parent value will be applied. For viewport, this
means that if the parent viewport is changed, the child will maintain its relative position. For
the two matrices,
"modify" is unlikely to give satisfactory results, but it is available
for possible use.
viewport parameter controls the rectangular region in which the subscene is displayed.
It is specified using
newviewport (in pixels relative to the whole window), or set to
match the parent viewport.
projection parameter controls settings corresponding to the observer. These
include the field of view and the zoom; they also include the position of the observer relative to
the model. The
par3d("projMatrix") matrix is determined by the projection.
model parameter controls settings corresponding to the model. Mouse rotations affect
the model, as does scaling. The
par3d("modelMatrix") matrix is determined by these as
well as by the position of the observer (since OpenGL assumes that the observer is at
(0, 0, 0) after the MODELVIEW transformation). Only those parts concerning the model are
model specifies inheritance, the observer setting is controlled by
TRUE, the background of the newly created child will
overwrite anything displayed in the parent subscene, regardless of depth.
If successful, each function returns the object id of the subscene, with the exception of
gc3d, which returns the count of objects which have been deleted,
useSubscene3d, which returns the previously active subscene id.
Duncan Murdoch and Fang He.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
# Show the Earth with a cutout by using clipplanes in subscenes lat <- matrix(seq(90, -90, len = 50)*pi/180, 50, 50, byrow = TRUE) long <- matrix(seq(-180, 180, len = 50)*pi/180, 50, 50) r <- 6378.1 # radius of Earth in km x <- r*cos(lat)*cos(long) y <- r*cos(lat)*sin(long) z <- r*sin(lat) open3d() obj <- surface3d(x, y, z, col = "white", texture = system.file("textures/worldsmall.png", package = "rgl"), specular = "black", axes = FALSE, box = FALSE, xlab = "", ylab = "", zlab = "", normal_x = x, normal_y = y, normal_z = z) cols <- c(rep("chocolate4", 4), rep("burlywood1", 4), "darkgoldenrod1") rs <- c(6350, 5639, 4928.5, 4207, 3486, (3486 + 2351)/2, 2351, (2351 + 1216)/2, 1216) for (i in seq_along(rs)) obj <- c(obj, spheres3d(0, 0, col = cols[i], radius = rs[i])) root <- currentSubscene3d() newSubscene3d("inherit", "inherit", "inherit", copyShapes = TRUE, parent = root) clipplanes3d(1, 0, 0, 0) newSubscene3d("inherit", "inherit", "inherit", copyShapes = TRUE, parent = root) clipplanes3d(0, 1, 0, 0) newSubscene3d("inherit", "inherit", "inherit", copyShapes = TRUE, parent = root) clipplanes3d(0, 0, 1, 0) # Now delete the objects from the root subscene, to reveal the clipping planes useSubscene3d(root) delFromSubscene3d(obj)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.