для этой страницы,
отображается код на другом
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.
- Mesh animations
Import Manager is used to create and manage importers and 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 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, etc.). It also has a set of flags that define 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:
- 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 (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.
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.).
If your application does not require any specific file saving operations, you can use DefaultProcessor, otherwise, you can implement your own custom processor with any additional functionality (e.g., import models directly to memory).
In order to be used, importers and processors must be registered in the system via 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, 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:
- Check the extension of the specified input file and find the appropriate importer among the registered ones.
- Extract scene metadata from the input file, put the data to the corresponding import structures (ImportMesh, ImportMaterial, etc.), and build the import scene.
- Use pre-processor(s) to prepare scene metadata when necessary (merge all static meshes into a single one, optimize vertex cache, etc.).
- Use the appropriate importer to generate UNIGINE objects (nodes, lights, cameras, materials, etc.) on the basis of scene metadata.
- Use the appropriate import processor to save generated objects to the corresponding files in the specified output directory.
- Use post-processor(s) to perform necessary operations with generated files.
The Import System is utilized by both the Engine and the Editor. Out-of-the-box it currently offers:
- Importer for FBX scenes implemented as FbxImporter plugin, which in addition to .fbx format also supports .obj, .dae, and .3ds.
- 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 (add functionality to process used-defined attributes of CAD models, some additional scene processing functionality, etc.).
In general, the workflow via the C++ API may be represented as follows:
// 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:
// 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());
Built-in Import Options#
The following table lists the names for the parameters available out of the box that can be set via the setParameterInt("name", value) method.
|Deletes the mesh from the FBX SDK after it has been converted.
|Creates unique names for materials with identical names.
|Optimizes vertex cache. This option reorders an indexed triangle list to improve vertex cache utilization at runtime. It can be turned off to accelerate saving process; however, it should always be turned on if saving the final version.
|Defines the workflow for the imported physically based materials (if any).
|Imports bones that are not attached to the skeleton and do not affect the animation's skin, for example, a weapon held in the character's hands. If disabled, such bone is not imported and bones connected to it, if any, become orphans.
|Imports built-in tangent space data instead of recalculating it.
If the option is enabled, but an FBX asset has no tangent space, it will be calculated with orientation for the right-handed coordinate system.
|Imports morph targets from the file.
|Imports the hierarchy of the joints (bones) for animated assets as a list of World Transform Bones.
|Defines orientation of bones for animations and animated geometry. When enabled, all bones will have the same forward axis as the geometry. This simplifies work with animations via code for programmers reducing excessive axis manipulations: if a mesh has +Y as a forward axis, the bones will have +Y as well.
|Imports FBX with mesh instances. When enabled, a single mesh is imported instead of several identical ones. If you add such FBX to the scene, all meshes in the World Hierarchy will refer to the single mesh stored inside the imported FBX container.
|Defines which axis is the up vector of the World Coordinate System.
The up_axis value should be different from the front_axis value.
|Defines which axis is the forward vector of the World Coordinate System.
The front_axis value should be different from the up_axis value.
|Enables correct triangulation of meshes, NURBS and patches.
|Skips empty nodes. Complex CAD models may contain a lot of empty nodes, resulting in an overloaded world hierarchy. You can enable this option to simplify generated hierarchy by ignoring nodes, that do not contain any useful information.
|Merges materials with the same settings, but different names.
|Sets the UV channel to store the lightmap.
|Sets the padding value from 0 to 8, in pixels. The default value is 0. Requires adding CreateUV post-processor.|
|Sets the resolution of the resulting lightmap. Available values: 32, 64, 128, 256, 512, 1024, 2048, 4096. The default value is 0. Requires adding CreateUV post-processor.|
|Defines the efficiency of UV islands layout on the texture.
The following table lists the names for the parameters available out of the box that can be set via the setParameterFloat("name", value) method.
|Geometry scale multiplier.|
|Number of frames per second of imported animation.|
|Size of the grid cell to split imported meshes, in units. Requires adding SplitByBound pre-processor.|
The following table lists the names for the parameters available out of the box that can be set via the setParameterString("name", value) method.
|Lists the postfixes to be used to differeciate between LODs, in the following format:
Requires adding CombineByPostfixes pre-processor.
The amount of postfixes should be the same as the amount of listed lods_distances.
|Lists the minimum distances for LODs, in the following format:
Requires adding CombineByPostfixes pre-processor.
The amount of distances should be the same as the amount of listed lods_postfixes.
Pre-processor Type Names#
The following table lists the type names for the pre-processors available out of the box that can be added via the addPreProcessor("type_name") method.
|Merges all of the children static meshes into a single one (named after the parent mesh). All surfaces of all meshes surfaces will be copied and shown in the Surfaces hierarchy.|
|Enables merging surfaces that have the same materials.|
|Places a pivot of generated mesh to its center. Can be used for meshes having their geometry located too far from their pivot, as this may lead to various artefacts (jitter, etc.) associated with positioning errors.|
|Splits imported meshes according to the grid size defined by bound_size parameter.|
|Enables automatic creation of the Levels of Detail (LODs) based on the values of the lods_postfixes and lods_distances parameters.|
Post-processor Type Names#
- 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).Import System API is not available for the Entertainment SDK edition.