Importers/Exporters

<< Click to Display Table of Contents >>

Navigation:  Simplygon API 7.1 User guide >

Importers/Exporters

The Simplygon library has native support for the Wavefront format.

 

Wavefront (.obj)

The Simplygon API provides classes for loading and saving Wavefront object (.obj) files. Alternatively, there is a Wavefront import/export example.

 

Wavefront Importing

Loading Wavefront object data is done by the IWavefrontImporter class. Loading Wavefront object data is done by the IWavefrontImporter class. The file information is then stored in an IScene, where both the geometries and materials of the Wavefront file can be found.

 
void LoadObj(const char* readFrom)
{
   spWavefrontImporter is = sg->CreateWavefrontImporter();
   //This makes the .obj reader import each group into a separate
   //scene mesh node
   is->SetExtractGroups(true);
   spScene myScene;
   // Set the path of the file to load.
   is->SetImportPath(readFrom);
   if( is->RunImport() )
   {  
       myScene = is->GetScene();
   }
   // ... do stuff with myScene.
}
 

Wavefront Exporting 

The IWavefrontExporter class provides a simple way of exporting geometry data as a Wavefront object file. 

 

 
void SaveObj(const char * filename, spScene myScene, rid selectionSetID)
{
    spWavefrontExporter os = sg->CreateWavefrontExporter();
    os->SetScene(myScene);
    // -1 means that the whole scene will be exported.
    os->SetSelectionSet(selectionSetID);
    os->SetExportFilePath(filename);
    // Override .mtl file name
    // os->SetMaterialFilePath( materialfilename );
    os->RunExport();
}