DATAKIT SDK  V2026.4
testlibcolladawrite.cpp File Reference

Functions

DtkErrorStatus ColladaWriteSample (const Dtk_string &inResultDirectory)
 Entry point: writes cube, cylinder, wireframe meshes with render infos and model display views into sample.dae. More...
 

Function Documentation

◆ ColladaWriteSample()

DtkErrorStatus ColladaWriteSample ( const Dtk_string &  inResultDirectory)

Entry point: writes cube, cylinder, wireframe meshes with render infos and model display views into sample.dae.

15 {
16  Dtk_ErrorStatus errorStatus = dtkNoError;
17  DtkErrorStatus status;
18  Dtk_MeshPtr cubeMesh = NULL;
19  Dtk_MeshPtr cubeMeshVC = NULL;
20  Dtk_MeshPtr cylinderMesh = NULL;
21  Dtk_MeshPtr wireMesh = NULL;
22  Dtk_ModelDisplayPtr modelDisplay = NULL;
23  Dtk_RenderInfosPtr renderInfos = NULL;
24  Dtk_string outputFileName, outputDirectory;
25  Dtk_string nodeName;
26  Dtk_tab<Dtk_MetaDataPtr> tabMetadata;
27  Dtk_tab<Dtk_ID> tabNodesView1;
28  Dtk_tab<Dtk_ID> tabNodesView2;
29  Dtk_tab<Dtk_ID> tabNodesView3;
30  Dtk_tab< Dtk_tab <Dtk_ID> > tabNodesViews;
31  Dtk_ID nodeID = 0;
32  Dtk_bool reinstanciate = DTK_TRUE;
33  Dtk_InfoPtr info;
34 
35  std::cout << std::endl << "----------------------------------------------" << std::endl;
36  std::cout << "Collada Write start" << std::endl;
37 
38  // Choosing output directory and file name
39  outputDirectory = inResultDirectory + L"Collada/";
40  outputDirectory.FixPathSeparator();
41  outputDirectory.mkdir();
42  outputFileName = outputDirectory + L"sample.dae";
43 
44  // Cube Sample
45  cubeMesh = sampleWriter::CreateMeshCube();
47 
48  // Cylinder Sample
49  cylinderMesh = sampleWriter::CreateMeshCylinder( 30 );
50 
51  //RenderInfos Sample
53 
54  // First we initialize writing
55  Colladaw::WriteOptions options;
56  options.ConvertRenderInfos = 1;
57 
58  status = Colladaw::InitWrite( outputFileName, Dtk_string( "testcolladaw.log" ), options );
59 
60  if( status != 0 )
61  {
62  errorStatus = Colladaw::EndWrite();
63  std::cout << "error : " << dtkTypeError( status ).c_str() << std::endl;
64  return status;
65  }
66 
67  // Lets write a small assembly composed by one cube and one cylinder
68 
69  // let a matrix moving the cube on the left
70  Dtk_transfo cubetransfo;
71  cubetransfo.addTranslate( Dtk_dir( -10, 0, 0 ) );
72 
73  // let a matrix moving the cylinder
74  Dtk_transfo cyltransfo;
75  cyltransfo.addTranslate( Dtk_dir( 10, 0, 0 ) );
76 
77  // let a matrix moving the first instance
78  Dtk_transfo transfo;
79  transfo.addTranslate( Dtk_dir( 100, 100, 100 ) );
80  transfo.setXdir( 0.0, 1.0, 0.0 );
81  transfo.setYdir( 0.0, 0.0, 1.0 );
82  transfo.setZdir( 1.0, 0.0, 0.0 );
83 
84  // Rootnode creation
85  if( errorStatus == dtkNoError )
86  {
87  nodeName = "RootNode";
88  errorStatus = Colladaw::InitNode( nodeName );
89  }
90  // Facetted data node creation
91  if( errorStatus == dtkNoError )
92  {
93  nodeName = "Facetted data";
94  info = Dtk_Info::Create();
95  errorStatus = Colladaw::InitNode( nodeName, Dtk_transfo(), info, nodeID );
96  }
97 
98  // from this node, create a Child for the cube, giving its matrix, and naming it "Cube"
99  if( errorStatus == dtkNoError )
100  {
101  nodeName = "Cube";
102  errorStatus = Colladaw::InitNode( nodeName, cubetransfo );
103  }
104  cubeMesh->info() = Dtk_Info::Create();
105  cubeMesh->info()->AddRenderInfos( renderInfos );
106  // Write the mesh cube
107  if( errorStatus == dtkNoError )
109  // Close the mesh cube node
110  if( errorStatus == dtkNoError )
111  errorStatus = Colladaw::EndNode();
112 
113  // From root node again, create a Child for the cylinder, giving its matrix, and naming it "Cylinder"
114  if( errorStatus == dtkNoError )
115  {
116  nodeName = "Cylinder";
117  errorStatus = Colladaw::InitNode( nodeName, cyltransfo );
118  }
119  // Write the mesh cylinder
120  if( errorStatus == dtkNoError )
121  errorStatus = Colladaw::WriteEntity( Dtk_EntityPtr::DtkDynamicCast( cylinderMesh ) );
122  // Close the mesh cylinder
123  if( errorStatus == dtkNoError )
124  errorStatus = Colladaw::EndNode();
125  // Close the facetted data node
126  if( errorStatus == dtkNoError )
127  errorStatus = Colladaw::EndNode();
128 
129  if( reinstanciate )
130  {
131  // "Facetted data (Reinstanciated)" creation
132  if( errorStatus == dtkNoError )
133  {
134  nodeName = "Facetted data (Reinstanciated)";
135  errorStatus = Colladaw::InitNode( nodeName, transfo );
136  }
137  // Reinstanciating prototype nodeID
138  if( errorStatus == dtkNoError )
139  errorStatus = Colladaw::ReinstanciatePrototype( nodeID );
140  // Closing node
141  if( errorStatus == dtkNoError )
142  errorStatus = Colladaw::EndNode();
143  }
144  // Rootnode closing : VERY IMPORTANT, you must close all nodes that were opened.
145  if( errorStatus == dtkNoError )
146  errorStatus = Colladaw::EndNode();
147  // And free memory allocated for writing
148  if( errorStatus == dtkNoError )
149  errorStatus = Colladaw::EndWrite();
150 
151  std::cout << "=> " << outputFileName.c_str() << std::endl << "Collada Write end" << std::endl;
152 
153  return errorStatus;
154 }
Dtk_Info::Create
static Dtk_SmartPtr< Dtk_Info > Create()
Calls default constructor to allocate a new object.
Dtk_ID
uint32_t Dtk_ID
Definition: define.h:688
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
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:726
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
Dtk_bool
char Dtk_bool
Definition: define.h:724
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:244
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()
Creates a Dtk_RenderInfos object with ambient, diffuse, and specular lighting and a texture for use o...
Definition: testcreatemesh.cpp:501
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_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:151
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