TDME2  1.9.200
DAEReader.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <string>
5 #include <vector>
6 
7 #include <tdme/tdme.h>
11 #include <tdme/engine/Color4.h>
14 
17 
18 #include <ext/tinyxml/tinyxml.h>
19 
20 using std::map;
21 using std::string;
22 using std::vector;
23 
31 
33 
34 /**
35  * Collada DAE model reader
36  * @author Andreas Drewke
37  */
39 {
40 
41 private:
43  static constexpr float BLENDER_AMBIENT_FROM_DIFFUSE_SCALE { 0.7f };
44  static constexpr float BLENDER_DIFFUSE_SCALE { 0.8f };
45 
46 public:
47 
48  /**
49  * Reads Collada DAE file
50  * @param pathName path name
51  * @param fileName file name
52  * @param useBC7TextureCompression use BC7 texture compression
53  * @throws tdme::engine::fileio::models::ModelFileIOException
54  * @throws tdme::os::filesystem::FileSystemException
55  * @return model instance
56  */
57  static Model* read(const string& pathName, const string& fileName, bool useBC7TextureCompression = true);
58 
59 private:
60 
61  /**
62  * Get authoring tool
63  * @param xmlRoot xml root
64  * @return authoring tool
65  */
66  static Model::AuthoringTool getAuthoringTool(TiXmlElement* xmlRoot);
67 
68  /**
69  * Get Up vector
70  * @param xmlRoot xml root
71  * @return up vector
72  * @throws tdme::engine::fileio::models::ModelFileIOException
73  */
74  static UpVector* getUpVector(TiXmlElement* xmlRoot);
75 
76  /**
77  * Set up model import rotation matrix
78  * @param xmlRoot xml root
79  * @param model model
80  */
81  static void setupModelImportRotationMatrix(TiXmlElement* xmlRoot, Model* model);
82 
83  /**
84  * Set up model import scale matrix
85  * @param xmlRoot xml root
86  * @param model model
87  */
88  static void setupModelImportScaleMatrix(TiXmlElement* xmlRoot, Model* model);
89 
90  /**
91  * Read a DAE visual scene node
92  * @param pathName path name
93  * @param model model
94  * @param parentNode parent node
95  * @param xmlRoot xml node
96  * @param xmlNode xml root
97  * @param fps frames per second
98  * @param useBC7TextureCompression use BC7 texture compression
99  * @return node
100  */
101  static Node* readVisualSceneNode(const string& pathName, Model* model, Node* parentNode, TiXmlElement* xmlRoot, TiXmlElement* xmlNode, float fps, bool useBC7TextureCompression);
102 
103  /**
104  * Reads a DAE visual scene node node
105  * @param pathName path name
106  * @param model model
107  * @param parentNode parent node
108  * @param xmlRoot xml node
109  * @param xmlNode xml root
110  * @param fps frames per seconds
111  * @param useBC7TextureCompression use BC7 texture compression
112  * @throws tdme::engine::fileio::models::ModelFileIOException
113  * @return node
114  */
115  static Node* readNode(const string& pathName, Model* model, Node* parentNode, TiXmlElement* xmlRoot, TiXmlElement* xmlNode, float fps, bool useBC7TextureCompression);
116 
117  /**
118  * Reads a instance controller
119  * @param pathName path name
120  * @param model model
121  * @param parentNode parent node
122  * @param xmlRoot xml root
123  * @param xmlNode xml node
124  * @param useBC7TextureCompression use BC7 texture compression
125  * @throws tdme::engine::fileio::models::ModelFileIOException
126  * @return Node
127  * @throws tdme::utilities::Exception
128  */
129  static Node* readVisualSceneInstanceController(const string& pathName, Model* model, Node* parentNode, TiXmlElement* xmlRoot, TiXmlElement* xmlNode, bool useBC7TextureCompression);
130 
131  /**
132  * Reads a geometry
133  * @param pathName path name
134  * @param model model
135  * @param node node
136  * @param xmlRoot xml root
137  * @param xmlNodeId xml node id
138  * @param materialSymbols material symbols
139  * @param useBC7TextureCompression use BC7 texture compression
140  * @throws tdme::engine::fileio::models::ModelFileIOException
141  */
142  static void readGeometry(const string& pathName, Model* model, Node* node, TiXmlElement* xmlRoot, const string& xmlNodeId, const map<string, string>& materialSymbols, bool useBC7TextureCompression);
143 
144  /**
145  * Reads a material
146  * @param pathName path name
147  * @param model model
148  * @param xmlRoot xml root
149  * @param xmlNodeId xml node id
150  * @param useBC7TextureCompression use BC7 texture compression
151  * @return material
152  */
153  static Material* readMaterial(const string& pathName, Model* model, TiXmlElement* xmlRoot, const string& xmlNodeId, bool useBC7TextureCompression);
154 
155  /**
156  * Make file name relative
157  * @param fileName file name
158  * @return file name
159  */
160  static const string makeFileNameRelative(const string& fileName);
161 
162  /**
163  * Get texture file name by id
164  * @param xmlRoot xml root
165  * @param xmlTextureId xml texture id
166  * @return xml texture file name
167  */
168  static const string getTextureFileNameById(TiXmlElement* xmlRoot, const string& xmlTextureId);
169 
170 public:
171 
172  /**
173  * Returns immediate children tags by tag name
174  * @param parent parent
175  * @param name name
176  * @return matching elements
177  */
178  static const vector<TiXmlElement*> getChildrenByTagName(TiXmlElement* parent, const char* name);
179 
180  /**
181  * Returns immediate children tags
182  * @param parent parent
183  * @return elements
184  */
185  static const vector<TiXmlElement*> getChildren(TiXmlElement* parent);
186 };
Color 4 definition class.
Definition: Color4.h:18
Collada DAE model reader.
Definition: DAEReader.h:39
static Node * readVisualSceneNode(const string &pathName, Model *model, Node *parentNode, TiXmlElement *xmlRoot, TiXmlElement *xmlNode, float fps, bool useBC7TextureCompression)
Read a DAE visual scene node.
Definition: DAEReader.cpp:255
static void readGeometry(const string &pathName, Model *model, Node *node, TiXmlElement *xmlRoot, const string &xmlNodeId, const map< string, string > &materialSymbols, bool useBC7TextureCompression)
Reads a geometry.
Definition: DAEReader.cpp:680
static Node * readNode(const string &pathName, Model *model, Node *parentNode, TiXmlElement *xmlRoot, TiXmlElement *xmlNode, float fps, bool useBC7TextureCompression)
Reads a DAE visual scene node node.
Definition: DAEReader.cpp:265
static const vector< TiXmlElement * > getChildren(TiXmlElement *parent)
Returns immediate children tags.
Definition: DAEReader.cpp:1278
static constexpr float BLENDER_AMBIENT_FROM_DIFFUSE_SCALE
Definition: DAEReader.h:43
static Node * readVisualSceneInstanceController(const string &pathName, Model *model, Node *parentNode, TiXmlElement *xmlRoot, TiXmlElement *xmlNode, bool useBC7TextureCompression)
Reads a instance controller.
Definition: DAEReader.cpp:475
static constexpr float BLENDER_DIFFUSE_SCALE
Definition: DAEReader.h:44
static UpVector * getUpVector(TiXmlElement *xmlRoot)
Get Up vector.
Definition: DAEReader.cpp:199
static void setupModelImportRotationMatrix(TiXmlElement *xmlRoot, Model *model)
Set up model import rotation matrix.
Definition: DAEReader.cpp:221
static const string makeFileNameRelative(const string &fileName)
Make file name relative.
Definition: DAEReader.cpp:1235
static const string getTextureFileNameById(TiXmlElement *xmlRoot, const string &xmlTextureId)
Get texture file name by id.
Definition: DAEReader.cpp:1253
static STATIC_DLL_IMPEXT const Color4 BLENDER_AMBIENT_NONE
Definition: DAEReader.h:42
static void setupModelImportScaleMatrix(TiXmlElement *xmlRoot, Model *model)
Set up model import scale matrix.
Definition: DAEReader.cpp:241
static Material * readMaterial(const string &pathName, Model *model, TiXmlElement *xmlRoot, const string &xmlNodeId, bool useBC7TextureCompression)
Reads a material.
Definition: DAEReader.cpp:942
static const vector< TiXmlElement * > getChildrenByTagName(TiXmlElement *parent, const char *name)
Returns immediate children tags by tag name.
Definition: DAEReader.cpp:1269
static Model::AuthoringTool getAuthoringTool(TiXmlElement *xmlRoot)
Get authoring tool.
Definition: DAEReader.cpp:185
static Model * read(const string &pathName, const string &fileName, bool useBC7TextureCompression=true)
Reads Collada DAE file.
Definition: DAEReader.cpp:96
Represents a material.
Definition: Material.h:23
Representation of a 3D model.
Definition: Model.h:35
Model node.
Definition: Node.h:32
Model up vector.
Definition: UpVector.h:20
The element is a container class.
Definition: tinyxml.h:886
#define STATIC_DLL_IMPEXT
Definition: tdme.h:15