writeOBJ {rgl} | R Documentation

## Write Wavefront OBJ format files; read simple ones

### Description

`writeOBJ` 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). `readOBJ` reads only some parts of OBJ files.

### Usage

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

### 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.
`...` | Additional arguments (typically just `material`) to pass to `tmesh3d`.

### Details

The current `writeOBJ` implementation only outputs triangles, quads, planes, spheres, points, line segments, line strips and surfaces. It does not output material properties such as colors, since the OBJ format does not support the per-vertex colors that RGL uses.

The `readOBJ` implementation can only read faces, and ignores information about normals and textures.

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.

### Value

`writeObj` invisibly returns the name of the connection to which the data was written.

`readObj` returns a mesh object constructed from the input file.

### Author(s)

Duncan Murdoch

### 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

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

    # The motivation for writing readObj() was to read this shape
    # file of Comet 67P/Churyumov-Gerasimenko, from the ESA:

    open3d()
    shade3d(readOBJ(url(
    "http://sci.esa.int/science-e/www/object/doc.cfm?fobjectid=54726"
    ), material = list(col = "gray")))

[Package rgl version 0.95.1441 Index]