All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ColladaLoader.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Nate Koenig
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef COLLADALOADER_HH
19 #define COLLADALOADER_HH
20 
21 #include <map>
22 #include <string>
23 #include <vector>
24 
25 #include "common/MeshLoader.hh"
26 #include "math/MathTypes.hh"
27 
28 class TiXmlElement;
29 
30 namespace gazebo
31 {
32  namespace common
33  {
34  class Material;
35 
38 
40  class ColladaLoader : public MeshLoader
41  {
43  public: ColladaLoader();
44 
46  public: virtual ~ColladaLoader();
47 
51  public: virtual Mesh *Load(const std::string &_filename);
52 
58  private: void LoadController(TiXmlElement *_contrXml,
59  TiXmlElement *_skelXml, const math::Matrix4 _transform, Mesh *_mesh);
60 
64  private: void LoadAnimations(TiXmlElement *_xml, Skeleton *_skel);
65 
69  private: void LoadAnimationSet(TiXmlElement *_xml, Skeleton *_skel);
70 
74  private: SkeletonNode* LoadSkeletonNodes(TiXmlElement *_xml,
75  SkeletonNode *_parent);
76 
80  private: void SetSkeletonNodeTransform(TiXmlElement *_elem,
81  SkeletonNode *_node);
82 
87  private: void LoadGeometry(TiXmlElement *_xml,
88  const math::Matrix4 &_transform, Mesh *_mesh);
89 
94  private: TiXmlElement *GetElementId(TiXmlElement *_parent,
95  const std::string &_name,
96  const std::string &_id);
97 
101  private: TiXmlElement *GetElementId(const std::string &_name,
102  const std::string &_id);
103 
108  private: void LoadNode(TiXmlElement *_elem, Mesh *_mesh,
109  const math::Matrix4 &_transform);
110 
114  private: math::Matrix4 LoadNodeTransform(TiXmlElement *_elem);
115 
121  private: void LoadVertices(const std::string &_id,
122  const math::Matrix4 &_transform,
123  std::vector<math::Vector3> &_verts,
124  std::vector<math::Vector3> &_norms);
125 
130  private: void LoadPositions(const std::string &_id,
131  const math::Matrix4 &_transform,
132  std::vector<math::Vector3> &_values);
133 
138  private: void LoadNormals(const std::string &_id,
139  const math::Matrix4 &_transform,
140  std::vector<math::Vector3> &_values);
141 
145  private: void LoadTexCoords(const std::string &_id,
146  std::vector<math::Vector2d> &_values);
147 
151  private: Material *LoadMaterial(const std::string &_name);
152 
157  private: void LoadColorOrTexture(TiXmlElement *_elem,
158  const std::string &_type,
159  Material *_mat);
160 
165  private: void LoadTriangles(TiXmlElement *_trianglesXml,
166  const math::Matrix4 &_transform,
167  Mesh *_mesh);
168 
173  private: void LoadPolylist(TiXmlElement *_polylistXml,
174  const math::Matrix4 &_transform,
175  Mesh *_mesh);
176 
181  private: void LoadLines(TiXmlElement *_xml,
182  const math::Matrix4 &_transform,
183  Mesh *_mesh);
184 
187  private: void LoadScene(Mesh *_mesh);
188 
192  private: float LoadFloat(TiXmlElement *_elem);
193 
197  private: void LoadTransparent(TiXmlElement *_elem, Material *_mat);
198 
200  private: double meter;
201 
203  private: std::string filename;
204 
206  private: std::map<std::string, std::string> materialMap;
207 
209  private: TiXmlElement *colladaXml;
210 
212  private: std::string path;
213  };
215  }
216 }
217 #endif