DATAKIT SDK  V2026.4
FBX Write Sample
//start_of_mainfbxmeshwritemain
//! \brief Sample 1: writes a cube and a cylinder mesh in a two-node hierarchy into an FBX file.
Dtk_ErrorStatus FbxwTwoMeshes( const Dtk_string& inOutputFileName )
{ // SAMPLE 1
Dtk_MeshPtr CubeMesh, CylinderMesh;
Dtk_bool useless; // useless for this sample
// Cube Sample
// Cylinder Sample
CylinderMesh = sampleWriter::CreateMeshCylinder( 30 );
DtkErrorStatus errorStatus = dtkNoError;
// First we initialize writing with name of files and protection fonction if needed (3rd parameter)
Dtk_FBXWriter fbxWriter( inOutputFileName, errorStatus );
if( errorStatus != dtkNoError )
return errorStatus;
// Rootnode creation
fbxWriter.OpenInstance( "RootNode", -1, useless );
// from this node, create a Child for the cube, and naming it "Cube"
fbxWriter.OpenInstance( "Cube", -1, useless );
// write the cube
fbxWriter.WriteMesh( CubeMesh );
// close the cube node
fbxWriter.CloseLastInstance();
// from root node again, create a Child for the cylinder, and naming it "Cylinder"
fbxWriter.OpenInstance( "Cylinder", -1, useless );
// write the cube
fbxWriter.WriteMesh( CylinderMesh );
// close the cube node
fbxWriter.CloseLastInstance();
// Rootnode closing.
fbxWriter.CloseLastInstance();
// CLeaning class save file
return dtkNoError;
}
//! \brief Sample 2: writes 10 re-instanced cubes into an FBX file, demonstrating geometry instancing via repeated OpenInstance IDs.
Dtk_ErrorStatus FbxwInstances( const Dtk_string& inOutputFileName )
{ // SAMPLE 2
Dtk_MeshPtr CubeMesh;
// Cube Sample
Dtk_transfo cubetransfo;
Dtk_bool useless, wasreinstancied; // useless for this sample
// For this sample, i will write 10 instances of cube.
// the matrix given is shifted in all iterations
// Inside the for below, we give an ID to OpenInstance. Then we add the cube, and close the child.
// For all others instances, we give the same ID to OpenInstance, and just close the child. Fbx Writer will recognize the ID and automatic reinstance the cube with another matrix.
DtkErrorStatus errorStatus = dtkNoError;
// First we initialize writing with name of files and protection fonction if needed (3rd parameter)
Dtk_FBXWriter fbxWriter( inOutputFileName, errorStatus );
if( errorStatus != dtkNoError )
return errorStatus;
fbxWriter.OpenInstance( "RootNode", -1, useless );
int instanceIdx;
for( instanceIdx = 0; instanceIdx < 10; instanceIdx++ )
{
fbxWriter.OpenInstance( "Cube", 1, wasreinstancied, cubetransfo ); // Giving ID 1
if( !wasreinstancied )
{
fbxWriter.WriteMesh( CubeMesh );
}
fbxWriter.CloseLastInstance();
cubetransfo.addTranslate( Dtk_dir( 10, 0, 0 ) ); // shift matrix.
}
fbxWriter.CloseLastInstance();
return dtkNoError;
}
FbxWriteSample( const Dtk_string &inResultDirectory )
{
Dtk_string outputDirectory, fileName;
std::cout << std::endl << "----------------------------------------------" << std::endl;
// Choosing output directory and file name
outputDirectory = inResultDirectory + L"Fbx/";
outputDirectory.FixPathSeparator();
outputDirectory.mkdir();
std::cout << "Fbx Write start" << std::endl;
// sample 1 : just wirte 2 meshes
fileName = outputDirectory + L"twomeshes.fbx";
Dtk_ErrorStatus errorStatus = FbxwTwoMeshes( fileName );
if( errorStatus == dtkNoError )
std::cout << "=> " << fileName.c_str() << std::endl;
else
std::cout << "error : " << dtkTypeError( errorStatus ).c_str() << std::endl;
// sample 2 : write instances
fileName = outputDirectory + L"twomeshes.fbx";
errorStatus = FbxwInstances( fileName );
if( errorStatus == dtkNoError )
std::cout << "=> " << fileName.c_str() << std::endl;
else
std::cout << "error : " << dtkTypeError( errorStatus ).c_str() << std::endl;
std::cout << "Fbx Write end" << std::endl;
return errorStatus;
}
//end_of_mainfbxmeshwrite
Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
FbxwTwoMeshes
Dtk_ErrorStatus FbxwTwoMeshes(const Dtk_string &inOutputFileName)
Sample 1: writes a cube and a cylinder mesh in a two-node hierarchy into an FBX file.
Definition: testlibfbxwrite.cpp:15
sampleWriter::CreateMeshCube
Dtk_MeshPtr CreateMeshCube()
Mesh Cube sample.
Definition: testcreatemesh.cpp:207
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
Dtk_bool
char Dtk_bool
Definition: define.h:724
Dtk_FBXWriter
FBX Writer main class.
Definition: fbxw.hpp:10
FbxWriteSample
DtkErrorStatus FbxWriteSample(const Dtk_string &inResultDirectory)
Definition: testlibfbxwrite.cpp:91
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
Dtk_SmartPtr
Definition: util_ptr_dtk.hpp:37
dtkTypeError
Dtk_string dtkTypeError(Dtk_Int32 errNumero)
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
sampleWriter::CreateMeshCylinder
Dtk_MeshPtr CreateMeshCylinder(int nbpoints)
Mesh Cylinder sample.
Definition: testcreatemesh.cpp:338
Dtk_string::mkdir
int mkdir() const
File Utility : Create a Directory.
Dtk_string::FixPathSeparator
void FixPathSeparator()
File Utility : Fixes path separator consistency. It lets you replace the '\' or '/' by the OS needed ...
Dtk_transfo::addTranslate
void addTranslate(const Dtk_dir &V)
Translate the Dtk_transfo.
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:151
FbxwInstances
Dtk_ErrorStatus FbxwInstances(const Dtk_string &inOutputFileName)
Sample 2: writes 10 re-instanced cubes into an FBX file, demonstrating geometry instancing via repeat...
Definition: testlibfbxwrite.cpp:57
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:14