Description Usage Arguments Details Value Author(s) Examples
View source: R/as.mesh3d.default.R
The as.mesh3d
generic function converts various objects
to mesh3d
objects.
The default method works takes takes a matrix of vertices
as input and (optionally) merges repeated vertices, producing a mesh3d
object as output. It will contain either triangles or quads
according to the triangles
argument.
If the generic is called without any argument, it will pass
all rgl ids from the current scene to the
as.mesh3d.rglId
method.
1 2 3 4 5 6 7 8 9 |
x, y, z |
For the generic, |
triangles |
Logical value indicating whether the coordinates are for triangles or quadrilaterals. |
smooth |
If |
tolerance |
The numerical tolerance to be used in |
notEqual |
If not |
merge |
Should apparently equal vertices be merged? |
... |
Material properties to pass to |
The motivation for this function is the following problem: I was asked whether rgl could render a surface made up of triangles or quadrilaterals to look smooth. It can do that, but needs normals at each vertex; they should be the average of the normals for each polygon sharing that vertex. Then OpenGL will interpolate the normals across the polygons and give the illusion of smoothness.
To do this, it needs to know which polygons share each vertex. If the
surface is described as a list of triangles or quadrilaterals, that
means identifying vertices that are in multiple polygons, and converting
the representation to a "mesh3d"
object (which is a matrix of vertices
and a matrix of vertex numbers making up triangles or quads). Then the
addNormals
function will add the normals.
Sometimes two polygons will share vertices (within numerical
tolerance) without the user wanting them to be considered internal to
the surface, or might want one sharp edge in an otherwise smooth
surface. This means I needed a way to declare that two vertices from
the original list of vertices in the triangles or quads are "not equal",
even when they test numerically equal. That's what the notEqual
matrix specifies.
A "mesh3d"
object with the same faces as in the
input, but (if merge=TRUE
) with vertices that test equal to
within tolerance
merged.
Duncan Murdoch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | xyz <- matrix(c(-1, -1, -1,
-1, 1, -1,
1, 1, -1,
1, -1, -1,
-1, 1, -1,
-1, 1, 1,
1, 1, 1,
1, 1, -1,
1, -1, -1,
1, 1, -1,
1, 1, 1,
1, -1, 1), byrow = TRUE, ncol = 3)
mesh <- as.mesh3d(xyz, triangles = FALSE, col = "red")
mesh$vb
mesh$ib
open3d()
shade3d(mesh)
# Stop vertices 2 and 5 from being merged
notEQ <- matrix(FALSE, 12, 12)
notEQ[2, 5] <- TRUE
mesh <- as.mesh3d(xyz, triangles = FALSE, notEqual = notEQ)
mesh$vb
mesh$ib
|
Warning messages:
1: In rgl.init(initValue, onlyNULL) : RGL: unable to open X11 display
2: 'rgl.init' failed, running with 'rgl.useNULL = TRUE'.
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] -1 -1 1 1 -1 1 1
[2,] -1 1 1 -1 1 1 -1
[3,] -1 -1 -1 -1 1 1 1
[4,] 1 1 1 1 1 1 1
[,1] [,2] [,3]
[1,] 1 2 4
[2,] 2 5 3
[3,] 3 6 6
[4,] 4 3 7
null
1
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,] -1 -1 1 1 -1 -1 1 1
[2,] -1 1 1 -1 1 1 1 -1
[3,] -1 -1 -1 -1 -1 1 1 1
[4,] 1 1 1 1 1 1 1 1
[,1] [,2] [,3]
[1,] 1 5 4
[2,] 2 6 3
[3,] 3 7 7
[4,] 4 3 8
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.