DATAKIT API  V2025.1
testlibgltfwrite.cpp File Reference

Functions

Dtk_ErrorStatus GltfwInstances (const Dtk_string &outputFileName)
 
int GltfWriteSample (const Dtk_string &inResultDirectory)
 
Dtk_ErrorStatus GltfwTwoMeshes (const Dtk_string &outputFileName)
 

Function Documentation

◆ GltfwInstances()

Dtk_ErrorStatus GltfwInstances ( const Dtk_string outputFileName)
58 { // SAMPLE 2
59  Dtk_MeshPtr CubeMesh;
60  // Cube Sample
61  CubeMesh = sampleWriter::CreateMeshCube();
62  Dtk_transfo cubetransfo;
63  Dtk_bool useless, isNewNode; // useless pour this sample
64 
65  // For this sample, we 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. Gltf Writer will recognize the ID and automatic reinstance the cube with another matrix.
70  // First we initialize writing with name of files and protection fonction if needed (3rd parameter)
71  Dtk_GltfWriter GW( outputFileName, err );
72  if( err != dtkNoError )
73  return err;
74  GW.OpenInstance( "RootNode", -1, useless );
75  int i;
76  for( i = 0; i < 10; i++ )
77  {
78  GW.OpenInstance( "Cube", 1, isNewNode, cubetransfo ); // Giving ID 1
79  if( isNewNode )
80  {
81  GW.WriteMesh( CubeMesh );
82  }
83  GW.CloseLastInstance();
84  cubetransfo.addTranslate( Dtk_dir( 10, 0, 0 ) ); // shift matrix.
85  }
86  GW.CloseLastInstance();
87  return dtkNoError;
88 }

◆ GltfWriteSample()

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

◆ GltfwTwoMeshes()

Dtk_ErrorStatus GltfwTwoMeshes ( 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_GltfWriter GW( outputFileName, err );
29  if( err != dtkNoError )
30  return err;
31 
32  // Rootnode creation
33  GW.OpenInstance( "RootNode", -1, useless );
34 
35  // from this node, create a Child for the cube, and naming it "Cube"
36  GW.OpenInstance( "Cube", -1, useless );
37  // write the cube
38  GW.WriteMesh( CubeMesh );
39 
40  // close the cube node
41  GW.CloseLastInstance();
42 
43  // from root node again, create a Child for the cylinder, and naming it "Cylinder"
44  GW.OpenInstance( "Cylinder", -1, useless );
45  // write the cube
46  GW.WriteMesh( CylinderMesh );
47  // close the cube node
48  GW.CloseLastInstance();
49 
50  // Rootnode closing.
51  GW.CloseLastInstance();
52 
53  return dtkNoError;
54 }
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
Dtk_GltfWriter
GLTF Writer main class.
Definition: gltfw.hpp:22
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:58
Dtk_bool
char Dtk_bool
Definition: define.h:725
GltfwTwoMeshes
Dtk_ErrorStatus GltfwTwoMeshes(const Dtk_string &outputFileName)
Definition: testlibgltfwrite.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.
GltfwInstances
Dtk_ErrorStatus GltfwInstances(const Dtk_string &outputFileName)
Definition: testlibgltfwrite.cpp:57
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:140
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:15