Learn R Programming

rgl (version 0.93.1098)

writeOBJ: Write Wavefront OBJ format files

Description

This function writes OBJ files. This is a file format that is commonly used in 3D graphics applications. It does not represent text, but does represent points, lines, polygons (and many other types that RGL doesn't support).

Usage

writeOBJ(con, 
         pointRadius = 0.005, pointShape = icosahedron3d(), 
         lineRadius = pointRadius, lineSides = 20, 
         pointsAsPoints = FALSE, linesAsLines = FALSE, 
         withNormals = TRUE, withTextures = TRUE, 
         separateObjects = TRUE,
         ids = NULL)

Arguments

con
A connection or filename.
pointRadius, lineRadius
The radius of points and lines relative to the overall scale of the figure, if they are converted to polyhedra.
pointShape
A mesh shape to use for points if they are converted. It is scaled by the pointRadius.
lineSides
Lines are rendered as cylinders with this many sides.
pointsAsPoints, linesAsLines
Whether to convert points and lines to point and line records in the OBJ output.
withNormals
Whether to output vertex normals for smooth shading.
separateObjects
Whether to mark each RGL object as a separate object in the file.
withTextures
Whether to output texture coordinates.
ids
The identifiers (from rgl.ids) of the objects to write. If NULL, try to write everything.

Value

  • Invisibly returns the name of the connection to which the data was written.

Details

The current implementation only outputs triangles, quads, planes, spheres, points, line segments, line strips and surfaces. It does not output material properties such as colours, since the OBJ format does not support the per-vertex colours that RGL uses. The defaults for pointsAsPoints and linesAsLines have been chosen because Blender (http://www.blender.org) does not import points or lines, only polygons. If you are exporting to other software you may want to change them. If present, texture coordinates are output by default, but the textures themselves are not. Individual RGL objects are output as separate objects in the file when separateObjects = TRUE, the default. The output file should be readable by Blender and Meshlab; the latter can write in a number of other formats, including U3D, suitable for import into a PDF document.

References

The file format was found at http://www.martinreddy.net/gfx/3d/OBJ.spec on November 11, 2012.

See Also

scene3d saves a copy of a scene to an R variable; writeWebGL, writePLY and writeSTL write the scene to a file in various other formats.

Examples

Run this code
filename <- tempfile(fileext=".obj")
open3d()
shade3d( icosahedron3d() )
writeOBJ(filename)

Run the code above in your browser using DataLab