DATAKIT SDK  V2026.4
testlibfbxwrite.cpp File Reference

Functions

Dtk_ErrorStatus FbxwInstances (const Dtk_string &inOutputFileName)
 Sample 2: writes 10 re-instanced cubes into an FBX file, demonstrating geometry instancing via repeated OpenInstance IDs. More...
 
DtkErrorStatus FbxWriteSample (const Dtk_string &inResultDirectory)
 
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. More...
 

Function Documentation

◆ FbxwInstances()

Dtk_ErrorStatus FbxwInstances ( const Dtk_string &  inOutputFileName)

Sample 2: writes 10 re-instanced cubes into an FBX file, demonstrating geometry instancing via repeated OpenInstance IDs.

58 { // SAMPLE 2
59  Dtk_MeshPtr CubeMesh;
60  // Cube Sample
61  CubeMesh = sampleWriter::CreateMeshCube();
62  Dtk_transfo cubetransfo;
63  Dtk_bool useless, wasreinstancied; // useless for this sample
64 
65  // For this sample, i will write 10 instances of cube.
66  // the matrix given is shifted in all iterations
67  // Inside the for below, we give an ID to OpenInstance. Then we add the cube, and close the child.
68  // 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.
69  DtkErrorStatus errorStatus = dtkNoError;
70  // First we initialize writing with name of files and protection fonction if needed (3rd parameter)
71  Dtk_FBXWriter fbxWriter( inOutputFileName, errorStatus );
72  if( errorStatus != dtkNoError )
73  return errorStatus;
74  fbxWriter.OpenInstance( "RootNode", -1, useless );
75  int instanceIdx;
76  for( instanceIdx = 0; instanceIdx < 10; instanceIdx++ )
77  {
78  fbxWriter.OpenInstance( "Cube", 1, wasreinstancied, cubetransfo ); // Giving ID 1
79  if( !wasreinstancied )
80  {
81  fbxWriter.WriteMesh( CubeMesh );
82  }
83  fbxWriter.CloseLastInstance();
84  cubetransfo.addTranslate( Dtk_dir( 10, 0, 0 ) ); // shift matrix.
85  }
86  fbxWriter.CloseLastInstance();
87  return dtkNoError;
88 }

◆ FbxWriteSample()

DtkErrorStatus FbxWriteSample ( const Dtk_string &  inResultDirectory)
92 {
93  Dtk_string outputDirectory, fileName;
94  std::cout << std::endl << "----------------------------------------------" << std::endl;
95 
96  // Choosing output directory and file name
97  outputDirectory = inResultDirectory + L"Fbx/";
98  outputDirectory.FixPathSeparator();
99  outputDirectory.mkdir();
100 
101  std::cout << "Fbx Write start" << std::endl;
102  // sample 1 : just wirte 2 meshes
103  fileName = outputDirectory + L"twomeshes.fbx";
104  Dtk_ErrorStatus errorStatus = FbxwTwoMeshes( fileName );
105  if( errorStatus == dtkNoError )
106  std::cout << "=> " << fileName.c_str() << std::endl;
107  else
108  std::cout << "error : " << dtkTypeError( errorStatus ).c_str() << std::endl;
109 
110  // sample 2 : write instances
111  fileName = outputDirectory + L"twomeshes.fbx";
112  errorStatus = FbxwInstances( fileName );
113  if( errorStatus == dtkNoError )
114  std::cout << "=> " << fileName.c_str() << std::endl;
115  else
116  std::cout << "error : " << dtkTypeError( errorStatus ).c_str() << std::endl;
117 
118  std::cout << "Fbx Write end" << std::endl;
119 
120  return errorStatus;
121 }

◆ 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.

16 { // SAMPLE 1
17  Dtk_MeshPtr CubeMesh, CylinderMesh;
18  Dtk_bool useless; // useless for this sample
19  // Cube Sample
20  CubeMesh = sampleWriter::CreateMeshCube();
21  // Cylinder Sample
22  CylinderMesh = sampleWriter::CreateMeshCylinder( 30 );
23 
24  DtkErrorStatus errorStatus = dtkNoError;
25  // First we initialize writing with name of files and protection fonction if needed (3rd parameter)
26  Dtk_FBXWriter fbxWriter( inOutputFileName, errorStatus );
27  if( errorStatus != dtkNoError )
28  return errorStatus;
29 
30  // Rootnode creation
31  fbxWriter.OpenInstance( "RootNode", -1, useless );
32 
33  // from this node, create a Child for the cube, and naming it "Cube"
34  fbxWriter.OpenInstance( "Cube", -1, useless );
35  // write the cube
36  fbxWriter.WriteMesh( CubeMesh );
37 
38  // close the cube node
39  fbxWriter.CloseLastInstance();
40 
41  // from root node again, create a Child for the cylinder, and naming it "Cylinder"
42  fbxWriter.OpenInstance( "Cylinder", -1, useless );
43  // write the cube
44  fbxWriter.WriteMesh( CylinderMesh );
45  // close the cube node
46  fbxWriter.CloseLastInstance();
47 
48  // Rootnode closing.
49  fbxWriter.CloseLastInstance();
50 
51  // CLeaning class save file
52  return dtkNoError;
53 }
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
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