ColladaLoader.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 _GAZEBO_COLLADALOADER_HH_
19 #define _GAZEBO_COLLADALOADER_HH_
20 
21 #include <string>
22 #include <vector>
23 #include <map>
24 
25 #include <ignition/math/Matrix4.hh>
26 #include <ignition/math/Vector3.hh>
27 #include <ignition/math/Vector2.hh>
28 
30 #include "gazebo/util/system.hh"
31 
32 class TiXmlElement;
33 
34 namespace gazebo
35 {
36  namespace common
37  {
38  class Material;
39  class ColladaLoaderPrivate;
40 
43 
46  class GZ_COMMON_VISIBLE ColladaLoader : public MeshLoader
47  {
49  public: ColladaLoader();
50 
52  public: virtual ~ColladaLoader();
53 
57  public: virtual Mesh *Load(const std::string &_filename);
58 
64  private: void LoadController(TiXmlElement *_contrXml,
65  const std::vector<TiXmlElement*> &rootNodeXmls,
66  const ignition::math::Matrix4d &_transform, Mesh *_mesh);
67 
71  private: void LoadAnimations(TiXmlElement *_xml, Skeleton *_skel);
72 
76  private: void LoadAnimationSet(TiXmlElement *_xml, Skeleton *_skel);
77 
81  private: SkeletonNode* LoadSingleSkeletonNode(TiXmlElement *_xml,
82  SkeletonNode *_parent);
83 
87  private: SkeletonNode* LoadSkeletonNodes(TiXmlElement *_xml,
88  SkeletonNode *_parent);
89 
93  private: void SetSkeletonNodeTransform(TiXmlElement *_elem,
94  SkeletonNode *_node);
95 
100  private: void LoadGeometry(TiXmlElement *_xml,
101  const ignition::math::Matrix4d &_transform, Mesh *_mesh);
102 
107  private: TiXmlElement *GetElementId(TiXmlElement *_parent,
108  const std::string &_name,
109  const std::string &_id);
110 
114  private: TiXmlElement *GetElementId(const std::string &_name,
115  const std::string &_id);
116 
121  private: void LoadNode(TiXmlElement *_elem, Mesh *_mesh,
122  const ignition::math::Matrix4d &_transform);
123 
127  private: ignition::math::Matrix4d LoadNodeTransform(TiXmlElement *_elem);
128 
134  private: void LoadVertices(const std::string &_id,
135  const ignition::math::Matrix4d &_transform,
136  std::vector<ignition::math::Vector3d> &_verts,
137  std::vector<ignition::math::Vector3d> &_norms);
138 
146  private: void LoadVertices(const std::string &_id,
147  const ignition::math::Matrix4d &_transform,
148  std::vector<ignition::math::Vector3d> &_verts,
149  std::vector<ignition::math::Vector3d> &_norms,
150  std::map<unsigned int, unsigned int> &_vertDup,
151  std::map<unsigned int, unsigned int> &_normDup);
152 
158  private: void LoadPositions(const std::string &_id,
159  const ignition::math::Matrix4d &_transform,
160  std::vector<ignition::math::Vector3d> &_values,
161  std::map<unsigned int, unsigned int> &_duplicates);
162 
168  private: void LoadNormals(const std::string &_id,
169  const ignition::math::Matrix4d &_transform,
170  std::vector<ignition::math::Vector3d> &_values,
171  std::map<unsigned int, unsigned int> &_duplicates);
172 
177  private: void LoadTexCoords(const std::string &_id,
178  std::vector<ignition::math::Vector2d> &_values,
179  std::map<unsigned int, unsigned int> &_duplicates);
180 
184  private: Material *LoadMaterial(const std::string &_name);
185 
190  private: void LoadColorOrTexture(TiXmlElement *_elem,
191  const std::string &_type,
192  Material *_mat);
193 
198  private: void LoadTriangles(TiXmlElement *_trianglesXml,
199  const ignition::math::Matrix4d &_transform,
200  Mesh *_mesh);
201 
206  private: void LoadPolylist(TiXmlElement *_polylistXml,
207  const ignition::math::Matrix4d &_transform,
208  Mesh *_mesh);
209 
214  private: void LoadLines(TiXmlElement *_xml,
215  const ignition::math::Matrix4d &_transform,
216  Mesh *_mesh);
217 
220  private: void LoadScene(Mesh *_mesh);
221 
225  private: float LoadFloat(TiXmlElement *_elem);
226 
230  private: void LoadTransparent(TiXmlElement *_elem, Material *_mat);
231 
241  private: void MergeSkeleton(Skeleton *_skeleton,
242  SkeletonNode *_mergeNode);
243 
251  private: void ApplyInvBindTransform(Skeleton *_skeleton);
252 
255  private: ColladaLoaderPrivate *dataPtr;
256  };
258  }
259 }
260 #endif
A 3D mesh.
Definition: Mesh.hh:42
Base class for loading meshes.
Definition: MeshLoader.hh:36
A skeleton.
Definition: Skeleton.hh:52
Encapsulates description of a material.
Definition: common/Material.hh:34
Forward declarations for the common classes.
Definition: Animation.hh:26
Class used to load Collada mesh files.
Definition: ColladaLoader.hh:46
A skeleton node.
Definition: Skeleton.hh:179
common
Definition: FuelModelDatabase.hh:37