Vector Array Commands

About

This functionset gives you all the commands you already know from mel (+ a few extras) wrapped so they work with arrays.  Vector arrays are frequently used throughout Maya (eg. in particle systems or deformers) and being able to handle them efficiently, greatly reduces the amount of mel work needed to do something useful with them.

Important conventions

A mVector in melfunctions is represented as an array of 3 floats.  All commands don’t change the actual data in place, but create a new output.

Summary
This functionset gives you all the commands you already know from mel (+ a few extras) wrapped so they work with arrays.
Create a vector array
Get number of vectors in a vector array
Append elements to the end of a vector array
Get elements from a vector array
Set elements in a vector array, this function will not grow the vector array, but error when you try to set an invalid array element!
Add two vector arrays together elementwise
Subtract two vector arrays elementwise
The dot product of two vector arrays elementwise
Cross product of two vector arrays elementwise
Multiply componentwise two vector arrays together
Multiplication of vector and double
Division of vector and double
The negate vector of an array
Multiplication of vector and matrix, the way to transform a vector between differnt spaces
The normalized vector of an array
Set length of vector
Distance between two vector position arrays elementwise
Angle between two vector arrays elementwise
Rotate vector by euler angles, euler angles are assumed to be in xyz rotation order
Rotate vector by defining an axis to rotate about and an angle (in rad)
Check if two mVectors are exactly equal
Check if two mVectors are not equal
Check if elements of two vector arrays are equivalent within a tolerance
Get the length of the elements of a vector array.
Get the sqr length of the elements of a vector array.
linear interpolation of two vectors
spherical linear interpolation of two vectors
Get vector component X within a vector array.
Get vector component Y within a vector array.
Get vector component Z within a vector array.
Get vector component at specified poistion within a vector array.
Set vector component X
Set vector component X
Set vector component X
Set vector component at specified poistion within a vector array.

Functions

mVecCreate

#define mel mVecCreate(int $count,
float $template[3])

Create a vector array

Parameters

nonereturn the null vector or
countreturn count null vectors or
countthe number of vector elements to create
templatethe template vector which will be used for creation

Returns

The vector array as a float array of its elements

mVecSize

#define mel int mVecSize(float $vectorArrayA[])

Get number of vectors in a vector array

Parameters

vectorArrayAvector array Returns:

The size of the vector array

mVecAppend

#define mel mVecAppend(float $vectorArrayA[],
float $vectorArrayB[])

Append elements to the end of a vector array

Parameters

vectorArrayAvector array to extract elements to
vectorArrayBvector array to append Returns:

The new vector array of as a float array of its elements

mVecGet

#define mel mVecGet(float $vectorArrayA[],
int $id[],
float $vectorArrayB[])

Get elements from a vector array

Parameters

vectorArrayAvector array to extract elements from
idsint array of ids to extraxt from the vector array optional
vectorArrayBvector array that will be used as a substitution if an id does not exist in array A, must be 1 or same size than id array Returns:

The vector array of as a float array of its elements

mVecSet

#define mel mVecSet(float $vectorArrayA[],
int $id[],
float $vectorArrayB[])

Set elements in a vector array, this function will not grow the vector array, but error when you try to set an invalid array element!

Parameters

vectorArrayAbase vector array
idsint array of ids defining where in A to insert B
vectorArrayBvector array of elements to be inserted into A, must be size 1 or same size than id array Returns:

The vector arrayA with elements inserted of of as a float array of its elements

mVecAdd

#define mel mVecAdd(float[] $vecArrayA,
float[] $vecArrayB)

Add two vector arrays together elementwise

Parameters

$vecArrayAthe first vector array
$vecArrayBthe second vector array

Returns

$vecArrayA + $vecArrayB, the sum of the two vector arrays elementswise as a float[]

mVecSub

#define mel mVecSub(float[] $vecArrayA,
float[] $vecArrayB)

Subtract two vector arrays elementwise

Parameters

$vecArrayAthe first vector array
$vecArrayBthe second vector array

Returns

$vecArrayA$vecArrayB, the difference of the two vector arrays elementswise as a float[]

mVecDot

#define mel mVecDot(float[] $vecArrayA,
float[] $vecArrayB)

The dot product of two vector arrays elementwise

Parameters

$vecArrayAthe first vector array
$vecArrayBthe second vector array

Returns

$vecArrayA * $vecArrayB, the dot product of the two vector arrays elementswise as a float[]

mVecCross

#define mel mVecCross(float[] $vecArrayA,
float[] $vecArrayB)

Cross product of two vector arrays elementwise

Parameters

$vecArrayAthe first vector array
$vecArrayBthe second vector array

Returns

$vecArrayA ^ $vecArrayB, the cross product of the two vector arrays elementswise as a float[]

mVecMult

#define mel mVecMult(float[] $vecArrayA,
float[] $vecArrayB)

Multiply componentwise two vector arrays together

Parameters

$vecArrayAthe first vector array
$vecArrayBthe second vector array

Returns

$vecArrayA.x * $vecArrayB.x, $vecArrayA.y * $vecArrayB.y, $vecArrayA.z * $vecArrayB.z, the component produkt of the two vector arrays as a float[]

mVecDblMult

#define mel mVecDblMult(float[] $vecArrayA,
float[] $vecArrayB)

Multiplication of vector and double

Parameters

$vecArrayAthe vector array
$dblArrayBthe double array

Returns

$vecArrayA * $dblArrayB, the product of the two arrays as a float[]

mVecDblDiv

#define mel mVecDblDiv(float[] $vecArrayA,
float[] $vecArrayB)

Division of vector and double

Parameters

$vecArrayAthe vector array
$dblArrayBthe double array

Returns

$vecArrayA / $dblArrayB, the product of the two arrays as a float[]

mVecNegate

#define mel mVecNegate(float[] $vecArrayA)

The negate vector of an array

Parameters

$vecArrayAthe vector array

Returns

-($vecArrayA) , the negated vectors in an array as a float[]

mVecMatMult

#define mel mVecMatMult(float[] $vecArrayA,
float[] $matArrayB)

Multiplication of vector and matrix, the way to transform a vector between differnt spaces

Parameters

$vecArrayAthe vector array
$matArrayBthe matrix array

Returns

$vecArrayA * $matArrayB, the product of the two arrays as a float[]

mVecNormal

#define mel mVecNormal(float[] $vecArrayA)

The normalized vector of an array

Parameters

$vecArrayAthe vector array

Returns

norm($vecArrayA) , the normalized vectors in an array as a float[]

mVecSetLength

#define mel mVecSetLength(float[] $vecArrayA,
float[] $vecArrayB)

Set length of vector

Parameters

$vecArrayAthe vector array
$dblArrayBthe double array

Returns

$vecArrayA * $dblArrayB, the product of the two arrays as a float[]

mVecDistance

#define mel mVecDistance(float[] $vecArrayA,
float[] $vecArrayB)

Distance between two vector position arrays elementwise

Parameters

$vecArrayAthe first vector array
$vecArrayBthe second vector array

Returns

the distance between the two vector arrays elementswise as a float[]

mVecAngle

#define mel mVecAngle(float[] $vecArrayA,
float[] $vecArrayB)

Angle between two vector arrays elementwise

Parameters

$vecArrayAthe first vector array
$vecArrayBthe second vector array

Returns

the angle between the two vector arrays elementswise in rad as a float[]

mVecRotateByEuler

#define mel mVecRotateByEuler(float[] $vecArrayA,
float[] $vecArrayB)

Rotate vector by euler angles, euler angles are assumed to be in xyz rotation order

Parameters

$vecArrayAthe first vector array
$vecArrayBthe second vector array of euler angles

Returns

the first vector rotate by the euler angles a float[]

mVecRotateByAxisAngle

#define mel mVecRotateByAxisAngle(float[] $vecArrayA,
float[] $vecArrayB)

Rotate vector by defining an axis to rotate about and an angle (in rad)

Parameters

$vecArrayAthe first vector
$vecArrayBthe axis
$dblArrayCthe angle

Returns

the first vector rotated about the axis by the angle as a float[]

mVecIsEqual

#define mel mVecIsEqual(float[] $vecArrayA,
float[] $vecArrayB)

Check if two mVectors are exactly equal

Parameters

$vecArrayAthe first vector array
$vecArrayBthe second vector array

Returns

$vecArrayA == $vecArrayB, the result of the elementwise comparison as a float[] of (0,1)

mVecIsNotEqual

#define mel mVecIsNotEqual(float[] $vecArrayA,
float[] $vecArrayB)

Check if two mVectors are not equal

Parameters

$vecArrayAthe first vector array
$vecArrayBthe second vector array

Returns

$vecArrayA != $vecArrayB, the result of the elementwise comparison as a float[] of (0,1)

mVecIsEquivalent

#define mel mVecIsEquivalent(float[] $vecArrayA,
float[] $vecArrayB), float[] $toleranceArray)

Check if elements of two vector arrays are equivalent within a tolerance

Parameters

$vecArrayAthe first matrix array
$vecArrayBthe second matrix array
$toleranceArraythe maximum amount of error allowed

Returns

the result of the comparison as a float array of (0,1)

mVecLength

#define mel mVecLength(float[] $vecArrayA)

Get the length of the elements of a vector array.

Parameters

$vecArrayAthe vector array

Returns

the lengths of the vectors as a float[]

mVecLengthSqr

#define mel mVecLengthSqr(float[] $vecArrayA)

Get the sqr length of the elements of a vector array.  If you only need this length for comparison reasons it is faster to compare the sqr(v) as this save you to take the sqrt!

Parameters

$vecArrayAthe vector array

Returns

the sqr lengths of the vectors as a float[]

mVecLerp

#define mel mVecLerp(float[] $vecArrayA,
float[] $vecArrayB,
float[] $param)

linear interpolation of two vectors

Parameters

$vecArrayAthe first vector array
$vecArrayBthe second vector array
$paramthe interpolation parameter [0-1] (will be clamped)

Returns

the interpolated vector array as a float array of (0,1)

mVecSlerp

#define mel mVecSlerp(float[] $vecArrayA,
float[] $vecArrayB,
float[] $param)

spherical linear interpolation of two vectors

Parameters

$vecArrayAthe first vector array
$vecArrayBthe second vector array
$paramthe interpolation parameter [0-1] (will be clamped)

Returns

the interpolated vector array as a float array of (0,1)

mVecGetX

#define mel mVecGetX(float $vecArrayA[])

Get vector component X within a vector array.

Parameters

$vecArrayAthe vector array

Returns

the elements at $vec.x as a float array

mVecGetY

#define mel mVecGetY(float $vecArrayA[])

Get vector component Y within a vector array.

Parameters

$vecArrayAthe vector array

Returns

the elements at $vec.y as a float array

mVecGetZ

#define mel mVecGetZ(float $vecArrayA[])

Get vector component Z within a vector array.

Parameters

$vecArrayAthe vector array

Returns

the elements at $vec.z as a float array

mVecGetComponent

#define mel mVecGetComponent(float $vecArrayA[],
int $component[])

Get vector component at specified poistion within a vector array.

Parameters

$vecArrayAthe vector array
$componentthe index [0-2] as an int array

Returns

the element at $vec[$component] as a float array

mVecSetX

#define mel mVecSetX(float $vecArrayA[],
float $value[])

Set vector component X

Parameters

$vecArrayAthe vector array
$valuethe double array to be set into the component

Returns

the vector array with the inserted as a float array

mVecSetY

#define mel mVecSetY(float $vecArrayA[],
float $value[])

Set vector component X

Parameters

$vecArrayAthe vector array
$valuethe double array to be set into the component

Returns

the vector array with the inserted as a float array

mVecSetZ

#define mel mVecSetZ(float $vecArrayA[],
float $value[])

Set vector component X

Parameters

$vecArrayAthe vector array
$valuethe double array to be set into the component

Returns

the vector array with the inserted as a float array

mVecSetComponent

#define mel mVecSetComponent(float $vecArrayA[],
int $component[],
float $value[])

Set vector component at specified poistion within a vector array.

Parameters

$vecArrayAthe vector array
$componentthe index [0-2] as an int array
$valuethe double array to be set into the component

Returns

the vector array with the inserted as a float array

#define mel mVecCreate(int $count,
float $template[3])
Create a vector array
#define mel int mVecSize(float $vectorArrayA[])
Get number of vectors in a vector array
#define mel mVecAppend(float $vectorArrayA[],
float $vectorArrayB[])
Append elements to the end of a vector array
#define mel mVecGet(float $vectorArrayA[],
int $id[],
float $vectorArrayB[])
Get elements from a vector array
#define mel mVecSet(float $vectorArrayA[],
int $id[],
float $vectorArrayB[])
Set elements in a vector array, this function will not grow the vector array, but error when you try to set an invalid array element!
#define mel mVecAdd(float[] $vecArrayA,
float[] $vecArrayB)
Add two vector arrays together elementwise
#define mel mVecSub(float[] $vecArrayA,
float[] $vecArrayB)
Subtract two vector arrays elementwise
#define mel mVecDot(float[] $vecArrayA,
float[] $vecArrayB)
The dot product of two vector arrays elementwise
#define mel mVecCross(float[] $vecArrayA,
float[] $vecArrayB)
Cross product of two vector arrays elementwise
#define mel mVecMult(float[] $vecArrayA,
float[] $vecArrayB)
Multiply componentwise two vector arrays together
#define mel mVecDblMult(float[] $vecArrayA,
float[] $vecArrayB)
Multiplication of vector and double
#define mel mVecDblDiv(float[] $vecArrayA,
float[] $vecArrayB)
Division of vector and double
#define mel mVecNegate(float[] $vecArrayA)
The negate vector of an array
#define mel mVecMatMult(float[] $vecArrayA,
float[] $matArrayB)
Multiplication of vector and matrix, the way to transform a vector between differnt spaces
#define mel mVecNormal(float[] $vecArrayA)
The normalized vector of an array
#define mel mVecSetLength(float[] $vecArrayA,
float[] $vecArrayB)
Set length of vector
#define mel mVecDistance(float[] $vecArrayA,
float[] $vecArrayB)
Distance between two vector position arrays elementwise
#define mel mVecAngle(float[] $vecArrayA,
float[] $vecArrayB)
Angle between two vector arrays elementwise
#define mel mVecRotateByEuler(float[] $vecArrayA,
float[] $vecArrayB)
Rotate vector by euler angles, euler angles are assumed to be in xyz rotation order
#define mel mVecRotateByAxisAngle(float[] $vecArrayA,
float[] $vecArrayB)
Rotate vector by defining an axis to rotate about and an angle (in rad)
#define mel mVecIsEqual(float[] $vecArrayA,
float[] $vecArrayB)
Check if two mVectors are exactly equal
#define mel mVecIsNotEqual(float[] $vecArrayA,
float[] $vecArrayB)
Check if two mVectors are not equal
#define mel mVecIsEquivalent(float[] $vecArrayA,
float[] $vecArrayB), float[] $toleranceArray)
Check if elements of two vector arrays are equivalent within a tolerance
#define mel mVecLength(float[] $vecArrayA)
Get the length of the elements of a vector array.
#define mel mVecLengthSqr(float[] $vecArrayA)
Get the sqr length of the elements of a vector array.
#define mel mVecLerp(float[] $vecArrayA,
float[] $vecArrayB,
float[] $param)
linear interpolation of two vectors
#define mel mVecSlerp(float[] $vecArrayA,
float[] $vecArrayB,
float[] $param)
spherical linear interpolation of two vectors
#define mel mVecGetX(float $vecArrayA[])
Get vector component X within a vector array.
#define mel mVecGetY(float $vecArrayA[])
Get vector component Y within a vector array.
#define mel mVecGetZ(float $vecArrayA[])
Get vector component Z within a vector array.
#define mel mVecGetComponent(float $vecArrayA[],
int $component[])
Get vector component at specified poistion within a vector array.
#define mel mVecSetX(float $vecArrayA[],
float $value[])
Set vector component X
#define mel mVecSetY(float $vecArrayA[],
float $value[])
Set vector component X
#define mel mVecSetZ(float $vecArrayA[],
float $value[])
Set vector component X
#define mel mVecSetComponent(float $vecArrayA[],
int $component[],
float $value[])
Set vector component at specified poistion within a vector array.