DATAKIT SDK  V2026.1
testlibcolladawrite.cpp File Reference

Functions

int ColladaWriteSample (const Dtk_string &inResultDirectory)
 

Function Documentation

◆ ColladaWriteSample()

int ColladaWriteSample ( const Dtk_string inResultDirectory)
12 {
14  int status;
15  Dtk_MeshPtr cubeMesh = NULL;
16  Dtk_MeshPtr cubeMeshVC = NULL;
17  Dtk_MeshPtr cylinderMesh = NULL;
18  Dtk_MeshPtr wireMesh = NULL;
19  Dtk_ModelDisplayPtr modelDisplay = NULL;
20  Dtk_RenderInfosPtr renderInfos = NULL;
21  Dtk_string outputFileName, outputDirectory;
22  Dtk_string nodeName;
23  Dtk_tab<Dtk_MetaDataPtr> tabMetadata;
24  Dtk_tab<Dtk_ID> tabNodesView1;
25  Dtk_tab<Dtk_ID> tabNodesView2;
26  Dtk_tab<Dtk_ID> tabNodesView3;
27  Dtk_tab< Dtk_tab <Dtk_ID> > tabNodesViews;
28  Dtk_ID nodeID = 0;
29  Dtk_bool reinstanciate = DTK_TRUE;
30  Dtk_InfoPtr info;
31 
32  cout << endl << "----------------------------------------------" << endl;
33  cout << "Collada Write start" << endl;
34 
35  // Choosing output directory and file name
36  outputDirectory = inResultDirectory + L"Collada/";
37  outputDirectory.FixPathSeparator();
38  outputDirectory.mkdir();
39  outputFileName = outputDirectory + L"sample.dae";
40 
41  // Cube Sample
42  cubeMesh = sampleWriter::CreateMeshCube();
44 
45  // Cylinder Sample
46  cylinderMesh = sampleWriter::CreateMeshCylinder( 30 );
47 
48  //RenderInfos Sample
50 
51  // First we initialize writing
52  Colladaw::WriteOptions options;
53  options.ConvertRenderInfos = 1;
54 
55  status = Colladaw::InitWrite( outputFileName, Dtk_string( "testcolladaw.log" ), options );
56 
57  if( status != 0 )
58  {
59  err = Colladaw::EndWrite();
60  cout << "error : " << dtkTypeError( status ).c_str() << endl;
61  return status;
62  }
63 
64  // Lets write a small assembly composed by one cube and one cylinder
65 
66  // let a matrix moving the cube on the left
67  Dtk_transfo cubetransfo;
68  cubetransfo.addTranslate( Dtk_dir( -10, 0, 0 ) );
69 
70  // let a matrix moving the cylinder
71  Dtk_transfo cyltransfo;
72  cyltransfo.addTranslate( Dtk_dir( 10, 0, 0 ) );
73 
74  // let a matrix moving the first instance
75  Dtk_transfo transfo;
76  transfo.addTranslate( Dtk_dir( 100, 100, 100 ) );
77  transfo.setXdir( 0.0, 1.0, 0.0 );
78  transfo.setYdir( 0.0, 0.0, 1.0 );
79  transfo.setZdir( 1.0, 0.0, 0.0 );
80 
81  // Rootnode creation
82  if( err == dtkNoError )
83  {
84  nodeName = "RootNode";
85  err = Colladaw::InitNode( nodeName );
86  }
87  // Facetted data node creation
88  if( err == dtkNoError )
89  {
90  nodeName = "Facetted data";
91  info = Dtk_Info::create();
92  err = Colladaw::InitNode( nodeName, Dtk_transfo(), info, nodeID );
93  }
94 
95  // from this node, create a Child for the cube, giving its matrix, and naming it "Cube"
96  if( err == dtkNoError )
97  {
98  nodeName = "Cube";
99  err = Colladaw::InitNode( nodeName, cubetransfo );
100  }
101  cubeMesh->info() = Dtk_Info::create();
102  cubeMesh->info()->AddRenderInfos( renderInfos );
103  // Write the mesh cube
104  if( err == dtkNoError )
106  // Close the mesh cube node
107  if( err == dtkNoError )
108  err = Colladaw::EndNode();
109 
110  // From root node again, create a Child for the cylinder, giving its matrix, and naming it "Cylinder"
111  if( err == dtkNoError )
112  {
113  nodeName = "Cylinder";
114  err = Colladaw::InitNode( nodeName, cyltransfo );
115  }
116  // Write the mesh cylinder
117  if( err == dtkNoError )
118  err = Colladaw::WriteEntity( Dtk_EntityPtr::DtkDynamicCast( cylinderMesh ) );
119  // Close the mesh cylinder
120  if( err == dtkNoError )
121  err = Colladaw::EndNode();
122  // Close the facetted data node
123  if( err == dtkNoError )
124  err = Colladaw::EndNode();
125 
126  if( reinstanciate )
127  {
128  // "Facetted data (Reinstanciated)" creation
129  if( err == dtkNoError )
130  {
131  nodeName = "Facetted data (Reinstanciated)";
132  err = Colladaw::InitNode( nodeName, transfo );
133  }
134  // Reinstanciating prototype nodeID
135  if( err == dtkNoError )
136  err = Colladaw::ReinstanciatePrototype( nodeID );
137  // Closing node
138  if( err == dtkNoError )
139  err = Colladaw::EndNode();
140  }
141  // Rootnode closing : VERY IMPORTANT, you must close all nodes that were opened.
142  if( err == dtkNoError )
143  err = Colladaw::EndNode();
144  // And free memory allocated for writing
145  if( err == dtkNoError )
146  err = Colladaw::EndWrite();
147 
148  cout << "=> " << outputFileName.c_str() << endl << "Collada Write end" << endl;
149 
150  return err;
151 }
Dtk_ID
uint32_t Dtk_ID
Definition: define.h:692
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
Colladaw::EndNode
DtkErrorStatus EndNode()
End the node.
Dtk_transfo::setZdir
void setZdir(const Dtk_dir &Z)
Set a new Z vector.
Colladaw::InitWrite
DtkErrorStatus InitWrite(const Dtk_string &inOutputFile, const Dtk_string &inLogFile, WriteOptions &inOptions)
Initialize the Collada Writer
DTK_TRUE
#define DTK_TRUE
Definition: define.h:730
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
Dtk_bool
char Dtk_bool
Definition: define.h:728
Colladaw::EndWrite
DtkErrorStatus EndWrite()
Creation of the output file and free the Collada Writer
Dtk_transfo::setXdir
void setXdir(const Dtk_dir &X)
Set a new X vector.
sampleWriter::FillFacesColors
void FillFacesColors(Dtk_MeshPtr &inoutCubeMesh)
Filling mesh faces with colors.
Definition: testcreatemesh.cpp:241
Colladaw::WriteOptions
This class provides several options to tune Collada Writer. It must be provided to Colladaw::InitWrit...
Definition: colladaw.hpp:23
Colladaw::WriteOptions::ConvertRenderInfos
Dtk_bool ConvertRenderInfos
Definition: colladaw.hpp:33
Dtk_SmartPtr< Dtk_Entity >::DtkDynamicCast
static Dtk_SmartPtr< Dtk_Entity > DtkDynamicCast(const Dtk_SmartPtr< T2 > &p)
Definition: util_ptr_dtk.hpp:101
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
sampleWriter::CreateCubeRenderInfos
Dtk_RenderInfosPtr CreateCubeRenderInfos()
Definition: testcreatemesh.cpp:495
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_transfo::setYdir
void setYdir(const Dtk_dir &Y)
Set a new Y vector.
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 ...
Colladaw::ReinstanciatePrototype
DtkErrorStatus ReinstanciatePrototype(Dtk_ID inID)
Reinstanciate a node.
Dtk_tab
This is a high level array class.
Definition: util_stl_dtk.hpp:84
Dtk_transfo::addTranslate
void addTranslate(const Dtk_dir &V)
Translate the Dtk_transfo.
Colladaw::InitNode
DtkErrorStatus InitNode(Dtk_string &inNodeName, const Dtk_transfo &inTransfo, Dtk_InfoPtr &inInfo, Dtk_ID &outID)
Initialize a node.
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:147
Dtk_Info::create
static Dtk_SmartPtr< Dtk_Info > create()
Calls default constructor to allocate a new object.
Colladaw::WriteEntity
Dtk_ErrorStatus WriteEntity(const Dtk_EntityPtr &inEntity)
Write the entity provided in parameter in a node.
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:14