Assign to a vector array attribute component

An expression can neither read nor assign a component of a vector or vector array attribute. The following example shows a technique for working around this limitation. For details on working with color attributes, see Work with color.

Example

Suppose you have a 100-particle Cloud of randomly positioned particles. You turn on Shading > Smooth Shade All, add a per particle rgbPP attribute. then enter the following creation expression:

CloudShape.position = sphrand(1);
vector $pos = CloudShape.position;
CloudShape.rgbPP = <<0,$pos.y,0>>;

The three statements execute once for each particle in Cloud.

The first statement gives a particle a random position within a spherical region of radius 1. The sphrand(1) function gives the X, Y, and Z position components a value no less than -1 and no greater than 1.

The second statement assigns a particle’s position to a vector variable $pos.

The third statement assigns an RGB color to a particle’s rgbPP attribute.

The left, middle, and right vector components of CloudShape.rgbPP represent red, green, and blue components of the RGB color scheme. The third statement therefore assigns 0 (no color) to the red and blue components of a particle’s colorRGB. It gives a particle’s green component the value of its Y coordinate position.

Because a value of 0 or less results in a 0 green value, a particle is black if it’s below the XZ plane. If a particle’s Y coordinate position is above the XZ plane, it has a green component varying from nearly 0 to a fully saturated green.

This colors the particles from black to green, depending on the position.

Example

particleShape1.rgbPP = <<1,0,CloudShape.position.z>>;

This causes an error. Maya interprets CloudShape.position.z as being an attribute named z of an object named CloudShape.position.

You can get the intended result with these statements:

vector $temp = CloudShape.position;
particleShape1.rgbPP = <<1,0,$temp.z>>;

The first statement reads all three components of vector attribute CloudShape.position and assigns it to the vector variable $temp. The second statement reads the value of the right component of $temp, which contains the right component of CloudShape.position. It then assigns this component to the right component of particleShape1.rgbPP.

Example

particleShape1.rgbPP.y = 1;

This also causes an error. You can’t assign a value to a vector array attribute component.