Data types

Myriad Grains Language support following data types, that reflects default types of array attributes passed through Maya DG graph:

  • int
  • float
  • vector

Variables with type listed above are considered as host variables.

Special type of objects introduced in MGL are:

  • vert (for vertices): representation of point-set
  • selection: subset of points from vert variable

Every variable needs to be declared in global scope of script.
Example variable declaration & definition:

int i;
vector v = <<0, 1, 0>>;
vert v;

vert variable

Vert variable is an object that represents set of points. This entity is used to access properties of vertices describing mesh or point-cloud. Instances of points are created during input operation from Maya node attributes:

vert v = inMesh[0];
vert p = inPoints[0];

In example above Maya objects connected to input attributes were decomposed to arrays of properties describing those objects. Values of properties are accessible through v and p identifiers. Mesh edges define neighborhood of vertices. This information is stored in v object as well to allow further computations involving field values of surrounding points.
Transformed vert object can be exposed to Maya as mesh or point array, that can be connected to instancer node:

// Transformations
outMesh[0] = v;
outPoints[0] = v;

Object p does not contain mesh definition. It is considered as point-cloud and thus it can only be exposed to Maya Dependency Graph as an array attribute:

outPoints[0] = p;

Point properties are described by fields, such as position, pointID, objectIndex or other user-defined values.

Fields

Point fields are declared in similar manner as host variables:

vert p;
vector p.color;
float p.factor = 1;

To access point field use a dot and field identifier. Following line of code moves every point in Y axis by one unit:

p.position.y += 1;

Transformation performed on vert variable field is executed in parallel mode – single thread per point per operation list. Operation on point field can involve other fields of same point set. Let’s move points along Y axis by value of pointID:

p.position.y += p.pointID*0.1;

moveYTransformation of points

Mixing point sets is not allowed in single expression.

selection variable

Sometimes when operating on instances only subset of points designated by given factor needs to be exported to Maya. For example we would like to output only this points which are above XZ axis. To do so selection variable can be utilized:

vert p = inMesh[0];
selection s;
if(p.position.y > 0)
{
    // Add point to selection 's' if 'y' component of point position if greather than 0
    addPoint(s); 
}
outPoints[0] = s;

selection

Selection variable can be exported only as array of points (using outPoints[n]).
Selection inherits fields from vert variable that is processed in current scope.
Selection can contain points from only one vert variable.

Language reference | Next: Default variables and point fields