Instances

Myriad Grains was designed to cooperate with Maya instancing system. Instances appearance depends on transformation and shading properties.

Transformation

In order to compose transformation matrix of instances and setup other display parameters like visibility or object type, Maya instancer node utilizes set of default per-particle attributes like position, scale, shear. While outputting point-set from mgAutomata node through outPoints[n] attribute, all fields are exposed to Maya DG graph under same identifier as field name declared in script scope.
For example: to assign random scale of instanced objects, define “scale” field of vert variable:

vert p = inMesh[0];
vector p.scale = <<1,1,1>> * rand(p.pointID);
outPoints[0] = p;

randomScale
Random scale assigned to instances

According to documentation, use flowing fields to define instances orientation:

vert p = inMesh[0];
vector target = inVector[0]; // translation attribute of blue sphere
int p.rotationType = 1; // 1 for AimDirection, see docs
vector p.aimWorldUp = <<0, 1, 0>>;
vector p.aimDirection = target - p.position;
outPoints[0] = p;

orientation
Orientation of instances controlled by per-particle attributes

In this case translation of blue sphere has been connected to inVector[0] attribute of mgAutomata node. This vector value was utilized in computation of aimDirection. Find other ways of defining instance orientation in documentation.

Other important per-particle attribute is objectIndex. Instancer node assigns geometry to particles based on value of objectIndex parameter. Use vertex color, shading network or random utility to define object type.

In following example objectIndex of instance is defined by vertex color transferred to point field:

vert p = inMesh[0];
vector p.color; // declare field "color" to get vertex color from Maya object
int p.objectIndex;

if(0 < p.color.x)
{
    p.objectIndex = 1; // Set objectIndex according to vertex color
}

outPoints[0] = p;

objectIndex
Instance object defined by vertex color

Instance shading properties

Myriad Grains in connection with Arnold renderer gives control over shading properties of instanced objects.
To affect shading properties of instanced geometry perform following steps:

1. Prepare Arnod stand-in with shading network based on user defined data:

shadingProps_network
Example shading network of instanced geometry

Diffuse color of shader clefMat applied to the mesh is driven by blendColor node, that mixes together colors from Arnold userDataColor nodes. Noise texture is set as mixing mask. Color attribute name of userDataColor is set to colorA and colorB respectively:

UDC
Export standin file.

2. Create mgAutomata network setup using prepared stand-in:

shadingNetwork

– In script executed by mgAutomata define vector fields of exported point set named “colorA” and “colorB”:

vert p = inMesh[0];
vector p.colorA = << rand(p.pointID)*0.4, rand(p.pointID+1)*0.4, rand(p.pointID+2)*0.4 >>;
vector p.colorB = << rand(p.pointID+3)*0.4, rand(p.pointID+4)*0.4, rand(p.pointID+5)*0.4 >>;
outPoints[0] = p;

– In instancer node properties, using attribute editor select mgAutomata translator:

translatorTranslator menu is available when mtoa.mll is loaded.

– In mgAutomata node properties, type name of user defined attributes that supposed to be exported with instances (in this case colorA and colorB):


While rendering, Maya will translate per-particle properties “colorA”, “colorB” and attach it to exported instances. Arnold renderer utilizes this data, user defined colors affects shader:

shadingProps_v05
Per-particle data affects shading network of stand-ins