Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
Read and write 3D files

Detailed Description

3D I/O files principles

C3DIo is the class for reading a 3D file and obtain a C3DScene, or writing a C3DScene to a file.
A specific file format is recognized using the file extension, and the appropriate C3DParser is then called to read or write the file.
*

Reading a 3D file and get the scene

Reading a file is quite simple.

C3DIo file(filename, FILE_PARSER_LOADING);
C3DScene* scene = file.Read(&options); // &options is optional and can be removed if you don't need JT
if (!scene)
{
file.ReportIoError();
return;
}
C3DIo class handles reading / writing / updating 3D file.
Definition Io3dmgr.h:233
The class allows to get access to the scene graph, node hierarchy, material.
Definition 3DScene.h:306

You can provide some specific options using CSceneImportOptions. For example, you might need to define an FBX file.

options.GetParserOptions().SetString(FBX_IO_OPTION_PASSWORD, "My-password");
C3DIo file(filename, FILE_PARSER_LOADING); // if filename is an fbx file, then the password will be used by the fbx parser
C3DScene* scene = file.Read(&options);
if (!scene)
{
file.ReportIoError();
return;
}
#define FBX_IO_OPTION_PASSWORD
CXString: String that contains a password to read/write the fbx.
Definition Io3dmgr.h:26
This class is used to provide some specific options when loading scene file.
Definition Io3dmgr.h:133

Writing a scene to a file

Writing a C3DScene to a file is also easy. Here is a sample that use some specific options to export the scene.

options.GetParserOptions().SetString(FBX_IO_OPTION_PASSWORD, "My-password"); // Cf. note above
C3DIo file(filename, FILE_PARSER_SAVING);
if (!file.Save(scene, &options))
{
file.ReportIoError(error);
}
@ SCENE_EXPORT_REMOVE_CURVE
Remove curves.
Definition 3DType.h:244
@ SCENE_EXPORT_MAKE_UNIQUE_NAME
Generate unique name for materials and nodes.
Definition 3DType.h:260
@ SCENE_EXPORT_CONVERT_PATCH
Convert patch to polygonal mesh.
Definition 3DType.h:258
@ SCENE_EXPORT_TRIANGULATE
Triangulate objects.
Definition 3DType.h:254
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
This class is used to provide some specific options when exporting a 3D scene.
Definition Io3dmgr.h:157
longuint flags
Definition Io3dmgr.h:173

Retrieve the list of registered extensions

By default the SDK integrates a lot of parsers for different format.
This can be useful for displaying a dialog box for example.

The following code retrieve the 3D extensions that are recognized for reading.

{
CXString filter;
unsigned int i=0, j, size;
filternum = 0;
filter.Empty();
unsigned int extproperties = 0;
unsigned int count;
CFileExt *fileinfo;
CFileExt *filesarray = fileGetRegisteredFiles(count, IMPORT_FILE|OBJECT_FILE); // EXPORT_FILE would get the file extensions for writing.
for (i=0; i<count; i++)
{
fileinfo = &filesarray[i];
size = fileGetExtensionArray(fileinfo->GetClass(), extArray); // A parser might register several extensions
XASSERT(size);
// Add the extension in the list
tmp1.Empty();
tmp2.Empty();
for (j=0; j<size; j++)
{
XASSERT(extArray[j] == LowerCaseString(extArray[j]));
tmp1 += '*'+extArray[j];
tmp2 += '*'+extArray[j];
if (j != size-1)
{
tmp1 += ", ";
tmp2 += ";";
}
allfiles += ";";
}
filter += fileinfo->GetDescription();
filter += _T("|");
filter += tmp2;
filter += _T("|");
}
fileFreeRegisteredFiles(filesarray, count);
if (filternum > 1)
{
filter += _T("All recognized files");
filter += "|";
allfiles.Replace(_T("."), _T("*."));
filter += allfiles; // Doesn't display file extension when too much extension are defined
filter += "||";
}
return filter;
}
CFileExt is the class that allows to add a custom file parser for supporting a new file format....
Definition FileInfo.h:182
CXStringArray implement an array of CXString.
Definition XStringArray.h:25

C3DParser information

C3DParser usually defines some default flags and some needed flags for reading in the C3DParser::LoadDefaultOptions implementation. C3DParser::SaveDefaultOptions defines some default flags and some needed flags for writing.

For example if the parser export only triangles, it will set C3DParser::neededflags |= SCENE_EXPORT_TRIANGULATE which will make the scene being triangulated before the export.

Modules

 Implementing your own 3D parser
 
 Keep as much as possible information when saving a scene using Update Mode