raisim::mjcf::LoadFromMjcf
class · #include <raisim/object/ArticulatedSystem/loaders.hpp>
Internal: MJCF body parser that fills an ArticulatedSystem. Used by the MJCF world loader.
Public member functions
load
void load(
ArticulatedSystem &sys,
RaiSimTinyXmlWrapper &c,
const std::unordered_map<std::string, RaiSimTinyXmlWrapper> &defaultDefaultNode,
const std::unordered_map<std::string, std::pair<std::string, Vec<3>>> &mesh,
const MjcfCompilerSetting &setting)Build the kinematic tree of sys from an MJCF body. A root that is neither floating nor fixed is wrapped in a fixed root.
Parameters
| Parameter | Description |
|---|---|
sys (in, out) | articulated system to fill |
c (in) | MJCF body element |
defaultDefaultNode (in) | default classes (and assets) keyed by name |
mesh (in) | mesh assets: name -> (file, scale) |
setting (in) | compiler settings |
Static member functions
readFromDefault static
template <typename T>
static bool readFromDefault(
const std::unordered_map<std::string, RaiSimTinyXmlWrapper> &defaults,
const std::string &className,
const std::string &typeName,
const std::string &attName,
T &value)Read an attribute of a default class, falling back to its parent classes up to the main class as it was where the class was defined (a class without a "parent" attribute ends the chain).
Parameters
| Parameter | Description |
|---|---|
defaults (in) | default classes keyed by name |
className (in) | class to start from |
typeName (in) | element type (e.g., "geom", "joint") |
attName (in) | attribute name |
value (out) | attribute value (unchanged if not found) |
Returns true if the attribute was found
getClassName static
static bool getClassName(
const RaiSimTinyXmlWrapper &node,
std::string &className)The default class of an MJCF element: its own class attribute, else the childclass of its nearest enclosing element that has one. MuJoCo's name of the main class, "main", is returned as "default", the key of the main class in the defaults.
Parameters
| Parameter | Description |
|---|---|
node (in) | MJCF element |
className (out) | the class (unchanged if neither is set) |
Returns true if a class applies
getParameter static
template <typename T>
static bool getParameter(
const std::unordered_map<std::string, RaiSimTinyXmlWrapper> &defaults,
const RaiSimTinyXmlWrapper &node,
const std::string &typeName,
const std::string &attName,
T &value)Read an attribute from a node, falling back to its class (or the element type's defaults).
Parameters
| Parameter | Description |
|---|---|
defaults (in) | default classes keyed by name |
node (in) | MJCF element |
typeName (in) | element type (e.g., "geom", "joint") |
attName (in) | attribute name |
value (out) | attribute value (unchanged if not found) |
Returns true if the attribute was found
getPoseAndParam static
static void getPoseAndParam(
const std::unordered_map<std::string, RaiSimTinyXmlWrapper> &defaults,
const RaiSimTinyXmlWrapper &node,
Shape::Type type,
const std::string &typeName,
Vec<4> ¶m,
Mat<3, 3> &rot,
Vec<3> &pos,
const MjcfCompilerSetting &setting)Resolve the pose and size of a geom/site, layering element-type defaults, class defaults and the node.
Parameters
| Parameter | Description |
|---|---|
defaults (in) | default classes keyed by name |
node (in) | MJCF element |
type (in) | shape type |
typeName (in) | element type ("geom" or "site") |
param (out) | raisim shape parameters |
rot (out) | orientation relative to the parent body |
pos (out) | position in the parent body frame |
setting (in) | compiler settings |
getMjcfSizeParam static
static void getMjcfSizeParam(
const RaiSimTinyXmlWrapper &g,
Shape::Type type,
Vec<4> ¶m)Convert the size/fromto attributes of an element to raisim shape parameters.
Parameters
| Parameter | Description |
|---|---|
g (in) | MJCF element |
type (in) | shape type |
param (out) | raisim shape parameters |
getMjcfPos static
static void getMjcfPos(const RaiSimTinyXmlWrapper &g, Vec<3> &pos)Read "pos" (or the midpoint of "fromto"). pos is left unchanged if neither is present.
Parameters
| Parameter | Description |
|---|---|
g (in) | MJCF element |
pos (in, out) | position |
posFromFromTo static
static void posFromFromTo(const RaiSimTinyXmlWrapper &g, Vec<3> &pos)Set pos to the midpoint of "fromto" if present (unchanged otherwise).
Parameters
| Parameter | Description |
|---|---|
g (in) | MJCF element |
pos (in, out) | position |
getMjcfOrientation static
static void getMjcfOrientation(
const RaiSimTinyXmlWrapper &g,
Mat<3, 3> &rot,
const std::string &eulerseq,
const std::string &anglerep)Read the orientation from fromto, xyaxes, axisangle, zaxis, quat or euler (first one present). rot is left unchanged if none is present.
Parameters
| Parameter | Description |
|---|---|
g (in) | MJCF element |
rot (in, out) | orientation |
eulerseq (in) | compiler euler sequence |
anglerep (in) | compiler angle unit ("degree" or "radian") |
getJointFrame static
static void getJointFrame(
const std::unordered_map<std::string, RaiSimTinyXmlWrapper> &defaults,
const RaiSimTinyXmlWrapper &joint,
const MjcfCompilerSetting &setting,
Mat<3, 3> &rot,
Vec<3> &pos)Read the frame of an MJCF joint in its body's frame: "pos" (with class fallback) and the orientation attributes.
Parameters
| Parameter | Description |
|---|---|
defaults (in) | default classes keyed by name |
joint (in) | MJCF joint or freejoint element |
setting (in) | compiler settings |
rot (out) | orientation of the joint frame |
pos (out) | origin of the joint frame |
getRaisimBodyFrame static
static void getRaisimBodyFrame(
const std::unordered_map<std::string, RaiSimTinyXmlWrapper> &defaults,
const RaiSimTinyXmlWrapper &body,
const MjcfCompilerSetting &setting,
Mat<3, 3> &rot,
Vec<3> &pos)The frame, in an MJCF body's frame, of the RaiSim body that keeps the MJCF body's name. It is the frame of the body's joint, of the last one if it has several (the others become a chain of massless bodies before it), and the MJCF body's own frame if it has none.
Parameters
| Parameter | Description |
|---|---|
defaults (in) | default classes keyed by name |
body (in) | MJCF body element |
setting (in) | compiler settings |
rot (out) | orientation of the RaiSim body frame |
pos (out) | origin of the RaiSim body frame |
getCollisionBitmaskParameter static
static bool getCollisionBitmaskParameter(
const std::unordered_map<std::string, RaiSimTinyXmlWrapper> &defaults,
const RaiSimTinyXmlWrapper &node,
const std::string &attName,
CollisionGroup &value)Read a geom collision bitmask attribute (e.g., contype/conaffinity) with class fallback.
Parameters
| Parameter | Description |
|---|---|
defaults (in) | default classes keyed by name |
node (in) | MJCF element |
attName (in) | attribute name |
value (out) | bitmask |
Returns true if the attribute was found
parseRgba static
static Vec<4> parseRgba(const std::string &text, const char *elementName)Parse an MJCF rgba attribute; fatal unless it holds 4 finite numbers.
Parameters
| Parameter | Description |
|---|---|
text (in) | attribute value |
elementName (in) | element named in the error message |
Returns the color
materialDefaultsKey static
static std::string materialDefaultsKey(const std::string &materialName)Key under which an <asset> <material> node is stored in the defaults map. Prefixed so that material names cannot collide with default-class names, which share that map.
Parameters
| Parameter | Description |
|---|---|
materialName (in) | MJCF material name |
Returns the key in the defaults map
getColorFromMaterial static
static bool getColorFromMaterial(
const std::unordered_map<std::string, RaiSimTinyXmlWrapper> &defaults,
const std::string &c,
std::string &color)Read "rgba" of an entry of the defaults map, following "parent" attributes.
Parameters
| Parameter | Description |
|---|---|
defaults (in) | default classes/materials keyed by name |
c (in) | key of the entry to start from |
color (out) | rgba attribute text |
Returns true if found