DART  6.10.1
MeshShape.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2021, 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 
41 #include "dart/dynamics/Shape.hpp"
42 
43 namespace dart {
44 namespace dynamics {
45 
46 class MeshShape : public Shape
47 {
48 public:
49  enum ColorMode
50  {
54  };
55 
59  enum AlphaMode
60  {
67  BLEND = 0,
68 
74 
77  };
78 
80  MeshShape(
81  const Eigen::Vector3d& scale,
82  const aiScene* mesh,
83  const common::Uri& uri = "",
84  common::ResourceRetrieverPtr resourceRetriever = nullptr);
85 
87  ~MeshShape() override;
88 
89  // Documentation inherited.
90  const std::string& getType() const override;
91 
93  static const std::string& getStaticType();
94 
95  const aiScene* getMesh() const;
96 
101  virtual void update();
102 
103  void setMesh(
104  const aiScene* mesh,
105  const std::string& path = "",
106  common::ResourceRetrieverPtr resourceRetriever = nullptr);
107 
108  void setMesh(
109  const aiScene* mesh,
110  const common::Uri& path,
111  common::ResourceRetrieverPtr resourceRetriever = nullptr);
112 
114  std::string getMeshUri() const;
115  // TODO(DART 7): Replace with getMeshUri2().
116 
118  const common::Uri& getMeshUri2() const;
119  // TODO(DART 7): Remove.
120 
122  const std::string& getMeshPath() const;
123 
125 
126  void setScale(const Eigen::Vector3d& scale);
127 
128  const Eigen::Vector3d& getScale() const;
129 
131  void setColorMode(ColorMode mode);
132 
134  ColorMode getColorMode() const;
135 
137  void setAlphaMode(AlphaMode mode);
138 
140  AlphaMode getAlphaMode() const;
141 
146  void setColorIndex(int index);
147 
149  int getColorIndex() const;
150 
151  int getDisplayList() const;
152 
153  void setDisplayList(int index);
154 
155  static const aiScene* loadMesh(const std::string& filePath);
156 
157  static const aiScene* loadMesh(
158  const std::string& _uri, const common::ResourceRetrieverPtr& retriever);
159 
160  static const aiScene* loadMesh(
161  const common::Uri& uri, const common::ResourceRetrieverPtr& retriever);
162 
163  // Documentation inherited.
164  Eigen::Matrix3d computeInertia(double mass) const override;
165 
166 protected:
167  // Documentation inherited.
168  void updateBoundingBox() const override;
169 
170  // Documentation inherited.
171  void updateVolume() const override;
172 
173  const aiScene* mMesh;
174 
177 
179  std::string mMeshPath;
180 
183 
186 
188  Eigen::Vector3d mScale;
189 
192 
195 
198 };
199 
200 } // namespace dynamics
201 } // namespace dart
202 
203 #endif // DART_DYNAMICS_MESHSHAPE_HPP_
std::size_t index
Definition: SkelParser.cpp:1672
Definition: MeshShape.hpp:47
common::ResourceRetrieverPtr mResourceRetriever
Optional method of loading resources by URI.
Definition: MeshShape.hpp:182
const aiScene * mMesh
Definition: MeshShape.hpp:173
int mColorIndex
Specifies which color index should be used when mColorMode is COLOR_INDEX.
Definition: MeshShape.hpp:197
common::ResourceRetrieverPtr getResourceRetriever()
Definition: MeshShape.cpp:195
Eigen::Vector3d mScale
Scale.
Definition: MeshShape.hpp:188
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
AlphaMode
Alpha mode to specify how the alpha of this mesh should be determined.
Definition: MeshShape.hpp:60
@ BLEND
Blend alphas of visual aspect and mesh.
Definition: MeshShape.hpp:67
@ SHAPE_ALPHA
Always use the alpha of visual aspect.
Definition: MeshShape.hpp:76
@ AUTO
Use the alpha of mesh or visual aspect.
Definition: MeshShape.hpp:73
MeshShape(const Eigen::Vector3d &scale, const aiScene *mesh, const common::Uri &uri="", common::ResourceRetrieverPtr resourceRetriever=nullptr)
Constructor.
Definition: MeshShape.cpp:130
void setScale(const Eigen::Vector3d &scale)
Definition: MeshShape.cpp:238
ColorMode
Definition: MeshShape.hpp:50
@ COLOR_INDEX
Use the colors specified by aiMesh::mColor.
Definition: MeshShape.hpp:52
@ MATERIAL_COLOR
Use the colors specified by the Mesh's material.
Definition: MeshShape.hpp:51
@ SHAPE_COLOR
Use the color specified by the visual aspect.
Definition: MeshShape.hpp:53
void updateVolume() const override
Updates volume.
Definition: MeshShape.cpp:355
int getDisplayList() const
Definition: MeshShape.cpp:292
ColorMode mColorMode
Specifies how the color of this mesh should be determined.
Definition: MeshShape.hpp:191
void updateBoundingBox() const override
Updates bounding box.
Definition: MeshShape.cpp:311
void setAlphaMode(AlphaMode mode)
Sets how the alpha of this mesh should be determined.
Definition: MeshShape.cpp:268
int mDisplayList
OpenGL DisplayList id for rendering.
Definition: MeshShape.hpp:185
AlphaMode mAlphaMode
Specifies how the alpha of this mesh should be determined.
Definition: MeshShape.hpp:194
~MeshShape() override
Destructor.
Definition: MeshShape.cpp:146
std::string mMeshPath
Path the mesh on disk, if available.
Definition: MeshShape.hpp:179
int getColorIndex() const
Get the index that will be used when the ColorMode is set to COLOR_INDEX.
Definition: MeshShape.cpp:286
const Eigen::Vector3d & getScale() const
Definition: MeshShape.cpp:250
Eigen::Matrix3d computeInertia(double mass) const override
Computes the inertia.
Definition: MeshShape.cpp:304
AlphaMode getAlphaMode() const
Returns the alpha mode that this mesh is using.
Definition: MeshShape.cpp:274
void setColorMode(ColorMode mode)
Set how the color of this mesh should be determined.
Definition: MeshShape.cpp:256
const std::string & getMeshPath() const
Returns path to the mesh on disk; an empty string if unavailable.
Definition: MeshShape.cpp:189
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:262
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:280
common::Uri mMeshUri
URI the mesh, if available).
Definition: MeshShape.hpp:176
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:435
void setDisplayList(int index)
Definition: MeshShape.cpp:298
void setMesh(const aiScene *mesh, const std::string &path="", common::ResourceRetrieverPtr resourceRetriever=nullptr)
Definition: MeshShape.cpp:201
Definition: Shape.hpp:54
std::shared_ptr< ResourceRetriever > ResourceRetrieverPtr
Definition: ResourceRetriever.hpp:76
Definition: BulletCollisionDetector.cpp:65
The Uri struct provides URI parsing and merging functionality based on RFC 3986.
Definition: Uri.hpp:87