World

The raisim::World class owns simulation resources: objects, constraints, materials, collision detection, contact solving, sensors, time, and gravity. All objects within a single World instance can collide with one another unless their collision group and mask settings disable that pair. See Contact and Collision and Collision Detection and Colliders for contact and collision details.

A World instance can be instantiated in two ways. The first method involves loading a RaiSim world configuration file in XML format. Further details regarding the XML format are available in the World Configuration File section.

The second method is to dynamically generate the world via code.

These methods can be combined by loading an initial XML configuration and subsequently adding objects dynamically.

An experimental MJCF (MuJoCo file format) reader is also available. MJCF files can be loaded with the same raisim::World constructor used for RaiSim XML:

raisim::World world("rsc/mjcf/gymnasium/hopper.xml");

The reader supports the subset used by the bundled MJCF examples: world bodies, articulated bodies, free, slide, and hinge joints, primitive geoms, mesh assets, inertial tags, defaults, compiler angle/eulerseq settings, compiler meshdir, and material colors. Mesh asset paths are resolved relative to the MJCF file directory, or relative to compiler meshdir when it is provided. MJCF files without an asset block are accepted.

It is not a complete MuJoCo replacement; advanced MJCF features such as include, tendons, equality constraints, actuators beyond the supported examples, and full simulator options should be validated before relying on them.

Example targets:

  • mjcf_gymnasium_hopper loads and actuates Gymnasium’s Hopper model.

  • mjcf_gymnasium_walker2d loads and actuates Gymnasium’s Walker2d model.

  • mjcf_gymnasium_humanoid loads Gymnasium’s Humanoid model and drops it from a raised arbitrary configuration.

Adding New Objects

To add a new object of type X, utilize the addX method. For example, to add a sphere:

raisim::World world;
auto sphere = world.addSphere(0.5, 1.0);

sphere represents a pointer to the internal resource. It facilitates access to and modification of internal variables.

Most object-creation methods accept optional material, collisionGroup, and collisionMask arguments. Static objects such as ground and heightmaps use a fixed collision group and expose only a collision mask. Collision variables are detailed in the “Contact and Collision” section. The material argument specifies the material governing contact dynamics, as further explained in the “Material System” chapter.

A comprehensive list of objects is provided in the “Object” chapter.

Upon object addition, a name may be assigned:

sphere->setName("ball");

An object pointer can be retrieved by name:

auto* ball = world.getObject("ball");

An object may consist of multiple bodies (e.g., an articulated system). A local index is used to designate individual bodies. To maintain API consistency, many methods require the local index argument even for single-body objects. For single-body objects, the local index is ignored, and users may pass 0 to comply with the API.

Saving the World to an XML File

raisim::World::exportToXml(dir, file) (or exportToXml(path)) saves the current world state to an XML file. The current examples index lists the source targets that exercise world creation and asset loading.

Stepping and time

World::integrate() advances the world by one timestep. It is equivalent to calling integrate1() and then integrate2().

Method

Work performed

setTimeStep(dt)

Updates the world timestep, contact solver timestep, and object-local timestep state.

integrate1()

Clears previous contacts, runs collision detection, registers contacts, and calls each object’s first pre-solver update hook.

integrate2()

Runs the second pre-solver update hook, solves contacts, and integrates object state.

integrate()

Runs integrate1(); integrate2();.

integrateNoContactDetection()

Updates objects without contact detection and contact-problem construction.

getWorldTime() returns the integrated simulation time, and setWorldTime(time) can manually adjust it. For visualization through RaisimServer, prefer RaisimServer::integrateWorldThreadSafe() so the server’s background reader and user interactions are synchronized.

Collision Detection and Broadphase

RaiSim performs collision detection in two stages: a broadphase pass that filters candidate pairs using axis-aligned bounding boxes (AABBs), followed by a narrowphase pass (analytic tests, SAT, MPR, and GJK/EPA depending on the shape pair) to generate contact points. You can configure the contact detector via setContactSettings or adjust only the broadphase via setBroadphaseSettings. These settings should be updated when the world is not stepping.

Broadphase options are defined by contact::BroadphaseType:

  • None (brute-force pairs, useful for debugging or very small scenes)

  • Sap3Axis (sweep-and-prune, default)

  • MultiBoxPrune (grid-based broadphase for large worlds)

The current contact::ContactSettings defaults are:

Setting

Default

gjkMaxIterations, gjkTolerance

32, 1e-6

epaMaxIterations, epaTolerance

64, 1e-4

maxContactsPerPair

8

sweptCcdEnabled

false

sweptCcdMinSpeed

0.0

sweptCcdSpeculativeMargin

1e-4

broadphase.type

Sap3Axis

broadphase.mbpWorldMin / mbpWorldMax

{-100, -100, -100} / {100, 100, 100}

broadphase.mbpCellSize

{1, 1, 1}

broadphase.mbpPadding

0.5

broadphase.mbpMaxCellsPerAxis / mbpMaxCellsPerObject

128 / 64

Example broadphase configuration (MultiBoxPrune):

#include <raisim/World.hpp>
#include <raisim/contact_engine/contact_engine.h>

raisim::World world;
auto settings = world.getContactSettings();
settings.broadphase.type = contact::BroadphaseType::MultiBoxPrune;
settings.broadphase.mbpWorldMin = {-50.0, -50.0, -2.0};
settings.broadphase.mbpWorldMax = { 50.0,  50.0, 10.0};
settings.broadphase.mbpCellSize = {  1.0,   1.0,  1.0};
settings.broadphase.mbpUseWorldBounds = true;
world.setContactSettings(settings);

Collision groups and masks still gate which pairs are considered in both broadphase and narrowphase.

Contact Solver Settings

World::setERP(erp, erp2) updates the contact solver’s error-reduction parameters. World::setContactSolverParam(alpha_init, alpha_min, alpha_decay, maxIter, threshold) updates the solver configuration. In the current public API, the alpha arguments are kept for compatibility; the practical knobs are maxIter and threshold. The solver defaults are maxIteration = 150 and error_to_terminate = 1e-8.

Use World::setContactSolverIterationOrder(order) when you need a fixed contact iteration order for determinism. Without an explicit order, the solver order may flip between integration calls.

Sleeping islands

RaiSim can skip simulation for sleeping islands: groups of dynamic objects connected by contacts. Sleeping is enabled by default. An island goes to sleep when all objects in the island remain quiet for a configurable number of consecutive steps (quietSteps, default 2) and their maximum linear and angular velocities stay below the configured thresholds (defaults: linear 0.002, angular 0.01).

Notes:

  • Only dynamic objects participate in sleeping islands.

  • Any user modification (e.g., changing state) keeps the island awake.

  • Contacts between awake and sleeping islands will wake the sleeping island on the next step.

Configuration API:

world.setSleepingEnabled(true);
world.setSleepingParameters(/*linear*/ 0.002, /*angular*/ 0.01, /*quietSteps*/ 2);
world.setSleepingVelocityThresholds(0.002, 0.01);
world.wakeObject(obj);   // wakes the object's island
world.wakeAll();

You can query whether a specific object is sleeping with isObjectSleeping.

API

class World

Public Functions

explicit World()

Create an empty world

inline explicit World(const std::string &configFile, const std::vector<ParameterContainer> &params = {})

Create an world as specified in the xml config file

void exportToXml(const std::string &dir, const std::string &fileName)

export the world to an xml config file, which can be loaded using a constructor

Parameters:
  • dir[in] directory to save the xml file

  • fileName[in] file name

inline void exportToXml(const std::string &pathIn)

export the world to an xml config file, which can be loaded using a constructor

Parameters:

pathIn[in] path to save the xml file

std::vector<std::string> exportMeshAssetsToObj(const std::string &directory, const std::string &prefix = "mesh") const

Exports every Mesh object in the world as a normalized OBJ asset. The returned paths are ordered by the world’s object list order.

inline void setTimeStep(double dt)

set the time step

Parameters:

dt[in] the time step

inline double getTimeStep() const
Returns:

the time step

Sphere *addSphere(double radius, double mass, const std::string &material = "default", CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1))
Parameters:
  • radius[in] radius

  • mass[in] mass

  • material[in] material of the height map (which defines the contact dynamics)

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”.

Returns:

pointer to the created box

Box *addBox(double xLength, double yLength, double zLength, double mass, const std::string &material = "default", CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1))
Parameters:
  • xLength[in] x dimension

  • yLength[in] y dimension

  • zLength[in] z dimension

  • mass[in] mass

  • material[in] material of the height map (which defines the contact dynamics)

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”.

Returns:

pointer to the created box

Cylinder *addCylinder(double radius, double height, double mass, const std::string &material = "default", CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1))
Parameters:
  • radius[in] radius

  • height[in] center-to-center distance

  • mass[in] mass

  • material[in] material of the height map (which defines the contact dynamics)

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”.

Returns:

pointer to the created cylinder

Capsule *addCapsule(double radius, double height, double mass, const std::string &material = "default", CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1))
Parameters:
  • radius[in] radius

  • height[in] center-to-center distance

  • mass[in] mass

  • material[in] material of the height map (which defines the contact dynamics)

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”.

Returns:

pointer to the created capsule

Ground *addGround(double zHeight = 0.0, const std::string &material = "default", CollisionGroup collisionMask = CollisionGroup(-1))
Parameters:
  • zHeight[in] height of the terrain

  • material[in] material of the height map (which defines the contact dynamics)

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”. Note that collision group of a static object is CollisionGroup(1) << 61ul

Returns:

pointer to the created ground

HeightMap *addHeightMap(size_t xSamples, size_t ySamples, double xSize, double ySize, double centerX, double centerY, const std::vector<double> &height, const std::string &material = "default", CollisionGroup collisionGroup = (CollisionGroup(1) << 63), CollisionGroup collisionMask = CollisionGroup(-1))
Parameters:
  • xSamples[in] how many points along x axis

  • ySamples[in] how many points along y axis

  • xSize[in] x width of the height map

  • ySize[in] y length of the height map

  • centerX[in] x coordinate of the center of the height map

  • centerY[in] y coordinate of the center of the height map

  • height[in] a vector of doubles representing heights. the size should be xSample X ySamples

  • material[in] material of the height map (which defines the contact dynamics)

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

Returns:

pointer to the created height map

HeightMap *addHeightMap(const std::string &raisimHeightMapFileName, double centerX, double centerY, const std::string &material = "default", CollisionGroup collisionGroup = (CollisionGroup(1) << 63), CollisionGroup collisionMask = CollisionGroup(-1))
Parameters:
  • raisimHeightMapFileName[in] the raisim text file which will be used to create the height map

  • centerX[in] x coordinate of the center of the height map

  • centerY[in] y coordinate of the center of the height map

  • material[in] material of the height map (which defines the contact dynamics)

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

Returns:

pointer to the created height map

HeightMap *addHeightMap(const std::string &pngFileName, double centerX, double centerY, double xSize, double ySize, double heightScale, double heightOffset, const std::string &material = "default", CollisionGroup collisionGroup = (CollisionGroup(1) << 63), CollisionGroup collisionMask = CollisionGroup(-1))
Parameters:
  • pngFileName[in] the png file which will be used to create the height map

  • centerX[in] x coordinate of the center of the height map

  • centerY[in] y coordinate of the center of the height map

  • xSize[in] x width of the height map

  • ySize[in] y length of the height map

  • heightScale[in] a png file (if 8-bit) has pixel values from 0 to 255. This parameter scales the pixel values to the actual height

  • heightOffset[in] height of the 0-value pixel

  • material[in] material of the height map (which defines the contact dynamics)

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

Returns:

pointer to the created height map

HeightMap *addHeightMap(double centerX, double centerY, TerrainProperties &terrainProperties, const std::string &material = "default", CollisionGroup collisionGroup = (CollisionGroup(1) << 63), CollisionGroup collisionMask = CollisionGroup(-1))
Parameters:
  • centerX[in] x coordinate of the center of the height map

  • centerY[in] y coordinate of the center of the height map

  • terrainProperties[in] perlin noise parameters which will be used to create the height map

  • material[in] material of the height map (which defines the contact dynamics)

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

Returns:

pointer to the created height map

HeightMap *addHeightMap(const HeightMap *heightmapToBeCloned, CollisionGroup collisionGroup = (CollisionGroup(1) << 63), CollisionGroup collisionMask = CollisionGroup(-1))
Parameters:
  • heightmapToBeCloned[in] Another height map to be cloned

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

Returns:

pointer to the created height map

ArticulatedSystem *addArticulatedSystem(const std::string &filePathOrURDFScript, const std::string &resPath = "", const std::vector<std::string> &jointOrder = {}, CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1), ArticulatedSystemOption options = ArticulatedSystemOption())
Parameters:
  • filePathOrURDFScript[in] Path to urdf file or a URDF string. Depending on the contents of the string, RaiSim will interpret it as an xml string or a file path.

  • resPath[in] Path to the resource directory. Leave it empty (“”) if it is the urdf file directory

  • jointOrder[in] this can be used to redefine the joint order. A child cannot precede its parent. Leave it empty ({}) to use the joint order defined in the URDF file.

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

  • options[in] Supports “doNotCollideWithParent” and “convexifyCollisionMeshes”

Returns:

pointer to the articulated system

ArticulatedSystem *addArticulatedSystem(const std::string &filePathOrURDFScript, const std::vector<std::string> &modules, const std::string &resPath = "", const std::vector<std::string> &jointOrder = {}, CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1), ArticulatedSystemOption options = ArticulatedSystemOption())
Parameters:
  • filePathOrURDFScript[in] Path to urdf file or a URDF string. Depending on the contents of the string, RaiSim will interpret it as an xml string or a file path.

  • modules[in] Optional URDF modules to include (URDF fragments).

  • resPath[in] Path to the resource directory. Leave it empty (“”) if it is the urdf file directory

  • jointOrder[in] this can be used to redefine the joint order. A child cannot precede its parent. Leave it empty ({}) to use the joint order defined in the URDF file.

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

  • options[in] Supports “doNotCollideWithParent” and “convexifyCollisionMeshes”

Returns:

pointer to the articulated system

ArticulatedSystem *addArticulatedSystem(const std::string &xmlFileTemplate, const std::vector<ParameterContainer> &params, const std::string &resPath = "", const std::vector<std::string> &jointOrder = {}, CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1), ArticulatedSystemOption options = ArticulatedSystemOption())
Parameters:
  • xmlFileTemplate[in] xml template file.

  • params[in] parameters for the xml file.

  • resPath[in] Path to the resource directory. Leave it empty (“”) if it is the urdf file directory

  • jointOrder[in] this can be used to redefine the joint order. A child cannot precede its parent. Leave it empty ({}) to use the joint order defined in the URDF file.

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

  • options[in] Supports “doNotCollideWithParent” and “convexifyCollisionMeshes”

Returns:

pointer to the articulated system

ArticulatedSystem *addArticulatedSystem(const Child &child, const std::string &resPath = "", CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1), ArticulatedSystemOption options = ArticulatedSystemOption())

This method programmatically creates an articulated system without an URDF file.

Parameters:
  • child[in] an instance of Child class which has an articulated system structure.

  • resPath[in] Path to the resource directory. Leave it empty (“”) if it is the urdf file directory

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

  • options[in] Supports “doNotCollideWithParent” and “convexifyCollisionMeshes”

Returns:

pointer to the articulated system

Compound *addCompound(const std::vector<Compound::CompoundObjectChild> &children, double mass, Vec<3> COM, const Mat<3, 3> &inertia, CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1))

Add a single body which is composed of multiple primitive collision shapes

Parameters:
  • children[in] a vector of CompoundObjectChild which contains each primitive shape’s position, orientation, material and shape parameters

  • mass[in] mass of the composite body

  • COM[in] center of the composite body

  • inertia[in] inertia of the composite body

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

Returns:

pointer to the created compound object

Mesh *addMesh(const std::string &meshFileInObjFormat, double mass, const Mat<3, 3> &inertia, const Vec<3> &COM, double scale = 1, const std::string &material = "", CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1))

create mesh collision body. Any mesh format supported by Assimp can be used; USD files are loaded through OpenUSD.

Parameters:
  • meshFileInObjFormat[in] mesh file of the object

  • mass[in] mass

  • inertia[in] inertia

  • COM[in] the center of the mass

  • scale[in] rescale the mesh

  • material[in] material of the mesh (which defines the contact dynamics)

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

Returns:

pointer to the created convexified mesh, or original mesh if CoACD fails

Mesh *addMesh(const std::string &meshFileInObjFormat, double mass, const Mat<3, 3> &inertia, const Vec<3> &COM, double scale, const std::string &material, MeshCollisionMode collisionMode, CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1), const CoacdOptions &coacdOptions = CoacdOptions())

create mesh collision body with an explicit mesh collision mode. Any mesh format supported by Assimp can be used; USD files are loaded through OpenUSD. MeshCollisionMode::ORIGINAL_MESH keeps the non-convex triangle mesh. MeshCollisionMode::CONVEX_HULL creates one convex hull. MeshCollisionMode::CONVEXIFY creates a CoACD convex decomposition using coacdOptions and falls back to original mesh on failure.

Parameters:
  • meshFileInObjFormat[in] mesh file of the object

  • mass[in] mass

  • inertia[in] inertia

  • COM[in] the center of the mass

  • scale[in] rescale the mesh

  • material[in] material of the mesh (which defines the contact dynamics)

  • collisionMode[in] original mesh, convex hull, or convex decomposition

  • coacdOptions[in] convex decomposition parameters. Used only with MeshCollisionMode::CONVEXIFY.

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

Returns:

pointer to the created mesh

Mesh *addMesh(const std::string &meshFileInObjFormat, double mass, const Mat<3, 3> &inertia, const Vec<3> &COM, double scale, const std::string &material, const CoacdOptions &coacdOptions, CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1))

create mesh collision body approximated by CoACD convex decomposition.

Parameters:
  • meshFileInObjFormat[in] mesh file of the object

  • mass[in] mass

  • inertia[in] inertia

  • COM[in] the center of the mass

  • scale[in] rescale the mesh

  • material[in] material of the mesh (which defines the contact dynamics)

  • coacdOptions[in] convex decomposition parameters

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

Returns:

pointer to the created mesh

Mesh *addMesh(const std::string &meshFileInObjFormat, double mass, double scale = 1, const std::string &material = "", CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1))

create mesh collision body. Any mesh format supported by Assimp can be used; USD files are loaded through OpenUSD. Inertia and COM are estimated by computing the axis-aligned bounding box of the (scaled) mesh and treating it as a uniform-density box.

Parameters:
  • meshFileInObjFormat[in] mesh file of the object

  • mass[in] mass

  • scale[in] rescale the mesh

  • material[in] material of the mesh (which defines the contact dynamics)

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

Returns:

pointer to the created convexified mesh, or original mesh if CoACD fails

Mesh *addMesh(const std::string &meshFileInObjFormat, double mass, double scale, const std::string &material, MeshCollisionMode collisionMode, CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1), const CoacdOptions &coacdOptions = CoacdOptions())

create mesh collision body with an explicit mesh collision mode. Inertia and COM are estimated by computing the axis-aligned bounding box of the (scaled) mesh and treating it as a uniform-density box. MeshCollisionMode::ORIGINAL_MESH keeps the non-convex triangle mesh. MeshCollisionMode::CONVEX_HULL creates one convex hull. MeshCollisionMode::CONVEXIFY creates a CoACD convex decomposition using coacdOptions and falls back to original mesh on failure.

Parameters:
  • meshFileInObjFormat[in] mesh file of the object

  • mass[in] mass

  • scale[in] rescale the mesh

  • material[in] material of the mesh (which defines the contact dynamics)

  • collisionMode[in] original mesh, convex hull, or convex decomposition

  • coacdOptions[in] convex decomposition parameters. Used only with MeshCollisionMode::CONVEXIFY.

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

Returns:

pointer to the created mesh

Mesh *addMesh(const std::string &meshFileInObjFormat, double mass, double scale, const std::string &material, const CoacdOptions &coacdOptions, CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1))

create mesh collision body approximated by CoACD convex decomposition. Inertia and COM are estimated by computing the axis-aligned bounding box of the (scaled) mesh and treating it as a uniform-density box.

Parameters:
  • meshFileInObjFormat[in] mesh file of the object

  • mass[in] mass

  • scale[in] rescale the mesh

  • material[in] material of the mesh (which defines the contact dynamics)

  • coacdOptions[in] convex decomposition parameters

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

Returns:

pointer to the created mesh

Mesh *addMesh(const Mesh *meshToClone, const std::string &material = "", CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1))

create mesh collision body. any mesh format supported by Assimp can be used

Parameters:
  • meshToClone[in] mesh to copy

  • material[in] material of the mesh (which defines the contact dynamics)

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

Returns:

pointer to the created wire

DeformableObject *addDeformableCloth(const std::vector<Vec<3>> &vertices, const std::vector<DeformableObject::Triangle> &triangles, const std::vector<unsigned int> &pinnedVertices = {}, const DeformableObject::Material &material = DeformableObject::Material(), const std::string &contactMaterial = "default", CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1))

Create a deformable cloth/shell object from vertices and triangle indices. The first implementation uses XPBD/PBD distance constraints generated from triangle edges and one spherical collision proxy per vertex.

Parameters:
  • vertices[in] particle positions in world coordinates

  • triangles[in] triangle vertex indices

  • pinnedVertices[in] vertices held fixed in world coordinates

  • material[in] deformable solver and material parameters

  • contactMaterial[in] material used by collision proxies

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

Returns:

pointer to the created deformable object

DeformableObject *addDeformableCloth(const std::string &meshFileInObjFormat, double scale = 1.0, const std::vector<unsigned int> &pinnedVertices = {}, const DeformableObject::Material &material = DeformableObject::Material(), const std::string &contactMaterial = "default", CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1))

Create a deformable cloth/shell object from an OBJ triangle mesh. Polygon faces are triangulated as a fan. Texture and normal indices are ignored.

Parameters:
  • meshFileInObjFormat[in] OBJ file path

  • scale[in] vertex scale

  • pinnedVertices[in] vertices held fixed in world coordinates

  • material[in] deformable solver and material parameters

  • contactMaterial[in] material used by collision proxies

  • collisionGroup[in] read “Contact and Collision/ Collision Group and Mask”

  • collisionMask[in] read “Contact and Collision/ Collision Group and Mask”

Returns:

pointer to the created deformable object

DeformableObject *addDeformableObject(const std::string &meshFileInObjFormat, const DeformableObject::Material &material, const DeformableObject::MeshBuildOptions &options, const std::vector<unsigned int> &pinnedVertices = {}, const std::string &contactMaterial = "default", CollisionGroup collisionGroup = 1, CollisionGroup collisionMask = CollisionGroup(-1))

Create a deformable object from an OBJ mesh and particle generation options. Surface mode uses the mesh vertices as particles. Filled mode requires a closed triangle mesh and adds interior particles on a regular grid. Internal struts can be generated automatically through DeformableObject::MeshBuildOptions.

GranularSystem *addGranularParticles(const std::vector<Vec<3>> &positions, const std::vector<double> &radii, const GranularSystem::Material &material = GranularSystem::Material())

Create a native granular particle system. Particles are stored and stepped as one object instead of thousands of independent Sphere objects. This first solver path handles particle-particle DEM contacts internally and can optionally collide with a horizontal ground plane through GranularSystem::setGroundPlane().

StiffLengthConstraint *addStiffWire(Object *obj1, size_t localIdx1, Vec<3> pos1_b, Object *obj2, size_t localIdx2, Vec<3> pos2_b, double length)

Stiff unilateral constraint. It cannot push. It can only pull.

Parameters:
  • obj1[in] the first object the wire is attached to

  • localIdx1[in] the body index (0 for a SingleBodyObject) for the first object

  • pos1_b[in] location of the cable attachment on the first object

  • obj2[in] the second object the wire is attached to

  • localIdx2[in] the body index (0 for a SingleBodyObject) for the second object

  • pos2_b[in] location of the cable attachment on the second object

  • length[in] length of the wire

Returns:

pointer to the created wire

CompliantLengthConstraint *addCompliantWire(Object *obj1, int localIdx1, Vec<3> pos1_b, Object *obj2, int localIdx2, Vec<3> pos2_b, double length, double stiffness)

soft unilateral constraint. It cannot push. It can only pull.

Parameters:
  • obj1[in] the first object the wire is attached to

  • localIdx1[in] the body index (0 for a SingleBodyObject) for the first object

  • pos1_b[in] location of the cable attachment on the first object

  • obj2[in] the second object the wire is attached to

  • localIdx2[in] the body index (0 for a SingleBodyObject) for the second object

  • pos2_b[in] location of the cable attachment on the second object

  • length[in] length of the wire

  • stiffness[in] stiffness of the wire

Returns:

pointer to the created wire

CustomLengthConstraint *addCustomWire(Object *obj1, int localIdx1, Vec<3> pos1_b, Object *obj2, int localIdx2, Vec<3> pos2_b, double length)

Custom wire that applies user-set tension between two points.

Parameters:
  • obj1[in] the first object the wire is attached to

  • localIdx1[in] the body index (0 for a SingleBodyObject) for the first object

  • pos1_b[in] location of the cable attachment on the first object

  • obj2[in] the second object the wire is attached to

  • localIdx2[in] the body index (0 for a SingleBodyObject) for the second object

  • pos2_b[in] location of the cable attachment on the second object

  • length[in] length of the wire. You can use this to compute how much it stretched from a nominal length. It might not be necessary for some wire types.

Returns:

pointer to the created wire

Object *getObject(const std::string &name)
Returns:

object with the given name. returns nullptr if the object doesn’t exist. The name can be set by Object::setName()

inline Object *getObject(std::size_t worldIndex)
Returns:

object with the given index. This index can be retrieved by Object::getIndexInWorld()

Object *getObjectById(ObjectId id)
Returns:

object with the stable runtime id, or nullptr if the object no longer exists.

const Object *getObjectById(ObjectId id) const
Returns:

object with the stable runtime id, or nullptr if the object no longer exists.

bool isObjectAlive(ObjectId id) const
Returns:

true if an object with the stable runtime id currently exists in the world.

std::vector<Object*> &getObjList()
Returns:

returns a non-const vector of the objects

Constraints *getConstraint(const std::string &name)
Returns:

a constraint (e.g., wires) with the given name. returns nullptr if the object doesn’t exist. The name can be set by Wire::setName(). This is equivalent to getWire(const std::string&)

LengthConstraint *getWire(const std::string &name)
Returns:

a wire with the given name. returns nullptr if the object doesn’t exist. The name can be set by Wire::setName()

inline unsigned long getConfigurationNumber()
Returns:

the configuration number. this number is updated every time an object is added or removed

bool setObjectCollisionFilter(Object *object, CollisionGroup collisionGroup, CollisionGroup collisionMask, size_t localIdx = size_t(-1))

Updates collision group and mask for all collision bodies on an object, or for a specific local body. Call this between simulation steps.

bool setObjectMaterial(Object *object, const std::string &material, size_t localIdx = size_t(-1))

Updates the collision material for all collision bodies on an object, or for a specific local body. Call this between simulation steps.

bool captureSingleBodySnapshot(const SingleBodyObject *object, SingleBodySnapshot &snapshot) const

Captures a single-body runtime state snapshot.

bool restoreSingleBodySnapshot(SingleBodyObject *object, const SingleBodySnapshot &snapshot, bool restoreCollisionProperties = true)

Restores a single-body runtime state snapshot. If restoreCollisionProperties is true, collision group, mask, and material are restored as well.

bool restoreSingleBodySnapshot(ObjectId id, const SingleBodySnapshot &snapshot, bool restoreCollisionProperties = true)

Restores a single-body runtime state snapshot by stable object id.

SingleBodyObject *cloneSingleBodyObject(const SingleBodyObject *source, const std::string &name = "")

Clones primitive single-body objects with pose, velocity, mass, body type, material, collision filter, and appearance. Returns nullptr for unsupported single-body types.

const RayCollisionList &rayTest(const Eigen::Ref<const Eigen::Vector3d, Eigen::Unaligned> &start, const Eigen::Ref<const Eigen::Vector3d, Eigen::Unaligned> &direction, double length, size_t objectId = size_t(-10), size_t localId = size_t(-10), CollisionGroup collisionMask = CollisionGroup(-1))

Returns the internal reference of the ray collision list. It stores only the closest hit. This returns

Parameters:
  • start[in] The start position of the ray.

  • direction[in] The direction of the ray.

  • length[in] The length of the ray.

  • objectId[in] Collision with objects with both matching objectId and localId will be ignored. This can be useful if the sensor is attached to a robot.

  • localId[in] Collision with objects with both matching objectId and localId will be ignored. This can be useful if the sensor is attached to a robot.

  • collisionMask[in] Collision mask to filter collisions. By default, it records collisions with all collision groups.

Returns:

A reference to the internal container which contains all ray collisions.

void rayTestLidar(const Mat<3, 3> &rot, const Vec<3> &pos, int yawStartCount, int yawEndCount, double yawIncrement, int spinDirection, int pitchSamples, double pitchMinAngle, double pitchIncrement, double rangeMin, double rangeMax, size_t objectId, size_t localId, CollisionGroup collisionMask, std::vector<Vec<3>, AlignedAllocator<Vec<3>, 32>> &scan)

Ray-cast helper for spinning lidar scans. Applies a frustum-based broadphase before running per-ray collision tests.

Parameters:
  • rot[in] Sensor orientation (sensor frame to world frame).

  • pos[in] Sensor position in world frame.

  • yawStartCount[in] Start yaw sample index (inclusive).

  • yawEndCount[in] End yaw sample index (inclusive).

  • yawIncrement[in] Yaw increment in radians.

  • spinDirection[in] Spin direction (+1 or -1).

  • pitchSamples[in] Number of pitch samples.

  • pitchMinAngle[in] Minimum pitch angle in radians.

  • pitchIncrement[in] Pitch increment in radians.

  • rangeMin[in] Minimum range in meters.

  • rangeMax[in] Maximum range in meters.

  • objectId[in] Object id to ignore (sensor owner).

  • localId[in] Local body id to ignore (sensor owner).

  • collisionMask[in] Collision mask to filter collisions.

  • scan[out] Output scan points in the sensor frame.

void captureDepthCamera(const Vec<3> &pos, const Mat<3, 3> &rot, const DepthCameraProperties &properties, DepthCameraFrame &frame, size_t objectId = size_t(-10), size_t localId = size_t(-10), CollisionGroup collisionMask = CollisionGroup(-1))

Captures a deterministic CPU ray-based depth camera frame. The camera uses the same convention as RaiSim depth sensors: +X is forward, +Y is left, and +Z is up in the camera frame. Depth is the distance along the camera forward axis, segmentation is the hit object’s world index, and -1 denotes background.

void removeObject(Object *obj)

removes an object

Parameters:

obj[in] object to be removed

void removeObject(LengthConstraint *wire)

removes a wire (i.e., LengthConstraint)

Parameters:

wire[in] the wire to be removed

void integrate()

integrate the world It is equivalent to “integrate1(); integrate2();”

void integrate1()

It performs 1) deletion contacts from previous time step 2) collision detection 3) register contacts to each body 4) calls “preContactSolverUpdate1()” of each object

void integrate2()

It performs 1) calls “preContactSolverUpdate2()” of each body 2) run collision solver 3) calls “integrate” method of each object

void integrateNoContactDetection()

It performs 1) deletion contacts from previous time step 2) updates collision objects 3) calls “preContactSolverUpdate1()” of each object It skips contact detection and contact problem construction.

inline const contact::ContactProblems *getContactProblem() const

It performs 1) calls “preContactSolverUpdate2()” of each body 2) run collision solver 3) calls “integrate” method of each object

void setGravity(const Vec<3> &gravity)

Set gravity

Parameters:

gravity[in] gravitational acceleration of the world

void updateMaterialProp(const MaterialManager &prop)

this deletes the existing material props and replace them with the argument

Parameters:

prop – new material prop

void setMaterialPairProp(const std::string &mat1, const std::string &mat2, double friction, double restitution, double resThreshold)

Add a new material pair property. In RaiSim, material property is defined by the pair.

Parameters:
  • mat1[in] name of the first material (the order of mat1 and mat2 is not important)

  • mat2[in] name of the first material

  • friction[in] the coefficient of friction

  • restitution[in] the coefficient of restitution

  • resThreshold[in] the minimum impact velocity to make the object bounce

void setMaterialPairProp(const std::string &mat1, const std::string &mat2, double friction, double restitution, double resThreshold, double staticFriction, double staticFrictionThresholdVelocity)

Add a new material pair property. In RaiSim, material property is defined by the pair.

Parameters:
  • mat1[in] name of the first material (the order of mat1 and mat2 is not important)

  • mat2[in] name of the first material

  • friction[in] the dynamic coefficient of friction

  • restitution[in] the coefficient of restitution

  • resThreshold[in] the minimum impact velocity to make the object bounce

  • staticFriction[in] the static coefficient of friction

  • staticFrictionThresholdVelocity[in] if the relative velocity of two points is bigger than this value, then the dynamic coefficient of friction is applied. Otherwise, the coefficient of friction is interpolated between the static and dynamic one proportional to the relative velocity.

void setDefaultMaterial(double friction, double restitution, double resThreshold)

this default material property is used if a material pair property is not defined for the specific collision

Parameters:
  • friction[in] the coefficient of friction

  • restitution[in] the coefficient of restitution

  • resThreshold[in] the minimum impact velocity to make the object bounce

void setDefaultMaterial(double friction, double restitution, double resThreshold, double staticFriction, double staticFrictionThresholdVelocity)

this default material property is used if a material pair property is not defined for the specific collision

Parameters:
  • friction[in] the coefficient of friction

  • restitution[in] the coefficient of restitution

  • resThreshold[in] the minimum impact velocity to make the object bounce

  • staticFriction[in] the static coefficient of friction

  • staticFrictionThresholdVelocity[in] if the relative velocity of two points is bigger than this value, then the dynamic coefficient of friction is applied. Otherwise, the coefficient of friction is interpolated between the static and dynamic one proportional to the relative velocity.

inline const Vec<3> &getGravity() const
Returns:

gravitational acceleration of the world

void setERP(double erp, double erp2 = 0)

Changes the Error Reduction Parameter. It often has very minimalistic impact on simulation

Parameters:
  • erp[in] spring constant between object. This constant is scaled by the apparent inertia so it has no well-defined physical meaning

  • erp2[in] damping constant between object. This constant is scaled by the apparent inertia so it has no well-defined physical meaning

void setContactSolverParam(double alpha_init, double alpha_min, double alpha_decay, int maxIter, double threshold)

Changes the contact solver parameter. For details, please check “Hwangbo, Jemin, Joonho Lee, and Marco Hutter. “Per-contact iteration method for solving contact dynamics.” IEEE Robotics and Automation Letters 3.2 (2018): 895-902.” We found that the three default alpha values are always the best. So they are hardcoded now. So only the maxIter and threshold will affect the simulation. The three input alpha values will be ignored

Parameters:
  • alpha_init[in] NOT_USED_ANYMORE (default: 1.0) how aggressive the solver is initially

  • alpha_min[in] NOT_USED_ANYMORE (default: 1.0) how aggressive the solver is after an infinite number of solver iterations

  • alpha_decay[in] NOT_USED_ANYMORE (default: 1.0) how fast alpha converges from alpha_init to alpha_min

  • threshold[in] (default: 1e-8) error threshold for termination

  • maxIter[in] (default: 150) the maximum number of iterations allowed

void setContactSettings(const ::contact::ContactSettings &settings)

Configure contact detection (broadphase/narrowphase) settings. Call this when the world is not stepping.

Parameters:

settings[in] Contact detector settings.

void setSleepingEnabled(bool enabled)

Enable or disable sleeping islands.

bool isSleepingEnabled() const

Returns true if sleeping islands are enabled.

void setSleepingParameters(double linearVelThreshold, double angularVelThreshold, int quietSteps)

Configure sleeping thresholds.

const SleepSettings &getSleepingParameters() const

Returns the current sleeping configuration.

void setSleepingVelocityThresholds(double linearVelThreshold, double angularVelThreshold)

Update only the sleeping velocity thresholds.

void wakeObject(Object *object)

Wake a specific object (and its island) on the next step.

void wakeAll()

Wake all objects.

bool isObjectSleeping(const Object *object) const

Returns true if the object is currently sleeping.

void setBroadphaseSettings(const ::contact::BroadphaseSettings &settings)

Configure broadphase settings only. Call this when the world is not stepping.

Parameters:

settings[in] Broadphase settings.

inline const ::contact::ContactSettings &getContactSettings() const
Returns:

current contact detection settings.

inline const ::contact::BroadphaseSettings &getBroadphaseSettings() const
Returns:

current broadphase settings.

inline double getWorldTime() const
Returns:

the total integrated time (which is updated at every integrate2() call)

inline void setWorldTime(double time)

manually adjust the world time

Parameters:

time[in] the world time

inline raisim::contact::BisectionContactSolver &getContactSolver()
Returns:

a non-const ref of the contact solver. contact::BisectionContactSolver::setOrder(bool) can be used to make the solver deterministic

inline void setContactSolverIterationOrder(bool order)

This sets the iteration order (e.g., forward and backward) of the contact solver. Given this order, Raisim is deterministic. Without an explicit order, the order flips in every integrate call.

Parameters:

order[in] True to keep a fixed iteration order for determinism.

inline const raisim::contact::BisectionContactSolver &getContactSolver() const
Returns:

a const ref of the contact solver. Internal states can be retrieved using this method

inline const std::string &getConfigFile()

get the config file if the world was created using a xml config file

Returns:

the path to the xml config file

inline std::vector<std::unique_ptr<LengthConstraint>> &getWires()

get a vector wires in the world

Returns:

a vector of unique_ptrs of wires

inline const MaterialPairProperties &getMaterialPairProperties(const std::string &mat1, const std::string &mat2) const

get the material pair properties. The order of materials does not matter.

Parameters:
  • mat1[in] material name

  • mat2[in] material name

Returns:

material pair properties

inline void lockMutex()

locks chart mutex. This can be used if you use raisim in a multi-threaded environment.

inline void unlockMutex()

unlock chart mutex. This can be used if you use raisim in a multi-threaded environment.

void updateSelfCollisionCache()

Refresh contact body metadata after collision filter changes.

Public Static Functions

static inline void setActivationKey(const std::string &activationKey)

export the world to an xml config file, which can be loaded using a constructor

Parameters:

activationKey[in] path to the license file

struct CollisionCounters
struct DepthCameraFrame
struct DepthCameraProperties
struct ParameterContainer
struct SingleBodySnapshot

Snapshot of a single-body object’s runtime state and collision properties. It is intended for fast RL reset/randomization workflows between simulation steps.

struct SleepSettings