Technical Documentation (API)

MEL/PYTHON COMMANDS

This section describes the different MEL/Python commands
 

Set/Get PPAttribute Value

If you want to build more complex behaviors it is generally useful to set/get ppAttribute values to control them. You can use the following helpers function to do that:
 
float getPPAttributeFloat(string ppAttrName, string particleSystemName, int particleId)
 
setPPAttributeFloat(string ppAttrName, float ppAttrValue, string particleSystemName, int particleId)
 
 
float[] getPPAttributeVector(string ppAttrName, string particleSystemName, int particleId)
 
setPPAttributeVector(string ppAttrName, float ppAttrValue[], string particleSystemName, int particleId)
 

Spatial Request

Golaem Crowd provides a way to query its neighborhood graph when the simulation is running and a navigation mesh terrain has been defined (i.e. the positions of the crowd entities contained in a cylinder). This query can be done with the glmSpatialRequestCmd:
string[] glmSpatialRequestCmd [-center float float float] [-radius float] [-type string] [-count int] [-showDistance boolean]
The result of this command can be easily sent to the glmCrowdFieldInfoCmd.
 

Flags

  • -center (-ce) float float float: defines the center of the query circle;
  • -radius (-r) float: defines the radius of the query circle;
  • -type (ty) string: defines the type of returned data (count|entityIds|particleIds);
  • -count (co) integer: specifies the number of entities to return. -1 for all of them;
  • -showDistance (sd) boolean: true if the distance of entities with the center is returned as well;

Return Value

Depending on the type, count and showDistance flags, this command returns different values:
  • "count" for the flag "type": returns the number of entities contained in the query circle;
  • "entityIds" for the flag "type": returns the XX first Golaem Crowd entity ids sorted by proximity order, following this template: [entityId][crowdFieldName];
  • "particleIds" for the flag "type": returns the XX first particle ids sorted by proximity order, following this template: [particleId][particleSystemName][crowdFieldName].
With XX defined with the flag "count". The flag "showDistance" can be used to append the distance value.
 

MEL Examples

// get the number of entities in a 2m circle around the scene origin
glmSpatialRequestCmd -center 0 0 0 -radius 2 -type "count";
// Result: 3 //
 
// get their particle ids
glmSpatialRequestCmd -center 0 0 0 -radius 2 -type "particleIds";
// Result: 7 particle2 crowdField1 6 particle2 crowdField1 3 particle2 crowdField1 //
 
// just the closest
glmSpatialRequestCmd -center 0 0 0 -radius 2 -type "particleIds" -count 1;
// Result: 7 particle2 crowdField1 //
 
// just the closest and its distance
glmSpatialRequestCmd -center 0 0 0 -radius 2 -type "particleIds" -count 1 -showDistance on;
// Result: 7 particle2 crowdField1 0.942455 //
 
// Note that being a command and not a function, you need to use ` ` when storing its result:
string $spatialResult [] = `glmSpatialRequestCmd -center 0 0 0 -radius 2 -type "particleIds" -count 1 -showDistance on;`;
// Result: 7 particle2 crowdField1 0.942455 //
 

Behavior & Trigger Callback Special Tags

Crowd behaviors and triggers allow to run MEL/Python commands when they start/stop/are successful. To interact between CrowdEntities and their related particles, Golaem Crowd defines two special tags which can be used in those commands:
  • #ps# this tag is replaced with the name of the particle system to which the entity is attached;
  • #pid# this tag is replaced with the id of the particle to which the entity is attached.
These two tags can be used to identify the particle attached to the CrowdEntity on which the behavior is run. For example, if the user defines the function: global proc increaseHealth(string $particleSystem, int $particleId) {…}
To call this function with the current particle, the MEL command to use is;
increaseHealth("#ps#", #pid#)