readobj (version 0.3.2)

read.obj: Read a Wavefront OBJ 3D scene file into an R list

Description

Read a Wavefront OBJ 3D scene file into an R list

Usage

read.obj(f, materialspath = NULL, convert.rgl = FALSE)

Arguments

f

Path to an OBJ file

materialspath

Path to a folder containing materials files. This is optional and only required if materials files are in a different folder from the OBJ file defined by f.

convert.rgl

Whether to convert the returned list to a rgl::shapelist3d object containing rgl::mesh3d objects.

Value

When convert.rgl=FALSE, the default, a named list with items shapes and materials, each containing sublists with one entry per object (shapes) or material (materials). Objects in the shapes list have the following structure

  • positions 3xN set of 3D vertices

  • normals 3xN set of normal directions for each vertex (has 3 rows and 0 cols when normals are not available)

  • texcoords vector containing unprocessed texture coordinates

  • indices 3/4xM set of indices into vertex array (trimesh/quadmesh) 0-indexed

  • material_ids (0-indexed, -1 when not set)

When convert.rgl=FALSE a list of class shapelist3d containing a mesh3d for each object or group element in the original OBJ file. See tinyobj2shapelist3d for details of rgl conversion.

Sample files

Note that at the request of the CRAN maintainers the sample files have the file extension .wavefront instead of the standard .obj because this triggers a false positive R CMD check NOTE.

See Also

tinyobj2shapelist3d, rgl::readOBJ for simpler, pure R implementation.

Examples

Run this code
# NOT RUN {
cube=read.obj(system.file("obj/cube.wavefront", package = "readobj"))
str(cube, max.level = 3)

# demonstrate direct conversion of result to rgl format
if(require('rgl')) {
  cuber=read.obj(system.file("obj/cube.wavefront", package = "readobj"),
    convert.rgl=TRUE)
  shade3d(cuber)
}
# }

Run the code above in your browser using DataCamp Workspace