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

◆ GltfWriteSample()

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

◆ GltfwTwoMeshes()

Dtk_ErrorStatus GltfwTwoMeshes ( const Dtk_string outputFileName)
14 { // SAMPLE 1
15  Dtk_MeshPtr CubeMesh, CylinderMesh;
16  Dtk_bool useless; // useless for this sample
17  // Cube Sample
18  CubeMesh = sampleWriter::CreateMeshCube();
19  // Cylinder Sample
20  CylinderMesh = sampleWriter::CreateMeshCylinder( 30 );
21 
23  // First we initialize writing with name of files and protection fonction if needed (3rd parameter)
24  Dtk_GltfWriter GW( outputFileName, err );
25  if( err != dtkNoError )
26  return err;
27 
28  // Rootnode creation
29  GW.OpenInstance( "RootNode", -1, useless );
30 
31  // from this node, create a Child for the cube, and naming it "Cube"
32  GW.OpenInstance( "Cube", -1, useless );
33  // write the cube
34  GW.WriteMesh( CubeMesh );
35 
36  // close the cube node
37  GW.CloseLastInstance();
38 
39  // from root node again, create a Child for the cylinder, and naming it "Cylinder"
40  GW.OpenInstance( "Cylinder", -1, useless );
41  // write the cube
42  GW.WriteMesh( CylinderMesh );
43  // close the cube node
44  GW.CloseLastInstance();
45 
46  // Rootnode closing.
47  GW.CloseLastInstance();
48 
49  return dtkNoError;
50 }
Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
sampleWriter::CreateMeshCube
Dtk_MeshPtr CreateMeshCube()
Mesh Cube sample.
Definition: testcreatemesh.cpp:204
Dtk_GltfWriter
GLTF Writer main class.
Definition: gltfw.hpp:22
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
Dtk_bool
char Dtk_bool
Definition: define.h:728
sampleWriter::CreateMeshWire
Dtk_MeshPtr CreateMeshWire()
Wire mesh sample.
Definition: testcreatemesh.cpp:385
GltfwTwoMeshes
Dtk_ErrorStatus GltfwTwoMeshes(const Dtk_string &outputFileName)
Definition: testlibgltfwrite.cpp:13
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:334
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:53
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:147
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:14