DATAKIT API  V2025.1
testlibfbxwrite.cpp File Reference

Functions

Dtk_ErrorStatus FbxwInstances (const Dtk_string &outputFileName)
 
int FbxWriteSample (const Dtk_string &inResultDirectory)
 
Dtk_ErrorStatus FbxwTwoMeshes (const Dtk_string &outputFileName)
 

Function Documentation

◆ FbxwInstances()

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

◆ FbxWriteSample()

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

◆ FbxwTwoMeshes()

Dtk_ErrorStatus FbxwTwoMeshes ( const Dtk_string outputFileName)
18 { // SAMPLE 1
19  Dtk_MeshPtr CubeMesh, CylinderMesh;
20  Dtk_bool useless; // useless for this sample
21  // Cube Sample
22  CubeMesh = sampleWriter::CreateMeshCube();
23  // Cylinder Sample
24  CylinderMesh = sampleWriter::CreateMeshCylinder( 30 );
25 
27  // First we initialize writing with name of files and protection fonction if needed (3rd parameter)
28  Dtk_FBXWriter Fb( outputFileName, err );
29  if( err != dtkNoError )
30  return err;
31 
32  // Rootnode creation
33  Fb.OpenInstance( "RootNode", -1, useless );
34 
35  // from this node, create a Child for the cube, and naming it "Cube"
36  Fb.OpenInstance( "Cube", -1, useless );
37  // write the cube
38  Fb.WriteMesh( CubeMesh );
39 
40  // close the cube node
41  Fb.CloseLastInstance();
42 
43  // from root node again, create a Child for the cylinder, and naming it "Cylinder"
44  Fb.OpenInstance( "Cylinder", -1, useless );
45  // write the cube
46  Fb.WriteMesh( CylinderMesh );
47  // close the cube node
48  Fb.CloseLastInstance();
49 
50  // Rootnode closing.
51  Fb.CloseLastInstance();
52 
53  // CLeaning class save file
54  return dtkNoError;
55 }
Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
sampleWriter::CreateMeshCube
Dtk_MeshPtr CreateMeshCube()
Mesh Cube sample.
Definition: testcreatemesh.cpp:207
FbxwInstances
Dtk_ErrorStatus FbxwInstances(const Dtk_string &outputFileName)
Definition: testlibfbxwrite.cpp:58
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:58
Dtk_bool
char Dtk_bool
Definition: define.h:725
Dtk_FBXWriter
FBX Writer main class.
Definition: fbxw.hpp:10
FbxwTwoMeshes
Dtk_ErrorStatus FbxwTwoMeshes(const Dtk_string &outputFileName)
Definition: testlibfbxwrite.cpp:17
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:337
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:140
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:15