DART  6.6.2
MeshShape.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2018, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  * https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  * Redistribution and use in source and binary forms, with or
10  * without modification, are permitted provided that the following
11  * conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef DART_DYNAMICS_MESHSHAPE_HPP_
34 #define DART_DYNAMICS_MESHSHAPE_HPP_
35 
36 #include <string>
37 
38 #include <assimp/scene.h>
39 
40 #include "dart/dynamics/Shape.hpp"
42 
43 namespace Assimp {
44 
45 class IOSystem;
46 
47 } // namespace Assimp
48 
49 namespace dart {
50 namespace dynamics {
51 
52 class MeshShape : public Shape
53 {
54 public:
55  enum ColorMode
56  {
60  };
61 
63  MeshShape(const Eigen::Vector3d& scale,
64  const aiScene* mesh,
65  const common::Uri& uri = "",
66  common::ResourceRetrieverPtr resourceRetriever = nullptr);
67 
69  virtual ~MeshShape();
70 
71  // Documentation inherited.
72  const std::string& getType() const override;
73 
75  static const std::string& getStaticType();
76 
77  const aiScene* getMesh() const;
78 
83  virtual void update();
84 
85  // Documentation inherited
86  void notifyAlphaUpdated(double alpha) override;
87 
88  void setMesh(
89  const aiScene* mesh,
90  const std::string& path = "",
91  common::ResourceRetrieverPtr resourceRetriever = nullptr);
92 
93  void setMesh(
94  const aiScene* mesh,
95  const common::Uri& path,
96  common::ResourceRetrieverPtr resourceRetriever = nullptr);
97 
99  std::string getMeshUri() const;
100  // TODO(DART 7): Replace with getMeshUri2().
101 
103  const common::Uri& getMeshUri2() const;
104  // TODO(DART 7): Remove.
105 
107  const std::string& getMeshPath() const;
108 
110 
111  void setScale(const Eigen::Vector3d& scale);
112 
113  const Eigen::Vector3d& getScale() const;
114 
116  void setColorMode(ColorMode mode);
117 
119  ColorMode getColorMode() const;
120 
125  void setColorIndex(int index);
126 
128  int getColorIndex() const;
129 
130  int getDisplayList() const;
131 
132  void setDisplayList(int index);
133 
134  static const aiScene* loadMesh(const std::string& filePath);
135 
136  static const aiScene* loadMesh(
137  const std::string& _uri, const common::ResourceRetrieverPtr& retriever);
138 
139  static const aiScene* loadMesh(
140  const common::Uri& uri, const common::ResourceRetrieverPtr& retriever);
141 
142  // Documentation inherited.
143  Eigen::Matrix3d computeInertia(double mass) const override;
144 
145 protected:
146  // Documentation inherited.
147  void updateBoundingBox() const override;
148 
149  // Documentation inherited.
150  void updateVolume() const override;
151 
152  const aiScene* mMesh;
153 
156 
158  std::string mMeshPath;
159 
162 
165 
167  Eigen::Vector3d mScale;
168 
171 
174 };
175 
176 } // namespace dynamics
177 } // namespace dart
178 
179 #endif // DART_DYNAMICS_MESHSHAPE_HPP_
std::size_t index
Definition: SkelParser.cpp:1617
Definition: MeshShape.hpp:53
void notifyAlphaUpdated(double alpha) override
Notify that the alpha of this shape has updated.
Definition: MeshShape.cpp:189
common::ResourceRetrieverPtr mResourceRetriever
Optional method of loading resources by URI.
Definition: MeshShape.hpp:161
const aiScene * mMesh
Definition: MeshShape.hpp:152
int mColorIndex
Specifies which color index should be used when mColorMode is COLOR_INDEX.
Definition: MeshShape.hpp:173
common::ResourceRetrieverPtr getResourceRetriever()
Definition: MeshShape.cpp:206
Eigen::Vector3d mScale
Scale.
Definition: MeshShape.hpp:167
const common::Uri & getMeshUri2() const
Returns URI to the mesh; an empty string if unavailable.
Definition: MeshShape.cpp:177
static const std::string & getStaticType()
Returns shape type for this class.
Definition: MeshShape.cpp:158
MeshShape(const Eigen::Vector3d &scale, const aiScene *mesh, const common::Uri &uri="", common::ResourceRetrieverPtr resourceRetriever=nullptr)
Constructor.
Definition: MeshShape.cpp:131
void setScale(const Eigen::Vector3d &scale)
Definition: MeshShape.cpp:246
ColorMode
Definition: MeshShape.hpp:56
@ COLOR_INDEX
Use the colors specified by aiMesh::mColor.
Definition: MeshShape.hpp:58
@ MATERIAL_COLOR
Use the colors specified by the Mesh's material.
Definition: MeshShape.hpp:57
@ SHAPE_COLOR
Use the color specified by the Shape base class.
Definition: MeshShape.hpp:59
void updateVolume() const override
Updates volume.
Definition: MeshShape.cpp:347
int getDisplayList() const
Definition: MeshShape.cpp:286
ColorMode mColorMode
Specifies how the color of this mesh should be determined.
Definition: MeshShape.hpp:170
void updateBoundingBox() const override
Updates bounding box.
Definition: MeshShape.cpp:305
int mDisplayList
OpenGL DisplayList id for rendering.
Definition: MeshShape.hpp:164
std::string mMeshPath
Path the mesh on disk, if available.
Definition: MeshShape.hpp:158
int getColorIndex() const
Get the index that will be used when the ColorMode is set to COLOR_INDEX.
Definition: MeshShape.cpp:280
const Eigen::Vector3d & getScale() const
Definition: MeshShape.cpp:256
Eigen::Matrix3d computeInertia(double mass) const override
Computes the inertia.
Definition: MeshShape.cpp:298
void setColorMode(ColorMode mode)
Set how the color of this mesh should be determined.
Definition: MeshShape.cpp:262
virtual ~MeshShape()
Destructor.
Definition: MeshShape.cpp:146
const std::string & getMeshPath() const
Returns path to the mesh on disk; an empty string if unavailable.
Definition: MeshShape.cpp:200
const aiScene * getMesh() const
Definition: MeshShape.cpp:165
std::string getMeshUri() const
Returns URI to the mesh as std::string; an empty string if unavailable.
Definition: MeshShape.cpp:171
ColorMode getColorMode() const
Get the coloring mode that this mesh is using.
Definition: MeshShape.cpp:268
virtual void update()
Updates positions of the vertices or the elements.
Definition: MeshShape.cpp:183
void setColorIndex(int index)
Set which entry in aiMesh::mColor should be used when the color mode is COLOR_INDEX.
Definition: MeshShape.cpp:274
common::Uri mMeshUri
URI the mesh, if available).
Definition: MeshShape.hpp:155
const std::string & getType() const override
Returns a string representing the shape type.
Definition: MeshShape.cpp:152
static const aiScene * loadMesh(const std::string &filePath)
Definition: MeshShape.cpp:427
void setDisplayList(int index)
Definition: MeshShape.cpp:292
void setMesh(const aiScene *mesh, const std::string &path="", common::ResourceRetrieverPtr resourceRetriever=nullptr)
Definition: MeshShape.cpp:212
Definition: Shape.hpp:49
Definition: MeshShape.hpp:43
std::shared_ptr< ResourceRetriever > ResourceRetrieverPtr
Definition: ResourceRetriever.hpp:76
Definition: BulletCollisionDetector.cpp:63
The Uri struct provides URI parsing and merging functionality based on RFC 3986.
Definition: Uri.hpp:87