writeWebGL(dir = "webGL", filename = file.path(dir, "index.html"),
template = system.file(file.path("WebGL", "template.html"), package = "rgl"),
prefix = "",
snapshot = TRUE, font = "Arial", width, height)
par3d("windowRect")
dimensions will be used.filename
is returned.template
argument to give the filename of a web page that is to contain the
code for the new scene. It should contain a single line containing paste("%", prefix, "WebGL%")
, e.g.
%WebGL%
with the default empty prefix. That line will be replaced by the Javascript and other
code necessary to reproduce the current scene. The template may also contain the string "%rglVersion%"
which will be replaced with the current prefix
for each. The prefix
will be used in identifiers in both Javascript and HTML, so it is safest to start with a letter and
only use alphanumeric characters.
WebGL is a fairly new technology for displaying 3D scenes in browsers. Most current browsers support it
to some extent, though it may not be enabled by default; see writeWebGL
has a number of known limitations, some of which will be gradually eliminated as
development progresses:
spin3d
) is supported.writeWebGL
will print a warning if this limit is exceeded, but it is up to the user
to break his scene into smaller objects. (And 65535 vertices may not be small enough!)scene3d
saves a copy of a scene to an R variable;
writePLY
, writeOBJ
and writeSTL
write the scene to a file in various other formats.plot3d(rnorm(100), rnorm(100), rnorm(100), type="s", col="red")
# This writes a copy into temporary directory 'webGL', and then displays it
browseURL(paste("file://", writeWebGL(dir=file.path(tempdir(), "webGL"),
width=500), sep=""))
Run the code above in your browser using DataLab