Magnum::Trade::AssimpImporter class

Assimp importer.

Imports various formats using Assimp, in particular:

  • Autodesk FBX (*.fbx)
  • COLLADA (*.dae)
  • glTF (*.gltf, *.glb)
  • Blender 3D (*.blend)
  • 3ds Max 3DS and ASE (*.3ds, *.ase)
  • Wavefront OBJ (*.obj)
  • Industry Foundation Classes (IFC/Step) (*.ifc)
  • XGL (*.xgl, *.zgl)
  • Stanford PLY (*.ply)
  • AutoCAD DXF (*.dxf)
  • LightWave, LightWave Scene (*.lwo, *.lws)
  • Modo (*.lxo)
  • Stereolithography (*.stl)
  • DirectX X (*.x)
  • AC3D (*.ac)
  • Milkshape 3D (*.ms3d)
  • TrueSpace (*.cob, *.scn)
  • Biovision BVH (*.bvh)
  • CharacterStudio Motion (*.csm)
  • Ogre XML (*.xml)
  • Irrlicht Mesh and Scene (*.irrmesh, *.irr)
  • Quake I (*.mdl)
  • Quake II (*.md2)
  • Quake III Mesh (*.md3)
  • Quake III Map/BSP (*.pk3)
  • Return to Castle Wolfenstein (*.mdc)
  • Doom 3 (*.md5*)
  • Valve Model (*.smd, *.vta)
  • Open Game Engine Exchange (*.ogex)
  • Unreal (*.3d)
  • BlitzBasic 3D (*.b3d)
  • Quick3D (*.q3d, *.q3s)
  • Neutral File Format (*.nff)
  • Sense8 WorldToolKit (*.nff)
  • Object File Format (*.off)
  • PovRAY Raw (*.raw)
  • Terragen Terrain (*.ter)
  • 3D GameStudio (3DGS), 3D GameStudio (3DGS) Terrain (*.mdl, *.hmp)
  • Izware Nendo (*.ndo)

Supports importing of scene, object, camera, mesh, texture and image data.

This plugin depends on the Trade and Assimp libraries and is built if WITH_ASSIMPIMPORTER is enabled when building Magnum Plugins. To use as a dynamic plugin, you need to load the "AssimpImporter" plugin from MAGNUM_PLUGINS_IMPORTER_DIR. To use as a static plugin or as a dependency of another plugin with CMake, you need to request the AssimpImporter component of the MagnumPlugins package and link to the MagnumPlugins::AssimpImporter target.

This plugin provides 3dsImporter, Ac3dImporter, BlenderImporter, BvhImporter, CsmImporter, ColladaImporter, DirectXImporter, DxfImporter, FbxImporter, GltfImporter, IfcImporter, IrrlichtImporter, LightWaveImporter, ModoImporter, MilkshapeImporter, ObjImporter, OgreImporter, OpenGexImporter, StanfordImporter, StlImporter, TrueSpaceImporter, UnrealImporter, ValveImporter and XglImporter plugins.

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

Behavior and limitations

The plugin supports Feature::OpenData and Feature::FileCallback features. The Assimp library loads everything during initial import, meaning all external file loading callbacks are called with ImporterFileCallbackPolicy::LoadTemporary and the resources can be safely freed right after the openData() / openFile() function exits. In some cases, Assimp will explicitly call ImporterFileCallbackPolicy::Close on the opened file and then open it again. In case of images, the files are loaded on-demand inside image2D() calls with ImporterFileCallbackPolicy::LoadTemporary and ImporterFileCallbackPolicy::Close is emitted right after the file is fully read.

Import of animation data is not supported at the moment.

Material import

  • Only materials with shading mode aiShadingMode_Phong are supported
  • Only the first diffuse/specular/ambient texture is loaded
  • Two-sided property and alpha mode is not imported

Light import

  • The following properties are ignored:
    • Angle inner/outer cone
    • Linear/quadratic/constant attenuation
    • Ambient/specular color
  • Assimp does not load a property which can be mapped to LightData::intensity()
  • Light types other than aiLightSource_DIRECTIONAL, aiLightSource_POINT and aiLightSource_SPOT are unsupported

Camera import

  • Aspect and up vector properties are not imported

Mesh import

  • Only the first mesh of a aiNode is loaded
  • Only triangle meshes are loaded
  • Texture coordinate layers with other than two components are skipped
  • For some file formats (such as COLLADA), Assimp may create a dummy "skeleton visualizer" mesh if the file has no mesh data. For others (such as glTF) not.

Texture import

  • Textures with mapping mode/wrapping aiTextureMapMode_Decal are loaded with SamplerWrapping::ClampToEdge
  • Assimp does not appear to load any filtering information
  • Raw embedded image data is not supported

Scene import

  • For some file formats (such as COLLADA), Assimp fails to load the file if it doesn't contain any scene. For some (such as glTF) it will succeed and sceneCount() / object3DCount() will return zero.
  • If the root node imported by Assimp has children, it's ignored and only its children are exposed through object3D(). On the other hand, for example in presence of postprocessing flags such as PreTransformVertices, there's sometimes just a single root node. In that case the single node is imported as a single object3D() instead of being ignored.

Plugin-specific configuration

Assimp has a versatile set of processing operations applied on imported scenes. The [postprocess] group of configuration() contains boolean toggles that correspond to the aiPostProcessSteps enum. Some of them are enabled by default, some not; options for not yet supported features are omitted. The full form of the configuration is shown below:

[configuration/postprocess]
JoinIdenticalVertices=true
Triangulate=true
GenNormals=false
GenSmoothNormals=false
SplitLargeMeshes=false
PreTransformVertices=false
ValidateDataStructure=false
ImproveCacheLocality=false
RemoveRedundantMaterials=false
FixInfacingNormals=false
SortByPType=true
FindDegenerates=false
FindInvalidData=false
GenUVCoords=false
TransformUVCoords=false
FindInstances=false
OptimizeMeshes=false
OptimizeGraph=false
FlipUVs=false
FlipWindingOrder=false

Access to internal importer state

The Assimp structures used to import data from a file can be accessed through importer state methods:

Base classes

class AbstractImporter
Base for importer plugins.

Constructors, destructors, conversion operators

AssimpImporter() explicit
Default constructor.
AssimpImporter(PluginManager::Manager<AbstractImporter>& manager) explicit
Constructor.
AssimpImporter(PluginManager::AbstractManager& manager, const std::string& plugin) explicit
Plugin manager constructor.

Private functions

auto doFeatures() const override -> Features virtual
Implementation for features()
auto doIsOpened() const override -> bool virtual
Implementation for isOpened()
void doSetFileCallback(Containers::Optional<Containers::ArrayView<const char>>(*)(const std::string&, Magnum::Trade::ImporterFileCallbackPolicy, void*) callback, void* userData) override virtual
Implementation for setFileCallback()
void doOpenData(Containers::ArrayView<const char> data) override virtual
Implementation for openData()
void doOpenState(const void* state, const std::string& filePath) override virtual
Implementation for openState()
void doOpenFile(const std::string& filename) override virtual
Implementation for openFile()
void doClose() override virtual
Implementation for close()
auto doDefaultScene() override -> Int virtual
Implementation for defaultScene()
auto doSceneCount() const override -> UnsignedInt virtual
Implementation for sceneCount()
auto doScene(UnsignedInt id) override -> Containers::Optional<SceneData> virtual
Implementation for scene()
auto doCameraCount() const override -> UnsignedInt virtual
Implementation for cameraCount()
auto doCamera(UnsignedInt id) override -> Containers::Optional<CameraData> virtual
Implementation for camera()
auto doObject3DCount() const override -> UnsignedInt virtual
Implementation for object3DCount()
auto doObject3DForName(const std::string& name) override -> Int virtual
Implementation for object3DForName()
auto doObject3DName(UnsignedInt id) override -> std::string virtual
Implementation for object3DName()
auto doObject3D(UnsignedInt id) override -> std::unique_ptr<ObjectData3D> virtual
Implementation for object3D()
auto doLightCount() const override -> UnsignedInt virtual
Implementation for lightCount()
auto doLight(UnsignedInt id) override -> Containers::Optional<LightData> virtual
Implementation for light()
auto doMesh3DCount() const override -> UnsignedInt virtual
Implementation for mesh3DCount()
auto doMesh3D(UnsignedInt id) override -> Containers::Optional<MeshData3D> virtual
Implementation for mesh3D()
auto doMaterialCount() const override -> UnsignedInt virtual
Implementation for materialCount()
auto doMaterialForName(const std::string& name) override -> Int virtual
Implementation for materialForName()
auto doMaterialName(UnsignedInt id) override -> std::string virtual
Implementation for materialName()
auto doMaterial(UnsignedInt id) override -> std::unique_ptr<AbstractMaterialData> virtual
Implementation for material()
auto doTextureCount() const override -> UnsignedInt virtual
Implementation for textureCount()
auto doTexture(UnsignedInt id) override -> Containers::Optional<TextureData> virtual
Implementation for texture()
auto doImage2DCount() const override -> UnsignedInt virtual
Implementation for image2DCount()
auto doImage2D(UnsignedInt id) override -> Containers::Optional<ImageData2D> virtual
Implementation for image2D()
auto doImporterState() const override -> const void* virtual
Implementation for importerState()

Function documentation

Magnum::Trade::AssimpImporter::AssimpImporter() explicit

Default constructor.

In case you want to open images, use AssimpImporter(PluginManager::Manager<AbstractImporter>&) instead.

Magnum::Trade::AssimpImporter::AssimpImporter(PluginManager::Manager<AbstractImporter>& manager) explicit

Constructor.

The plugin needs access to plugin manager for importing images.

void Magnum::Trade::AssimpImporter::doSetFileCallback(Containers::Optional<Containers::ArrayView<const char>>(*)(const std::string&, Magnum::Trade::ImporterFileCallbackPolicy, void*) callback, void* userData) override virtual private

Implementation for setFileCallback()

Useful when the importer needs to modify some internal state on callback setup. Default implementation does nothing and this function doesn't need to be implemented — the callback function and user data pointer are available through fileCallback() and fileCallbackUserData().

void Magnum::Trade::AssimpImporter::doOpenFile(const std::string& filename) override virtual private

Implementation for openFile()

If Feature::OpenData is supported, default implementation opens the file and calls doOpenData() with its contents. It is allowed to call this function from your doOpenFile() implementation — in particular, this implementation will also correctly handle callbacks set through setFileCallback().

This function is not called when file callbacks are set through setFileCallback() and Feature::FileCallback is not supported — instead, file is loaded though the callback and data passed through to doOpenData().

Int Magnum::Trade::AssimpImporter::doDefaultScene() override virtual private

Implementation for defaultScene()

Default implementation returns -1.

UnsignedInt Magnum::Trade::AssimpImporter::doSceneCount() const override virtual private

Implementation for sceneCount()

Default implementation returns 0.

UnsignedInt Magnum::Trade::AssimpImporter::doCameraCount() const override virtual private

Implementation for cameraCount()

Default implementation returns 0.

UnsignedInt Magnum::Trade::AssimpImporter::doObject3DCount() const override virtual private

Implementation for object3DCount()

Default implementation returns 0.

Int Magnum::Trade::AssimpImporter::doObject3DForName(const std::string& name) override virtual private

Implementation for object3DForName()

Default implementation returns -1.

std::string Magnum::Trade::AssimpImporter::doObject3DName(UnsignedInt id) override virtual private

Implementation for object3DName()

Default implementation returns empty string.

UnsignedInt Magnum::Trade::AssimpImporter::doLightCount() const override virtual private

Implementation for lightCount()

Default implementation returns 0.

UnsignedInt Magnum::Trade::AssimpImporter::doMesh3DCount() const override virtual private

Implementation for mesh3DCount()

Default implementation returns 0.

UnsignedInt Magnum::Trade::AssimpImporter::doMaterialCount() const override virtual private

Implementation for materialCount()

Default implementation returns 0.

Int Magnum::Trade::AssimpImporter::doMaterialForName(const std::string& name) override virtual private

Implementation for materialForName()

Default implementation returns -1.

std::string Magnum::Trade::AssimpImporter::doMaterialName(UnsignedInt id) override virtual private

Implementation for materialName()

Default implementation returns empty string.

UnsignedInt Magnum::Trade::AssimpImporter::doTextureCount() const override virtual private

Implementation for textureCount()

Default implementation returns 0.

UnsignedInt Magnum::Trade::AssimpImporter::doImage2DCount() const override virtual private

Implementation for image2DCount()

Default implementation returns 0.