UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
FAQ
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
CIGI Client Plugin
Rendering-Related Classes

Import System

UNIGINE offers a flexible and extendable Import System, enabling you to import whole scenes as well as selected scene components from any external format and use them in your projects.

Notice
Runtime import feature is not available for Entertainment SDK edition.

Imported Scene is a set of metadata on objects to be brought to UNIGINE and can contain the following components:

  • lights
  • cameras
  • meshes
  • mesh animations
  • textures
  • materials
  • nodes

The structure of the Import System is shown below. It includes Import Manager and a dynamic set of importers and processors for various external file formats.

Import System

Import System Structure

Import Manager is used to create and manage importers, processors as well as to directly import files in non-native formats, if an importer for such files was previously registered.

Importers and Processors#

Importer is a module used by the Import System to bring the data stored in various non-native formats to UNIGINE, it generates UNIGINE objects on the basis of metadata extracted from the imported file. A single importer can be used to import multiple external file formats (extensions), but there shouldn't be two or more importers registered for a single file format.

Each importer has a set of parameters that control the whole import process (e.g., scale multiplier, use of various processors such as static mesh merger or vertex cache optimizer e.t.c.). It also has a set of flags defining which scene components are to be extracted and imported. So, the importer should be initialized before use.

Importers use a set of processors to perform all necessary auxiliary operations. A processor is a module that performs auxiliary operations during the import process (data preparation, file saving, file management, etc.). The list of processor types that can be used includes the following ones:

  • pre-processor - performs additional operations on scene metadata (ImportScene) and prepares it for the object generation stage.
  • import processor - saves UNIGINE objects, generated by an importer on the basis of metadata, to a file in UNIGINE’s native format. You can use a set of different processors for each scene component or a single processor for all of them.
  • post-processor - performs additional operations with generated files (e.g. copying files to other folders, adding files to packages, etc.).

Importer allows you to add any number of pre- and post-processors. However, you can set only one processor for each scene component.

The Import System offers you the DefaultProcessor - it is, as its name says, a default processor used to save objects, that were generated by an importer, to corresponding UNIGINE file formats (.mesh, .dds, .node, etc.).

In case if your application does not require any specific file saving operations you can use the default processor, otherwise, you can implement your own custom processor with any additional functionality (e.g., import models directly to memory).

Basic Workflow#

In order to be used, importers and processors must be registered in the system via the Import Manager. You can manage the list of available modules dynamically by adding them to or removing from the registry. When you import a file in any external format the Import System automatically tries to find and use an appropriate importer registered for the specified file extension.

The basic file import workflow is as follows:

  1. Check the extension of the specified input file and find the appropriate importer among the ones registered.
  2. Extract scene metadata from the input file, put the data to the corresponding import structures (ImportMesh, ImportMaterial, etc.) and build the import scene.
  3. Use pre-processor(s) to prepare scene metadata when necessary (e.g. merge all static meshes into a single one, optimize vertex cache, etc.).
  4. Use the appropriate importer to generate UNIGINE objects (nodes, lights, cameras, materials, etc.) on the basis of scene metadata.
  5. Use the appropriate import processor to save generated objects to the corresponding files in the specified output directory.
  6. Use post-processor(s) to perform necessary operations with generated files.

Customization#

The Import System is utilized by both the Engine and the Editor. Out-of-the-box it currently offers:

  • an importer for FBX scenes implemented as FbxImporter plugin, which apart from .fbx format also supports .obj, .dae, and .3ds.
  • an importer for CAD models implemented as CadImporter plugin, which supports .iges, .step, and .stl CAD formats.

Custom importing modules (importers and processors) for any file format containing 3D scene data are also to be implemented as plugins. So, you can consider the FbxImporter and CadImporter plugins as examples to build your own custom importing modules. You can also modify and rebuild these plugins to use your own custom importer in the Editor (e.g. add functionality to process used-defined attributes of CAD models, some additional scene processing functionality, etc.).

To use the FbxImporter plugin, just load it via the plugin_load console command or the following command line option on the application start-up:

Shell commands
-extern_plugin FbxImport

In general the workflow via the C++ API may be represented as follows:

Source code (C++)
// create an importer for the imported file ("1.fbx" in our case)
Importer *importer = Import::get()->createImporterByFileName("1.fbx"); 

// set up import parameter "scale" to 0.5
importer->setParameterFloat("scale", 0.5f); 

// add a pre-processor to merge static meshes
impoter->addPreProcessor("MergeStaticMeshes");

// initialize importer with all available import flags
importer->init("1.fbx", ~0);

// import our model to the specified directory
importer->import("../data/1/"); 

// create a node reference using the .node file generated for our model
NodeReferencePtr noderef = NodeReference::create(importer->getOutputFilepath());

You can also load a model with default settings simply like this:

Source code (C++)
// string to store the path to the .node file for your model
String filepath_node;

// import an fbx file to the specified location and get the path to the generated .node file
Unigine::Import::get()->import("../my_data/1.fbx", "../data/1/", filepath_node);

// create a node reference using the .node file generated
NodeReferencePtr noderef = NodeReference::create(filepath_node.get());

See Also#

  • FbxImporter plugin as an a example for your custom import plugin: source/plugins/Import/FbxImporter.
  • CadImporter plugin as an a example for your custom import plugin: source/plugins/Import/CadImporter.
  • Custom Import Plugin usage example to learn the basics of writing your own custom import plugin.
  • Importing Models Directly to Memory usage example to learn the basics of writing your own custom import processor.

File Import System API:

  • File Import Functionality classes for more details on managing the Import System, importers and processors via code (C++, UnigineScript).

    Notice
    Import System API is not available for Entertainment SDK edition.
Last update: 2019-11-28