A mesh object can have the same vertex listed twice. Each copy is allowed to have separate normals, texture coordinates, and color. However, it is more efficient to have just a single copy if those differences aren't needed. For automatic smoothing using addNormals, triangles and quads need to share vertices. This function merges identical (or similar) vertices to achieve this.

mergeVertices(mesh,
notEqual = NULL,
attribute = "vertices",
tolerance = sqrt(.Machine\$double.eps))

## Arguments

mesh A mesh3d object. A logical matrix indicating that certain pairs should not be merged even if they appear identical. Which attribute(s) should be considered in comparing vertices? A vector chosen from c("vertices", "colors", "normals", "texcoords")) When comparing vertices using all.equal, this tolerance will be used to ignore rounding error.

## Value

A new mesh object.

## Author

Duncan Murdoch

as.mesh3d.rglId, which often constructs mesh objects containing a lot of duplication.

## Examples

open3d()
(mesh1 <- cuboctahedron3d(col = rainbow(14), meshColor = "face"))
#>  mesh3d object with 12 vertices, 8 triangles, 6 quads.
{"x":{"material":{"color":"#000000","alpha":1,"lit":true,"ambient":"#000000","specular":"#FFFFFF","emission":"#000000","shininess":50,"smooth":true,"front":"filled","back":"filled","size":3,"lwd":1,"fog":true,"point_antialias":false,"line_antialias":false,"texture":null,"textype":"rgb","texmipmap":false,"texminfilter":"linear","texmagfilter":"linear","texenvmap":false,"depth_mask":true,"depth_test":"less","isTransparent":false,"polygon_offset":[0,0],"margin":"","floating":false},"rootSubscene":790,"objects":{"796":{"id":796,"type":"triangles","material":{},"vertices":[[-1,-1,0],[-1,0,-1],[0,-1,-1],[-1,-1,0],[0,-1,1],[-1,0,1],[-1,1,0],[0,1,-1],[-1,0,-1],[-1,1,0],[-1,0,1],[0,1,1],[1,-1,0],[0,-1,-1],[1,0,-1],[1,-1,0],[1,0,1],[0,-1,1],[1,1,0],[1,0,-1],[0,1,-1],[1,1,0],[0,1,1],[1,0,1]],"colors":[[1,0,0,1],[1,0,0,1],[1,0,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1],[0,1,0.572549045085907,1],[0,1,0.572549045085907,1],[0,1,0.572549045085907,1],[0,1,1,1],[0,1,1,1],[0,1,1,1]],"centers":[[-0.666666686534882,-0.666666686534882,-0.666666686534882],[-0.666666686534882,-0.666666686534882,0.666666686534882],[-0.666666686534882,0.666666686534882,-0.666666686534882],[-0.666666686534882,0.666666686534882,0.666666686534882],[0.666666686534882,-0.666666686534882,-0.666666686534882],[0.666666686534882,-0.666666686534882,0.666666686534882],[0.666666686534882,0.666666686534882,-0.666666686534882],[0.666666686534882,0.666666686534882,0.666666686534882]],"normals":[[-0.577350258827209,-0.577350258827209,-0.577350258827209],[-0.577350258827209,-0.577350258827209,-0.577350258827209],[-0.577350258827209,-0.577350258827209,-0.577350258827209],[-0.577350258827209,-0.577350258827209,0.577350258827209],[-0.577350258827209,-0.577350258827209,0.577350258827209],[-0.577350258827209,-0.577350258827209,0.577350258827209],[-0.577350258827209,0.577350258827209,-0.577350258827209],[-0.577350258827209,0.577350258827209,-0.577350258827209],[-0.577350258827209,0.577350258827209,-0.577350258827209],[-0.577350258827209,0.577350258827209,0.577350258827209],[-0.577350258827209,0.577350258827209,0.577350258827209],[-0.577350258827209,0.577350258827209,0.577350258827209],[0.577350258827209,-0.577350258827209,-0.577350258827209],[0.577350258827209,-0.577350258827209,-0.577350258827209],[0.577350258827209,-0.577350258827209,-0.577350258827209],[0.577350258827209,-0.577350258827209,0.577350258827209],[0.577350258827209,-0.577350258827209,0.577350258827209],[0.577350258827209,-0.577350258827209,0.577350258827209],[0.577350258827209,0.577350258827209,-0.577350258827209],[0.577350258827209,0.577350258827209,-0.577350258827209],[0.577350258827209,0.577350258827209,-0.577350258827209],[0.577350258827209,0.577350258827209,0.577350258827209],[0.577350258827209,0.577350258827209,0.577350258827209],[0.577350258827209,0.577350258827209,0.577350258827209]],"ignoreExtent":false,"flags":32771},"797":{"id":797,"type":"quads","material":{},"vertices":[[-1,-1,0],[-1,0,1],[-1,1,0],[-1,0,-1],[-1,-1,0],[0,-1,-1],[1,-1,0],[0,-1,1],[-1,1,0],[0,1,1],[1,1,0],[0,1,-1],[1,-1,0],[1,0,-1],[1,1,0],[1,0,1],[-1,0,-1],[0,1,-1],[1,0,-1],[0,-1,-1],[-1,0,1],[0,-1,1],[1,0,1],[0,1,1]],"colors":[[1,0,0,1],[1,0,0,1],[1,0,0,1],[1,0,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1]],"centers":[[-1,0,0],[0,-1,0],[0,1,0],[1,0,0],[0,0,-1],[0,0,1]],"normals":[[-1,0,-0],[-1,0,-0],[-1,0,-0],[-1,0,-0],[0,-1,0],[0,-1,0],[0,-1,0],[0,-1,0],[0,1,0],[0,1,0],[0,1,0],[0,1,0],[1,0,-0],[1,0,-0],[1,0,-0],[1,0,-0],[0,-0,-1],[0,-0,-1],[0,-0,-1],[0,-0,-1],[0,-0,1],[0,-0,1],[0,-0,1],[0,-0,1]],"ignoreExtent":false,"flags":32771},"798":{"id":798,"type":"triangles","material":{},"vertices":[[2,-1,0],[2,0,-1],[3,-1,-1],[2,-1,0],[3,-1,1],[2,0,1],[2,1,0],[3,1,-1],[2,0,-1],[2,1,0],[2,0,1],[3,1,1],[4,-1,0],[3,-1,-1],[4,0,-1],[4,-1,0],[4,0,1],[3,-1,1],[4,1,0],[4,0,-1],[3,1,-1],[4,1,0],[3,1,1],[4,0,1],[2,-1,0],[2,0,1],[2,1,0],[2,-1,0],[2,1,0],[2,0,-1],[2,-1,0],[3,-1,-1],[4,-1,0],[2,-1,0],[4,-1,0],[3,-1,1],[2,1,0],[3,1,1],[4,1,0],[2,1,0],[4,1,0],[3,1,-1],[4,-1,0],[4,0,-1],[4,1,0],[4,-1,0],[4,1,0],[4,0,1],[2,0,-1],[3,1,-1],[4,0,-1],[2,0,-1],[4,0,-1],[3,-1,-1],[2,0,1],[3,-1,1],[4,0,1],[2,0,1],[4,0,1],[3,1,1]],"colors":[[1,0,0,1],[1,0,0,1],[1,0,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1],[0,1,0.572549045085907,1],[0,1,0.572549045085907,1],[0,1,0.572549045085907,1],[0,1,1,1],[0,1,1,1],[0,1,1,1],[1,0,0,1],[1,0,0,1],[1,0,0,1],[1,0,0,1],[1,0,0,1],[1,0,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1]],"centers":[[2.33333349227905,-0.666666686534882,-0.666666686534882],[2.33333349227905,-0.666666686534882,0.666666686534882],[2.33333349227905,0.666666686534882,-0.666666686534882],[2.33333349227905,0.666666686534882,0.666666686534882],[3.66666674613953,-0.666666686534882,-0.666666686534882],[3.66666674613953,-0.666666686534882,0.666666686534882],[3.66666674613953,0.666666686534882,-0.666666686534882],[3.66666674613953,0.666666686534882,0.666666686534882],[2,0,0.333333343267441],[2,0,-0.333333343267441],[3,-1,-0.333333343267441],[3,-1,0.333333343267441],[3,1,0.333333343267441],[3,1,-0.333333343267441],[4,0,-0.333333343267441],[4,0,0.333333343267441],[3,0.333333343267441,-1],[3,-0.333333343267441,-1],[3,-0.333333343267441,1],[3,0.333333343267441,1]],"normals":[[-0.577350258827209,-0.577350258827209,-0.577350258827209],[-0.577350258827209,-0.577350258827209,-0.577350258827209],[-0.577350258827209,-0.577350258827209,-0.577350258827209],[-0.577350258827209,-0.577350258827209,0.577350258827209],[-0.577350258827209,-0.577350258827209,0.577350258827209],[-0.577350258827209,-0.577350258827209,0.577350258827209],[-0.577350258827209,0.577350258827209,-0.577350258827209],[-0.577350258827209,0.577350258827209,-0.577350258827209],[-0.577350258827209,0.577350258827209,-0.577350258827209],[-0.577350258827209,0.577350258827209,0.577350258827209],[-0.577350258827209,0.577350258827209,0.577350258827209],[-0.577350258827209,0.577350258827209,0.577350258827209],[0.577350258827209,-0.577350258827209,-0.577350258827209],[0.577350258827209,-0.577350258827209,-0.577350258827209],[0.577350258827209,-0.577350258827209,-0.577350258827209],[0.577350258827209,-0.577350258827209,0.577350258827209],[0.577350258827209,-0.577350258827209,0.577350258827209],[0.577350258827209,-0.577350258827209,0.577350258827209],[0.577350258827209,0.577350258827209,-0.577350258827209],[0.577350258827209,0.577350258827209,-0.577350258827209],[0.577350258827209,0.577350258827209,-0.577350258827209],[0.577350258827209,0.577350258827209,0.577350258827209],[0.577350258827209,0.577350258827209,0.577350258827209],[0.577350258827209,0.577350258827209,0.577350258827209],[-1,0,-0],[-1,0,-0],[-1,0,-0],[-1,0,-0],[-1,0,-0],[-1,0,-0],[0,-1,0],[0,-1,0],[0,-1,0],[0,-1,0],[0,-1,0],[0,-1,0],[0,1,0],[0,1,0],[0,1,0],[0,1,0],[0,1,0],[0,1,0],[1,0,-0],[1,0,-0],[1,0,-0],[1,0,-0],[1,0,-0],[1,0,-0],[0,-0,-1],[0,-0,-1],[0,-0,-1],[0,-0,-1],[0,-0,-1],[0,-0,-1],[0,-0,1],[0,-0,1],[0,-0,1],[0,-0,1],[0,-0,1],[0,-0,1]],"ignoreExtent":false,"flags":32771},"799":{"id":799,"type":"triangles","material":{},"vertices":[[5,-1,0],[5,0,-1],[6,-1,-1],[5,-1,0],[6,-1,1],[5,0,1],[5,1,0],[6,1,-1],[5,0,-1],[5,1,0],[5,0,1],[6,1,1],[7,-1,0],[6,-1,-1],[7,0,-1],[7,-1,0],[7,0,1],[6,-1,1],[7,1,0],[7,0,-1],[6,1,-1],[7,1,0],[6,1,1],[7,0,1],[5,-1,0],[5,0,1],[5,1,0],[5,-1,0],[5,1,0],[5,0,-1],[5,-1,0],[6,-1,-1],[7,-1,0],[5,-1,0],[7,-1,0],[6,-1,1],[5,1,0],[6,1,1],[7,1,0],[5,1,0],[7,1,0],[6,1,-1],[7,-1,0],[7,0,-1],[7,1,0],[7,-1,0],[7,1,0],[7,0,1],[5,0,-1],[6,1,-1],[7,0,-1],[5,0,-1],[7,0,-1],[6,-1,-1],[5,0,1],[6,-1,1],[7,0,1],[5,0,1],[7,0,1],[6,1,1]],"colors":[[1,0,0,1],[1,0,0,1],[1,0,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1],[0,1,0.572549045085907,1],[0,1,0.572549045085907,1],[0,1,0.572549045085907,1],[0,1,1,1],[0,1,1,1],[0,1,1,1],[1,0,0,1],[1,0,0,1],[1,0,0,1],[1,0,0,1],[1,0,0,1],[1,0,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.427450984716415,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[1,0.858823537826538,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.713725507259369,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0.286274522542953,1,0,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1],[0,1,0.141176477074623,1]],"centers":[[5.33333349227905,-0.666666686534882,-0.666666686534882],[5.33333349227905,-0.666666686534882,0.666666686534882],[5.33333349227905,0.666666686534882,-0.666666686534882],[5.33333349227905,0.666666686534882,0.666666686534882],[6.66666698455811,-0.666666686534882,-0.666666686534882],[6.66666698455811,-0.666666686534882,0.666666686534882],[6.66666698455811,0.666666686534882,-0.666666686534882],[6.66666698455811,0.666666686534882,0.666666686534882],[5,0,0.333333343267441],[5,0,-0.333333343267441],[6,-1,-0.333333343267441],[6,-1,0.333333343267441],[6,1,0.333333343267441],[6,1,-0.333333343267441],[7,0,-0.333333343267441],[7,0,0.333333343267441],[6,0.333333343267441,-1],[6,-0.333333343267441,-1],[6,-0.333333343267441,1],[6,0.333333343267441,1]],"normals":[[-0.577350258827209,-0.577350258827209,-0.577350258827209],[-0.577350258827209,-0.577350258827209,-0.577350258827209],[-0.577350258827209,-0.577350258827209,-0.577350258827209],[-0.577350258827209,-0.577350258827209,0.577350258827209],[-0.577350258827209,-0.577350258827209,0.577350258827209],[-0.577350258827209,-0.577350258827209,0.577350258827209],[-0.577350258827209,0.577350258827209,-0.577350258827209],[-0.577350258827209,0.577350258827209,-0.577350258827209],[-0.577350258827209,0.577350258827209,-0.577350258827209],[-0.577350258827209,0.577350258827209,0.577350258827209],[-0.577350258827209,0.577350258827209,0.577350258827209],[-0.577350258827209,0.577350258827209,0.577350258827209],[0.577350258827209,-0.577350258827209,-0.577350258827209],[0.577350258827209,-0.577350258827209,-0.577350258827209],[0.577350258827209,-0.577350258827209,-0.577350258827209],[0.577350258827209,-0.577350258827209,0.577350258827209],[0.577350258827209,-0.577350258827209,0.577350258827209],[0.577350258827209,-0.577350258827209,0.577350258827209],[0.577350258827209,0.577350258827209,-0.577350258827209],[0.577350258827209,0.577350258827209,-0.577350258827209],[0.577350258827209,0.577350258827209,-0.577350258827209],[0.577350258827209,0.577350258827209,0.577350258827209],[0.577350258827209,0.577350258827209,0.577350258827209],[0.577350258827209,0.577350258827209,0.577350258827209],[-1,0,-0],[-1,0,-0],[-1,0,-0],[-1,-0,0],[-1,-0,0],[-1,-0,0],[0,-1,0],[0,-1,0],[0,-1,0],[0,-1,0],[0,-1,0],[0,-1,0],[0,1,0],[0,1,0],[0,1,0],[0,1,0],[0,1,0],[0,1,0],[1,0,-0],[1,0,-0],[1,0,-0],[1,0,0],[1,0,0],[1,0,0],[0,-0,-1],[0,-0,-1],[0,-0,-1],[-0,0,-1],[-0,0,-1],[-0,0,-1],[0,-0,1],[0,-0,1],[0,-0,1],[0,0,1],[0,0,1],[0,0,1]],"ignoreExtent":false,"flags":32771},"794":{"id":794,"type":"light","vertices":[[0,0,1]],"colors":[[1,1,1,1],[1,1,1,1],[1,1,1,1]],"viewpoint":true,"finite":false},"793":{"id":793,"type":"background","material":{},"colors":[[0.298039227724075,0.298039227724075,0.298039227724075,1]],"centers":[[0,0,0]],"sphere":false,"fogtype":"none","fogscale":1,"flags":32768},"795":{"id":795,"type":"background","material":{"lit":false,"back":"lines"},"colors":[[1,1,1,1]],"centers":[[0,0,0]],"sphere":false,"fogtype":"none","fogscale":1,"flags":32768},"790":{"id":790,"type":"subscene","par3d":{"antialias":8,"FOV":30,"ignoreExtent":false,"listeners":790,"mouseMode":{"none":"none","left":"trackball","right":"zoom","middle":"fov","wheel":"pull"},"observer":[0,0,16.3923034667969],"modelMatrix":[[1,0,0,-3],[0,0.342020153999329,0.939692616462708,0],[0,-0.939692616462708,0.342020153999329,-16.3923034667969],[0,0,0,1]],"projMatrix":[[3.73205065727234,0,0,0],[0,3.73205065727234,0,0],[0,0,-3.86370277404785,-59.0923500061035],[0,0,-1,0]],"skipRedraw":false,"userMatrix":[[1,0,0,0],[0,0.342020143325668,0.939692620785909,0],[0,-0.939692620785909,0.342020143325668,0],[0,0,0,1]],"userProjection":[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],"scale":[1,1,1],"viewport":{"x":0,"y":0,"width":1,"height":1},"zoom":1,"bbox":[-1,7,-1,1,-1,1],"windowRect":[468,368,724,624],"family":"sans","font":1,"cex":1,"useFreeType":true,"fontname":"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgl/fonts/FreeSans.ttf","maxClipPlanes":6,"glVersion":2.1,"activeSubscene":0},"embeddings":{"viewport":"replace","projection":"replace","model":"replace","mouse":"replace"},"objects":[795,796,797,798,799,794],"subscenes":[],"flags":33027}},"crosstalk":{"key":[],"group":[],"id":[],"options":[]},"width":480,"height":480,"context":{"shiny":false,"rmarkdown":null},"players":[],"webGLoptions":{"preserveDrawingBuffer":true}},"evals":[],"jsHooks":[]}