DART  6.6.2
dart::dynamics::MeshShape Class Reference

#include <MeshShape.hpp>

Inheritance diagram for dart::dynamics::MeshShape:
dart::dynamics::Shape dart::common::Subject dart::dynamics::ArrowShape

Public Types

enum  ColorMode { MATERIAL_COLOR = 0 , COLOR_INDEX , SHAPE_COLOR }
 
enum  ShapeType {
  SPHERE , BOX , ELLIPSOID , CYLINDER ,
  CAPSULE , CONE , PLANE , MULTISPHERE ,
  MESH , SOFT_MESH , LINE_SEGMENT , HEIGHTMAP ,
  UNSUPPORTED
}
 
enum  DataVariance {
  STATIC =0 , DYNAMIC_TRANSFORM = 1 << 1 , DYNAMIC_PRIMITIVE = 1 << 2 , DYNAMIC_COLOR = 1 << 3 ,
  DYNAMIC_VERTICES = 1 << 4 , DYNAMIC_ELEMENTS = 1 << 5 , DYNAMIC = 0xFF
}
 DataVariance can be used by renderers to determine whether it should expect data for this shape to change during each update. More...
 

Public Member Functions

 MeshShape (const Eigen::Vector3d &scale, const aiScene *mesh, const common::Uri &uri="", common::ResourceRetrieverPtr resourceRetriever=nullptr)
 Constructor. More...
 
virtual ~MeshShape ()
 Destructor. More...
 
const std::string & getType () const override
 Returns a string representing the shape type. More...
 
const aiScene * getMesh () const
 
virtual void update ()
 Updates positions of the vertices or the elements. More...
 
void notifyAlphaUpdated (double alpha) override
 Notify that the alpha of this shape has updated. More...
 
void setMesh (const aiScene *mesh, const std::string &path="", common::ResourceRetrieverPtr resourceRetriever=nullptr)
 
void setMesh (const aiScene *mesh, const common::Uri &path, common::ResourceRetrieverPtr resourceRetriever=nullptr)
 
std::string getMeshUri () const
 Returns URI to the mesh as std::string; an empty string if unavailable. More...
 
const common::UrigetMeshUri2 () const
 Returns URI to the mesh; an empty string if unavailable. More...
 
const std::string & getMeshPath () const
 Returns path to the mesh on disk; an empty string if unavailable. More...
 
common::ResourceRetrieverPtr getResourceRetriever ()
 
void setScale (const Eigen::Vector3d &scale)
 
const Eigen::Vector3d & getScale () const
 
void setColorMode (ColorMode mode)
 Set how the color of this mesh should be determined. More...
 
ColorMode getColorMode () const
 Get the coloring mode that this mesh is using. More...
 
void setColorIndex (int index)
 Set which entry in aiMesh::mColor should be used when the color mode is COLOR_INDEX. More...
 
int getColorIndex () const
 Get the index that will be used when the ColorMode is set to COLOR_INDEX. More...
 
int getDisplayList () const
 
void setDisplayList (int index)
 
Eigen::Matrix3d computeInertia (double mass) const override
 Computes the inertia. More...
 
template<typename ShapeT >
bool is () const
 Get true if the types of this Shape and the template parameter (a shape class) are identical. More...
 
const math::BoundingBoxgetBoundingBox () const
 Get the bounding box of the shape in its local coordinate frame. More...
 
Eigen::Matrix3d computeInertiaFromDensity (double density) const
 
Eigen::Matrix3d computeInertiaFromMass (double mass) const
 
double getVolume () const
 Returns volume of this shape. More...
 
int getID () const
 
ShapeType getShapeType () const
 
void setDataVariance (unsigned int _variance)
 Set the data variance of this shape. More...
 
void addDataVariance (unsigned int _variance)
 Add a type of variance to this shape. More...
 
void removeDataVariance (unsigned int _variance)
 Remove a type of variance from this shape. More...
 
unsigned int getDataVariance () const
 Get the data variance of this shape. More...
 
bool checkDataVariance (DataVariance type) const
 True iff this Shape has the specified type of DataVariance. More...
 
virtual void refreshData ()
 Instruct this shape to update its data. More...
 
virtual void notifyAlphaUpdate (double alpha)
 Notify that the alpha of this shape has updated. More...
 
virtual void notifyColorUpdate (const Eigen::Vector4d &color)
 Notify that the color (rgba) of this shape has updated. More...
 
virtual void notifyColorUpdated (const Eigen::Vector4d &color)
 Notify that the color (rgba) of this shape has updated. More...
 

Static Public Member Functions

static const std::string & getStaticType ()
 Returns shape type for this class. More...
 
static const aiScene * loadMesh (const std::string &filePath)
 
static const aiScene * loadMesh (const std::string &_uri, const common::ResourceRetrieverPtr &retriever)
 
static const aiScene * loadMesh (const common::Uri &uri, const common::ResourceRetrieverPtr &retriever)
 

Protected Member Functions

void updateBoundingBox () const override
 Updates bounding box. More...
 
void updateVolume () const override
 Updates volume. More...
 
void sendDestructionNotification () const
 Send a destruction notification to all Observers. More...
 
void addObserver (Observer *_observer) const
 Add an Observer to the list of Observers. More...
 
void removeObserver (Observer *_observer) const
 Remove an Observer from the list of Observers. More...
 

Protected Attributes

const aiScene * mMesh
 
common::Uri mMeshUri
 URI the mesh, if available). More...
 
std::string mMeshPath
 Path the mesh on disk, if available. More...
 
common::ResourceRetrieverPtr mResourceRetriever
 Optional method of loading resources by URI. More...
 
int mDisplayList
 OpenGL DisplayList id for rendering. More...
 
Eigen::Vector3d mScale
 Scale. More...
 
ColorMode mColorMode
 Specifies how the color of this mesh should be determined. More...
 
int mColorIndex
 Specifies which color index should be used when mColorMode is COLOR_INDEX. More...
 
math::BoundingBox mBoundingBox
 The bounding box (in the local coordinate frame) of the shape. More...
 
bool mIsBoundingBoxDirty
 Whether bounding box needs update. More...
 
double mVolume
 Volume enclosed by the geometry. More...
 
bool mIsVolumeDirty
 Whether volume needs update. More...
 
int mID
 Unique id. More...
 
unsigned int mVariance
 The DataVariance of this Shape. More...
 
ShapeType mType
 
std::set< Observer * > mObservers
 List of current Observers. More...
 

Static Protected Attributes

static int mCounter = 1000
 

Member Enumeration Documentation

◆ ColorMode

Enumerator
MATERIAL_COLOR 

Use the colors specified by the Mesh's material.

COLOR_INDEX 

Use the colors specified by aiMesh::mColor.

SHAPE_COLOR 

Use the color specified by the Shape base class.

◆ DataVariance

DataVariance can be used by renderers to determine whether it should expect data for this shape to change during each update.

Enumerator
STATIC 
DYNAMIC_TRANSFORM 

No data will ever change.

DYNAMIC_PRIMITIVE 

The relative transform of the Shape might change.

DYNAMIC_COLOR 

The primitive properties (such as x/y/z scaling) of the shape might change.

DYNAMIC_VERTICES 

The coloring or textures of the shape might change.

DYNAMIC_ELEMENTS 

Vertex positions of a mesh might change (this does not include adding or removing vertices) (this enum is not relevant for primitive shapes)

DYNAMIC 

The number of elements and/or arrangement of elements might change (this includes adding and removing vertices) (this enum is not relevant for primitive shapes)

◆ ShapeType

Deprecated:
Deprecated in 6.1. Please use getType() instead.
Enumerator
SPHERE 
BOX 
ELLIPSOID 
CYLINDER 
CAPSULE 
CONE 
PLANE 
MULTISPHERE 
MESH 
SOFT_MESH 
LINE_SEGMENT 
HEIGHTMAP 
UNSUPPORTED 

Constructor & Destructor Documentation

◆ MeshShape()

dart::dynamics::MeshShape::MeshShape ( const Eigen::Vector3d &  scale,
const aiScene *  mesh,
const common::Uri uri = "",
common::ResourceRetrieverPtr  resourceRetriever = nullptr 
)

Constructor.

◆ ~MeshShape()

dart::dynamics::MeshShape::~MeshShape ( )
virtual

Destructor.

Member Function Documentation

◆ addDataVariance()

void dart::dynamics::Shape::addDataVariance ( unsigned int  _variance)
inherited

Add a type of variance to this shape.

All other variance types will remain the same.

◆ addObserver()

void dart::common::Subject::addObserver ( Observer _observer) const
protectedinherited

Add an Observer to the list of Observers.

◆ checkDataVariance()

bool dart::dynamics::Shape::checkDataVariance ( DataVariance  type) const
inherited

True iff this Shape has the specified type of DataVariance.

◆ computeInertia()

Eigen::Matrix3d dart::dynamics::MeshShape::computeInertia ( double  mass) const
overridevirtual

Computes the inertia.

Implements dart::dynamics::Shape.

◆ computeInertiaFromDensity()

Eigen::Matrix3d dart::dynamics::Shape::computeInertiaFromDensity ( double  density) const
inherited

◆ computeInertiaFromMass()

Eigen::Matrix3d dart::dynamics::Shape::computeInertiaFromMass ( double  mass) const
inherited

◆ getBoundingBox()

const math::BoundingBox & dart::dynamics::Shape::getBoundingBox ( ) const
inherited

Get the bounding box of the shape in its local coordinate frame.

The dimension will be automatically determined by the sub-classes such as BoxShape, EllipsoidShape, CylinderShape, and MeshShape.

◆ getColorIndex()

int dart::dynamics::MeshShape::getColorIndex ( ) const

Get the index that will be used when the ColorMode is set to COLOR_INDEX.

◆ getColorMode()

MeshShape::ColorMode dart::dynamics::MeshShape::getColorMode ( ) const

Get the coloring mode that this mesh is using.

◆ getDataVariance()

unsigned int dart::dynamics::Shape::getDataVariance ( ) const
inherited

Get the data variance of this shape.

◆ getDisplayList()

int dart::dynamics::MeshShape::getDisplayList ( ) const

◆ getID()

int dart::dynamics::Shape::getID ( ) const
inherited

◆ getMesh()

const aiScene * dart::dynamics::MeshShape::getMesh ( ) const

◆ getMeshPath()

const std::string & dart::dynamics::MeshShape::getMeshPath ( ) const

Returns path to the mesh on disk; an empty string if unavailable.

◆ getMeshUri()

std::string dart::dynamics::MeshShape::getMeshUri ( ) const

Returns URI to the mesh as std::string; an empty string if unavailable.

◆ getMeshUri2()

const common::Uri & dart::dynamics::MeshShape::getMeshUri2 ( ) const

Returns URI to the mesh; an empty string if unavailable.

◆ getResourceRetriever()

common::ResourceRetrieverPtr dart::dynamics::MeshShape::getResourceRetriever ( )

◆ getScale()

const Eigen::Vector3d & dart::dynamics::MeshShape::getScale ( ) const

◆ getShapeType()

Shape::ShapeType dart::dynamics::Shape::getShapeType ( ) const
inherited
Deprecated:
Deprecated in 6.1. Please use getType() instead.

◆ getStaticType()

const std::string & dart::dynamics::MeshShape::getStaticType ( )
static

Returns shape type for this class.

◆ getType()

const std::string & dart::dynamics::MeshShape::getType ( ) const
overridevirtual

Returns a string representing the shape type.

See also
is()

Implements dart::dynamics::Shape.

◆ getVolume()

double dart::dynamics::Shape::getVolume ( ) const
inherited

Returns volume of this shape.

The volume will be automatically calculated by the sub-classes such as BoxShape, EllipsoidShape, CylinderShape, and MeshShape.

◆ is()

template<typename ShapeT >
bool dart::dynamics::Shape::is
inherited

Get true if the types of this Shape and the template parameter (a shape class) are identical.

This function is a syntactic sugar, which is identical to: (getType() == ShapeType::getStaticType()).

Example code:

auto shape = bodyNode->getShapeNode(0)->getShape();
if (shape->is<BoxShape>())
std::cout << "The shape type is box!\n";
See also
getType()

◆ loadMesh() [1/3]

const aiScene * dart::dynamics::MeshShape::loadMesh ( const common::Uri uri,
const common::ResourceRetrieverPtr retriever 
)
static

◆ loadMesh() [2/3]

const aiScene * dart::dynamics::MeshShape::loadMesh ( const std::string &  _uri,
const common::ResourceRetrieverPtr retriever 
)
static

◆ loadMesh() [3/3]

const aiScene * dart::dynamics::MeshShape::loadMesh ( const std::string &  filePath)
static

◆ notifyAlphaUpdate()

void dart::dynamics::Shape::notifyAlphaUpdate ( double  alpha)
virtualinherited

Notify that the alpha of this shape has updated.

◆ notifyAlphaUpdated()

void dart::dynamics::MeshShape::notifyAlphaUpdated ( double  alpha)
overridevirtual

Notify that the alpha of this shape has updated.

Reimplemented from dart::dynamics::Shape.

◆ notifyColorUpdate()

void dart::dynamics::Shape::notifyColorUpdate ( const Eigen::Vector4d &  color)
virtualinherited

Notify that the color (rgba) of this shape has updated.

◆ notifyColorUpdated()

void dart::dynamics::Shape::notifyColorUpdated ( const Eigen::Vector4d &  color)
virtualinherited

Notify that the color (rgba) of this shape has updated.

Reimplemented in dart::dynamics::ArrowShape.

◆ refreshData()

void dart::dynamics::Shape::refreshData ( )
virtualinherited

Instruct this shape to update its data.

◆ removeDataVariance()

void dart::dynamics::Shape::removeDataVariance ( unsigned int  _variance)
inherited

Remove a type of variance from this shape.

All other variance types will remain the same.

◆ removeObserver()

void dart::common::Subject::removeObserver ( Observer _observer) const
protectedinherited

Remove an Observer from the list of Observers.

◆ sendDestructionNotification()

void dart::common::Subject::sendDestructionNotification ( ) const
protectedinherited

Send a destruction notification to all Observers.

This will cause all Observers to behave as if this Subject has been permanently deleted, so it should only be called when that behavior is desired.

◆ setColorIndex()

void dart::dynamics::MeshShape::setColorIndex ( int  index)

Set which entry in aiMesh::mColor should be used when the color mode is COLOR_INDEX.

This value must be smaller than AI_MAX_NUMBER_OF_COLOR_SETS. If the color index is higher than what the mesh has available, then we will use the highest index possible.

◆ setColorMode()

void dart::dynamics::MeshShape::setColorMode ( ColorMode  mode)

Set how the color of this mesh should be determined.

◆ setDataVariance()

void dart::dynamics::Shape::setDataVariance ( unsigned int  _variance)
inherited

Set the data variance of this shape.

Use the DataVariance to indicate what kind of shape information might change during run time so that renderers can optimize reliably.

◆ setDisplayList()

void dart::dynamics::MeshShape::setDisplayList ( int  index)

◆ setMesh() [1/2]

void dart::dynamics::MeshShape::setMesh ( const aiScene *  mesh,
const common::Uri path,
common::ResourceRetrieverPtr  resourceRetriever = nullptr 
)

◆ setMesh() [2/2]

void dart::dynamics::MeshShape::setMesh ( const aiScene *  mesh,
const std::string &  path = "",
common::ResourceRetrieverPtr  resourceRetriever = nullptr 
)

◆ setScale()

void dart::dynamics::MeshShape::setScale ( const Eigen::Vector3d &  scale)

◆ update()

void dart::dynamics::MeshShape::update ( )
virtual

Updates positions of the vertices or the elements.

By default, this does nothing; you must extend the MeshShape class and implement your own version of this function if you want the mesh data to get updated before rendering

◆ updateBoundingBox()

void dart::dynamics::MeshShape::updateBoundingBox ( ) const
overrideprotectedvirtual

Updates bounding box.

Implements dart::dynamics::Shape.

◆ updateVolume()

void dart::dynamics::MeshShape::updateVolume ( ) const
overrideprotectedvirtual

Updates volume.

Implements dart::dynamics::Shape.

Member Data Documentation

◆ mBoundingBox

math::BoundingBox dart::dynamics::Shape::mBoundingBox
mutableprotectedinherited

The bounding box (in the local coordinate frame) of the shape.

◆ mColorIndex

int dart::dynamics::MeshShape::mColorIndex
protected

Specifies which color index should be used when mColorMode is COLOR_INDEX.

◆ mColorMode

ColorMode dart::dynamics::MeshShape::mColorMode
protected

Specifies how the color of this mesh should be determined.

◆ mCounter

int dart::dynamics::Shape::mCounter = 1000
staticprotectedinherited

◆ mDisplayList

int dart::dynamics::MeshShape::mDisplayList
protected

OpenGL DisplayList id for rendering.

◆ mID

int dart::dynamics::Shape::mID
protectedinherited

Unique id.

◆ mIsBoundingBoxDirty

bool dart::dynamics::Shape::mIsBoundingBoxDirty
mutableprotectedinherited

Whether bounding box needs update.

◆ mIsVolumeDirty

bool dart::dynamics::Shape::mIsVolumeDirty
mutableprotectedinherited

Whether volume needs update.

◆ mMesh

const aiScene* dart::dynamics::MeshShape::mMesh
protected

◆ mMeshPath

std::string dart::dynamics::MeshShape::mMeshPath
protected

Path the mesh on disk, if available.

◆ mMeshUri

common::Uri dart::dynamics::MeshShape::mMeshUri
protected

URI the mesh, if available).

◆ mObservers

std::set<Observer*> dart::common::Subject::mObservers
mutableprotectedinherited

List of current Observers.

◆ mResourceRetriever

common::ResourceRetrieverPtr dart::dynamics::MeshShape::mResourceRetriever
protected

Optional method of loading resources by URI.

◆ mScale

Eigen::Vector3d dart::dynamics::MeshShape::mScale
protected

Scale.

◆ mType

ShapeType dart::dynamics::Shape::mType
protectedinherited
Deprecated:
Deprecated in 6.1.

Please use getType() instead. Type of primitive shpae.

◆ mVariance

unsigned int dart::dynamics::Shape::mVariance
protectedinherited

The DataVariance of this Shape.

◆ mVolume

double dart::dynamics::Shape::mVolume
mutableprotectedinherited

Volume enclosed by the geometry.