Magnum::Trade::ObjImporter class

Wavefront OBJ importer plugin.

Loads meshes from Wavefront OBJ (*.obj) files.

Usage

This plugin depends on the Trade library and is built if MAGNUM_WITH_OBJIMPORTER is enabled when building Magnum. To use as a dynamic plugin, load "ObjImporter" via Corrade::PluginManager::Manager.

Additionally, if you're using Magnum as a CMake subproject, do the following:

set(MAGNUM_WITH_OBJIMPORTER ON CACHE BOOL "" FORCE)
add_subdirectory(magnum EXCLUDE_FROM_ALL)

# So the dynamically loaded plugin gets built implicitly
add_dependencies(your-app Magnum::ObjImporter)

To use as a static plugin or as a dependency of another plugin with CMake, you need to request the ObjImporter component of the Magnum package and link to the Magnum::ObjImporter target:

find_package(Magnum REQUIRED ObjImporter)

# ...
target_link_libraries(your-app PRIVATE Magnum::ObjImporter)

See Downloading and building, Usage with CMake, Loading and using plugins and File format support for more information.

Behavior and limitations

Meshes are imported as MeshPrimitive::Triangles, MeshPrimitive::Lines or MeshPrimitive::Points with VertexFormat::Vector3 positions interleaved with optional VertexFormat::Vector3 normals and VertexFormat::Vector2 texture coordinates, if present in the source file. By default the per-attribute index arrays are merged into a single MeshIndexType::UnsignedInt index buffer. If you disable the mergeIndexArrays configuration option, the resulting mesh will be non-indexed, with the vertex data duplicated according to per-attribute index arrays.

Optional fourth position coordinates are allowed if they're set to 1, optional third texture coordinate is allowed if it's set to 0.

Negative indices (where -1 is the last position / texture coordinate / normal known at given point in the file, -2 is the second-to-last, etc.), produced for example by 3ds Max or Mineways, are supported. Quads are converted to two triangles. Higher-order polygons are not supported, meshes that mix points, lines and faces together are not supported.

Files containing object name annotations (o) are split into multiple meshes, with the object name available through meshName() / meshForName().

Material properties are currently not supported.

Plugin-specific configuration

It's possible to tune various import options through configuration(). See below for all options and their default values:

[configuration]
# Merge the per-attribute index arrays into a single index buffer. If disabled,
# the resulting mesh will be non-indexed, with vertex data duplicated according
# to per-attribute index arrays.
mergeIndexArrays=true

See Editing plugin-specific configuration for more information and an example showing how to edit the configuration values.

Base classes

class AbstractImporter
Base for importer plugins.

Constructors, destructors, conversion operators

ObjImporter() deprecated in Git master explicit
Default constructor.
ObjImporter(PluginManager::AbstractManager& manager, const Containers::StringView& plugin) explicit
Plugin manager constructor.

Function documentation

Magnum::Trade::ObjImporter::ObjImporter() explicit

Default constructor.