Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
Implementing your own 3D parser

3

Steps to make an extension being recognized by the SDK

Please have a look at the 3DCustomFormat in the SDK samples.

Make the scene being prepared after import or before export

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

This method are optional. In this case default import / export processing occurs.

Here are some example of implementation:

void CExampleParser::LoadDefaultOptions(CSceneImportOptions& options) const
{
options.targetunit = UNIT_M;
}
void CExampleParser::SaveDefaultOptions(CSceneExportOptions& options) const
{
options.swapmode = SWAP_YZ; // Swap Y & Z coordinate before export
}
@ SCENE_IMPORT_CLEAN_GROUPS
Deletes any group which has no childs.
Definition 3DType.h:301
@ SCENE_IMPORT_CONCATENATE
Concatenates all mesh to a single one.
Definition 3DType.h:298
@ SCENE_EXPORT_CONVERT_TO_STANDARD_MATERIALS
Convert any materials to standard ones.
Definition 3DType.h:274
@ SCENE_EXPORT_GLOBAL_COORDINATES
The scene is exported with global coordinates.
Definition 3DType.h:263
@ SCENE_EXPORT_TRIANGULATE
Triangulate objects.
Definition 3DType.h:254
This class is used to provide some specific options when exporting a 3D scene.
Definition Io3dmgr.h:157
longuint neededflags
Fill by the parser. A combination of SCENE_EXPORT_FLAGS that are absolutely required.
Definition Io3dmgr.h:179
This class is used to provide some specific options when loading scene file.
Definition Io3dmgr.h:133

Implement Read or Save method

Implementation depends on your files. If the process fails, properly inform the C3DIo about what occurs.

Here are some example of read / write process, using the C3DScene::Serialize mechanism.

#define CUSTOM_3D_STRING MAKE_CUSTOM_ID('C', 'S', 'S', 'T')
#define CUSTOM_3D_INT MAKE_CUSTOM_ID('C', 'S', 'I', 'T')
C3DScene *C3DCustomFormat::Read(const CXString& filename, CSceneImportOptions& options)
{
IoFile file(IsSilentMode(), IOFILE_MEMORY_FILE);
if (!file.OpenFile(filename, true))
{
io->SetIoError(IO_FILE_CANT_OPEN_FILE, &options, IoLogInfo::LOG_ERROR);
file.CloseFile();
return NULL;
}
// You might exposes some specific controls for the caller. Here is the way to access to your specific data
unsigned int value;
options.GetParserOptions().GetUInt(CUSTOM_3D_INT, value, 0);
options.GetParserOptions().GetString(CUSTOM_3D_STRING, string, CXString());
ioscene = xNew(C3DScene);
CXArchive ar(file.GetCFile(), CXArchive::load);
ioscene->Serialize(ar);
ar.Close();
file.CloseFile();
return ioscene;
}
bool C3DCustomFormat::Save(const CXString& filename, C3DScene *userScene, CSceneExportOptions& options)
{
IoFile iofile(IsSilentMode(), IOFILE_MEMORY_FILE);
if (!iofile.OpenFile(filename, false))
{
io->SetIoError(IO_FILE_CANT_OPEN_FILE, &options, IoLogInfo::LOG_ERROR);
return false;
}
userScene->SetFilename(CXString());
CXArchive ar(iofile.GetCFile(), CXArchive::store);
userScene->Serialize(ar);
ar.Close();
iofile.CloseFile();
return true;
}
CXTString< TCHAR > CXString
CXString depend on the target OS. Could be CXStringW (Windows) or CXStringA (Linux / Macos)
Definition XString.h:118
The class allows to get access to the scene graph, node hierarchy, material.
Definition 3DScene.h:306
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
Definition XArchive.h:17
IoFile is a class for reading binary or ascii file using internally a CStdioFileEx.
Definition IoFile.h:45

Implement a function to initialize / destroy the parser on request

When C3DIo recognized your format extension, it will ask you to create your C3DParser object and once finished to destroy it.

bool Init3DParser(IoPluginMode mode, void *data)
{
switch (mode)
{
case IO_INIT_PLUGIN:
{
}
case IO_GET_PARSER:
{
switch (initParserInfo->fileclass)
{
initParserInfo->parser = xNewParams(C3DCustomFormat, *(initParserInfo->io));
break;
}
break;
}
}
return TRUE;
}
Definition Plugins.h:20

Register your parser and extension

You have to inform the SDK that a new extension is recognized. You have to give your extension a file class and give some information about what the parser does.

ext.description = "My custom 3D files"; // The parser name
ext.ext = ".mesh1|.mesh2"; // your 3d parser extensions
ext.fileclass = MAKE_CUSTOM_ID('C', 'S', 'T', 'M');
ext.properties = IMPORT_FILE | EXPORT_FILE | OBJECT_FILE | COMMON_EXTENSION_FILE | LOAD_HAS_DIALOG;
ext.iocallback = Init3DParser;
ext.loader = CALLBACK_PARSER; // Means that Init3DParser will be called when loading...
ext.saver = CALLBACK_PARSER; // ... and writing
fileRegisterFile(ext);
CFileExt is the class that allows to add a custom file parser for supporting a new file format....
Definition FileInfo.h:182
unsigned int fileclass
A tag created with MAKE_CUSTOM_ID.
Definition FileInfo.h:186
InitIOPluginFunc iocallback
The function which allows to create parser.
Definition FileInfo.h:194
unsigned int properties
Definition FileInfo.h:187
unsigned int saver
Inform about the file saver: MOOTOOLS_PARSER, PLUGIN_PARSER, CALLBACK_PARSER or something else (ie....
Definition FileInfo.h:193
unsigned int loader
Definition FileInfo.h:192