Last chance! 50% off unlimited learning
Sale ends in
3D triangle and quadrangle mesh object creation and a collection of sample objects.
qmesh3d(vertices, indices, homogeneous = TRUE, material = NULL,
normals = NULL, texcoords = NULL,
meshColor = c("vertices", "edges", "faces", "legacy"))
tmesh3d(vertices, indices, homogeneous = TRUE, material = NULL,
normals = NULL, texcoords = NULL,
meshColor = c("vertices", "edges", "faces", "legacy"))
cube3d(trans = identityMatrix(), ...)
tetrahedron3d(trans = identityMatrix(), ...)
octahedron3d(trans = identityMatrix(), ...)
icosahedron3d(trans = identityMatrix(), ...)
dodecahedron3d(trans = identityMatrix(), ...)
cuboctahedron3d(trans = identityMatrix(), ...)
oh3d(trans = identityMatrix(), ...) # an 'o' object
dot3d(x, ...) # draw dots at the vertices of an object
# S3 method for mesh3d
dot3d(x, override = TRUE,
meshColor = c("vertices", "edges", "faces", "legacy"),...)
wire3d(x, ...) # draw a wireframe object
# S3 method for mesh3d
wire3d(x, override = TRUE,
meshColor = c("vertices", "edges", "faces", "legacy"), ...)
shade3d(x, ...) # draw a shaded object
# S3 method for mesh3d
shade3d(x, override = TRUE,
meshColor = c("vertices", "faces", "legacy"), ...)
a mesh3d
object (class qmesh3d
or tmesh3d
).
3- or 4-component vector of coordinates
4-component vector of vertex indices
logical indicating if homogeneous (four component) coordinates are used.
material properties for later rendering
normals at each vertex
texture coordinates at each vertex
transformation to apply to objects; see below for defaults
additional rendering parameters
should the parameters specified here override those stored in the object?
how should colours be interpreted? See details below
qmesh3d
, cube3d
, oh3d
, tmesh3d
,
tetrahedron3d
, octahedron3d
, icosahedron3d
and
dodecahedron3d
return objects of class c("mesh3d",
"shape3d")
. The first three of these are quad meshes, the rest are
triangle meshes.
dot3d
, wire3d
, and shade3d
are called for their side effect
of drawing an object into the scene; they return an object ID (or vector of IDs, for some
classes) invisibly.
See rgl.primitive
for a discussion of texture coordinates.
These functions create and work with mesh3d
objects, which consist of a matrix
of vertex coordinates together with a matrix of indices indicating which vertex is
part of which face. Such objects may have triangular faces,
planar quadrilateral faces, or both.
The sample objects optionally take a matrix transformation trans
as
an argument. This transformation is applied to all vertices of the default shape.
The default is an identity transformation.
The "shape3d"
class is a general class for shapes that can be plotted
by dot3d
, wire3d
or shade3d
.
The "mesh3d"
class is a class of objects that form meshes: the vertices
are in member vb
, as a 3 or 4 by n
matrix. Meshes with triangular
faces will contain it
, a 3 * n
matrix giving the indices of the
vertices in each face. Quad meshes will have vertex indices in ib
,
a 4 * n
matrix. Individual meshes may have both types
of faces.
The meshColor
argument controls how material colours are interpreted. This parameter
was added in rgl version 0.100.1 (0.100.27 for dot3d
, tmesh3d
and qmesh3d
). Possible values are:
"vertices"
Colours are applied by vertex, in the order
they appear in the vb
matrix.
"edges"
Colours are applied to each edge: first to the
3 edges of each triangle in the it
matrix, then the 4
edges of each quad in the ib
matrix.
"faces"
Colours are applied to each face: first to the
triangles in the it
matrix, then to the quads in the ib
matrix.
"legacy"
Colours are applied in the same way as in rgl versions earlier than 0.100.1.
Unique partial matches of these values will be recognized.
If colours are specified but meshColor
is not
and options(rgl.meshColorWarning = TRUE)
,
a warning will be given that their
interpretation may have changed. In versions 0.100.1 to 0.100.26
of rgl, the default
was to give the warning; now the default is for no warning.
Note that the shade3d
function doesn't support meshColor = "edges"
, and dot3d
and wire3d
function may draw
items more than once (dot3d
for other than meshColor = "vertices"
,
wire3d
for meshColor = "faces"
). Which
copy is visible depends on the order of drawing and the
material3d("depth_test")
setting.
r3d
, par3d
, shapelist3d
for multiple shapes
# NOT RUN {
# generate a quad mesh object
vertices <- c(
-1.0, -1.0, 0, 1.0,
1.0, -1.0, 0, 1.0,
1.0, 1.0, 0, 1.0,
-1.0, 1.0, 0, 1.0
)
indices <- c( 1, 2, 3, 4 )
open3d()
wire3d( qmesh3d(vertices, indices) )
# render 4 meshes vertically in the current view
open3d()
bg3d("gray")
l0 <- oh3d(tran = par3d("userMatrix"), color = "green" )
shade3d( translate3d( l0, -6, 0, 0 ))
l1 <- subdivision3d( l0 )
shade3d( translate3d( l1 , -2, 0, 0 ), color = "red", override = FALSE )
l2 <- subdivision3d( l1 )
shade3d( translate3d( l2 , 2, 0, 0 ), color = "red", override = TRUE )
l3 <- subdivision3d( l2 )
shade3d( translate3d( l3 , 6, 0, 0 ), color = "red" )
# render all of the Platonic solids
open3d()
shade3d( translate3d( tetrahedron3d(col = "red"), 0, 0, 0) )
shade3d( translate3d( cube3d(col = "green"), 3, 0, 0) )
shade3d( translate3d( octahedron3d(col = "blue"), 6, 0, 0) )
shade3d( translate3d( dodecahedron3d(col = "cyan"), 9, 0, 0) )
shade3d( translate3d( icosahedron3d(col = "magenta"), 12, 0, 0) )
# }
Run the code above in your browser using DataLab