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 2012 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 
41  class ColladaLoader : public MeshLoader
42  {
44  public: ColladaLoader();
45 
47  public: virtual ~ColladaLoader();
48 
52  public: virtual Mesh *Load(const std::string &_filename);
53 
59  private: void LoadController(TiXmlElement *_contrXml,
60  TiXmlElement *_skelXml, const math::Matrix4 _transform, Mesh *_mesh);
61 
65  private: void LoadAnimations(TiXmlElement *_xml, Skeleton *_skel);
66 
70  private: void LoadAnimationSet(TiXmlElement *_xml, Skeleton *_skel);
71 
75  private: SkeletonNode* LoadSkeletonNodes(TiXmlElement *_xml,
76  SkeletonNode *_parent);
77 
81  private: void SetSkeletonNodeTransform(TiXmlElement *_elem,
82  SkeletonNode *_node);
83 
88  private: void LoadGeometry(TiXmlElement *_xml,
89  const math::Matrix4 &_transform, Mesh *_mesh);
90 
95  private: TiXmlElement *GetElementId(TiXmlElement *_parent,
96  const std::string &_name,
97  const std::string &_id);
98 
102  private: TiXmlElement *GetElementId(const std::string &_name,
103  const std::string &_id);
104 
109  private: void LoadNode(TiXmlElement *_elem, Mesh *_mesh,
110  const math::Matrix4 &_transform);
111 
115  private: math::Matrix4 LoadNodeTransform(TiXmlElement *_elem);
116 
122  private: void LoadVertices(const std::string &_id,
123  const math::Matrix4 &_transform,
124  std::vector<math::Vector3> &_verts,
125  std::vector<math::Vector3> &_norms);
126 
131  private: void LoadPositions(const std::string &_id,
132  const math::Matrix4 &_transform,
133  std::vector<math::Vector3> &_values);
134 
139  private: void LoadNormals(const std::string &_id,
140  const math::Matrix4 &_transform,
141  std::vector<math::Vector3> &_values);
142 
146  private: void LoadTexCoords(const std::string &_id,
147  std::vector<math::Vector2d> &_values);
148 
152  private: Material *LoadMaterial(const std::string &_name);
153 
158  private: void LoadColorOrTexture(TiXmlElement *_elem,
159  const std::string &_type,
160  Material *_mat);
161 
166  private: void LoadTriangles(TiXmlElement *_trianglesXml,
167  const math::Matrix4 &_transform,
168  Mesh *_mesh);
169 
174  private: void LoadPolylist(TiXmlElement *_polylistXml,
175  const math::Matrix4 &_transform,
176  Mesh *_mesh);
177 
182  private: void LoadLines(TiXmlElement *_xml,
183  const math::Matrix4 &_transform,
184  Mesh *_mesh);
185 
188  private: void LoadScene(Mesh *_mesh);
189 
193  private: float LoadFloat(TiXmlElement *_elem);
194 
198  private: void LoadTransparent(TiXmlElement *_elem, Material *_mat);
199 
201  private: double meter;
202 
204  private: std::string filename;
205 
207  private: std::map<std::string, std::string> materialMap;
208 
210  private: TiXmlElement *colladaXml;
211 
213  private: std::string path;
214  };
216  }
217 }
218 #endif