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
structConvexPart — One convex part of a CoACD decomposition, in the body frame.classFileCache — Mesh files read by World::addMesh(), so a mesh placed many times (a .rasset collider, say) is read from disk once per world.structPreprocessOptions — Options for preprocessMesh().structPreprocessResult — Result of preprocessMesh().
Constructors & destructor
Mesh
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
| Parameter | Description |
|---|---|
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 |
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
| Parameter | Description |
|---|---|
filename (in) | mesh file (OBJ, USD, or any format supported by Assimp) |
mass (in) | mass (kg) |
scale (in) | uniform scale applied to the vertices |
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
| Parameter | Description |
|---|---|
filename (in) | mesh file |
mass (in) | mass (kg) |
scale (in) | uniform scale applied to the vertices |
coacdOptions (in) | decomposition parameters |
~Mesh
~Mesh() finalPublic member functions
getMeshFileName
const std::string &getMeshFileName() constReturns mesh file name if it was created with a file. Otherwise, returns an empty string
getVerticies
const std::vector<float> &getVerticies() constReturns the scaled vertices as a flat xyz array in the body frame.
getIndicies
const std::vector<std::uint32_t> &getIndicies() constReturns the triangle index buffer (three indices per triangle).
getScale
double getScale() constReturns the uniform scale applied to the vertices.
isConvexified
bool isConvexified() constReturns true unless the original (possibly concave) triangle mesh is used for collision, i.e., true for both convex hull and CoACD.
getCoacdOptions
const CoacdOptions &getCoacdOptions() constReturns the CoACD options given at construction.
getCoacdConvexParts
const std::vector<ConvexPart> &getCoacdConvexParts() constReturns the CoACD convex parts; empty unless a decomposition is in use.
getCollisionBodyCount
size_t getCollisionBodyCount() constReturns the number of collision bodies (1, or the number of convex parts for CoACD).
getCollisionBodyAt
CollisionBodyHandlePtr getCollisionBodyAt(size_t index)Parameters
| Parameter | Description |
|---|---|
index (in) | collision body index, less than getCollisionBodyCount() |
Returns the collision body (owned by the mesh), or nullptr if out of range
CollisionBodyHandleConstPtr getCollisionBodyAt(size_t index) constParameters
| Parameter | Description |
|---|---|
index (in) | collision body index, less than getCollisionBodyCount() |
Returns the collision body (owned by the mesh), or nullptr if out of range
setBodyType
void setBodyType(BodyType type) overrideSame as SingleBodyObject::setBodyType(), applied to all collision bodies.
Parameters
| Parameter | Description |
|---|---|
type (in) | the body type |
updateContactAabbs
void updateContactAabbs() overrideInternal: recomputes the world-frame AABBs used by the broadphase.
updateCollision
void updateCollision() overrideInternal: synchronizes the collision geometry with the current pose.
Static member functions
loadMesh static
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
| Parameter | Description |
|---|---|
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
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
| Parameter | Description |
|---|---|
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
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
| Parameter | Description |
|---|---|
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
static std::uint64_t computeFileHash(const std::string &filename)Computes a deterministic content hash for an asset file.
Parameters
| Parameter | Description |
|---|---|
filename (in) | file to hash (fatal error if it cannot be opened) |
Returns 64-bit content hash
preprocessMesh static
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
| Parameter | Description |
|---|---|
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