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 (C) 2012-2014 Open Source Robotics Foundation
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 
26 #include "gazebo/math/MathTypes.hh"
27 #include "gazebo/util/system.hh"
28 
29 class TiXmlElement;
30 
31 namespace gazebo
32 {
33  namespace common
34  {
35  class Material;
36 
39 
43  {
45  public: ColladaLoader();
46 
48  public: virtual ~ColladaLoader();
49 
53  public: virtual Mesh *Load(const std::string &_filename);
54 
60  private: void LoadController(TiXmlElement *_contrXml,
61  TiXmlElement *_skelXml, const math::Matrix4 &_transform, Mesh *_mesh);
62 
66  private: void LoadAnimations(TiXmlElement *_xml, Skeleton *_skel);
67 
71  private: void LoadAnimationSet(TiXmlElement *_xml, Skeleton *_skel);
72 
76  private: SkeletonNode* LoadSkeletonNodes(TiXmlElement *_xml,
77  SkeletonNode *_parent);
78 
82  private: void SetSkeletonNodeTransform(TiXmlElement *_elem,
83  SkeletonNode *_node);
84 
89  private: void LoadGeometry(TiXmlElement *_xml,
90  const math::Matrix4 &_transform, Mesh *_mesh);
91 
96  private: TiXmlElement *GetElementId(TiXmlElement *_parent,
97  const std::string &_name,
98  const std::string &_id);
99 
103  private: TiXmlElement *GetElementId(const std::string &_name,
104  const std::string &_id);
105 
110  private: void LoadNode(TiXmlElement *_elem, Mesh *_mesh,
111  const math::Matrix4 &_transform);
112 
116  private: math::Matrix4 LoadNodeTransform(TiXmlElement *_elem);
117 
123  private: void LoadVertices(const std::string &_id,
124  const math::Matrix4 &_transform,
125  std::vector<math::Vector3> &_verts,
126  std::vector<math::Vector3> &_norms);
127 
132  private: void LoadPositions(const std::string &_id,
133  const math::Matrix4 &_transform,
134  std::vector<math::Vector3> &_values);
135 
140  private: void LoadNormals(const std::string &_id,
141  const math::Matrix4 &_transform,
142  std::vector<math::Vector3> &_values);
143 
147  private: void LoadTexCoords(const std::string &_id,
148  std::vector<math::Vector2d> &_values);
149 
153  private: Material *LoadMaterial(const std::string &_name);
154 
159  private: void LoadColorOrTexture(TiXmlElement *_elem,
160  const std::string &_type,
161  Material *_mat);
162 
167  private: void LoadTriangles(TiXmlElement *_trianglesXml,
168  const math::Matrix4 &_transform,
169  Mesh *_mesh);
170 
175  private: void LoadPolylist(TiXmlElement *_polylistXml,
176  const math::Matrix4 &_transform,
177  Mesh *_mesh);
178 
183  private: void LoadLines(TiXmlElement *_xml,
184  const math::Matrix4 &_transform,
185  Mesh *_mesh);
186 
189  private: void LoadScene(Mesh *_mesh);
190 
194  private: float LoadFloat(TiXmlElement *_elem);
195 
199  private: void LoadTransparent(TiXmlElement *_elem, Material *_mat);
200 
202  private: double meter;
203 
205  private: std::string filename;
206 
208  private: std::map<std::string, std::string> materialMap;
209 
211  private: TiXmlElement *colladaXml;
212 
214  private: std::string path;
215 
217  private: std::string currentNodeName;
218  };
220  }
221 }
222 #endif