Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

scene3d

Saves the current scene to a variable, and displays such variables


Description

This function saves a large part of the RGL state associated with the current window to a variable.

Usage

scene3d(minimal = TRUE)
## S3 method for class 'rglscene'
plot3d(x, add = FALSE, ...)
## S3 method for class 'rglobject'
plot3d(x, ...)
## S3 method for class 'rglscene'
print(x, ...)
## S3 method for class 'rglobject'
print(x, ...)

Arguments

minimal

Should attributes be skipped if they currently have no effect? See Details.

x

An object of class "rglscene"

add

Whether to open a new window, or add to the existing one.

...

Additional parameters, currently ignored.

Details

The components saved are: the par3d settings, the material3d settings, the bg3d settings, the lights and the objects in the scene.

In most cases, calling plot3d on that variable will duplicate the scene. (There are likely to be small differences, mostly internal, but some aspects of the scene are not currently available.) If textures are used, the name of the texture will be saved, rather than the contents of the texture file.

Other than saving the code to recreate a scene, saving the result of scene3d to a file will allow it to be reproduced later most accurately. In roughly decreasing order of fidelity, writeWebGL (now obsolete), writePLY, writeOBJ and writeSTL write the scene to a file in formats readable by other software.

If minimal = TRUE (the default), then attributes of objects will not be saved if they currently have no effect on the display, thereby reducing the file size. Set minimal = FALSE if the scene is intended to be used in a context where the appearance could be changed. Currently this only affects the inclusion of normals; with minimal = TRUE they are omitted for objects when the material is not lit.

Value

The scene3d function returns an object of class "rglscene". This is a list with some or all of the components:

material

The results returned from a material3d call.

rootSubscene

A list containing information about the main ("root") subscene. This may include:

id

The scene id.

type

"subscene"

par3d

The par3d settings for the subscene.

embeddings

The subsceneInfo()$embeddings for the main subscene.

objects

The ids for objects in the subscene.

subscenes

A recursive list of child subscenes.

objects

A list containing the RGL lights, background and objects in the scene.

The objects in the objects component are of class "rglobject". They are lists containing some or all of the components

id

The RGL identifier of the object in the original scene.

type

A character variable identifying the type of object.

material

Components of the material that differ from the scene material.

vertices, normals, etc.

Any of the attributes of the object retrievable by rgl.attrib.

ignoreExtent

A logical value indicating whether this object contributes to the bounding box. Currently this may differ from the object in the original scene.

objects

Sprites may contain other objects; they will be stored here as a list of "rglobject"s.

Lights in the scene are stored similarly, mixed into the objects list.

The plot3d methods invisibly return a vector of RGL object ids that were plotted. The print methods invisibly return the object that was printed.

Author(s)

Duncan Murdoch

See Also

rglwidget, writePLY, writeOBJ and writeSTL write the scene to a file in various formats.

Examples

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)

rgl

3D Visualization Using OpenGL

v0.106.8
GPL
Authors
Duncan Murdoch [aut, cre], Daniel Adler [aut], Oleg Nenadic [ctb], Simon Urbanek [ctb], Ming Chen [ctb], Albrecht Gebhardt [ctb], Ben Bolker [ctb], Gabor Csardi [ctb], Adam Strzelecki [ctb], Alexander Senger [ctb], The R Core Team [ctb, cph], Dirk Eddelbuettel [ctb], The authors of Shiny [cph], The authors of knitr [cph], Jeroen Ooms [ctb], Yohann Demont [ctb], Joshua Ulrich [ctb], Xavier Fernandez i Marin [ctb], George Helffrich [ctb], Ivan Krylov [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.