Skip to content

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 ​

cpp
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

ParameterDescription
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 ​

cpp
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

ParameterDescription
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 ​

cpp
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

ParameterDescription
node (in)MJCF element
className (out)the class (unchanged if neither is set)

Returns true if a class applies

getParameter static ​

cpp
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

ParameterDescription
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 ​

cpp
static void getPoseAndParam(
    const std::unordered_map<std::string, RaiSimTinyXmlWrapper> &defaults,
    const RaiSimTinyXmlWrapper &node,
    Shape::Type type,
    const std::string &typeName,
    Vec<4> &param,
    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

ParameterDescription
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 ​

cpp
static void getMjcfSizeParam(
    const RaiSimTinyXmlWrapper &g,
    Shape::Type type,
    Vec<4> &param)

Convert the size/fromto attributes of an element to raisim shape parameters.

Parameters

ParameterDescription
g (in)MJCF element
type (in)shape type
param (out)raisim shape parameters

getMjcfPos static ​

cpp
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

ParameterDescription
g (in)MJCF element
pos (in, out)position

posFromFromTo static ​

cpp
static void posFromFromTo(const RaiSimTinyXmlWrapper &g, Vec<3> &pos)

Set pos to the midpoint of "fromto" if present (unchanged otherwise).

Parameters

ParameterDescription
g (in)MJCF element
pos (in, out)position

getMjcfOrientation static ​

cpp
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

ParameterDescription
g (in)MJCF element
rot (in, out)orientation
eulerseq (in)compiler euler sequence
anglerep (in)compiler angle unit ("degree" or "radian")

getJointFrame static ​

cpp
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

ParameterDescription
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 ​

cpp
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

ParameterDescription
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 ​

cpp
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

ParameterDescription
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 ​

cpp
static Vec<4> parseRgba(const std::string &text, const char *elementName)

Parse an MJCF rgba attribute; fatal unless it holds 4 finite numbers.

Parameters

ParameterDescription
text (in)attribute value
elementName (in)element named in the error message

Returns the color

materialDefaultsKey static ​

cpp
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

ParameterDescription
materialName (in)MJCF material name

Returns the key in the defaults map

getColorFromMaterial static ​

cpp
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

ParameterDescription
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

RaiSim — physics for robotics and AI.