17. RigidBody emitter

An agx::RigidBodyEmitter creates new rigid bodies at a certain rate within a specified volume and adds them to the simulation. This is useful when you do not want to create all the rigid bodies at the start of the simulation and/or when the rigid bodies in your simulation should follow some kind of size/shape distribution.

The following code snippet demonstrates how to create a rigid body emitter in c++:

agx::RigidBodyEmitterRef emitter = new agx::RigidBodyEmitter();
emitter->setRate(30.0);
emitter->setMaximumEmittedQuantity(200);
emitter->setQuantity(agx::Emitter::QUANTITY_COUNT);

The rate and the maximumEmittedQuantity decides how fast the emitter creates new bodies and what the maximum quantity is. There are three different ways of counting the quantity of the emitter.

Table 17.1 Different quantity settings of the emitter and distribution table

QUANTITY_COUNT

Counting number of individual rocks as the quantity.

QUANTITY_VOLUME

Counting the total volume of emitted rocks as the quantity.

QUANTITY_MASS

Counting the total mass of the emitted rocks as the quantity.

When the emitter creates a new rigid body it randomly chooses a distributionModel from the distributionTable. A distributionModel consists of a rigidBody template and a weight. The weight is the probability to create a clone of the corresponding rigid body template and adding it to the simulation. By adding several different distributionModels to the distributionTable of the rigid body emitter, the same emitter can emit rigid bodies with different geometries, sizes and materials. A short code example on how to create a distributionTable with one distributionModel:

// Create distribution table
agx::Emitter::DistributionTableRef distributionTable = new agx::Emitter::DistributionTable(agx::Emitter::Quantity::QUANTITY_MASS);

// Create template
agx::RigidBodyRef bodyTemplate1 = new agx::RigidBody();
agxCollide::GeometryRef geometryTemplate1 = new agxCollide::Geometry(new agxCollide::Cylinder(0.4, 0.1));
geometryTemplate1->setMaterial(material);
bodyTemplate1->add(geometryTemplate1);

distributionTable->addModel(new agx::RigidBodyEmitter::DistributionModel(bodyTemplate1, 0.3));
emitter->setDistributionTable(distributionTable);

Finally the rigidBodyEmitter needs a volume in which rigid bodies will spawn. It is defined as an agxCollide::Geometry:

agxCollide::GeometryRef emitGeometry = new agxCollide::Geometry(new agxCollide::Sphere(3.0));
emitGeometry->setSensor(true);
emitter->setGeometry(emitGeometry);