Skip to content

raisim::Mesh ​

final class · #include <raisim/object/singleBodies/Mesh.hpp>

Inherits: raisim::SingleBodyObject

A rigid body defined by a triangle mesh (create it with World::addMesh()). By default the collision geometry is the convex hull of the mesh; it can also be the original triangle mesh or a CoACD convex decomposition. Vertices are stored scaled, in the body frame.

Nested classes ​

  • struct ConvexPart — One convex part of a CoACD decomposition, in the body frame.
  • class FileCache — Mesh files read by World::addMesh(), so a mesh placed many times (a .rasset collider, say) is read from disk once per world.
  • struct PreprocessOptions — Options for preprocessMesh().
  • struct PreprocessResult — Result of preprocessMesh().

Constructors & destructor ​

Mesh ​

cpp
explicit Mesh(
    const std::string &filename,
    double mass,
    const Mat<3, 3> &inertia,
    const Vec<3> &COM,
    double scale,
    const CoacdOptions &coacdOptions)

Load a mesh with user-given mass properties and use a CoACD convex decomposition for collision (falls back to the convex hull with a warning if the decomposition fails).

Parameters

ParameterDescription
filename (in)mesh file (OBJ, USD, or any format supported by Assimp)
mass (in)mass (kg)
inertia (in)inertia about the COM in the body frame (kg m^2)
COM (in)center of mass in the body frame (m, after scaling)
scale (in)uniform scale applied to the vertices
coacdOptions (in)decomposition parameters
cpp
explicit Mesh(const std::string &filename, double mass, double scale=1.0)

Load a mesh and use its convex hull for collision. The COM is the center of the vertex bounding box and the inertia is that of a uniform box with the bounding box dimensions.

Parameters

ParameterDescription
filename (in)mesh file (OBJ, USD, or any format supported by Assimp)
mass (in)mass (kg)
scale (in)uniform scale applied to the vertices
cpp
explicit Mesh(
    const std::string &filename,
    double mass,
    double scale,
    const CoacdOptions &coacdOptions)

Same as Mesh(const std::string&, double, double) but uses a CoACD convex decomposition for collision.

Parameters

ParameterDescription
filename (in)mesh file
mass (in)mass (kg)
scale (in)uniform scale applied to the vertices
coacdOptions (in)decomposition parameters

~Mesh ​

cpp
~Mesh() final

Public member functions ​

getMeshFileName ​

cpp
const std::string &getMeshFileName() const

Returns mesh file name if it was created with a file. Otherwise, returns an empty string

getVerticies ​

cpp
const std::vector<float> &getVerticies() const

Returns the scaled vertices as a flat xyz array in the body frame.

getIndicies ​

cpp
const std::vector<std::uint32_t> &getIndicies() const

Returns the triangle index buffer (three indices per triangle).

getScale ​

cpp
double getScale() const

Returns the uniform scale applied to the vertices.

isConvexified ​

cpp
bool isConvexified() const

Returns true unless the original (possibly concave) triangle mesh is used for collision, i.e., true for both convex hull and CoACD.

getCoacdOptions ​

cpp
const CoacdOptions &getCoacdOptions() const

Returns the CoACD options given at construction.

getCoacdConvexParts ​

cpp
const std::vector<ConvexPart> &getCoacdConvexParts() const

Returns the CoACD convex parts; empty unless a decomposition is in use.

getCollisionBodyCount ​

cpp
size_t getCollisionBodyCount() const

Returns the number of collision bodies (1, or the number of convex parts for CoACD).

getCollisionBodyAt ​

cpp
CollisionBodyHandlePtr getCollisionBodyAt(size_t index)

Parameters

ParameterDescription
index (in)collision body index, less than getCollisionBodyCount()

Returns the collision body (owned by the mesh), or nullptr if out of range

cpp
CollisionBodyHandleConstPtr getCollisionBodyAt(size_t index) const

Parameters

ParameterDescription
index (in)collision body index, less than getCollisionBodyCount()

Returns the collision body (owned by the mesh), or nullptr if out of range

setBodyType ​

cpp
void setBodyType(BodyType type) override

Same as SingleBodyObject::setBodyType(), applied to all collision bodies.

Parameters

ParameterDescription
type (in)the body type

updateContactAabbs ​

cpp
void updateContactAabbs() override

Internal: recomputes the world-frame AABBs used by the broadphase.

updateCollision ​

cpp
void updateCollision() override

Internal: synchronizes the collision geometry with the current pose.

Static member functions ​

loadMesh static ​

cpp
static void loadMesh(
    const std::string &filename,
    std::vector<float> &verticies,
    std::vector<std::uint32_t> &idx,
    double scale=1)

Load a triangle mesh. OBJ and USD files use built-in loaders; other formats use Assimp. Fatal error on failure.

Parameters

ParameterDescription
filename (in)mesh file
verticies (out)flat xyz vertex buffer
idx (out)triangle index buffer
scale (in)uniform scale applied to the vertices

loadObj static ​

cpp
static void loadObj(
    const std::string &filename,
    std::vector<float> &verticies,
    std::vector<std::uint32_t> &idx,
    double scale=1)

Load an OBJ file (the extension must be .obj). Fatal error on failure.

Parameters

ParameterDescription
filename (in)OBJ file
verticies (out)flat xyz vertex buffer
idx (out)triangle index buffer
scale (in)uniform scale applied to the vertices

writeObj static ​

cpp
static void writeObj(
    const std::string &filename,
    const std::vector<float> &vertices,
    const std::vector<std::uint32_t> &idx)

Writes a triangle mesh as a normalized OBJ file. Missing parent directories are created.

Parameters

ParameterDescription
filename (in)output path
vertices (in)flat xyz vertex buffer (size must be a multiple of 3)
idx (in)triangle index buffer (size must be a multiple of 3)

computeFileHash static ​

cpp
static std::uint64_t computeFileHash(const std::string &filename)

Computes a deterministic content hash for an asset file.

Parameters

ParameterDescription
filename (in)file to hash (fatal error if it cannot be opened)

Returns 64-bit content hash

preprocessMesh static ​

cpp
static PreprocessResult preprocessMesh(
    const std::string &filename,
    const PreprocessOptions &options)

Loads any supported mesh format and writes a normalized triangulated OBJ cache. The cache filename includes the source content hash and the scale so stale cached assets are not reused after source or scale changes.

Parameters

ParameterDescription
filename (in)source mesh (any format supported by loadMesh())
options (in)scale, cache directory and force flag

Returns paths, hash and size of the processed mesh

Inherited members ​

From raisim::SingleBodyObject: clearExternalForcesAndTorques, getAngularVelocity, getAppearance, getBodyToComPosition_rs, getCollisionBody, getCollisionGroup, getCollisionMask, getCom, getComPosition, getComPosition_rs, getContactPointVel, getDOF, getEnergy, getGeneralizedCoordinateDim, getGyroscopicMode, getInertiaMatrix_B, getInertiaMatrix_B_rs, getInertiaMatrix_W, getInertiaMatrix_W_rs, getKineticEnergy, getLinearMomentum, getLinearVelocity, getMass, getObjectType, getOrientation, getPosition, getPotentialEnergy, getQuaternion, getRotationMatrix, getVelocity, integrate, preContactSolverUpdate1, preContactSolverUpdate2, setAngularDamping, setAngularVelocity, setAppearance, setCom, setConstraintForce, setExternalForce, setExternalTorque, setGyroscopicMode, setInertia, setLinearDamping, setLinearVelocity, setMass, setOrientation, setPose, setPosition, setVelocity

From raisim::Object: addContactToPerObjectContact, clearPerObjectContact, getBodyType, getContactAabb, getContactAabbCount, getContacts, getExternalForce, getExternalForcePosition, getExternalTorque, getExternalTorquePosition, getId, getIndexInWorld, getName, getRenderRevision, Id, lock, lockMutex, setIndexInWorld, setName, try_lock, unlock, unlockMutex

RaiSim — physics for robotics and AI.