Magnum::Trade::StlImporter class new in 2020.06

STL importer plugin.

Imports Stereolitography STL (*.stl) files.

Usage

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

Additionally, if you're using Magnum as a CMake subproject, bundle the magnum-plugins repository and do the following:

set(MAGNUM_WITH_STLIMPORTER ON CACHE BOOL "" FORCE)
add_subdirectory(magnum-plugins EXCLUDE_FROM_ALL)

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

To use as a static plugin or as a dependency of another plugin with CMake, put FindMagnumPlugins.cmake into your modules/ directory, request the StlImporter component of the MagnumPlugins package and link to the MagnumPlugins::StlImporter target:

find_package(MagnumPlugins REQUIRED StlImporter)

# ...
target_link_libraries(your-app PRIVATE MagnumPlugins::StlImporter)

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

Behavior and limitations

A binary STL file is always imported as a non-indexed triangle mesh with per-face normals (i.e., same normal for all vertices in the triangle). Both positions and normals are imported as VertexFormat::Vector3. Using the perFaceToPerVertex configuration option it's possible to import per-face normals separately without duplicating them for each vertex — useful for example when you want to deduplicate the positions and generate smooth normals from these.

The non-standard extensions for vertex colors are not supported due to a lack of generally available files for testing.

ASCII files

The plugin implements parsing of binary files only. If an ASCII file is detected, it's forwarded to the AssimpImporter plugin, if available. Calls to meshCount(), meshLevelCount() and mesh() are then proxied to AssimpImporter. The close() function closes and discards the internally instantiated plugin; isOpened() works as usual.

Note that AssimpImporter will import the meshes as indexed and may do other changes to the data such as vertex deduplication or normal smoothing.

Plugin-specific configuration

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

[configuration]
# Turn per-face normals into per-vertex. If enabled, normals from the file
# are duplicated to each vertex, expanding the data size roughly by 50%,
# possibly complicating duplicate vertex removal or smooth normal generation.
# If disabled, the mesh is imported just with positions and per-face normals
# are available in a separate mesh level.
perFaceToPerVertex=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

StlImporter() explicit
Default constructor.
StlImporter(PluginManager::AbstractManager& manager, const Containers::StringView& plugin) explicit
Plugin manager constructor.