Data types

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

  • int
  • float
  • vector

Special types of objects introduced in MGL are:

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

Every variable needs to be declared in global scope of a 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, which describe 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 are decomposed to arrays of properties. Values of properties are accessible through v and p identifiers.
Transformed vert object can be exposed to Maya as a mesh or point cloud, that can be connected to instancer node:

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

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

Fields

Declaring and defining point fields:

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

Accessing and modifying point field:

p.position.y += 1;

Above line of code moves every point in Y axis by one unit:

Transformation performed on a vert field is executed in parallel. Operation on a 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 a single expression.

selection variable

Determining subset of points:

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 an 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