Unigine::Importer Class
You should upgrade to
Header: | #include <UnigineImport.h> |
This class is used to manage a file importer. File importers are used by the Engine's import system to bring the data stored in various non-native formats to UNIGINE. Each importer can be used to import multiple file formats, but there shouldn't be two or more importers registered for a single file format.
Importer has a set of flags defining which scene components are to be extracted and imported. So, the importer should be initialized before use.
Each importer generates UNIGINE objects on the basis of metadata extracted from the imported files and uses a set of processors to perform all necessary auxiliary operations (data preparation, file saving, file management, etc.). Importer allows you to add any number of pre- and post-processors. However, you can set only one processor for each scene component.
You can customize actions to be performed when importing the whole scene as well as when importing textures, materials, meshes, animations, lights, cameras by overriding the corresponding event handler functions for your custom importer
class MyCustomImporter : public Unigine::Importer
{
public:
MyCustomImporter();
virtual ~MyCustomImporter();
/*...*/
// overrides of event functions
protected:
virtual Unigine::ImportScene *onInit(const Unigine::String &filepath) override;
virtual bool onImport(const char *output_path) override;
virtual bool onImportTexture(ImportProcessor *processor, ImportTexture *import_texture) override;
virtual bool onImportMaterial(ImportProcessor *processor, Unigine::MaterialPtr &material, ImportMaterial *import_material) override;
virtual bool onImportMesh(ImportProcessor *processor, Unigine::MeshPtr &mesh, ImportMesh *import_mesh) override;
virtual bool onImportLight(ImportProcessor *processor, Unigine::LightPtr &light, ImportLight *import_light) override;
virtual bool onImportCamera(ImportProcessor *processor, Unigine::PlayerPtr &camera, ImportCamera *import_camera);
virtual bool onImportNode(ImportProcessor *processor, Unigine::NodePtr &node, ImportNode *import_node) override;
virtual bool onImportAnimation(ImportProcessor *processor, Unigine::MeshPtr &animation, ImportMesh *import_mesh, ImportAnimation *import_animation) override;
private:
ImportScene *import_scene();
void import_textures(ImportScene *scene);
void import_materials(ImportScene *scene);
void import_animations(ImportScene *scene);
void process_node(ImportScene *import_scene, ImportNode *parent, fbx::FbxNode *fbx_node);
void process_mesh(ImportScene *import_scene, ImportNode *node, fbx::FbxNode *fbx_node, fbx::FbxMesh *fbx_mesh);
void process_light(ImportScene *import_scene, ImportNode *node, fbx::FbxNode *fbx_node, fbx::FbxLight *fbx_light);
void process_camera(ImportScene *import_scene, ImportNode *node, fbx::FbxNode *fbx_node, fbx::FbxCamera *fbx_camera);
/*...*/
};
Importer Class
Members
Importer ( ) #
Constructor. Creates an importer with default settings.ImportScene * getScene ( ) const#
Returns the imported scene.Return value
ImportScene instance.int containsParameter ( const char * name ) const#
Returns a value indicating whether the list of import parameters includes a parameter with a given name.Arguments
- const char * name - Parameter name.
Return value
1 if the list of import parameters includes a parameter with a given name; otherwise, 0.void setParameterInt ( const char * name, int v ) #
Sets a new value for the specified integer parameter. There are built-in parameters that can also be used in custom importers.Arguments
- const char * name - Name of the integer parameter.
- int v - New value to be set.
int getParameterInt ( const char * name ) const#
Returns the current value of the specified integer parameter. There are built-in parameters that can also be used in custom importers.Arguments
- const char * name - Name of the integer parameter.
Return value
Value of the integer parameter.void setParameterFloat ( const char * name, float v ) #
Sets a new value for the specified float parameter. There are built-in parameters that can also be used in custom importers.Arguments
- const char * name - Name of the float parameter.
- float v - New value to be set.
float getParameterFloat ( const char * name ) const#
Returns the current value of the specified float parameter. There are built-in parameters that can also be used in custom importers.Arguments
- const char * name - Name of the float parameter.
Return value
Value of the float parameter.void setParameterDouble ( const char * name, double v ) #
Sets a new value for the specified double parameter.Arguments
- const char * name - Name of the double parameter.
- double v - New value to be set.
double getParameterDouble ( const char * name ) const#
Returns the current value of the specified double parameter.Arguments
- const char * name - Name of the double parameter.
Return value
Value of the double parameter.void setParameterString ( const char * name, const char * v ) #
Sets a new value for the specified string parameter. There are built-in parameters that can also be used in custom importers.Arguments
- const char * name - Name of the string parameter.
- const char * v - New value to be set.
const char * getParameterString ( const char * name ) const#
Returns the current value of the specified string parameter. There are built-in parameters that can also be used in custom importers.Arguments
- const char * name - Name of the string parameter.
Return value
Value of the string parameter.int addPreProcessor ( const char * type_name ) #
Adds an import pre-processor with a given name. There are built-in pre-processors that can also be added to custom importers.Arguments
- const char * type_name - Pre-processor name.
Return value
1 if the specified import pre-processor is successfully added; otherwise, 0.void removePreProcessor ( const char * type_name ) #
Removes an import pre-processor with a given name. There are built-in pre-processors that can also be added to custom importers.Arguments
- const char * type_name - Pre-processor name.
int addPostProcessor ( const char * type_name ) #
Adds an import post-processor with a given name. There are built-in post-processors that can also be added to custom importers.Arguments
- const char * type_name - Post-processor name.
Return value
1 if the specified import post-processor is successfully added; otherwise, 0.void removePostProcessor ( const char * type_name ) #
Removes an import post-processor with a given name. There are built-in post-processors that can also be added to custom importers.Arguments
- const char * type_name - Post-processor name.
void setAnimationsProcessor ( const char * type_name ) #
Sets the specified processor to be used for importing animations.Arguments
- const char * type_name - Name of the animations processor to be set.
void setCamerasProcessor ( const char * type_name ) #
Sets the specified processor to be used for importing cameras.Arguments
- const char * type_name - Name of the cameras processor to be set.
void setLightsProcessor ( const char * type_name ) #
Sets the specified processor to be used for importing lights.Arguments
- const char * type_name - Name of the lights processor to be set.
void setMaterialsProcessor ( const char * type_name ) #
Sets the specified processor to be used for importing materials.Arguments
- const char * type_name - Name of the materials processor to be set.
void setMeshesProcessor ( const char * type_name ) #
Sets the specified processor to be used for importing meshes.Arguments
- const char * type_name - Name of the meshes processor to be set.
void setNodesProcessor ( const char * type_name ) #
Sets the specified processor to be used for importing nodes.Arguments
- const char * type_name - Name of the nodes processor to be set.
void setTexturesProcessor ( const char * type_name ) #
Sets the specified processor to be used for importing textures.Arguments
- const char * type_name - Name of the textures processor to be set.
int init ( const char * filepath, int flags ) #
Initializes the importer for the specified file using the given flags. Import flags specify which scene components are to be imported.Arguments
- const char * filepath - Path to a file to be imported.
- int flags - Set of import flags. Any combination of IMPORT_* flags, or ~0 to set all of them.
Return value
1 if the importer was initialized successfully; otherwise, 0.int import ( const char * output_path ) #
Imports the contents of the input file to the specified output path.Arguments
- const char * output_path - Output path.
Return value
1 if the contents of the input file are successfully imported to the specified output path; otherwise, 0.const char * getOutputFilepath ( ) const#
Returns the resulting output file path for imported scene component(s). In case if a set of files were generated the path to resulting *.node file will be returned.Return value
Output file path.bool preprocess ( ) #
Starts execution of all added pre-processors.Return value
true if the pre-processing is completed successfully.bool importAnimation ( ImportProcessor * processor, MeshPtr & animation, ImportMesh * import_mesh, ImportAnimation * import_animation ) #
Imports the specified mesh animation and uses the specified processor to process and save the generated mesh animation to a corresponding file in the output directory specified in the import() method.Arguments
- ImportProcessor * processor - Import processor to be used for this import operation.
- MeshPtr & animation - Target UNIGINE's mesh instance to store the specified imported mesh animation.
- ImportMesh * import_mesh - ImportMesh structure pointer.
- ImportAnimation * import_animation - ImportAnimation structure pointer.
Return value
true if the specified mesh animation was successfully imported; otherwise, false.bool importCamera ( ImportProcessor * processor, PlayerPtr & camera, ImportCamera * import_camera ) #
Imports the specified camera and uses the specified processor to process and save the generated player to a corresponding *.node file in the output directory specified in the import() method.Arguments
- ImportProcessor * processor - Import processor to be used for this import operation.
- PlayerPtr & camera - Target UNIGINE's player instance to store the specified imported camera.
- ImportCamera * import_camera - ImportCamera structure pointer.
Return value
true if the specified camera was successfully imported; otherwise, false.bool importLight ( ImportProcessor * processor, LightPtr & light, ImportLight * import_light ) #
Imports the specified light and uses the specified processor to process and save the generated light to a corresponding *.node file in the output directory specified in the import() method.Arguments
- ImportProcessor * processor - Import processor to be used for this import operation.
- LightPtr & light - Target UNIGINE's light instance to store the specified imported light.
- ImportLight * import_light - ImportLight structure pointer.
Return value
true if the specified light was successfully imported; otherwise, false.bool importMaterial ( ImportProcessor * processor, MaterialPtr & material, ImportMaterial * import_material ) #
Imports the specified material and uses the specified processor to process and save the generated material to a corresponding file in the output directory specified in the import() method.Arguments
- ImportProcessor * processor - Import processor to be used for this import operation.
- MaterialPtr & material - Target UNIGINE's material instance to store the specified imported material.
- ImportMaterial * import_material - ImportMaterial structure pointer.
Return value
true if the specified material was successfully imported; otherwise, false.bool importMesh ( ImportProcessor * processor, MeshPtr & mesh, ImportMesh * import_mesh ) #
Imports the specified mesh and uses the specified processor to process and save the generated mesh to a corresponding file in the output directory specified in the import() method.Arguments
- ImportProcessor * processor - Import processor to be used for this import operation.
- MeshPtr & mesh - Target UNIGINE's mesh instance to store the specified imported mesh.
- ImportMesh * import_mesh - ImportMesh structure pointer.
Return value
true if the specified mesh was successfully imported; otherwise, false.bool importNode ( ImportProcessor * processor, NodePtr & node, ImportNode * import_node ) #
Imports the specified node and uses the specified processor to process and save the generated node to a corresponding file in the output directory specified in the import() method.Arguments
- ImportProcessor * processor - Import processor to be used for this import operation.
- NodePtr & node - Target UNIGINE's node instance to store the specified imported node.
- ImportNode * import_node - ImportNode structure pointer.
Return value
true if the specified node was successfully imported; otherwise, false.bool importTexture ( ImportProcessor * processor, ImportTexture * import_texture ) #
Imports the specified texture and uses the specified processor to process and save the generated texture to a corresponding file in the output directory specified in the import() method.Arguments
- ImportProcessor * processor - Import processor to be used for this import operation.
- ImportTexture * import_texture - ImportTexture structure pointer.
Return value
true if the specified texture was successfully imported; otherwise, false.bool postprocess ( ) #
Starts execution of all added post-processors. Post-processors can be used to manage files generated in the process of import.Return value
true if the post-processing is completed successfully.ImportScene * onInit ( const String & filepath ) #
Imports the scene contained in the specified input file.Arguments
- const String & filepath - Path to a file to be imported.
Return value
Scene contained in the specified input file.bool onImport ( const char * output_path ) #
Import event handler function. This function is called each time when the Import() function is called. You can specify your custom actions to be performed on scene import.class MyCustomImporter : public Unigine::Importer
{
public:
MyCustomImporter();
virtual ~MyCustomImporter();
/*...*/
// overrides of event functions
protected:
virtual bool onImport(const char *output_path) override;
/*...*/
};
/*...*/
bool MyCustomImporter::onImport(const char *output_path)
{
bool result = false;
// your custom actions
return result;
}
Arguments
- const char * output_path - Output path to be used to store generated file(s) with imported data.
Return value
true if import operation for the specified output path was successful; otherwise, false.bool onImportAnimation ( ImportProcessor * processor, MeshPtr & animation, ImportMesh * import_mesh, ImportAnimation * import_animation ) #
Animation import event handler function. This function is called each time when the importAnimation() function is called. You can specify your custom actions to be performed on animation import.class MyCustomImporter : public Unigine::Importer
{
public:
MyCustomImporter();
virtual ~MyCustomImporter();
/*...*/
// overrides of event functions
protected:
virtual bool onImportAnimation(ImportProcessor *processor, MeshPtr &animation, ImportMesh *import_mesh, ImportAnimation *import_animation) override;
/*...*/
};
/*...*/
bool MyCustomImporter::onImportAnimation(ImportProcessor *processor, MeshPtr &animation, ImportMesh *import_mesh, ImportAnimation *import_animation)
{
bool result = false;
// your custom actions
return result;
}
Arguments
- ImportProcessor * processor - Import processor used for this import operation.
- MeshPtr & animation - Target UNIGINE's mesh instance to store the specified imported mesh animation.
- ImportMesh * import_mesh - ImportMesh structure pointer.
- ImportAnimation * import_animation - ImportAnimation structure pointer.
Return value
true if the specified mesh animation was successfully imported; otherwise, false.bool onImportCamera ( ImportProcessor * processor, PlayerPtr & camera, ImportCamera * import_camera ) #
Camera import event handler function. This function is called each time when the importCamera() function is called. You can specify your custom actions to be performed on camera import.class MyCustomImporter : public Unigine::Importer
{
public:
MyCustomImporter();
virtual ~MyCustomImporter();
/*...*/
// overrides of event functions
protected:
virtual bool onImportCamera(ImportProcessor *processor, Unigine::PlayerPtr &camera, ImportCamera *import_camera) override;
/*...*/
};
/*...*/
bool MyCustomImporter::onImportCamera(ImportProcessor *processor, Unigine::PlayerPtr &camera, ImportCamera *import_camera)
{
bool result = false;
// your custom actions
return result;
}
Arguments
- ImportProcessor * processor - Import processor used for this import operation.
- PlayerPtr & camera - Target UNIGINE's player instance to store the specified imported camera.
- ImportCamera * import_camera - ImportCamera structure pointer.
Return value
true if the specified camera was successfully imported; otherwise, false.bool onImportLight ( ImportProcessor * processor, LightPtr & light, ImportLight * import_light ) #
Light import event handler function. This function is called each time when the importLight() function is called. You can specify your custom actions to be performed on light import.class MyCustomImporter : public Unigine::Importer
{
public:
MyCustomImporter();
virtual ~MyCustomImporter();
/*...*/
// overrides of event functions
protected:
virtual bool onImportLight(ImportProcessor *processor, Unigine::LightPtr &light, ImportLight *import_light) override;
/*...*/
};
/*...*/
bool MyCustomImporter::onImportLight(ImportProcessor *processor, Unigine::LightPtr &light, ImportLight *import_light)
{
bool result = false;
// your custom actions
return result;
}
Arguments
- ImportProcessor * processor - Import processor used for this import operation.
- LightPtr & light - Target UNIGINE's light instance to store the specified imported light.
- ImportLight * import_light - ImportLight structure pointer.
Return value
true if the specified light was successfully imported; otherwise, false.bool onImportMaterial ( ImportProcessor * processor, MaterialPtr & material, ImportMaterial * import_material ) #
Material import event handler function. This function is called each time when the importMaterial() function is called. You can specify your custom actions to be performed on material import.class MyCustomImporter : public Unigine::Importer
{
public:
MyCustomImporter();
virtual ~MyCustomImporter();
/*...*/
// overrides of event functions
protected:
virtual bool onImportMaterial(ImportProcessor *processor, Unigine::MaterialPtr &material, ImportMaterial *import_material) override;
/*...*/
};
/*...*/
bool MyCustomImporter::onImportMaterial(ImportProcessor *processor, Unigine::MaterialPtr &material, ImportMaterial *import_material)
{
bool result = false;
// your custom actions
return result;
}
Arguments
- ImportProcessor * processor - Import processor used for this import operation.
- MaterialPtr & material - Target UNIGINE's material instance to store the specified imported material.
- ImportMaterial * import_material - ImportMaterial structure pointer.
Return value
true if the specified material was successfully imported; otherwise, false.bool onImportMesh ( ImportProcessor * processor, MeshPtr & mesh, ImportMesh * import_mesh ) #
Mesh import event handler function. This function is called each time when the importMesh() function is called. You can specify your custom actions to be performed on mesh import.class MyCustomImporter : public Unigine::Importer
{
public:
MyCustomImporter();
virtual ~MyCustomImporter();
/*...*/
// overrides of event functions
protected:
virtual bool onImportMesh(ImportProcessor *processor, Unigine::MeshPtr &mesh, ImportMesh *import_mesh) override;
/*...*/
};
/*...*/
bool MyCustomImporter::onImportMesh(ImportProcessor *processor, Unigine::MeshPtr &mesh, ImportMesh *import_mesh)
{
bool result = false;
// your custom actions
return result;
}
Arguments
- ImportProcessor * processor - Import processor used for this import operation.
- MeshPtr & mesh - Target UNIGINE's mesh instance to store the specified imported mesh animation.
- ImportMesh * import_mesh - ImportMesh structure pointer.
Return value
true if the specified mesh was successfully imported; otherwise, false.bool onImportNode ( ImportProcessor * processor, NodePtr & node, ImportNode * import_node ) #
Node import event handler function. This function is called each time when the importNode() function is called. You can specify your custom actions to be performed on node import.class MyCustomImporter : public Unigine::Importer
{
public:
MyCustomImporter();
virtual ~MyCustomImporter();
/*...*/
// overrides of event functions
protected:
virtual bool onImportNode(ImportProcessor *processor, Unigine::NodePtr &node, ImportNode *import_node) override;
/*...*/
};
/*...*/
bool MyCustomImporter::onImportNode(ImportProcessor *processor, Unigine::NodePtr &node, ImportNode *import_node)
{
bool result = false;
// your custom actions
return result;
}
Arguments
- ImportProcessor * processor - Import processor used for this import operation.
- NodePtr & node - Target UNIGINE's node instance to store the specified imported node.
- ImportNode * import_node - ImportNode structure pointer.
Return value
true if the specified node was successfully imported; otherwise, false.bool onImportTexture ( ImportProcessor * processor, ImportTexture * import_texture ) #
Texture import event handler function. This function is called each time when the importTexture() function is called. You can specify your custom actions to be performed on texture import.class MyCustomImporter : public Unigine::Importer
{
public:
MyCustomImporter();
virtual ~MyCustomImporter();
/*...*/
// overrides of event functions
protected:
virtual bool onImportTexture(ImportProcessor *processor, ImportTexture *import_texture) override;
/*...*/
};
/*...*/
bool MyCustomImporter::onImportTexture(ImportProcessor *processor, ImportTexture *import_texture)
{
bool result = false;
// your custom actions
return result;
}
Arguments
- ImportProcessor * processor - Import processor used for this import operation.
- ImportTexture * import_texture - ImportTexture structure pointer.
Return value
true if the specified texture was successfully imported; otherwise, false.bool hasPreProcessor ( const char * type_name ) #
Checks if the specified import pre-processor type exists.Arguments
- const char * type_name - Import pre-processor type to check.
const char * getSourceFilepath ( ) const#
Returns the source file path.Return value
Source file path.bool computeBoundBox ( ImportMesh * import_mesh ) #
Computes a bound box for the mesh.Arguments
- ImportMesh * import_mesh - Imported mesh.
bool importAnimation ( ImportProcessor * processor, MeshPtr & animation, ImportAnimation * import_animation ) #
Imports the specified mesh animation and uses the specified processor to process and save the generated mesh animation to a corresponding file in the output directory specified in the import() method.Arguments
- ImportProcessor * processor - Import processor to be used for this import operation.
- MeshPtr & animation - Target UNIGINE's mesh instance to store the specified imported mesh animation.
- ImportAnimation * import_animation - ImportMesh structure pointer. The metadata for the animation that needs to be imported.
bool getBasis ( Importer::Axis up_axis, Importer::Axis front_axis, dmat4 & ret ) #
Returns the transformation matrix for the basis specified by axes.Arguments
- Importer::Axis up_axis - Up axis of the basis.
- Importer::Axis front_axis - Front axis of the basis.
- dmat4 & ret - Transformation matrix for the basis specified by axes.
bool onComputeBoundBox ( ImportMesh * import_mesh ) #
Extendable method for custom bound box computation.Arguments
- ImportMesh * import_mesh - Imported mesh.
bool onImportAnimation ( ImportProcessor * processor, MeshPtr & animation, ImportAnimation * import_animation ) #
Animation import event handler function. This function is called each time when the importAnimation() function is called. You can specify your custom actions to be performed on animation import.Arguments
- ImportProcessor * processor - Import processor used for this import operation.
- MeshPtr & animation - Target UNIGINE's mesh instance to store the specified imported mesh animation.
- ImportAnimation * import_animation - ImportMesh structure pointer.The metadata for the animation that needs to be imported.