Magnum::Trade::PrimitiveImporter class new in 2020.06

Primitive importer plugin.

Exposes primitives from the Primitives library through importer APIs. Applications that have an importer pipeline already set up can use this plugin to access builtin primitives for prototyping and testing purposes without needing to write explicit code. For applications that don't have an importer pipeline, using the Primitives library directly is more straightforward.

Usage

This plugin depends on the Trade library and is built if MAGNUM_WITH_PRIMITIVEIMPORTER is enabled when building Magnum Plugins. To use as a dynamic plugin, load "PrimitiveImporter" 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_PRIMITIVEIMPORTER ON CACHE BOOL "" FORCE)
add_subdirectory(magnum-plugins EXCLUDE_FROM_ALL)

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

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

find_package(MagnumPlugins REQUIRED PrimitiveImporter)

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

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

Behavior

Upon calling openData() with arbitrary data (or openFile() with an arbitrary existing file), the importer will expose all primitives through mesh(). The returned MeshData instances come directly from the functions in the Primitives namespace, see their documentation for more information about present attributes and their types.

The importer additionally lists two scenes, first with all 2D primitives and second with all 3D primitives for easy import to existing scenes. The 3D scene is the defaultScene(). For simplicity, both scenes have SceneMappingType::UnsignedInt with the 2D and 3D object IDs interleaved and SceneData::mappingBound() returning the same value as objectCount() for both scenes. The scenes have a SceneField::Parent (of type SceneFieldType::Int) that's -1 for all objects and a SceneField::Translation (of either SceneFieldType::Vector2 or SceneFieldType::Vector3) and a SceneField::Mesh (of type SceneFieldType::UnsignedInt). The three fields share the same object mapping, which is monotonically increasing but sparse.

Both objects and meshes can be accessed through name of the respective function in the Primitives namespace (so e.g. loading a uvSphereSolid mesh will give you Primitives::uvSphereSolid()).

Plugin-specific configuration

By default the primitives are created with the same options that were used to create screenshots in the Primitives names. Those options can be then customized through various import options through configuration(). See below for all options and their default values:

[configuration]
[configuration/capsule2DWireframe]
hemisphereRings=8
cylinderRings=1
halfLength=0.75

[configuration/capsule3DSolid]
hemisphereRings=4
cylinderRings=1
segments=12
halfLength=0.75
textureCoordinates=false
tangents=false

[configuration/capsule3DWireframe]
hemisphereRings=8
cylinderRings=1
segments=16
halfLength=1.0

[configuration/circle2DSolid]
segments=16
textureCoordinates=false

[configuration/circle2DWireframe]
segments=32

[configuration/circle3DSolid]
segments=16
textureCoordinates=false
tangents=false

[configuration/circle3DWireframe]
segments=32

[configuration/coneSolid]
rings=1
segments=12
halfLength=1.25
textureCoordinates=false
tangents=false
capEnd=true

[configuration/coneWireframe]
segments=32
halfLength=1.25

[configuration/cylinderSolid]
rings=1
segments=12
halfLength=1.0
textureCoordinates=false
tangents=false
capEnds=true

[configuration/cylinderWireframe]
rings=1
segments=32
halfLength=1.0

# Shared by gradient2D and gradient2DHorizontal / gradient2DVertical, in the
# latter two cases the a / b is ignored
[configuration/gradient2D]
a=1.0 -2.0
b=-1.0 2.0
colorA=0.184314 0.513725 0.8 1.0
colorB=0.231373 0.823529 0.403921 1.0

# Shared by gradient3D and gradient3DHorizontal / gradient3DVertical, in the
# latter two cases the a / b is ignored
[configuration/gradient3D]
a=1.0 -2.0 -1.5
b=-1.0 2.0 -1.5
colorA=0.184314 0.513725 0.8 1.0
colorB=0.231373 0.823529 0.403921 1.0

[configuration/grid3DSolid]
subdivisions=5 3
textureCoordinates=false
tangents=false
normals=true

[configuration/grid3DWireframe]
subdivisions=5 3

[configuration/icosphereSolid]
subdivisions=1

[configuration/line2D]
a=-1.0 0.0
b=1.0 0.0

[configuration/line3D]
a=-1.0 0.0 0.0
b=1.0 0.0 0.0

[configuration/planeSolid]
textureCoordinates=false
tangents=false

[configuration/squareSolid]
textureCoordinates=false

[configuration/uvSphereSolid]
rings=8
segments=16
textureCoordinates=false
tangents=false

[configuration/uvSphereWireframe]
rings=16
segments=32

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

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