This
document will explain how to use the vector product node in Maya to
calculate vector cross and dot products as well as to find out
object's translation in a custom space, as in to find out object's
world space coordinates without moving it from the hierarchy or vice
versa. This method bypasses the rotation problem that you get if
trying to find out object’s world space by doing maths on the basic
translation values of objects that have also rotations in the mix.
Vector
Product node can be found under utilities in Hypershade. It has
operation option which defines which calculation you want to perform,
they include dot product, cross product, vector matrix product and
point matrix product. You can attach 2 vectors into input1 and
input2 of the vector product. You can also attach a matrix into the
node; this does not show up on the attribute menu which is why you
need to use the connection editor to do this. This will become
necessary when trying to find out custom space translations. It also
has a normalize option which you can switch on and off, based on your
needs (more uses explained below)
Dot
product
Output:
float
Output
represents the angle between the 2 input vectors. If the output is
normalized output is the actual cosine value and will vary between -1
and 1.If the normalized output is one it signifies that the input
vectors run parallel to each other. If the output is 0 the vectors
are perpendicular. And if the output is -1 the vectors run in
opposite directions
Cross
Product
Output:
vector
The
output vector will be in right angle (perpendicular) to the input
vectors. In other words the output vector is almost like the normal
of the plane that is defined by the 2 input vectors.
Vector
matrix Product and Point Matrix product
Output:
vector/point
Point
Matrix product allows you to find out object’s translations in a
custom space i.e. under some other hierarchy in the scene that it
currently is in.
Example
scene:
hierarchy:
purpleCone
(world/local t:0,4,0 r:0,0,0 s:1,1,1)
orangeSphere
(local t:2,-2,2 r:45,45,45 s:1,1,1)
blueCube
(local t:-3,-3,-3 r:0,0,0 s:1,1,1)
greenTorus
(world/local t:-3,-3,-3 r:0,0,0 s:1,1,1)
To
find out object's translation in it’s parents local space as in move
the translation values up one level in the hierarchy without breaking
the current hierarchy, you need to connect the parent object's
xFormMatrix into the vector product node’s matrix input. You also
need to connect the queried object's translation vector into the
vector products input1 slot. The input2 vector will be left blank.
Change the operation of the vector product node into `point matrix
product` under the attribute editor. The resulting vector is the
queried object's translation in the parent objects local space, if the
parent object is under the world then you get the world space
coordinates of the queried object.
In
the example scene we could find out the blueCube's (bottom of the
hierarchy) translation values under the purpleCone (top of the
hierarchy) without braking the hierarchy. So we would connect the
spheres xFormMatrix into the input matrix of a vectorProduct node and
then connect the translate output of the cube into the first input
vector of the vectorProduct node. Switch the vectorProduct node's
operation into Point Matrix Product. The output is the translation of
the cube as if it were under the cone. (t:-1.6. -5.6. 1.1)
Notice
how the the rotations of the sphere are taken into account
translation because we use matrices, without having to worry about
rotation orders.
If
you have an object buried under a hierarchy of multiple objects and
you need to move up multiple levels, you can feed the output
translate from the vector product into another vector product and
attach the xFormMatrix of the next-object-up-in-the-hierarchy into
the matrix input in the new vectorProduct node. This way you can walk
up the hierarchy as you wish. On the other hand if you want to know
the objects translation in world space you can do this easily by
using the parent objects worldMatrix instead of the xFormMatrix and
this will give you the world translation straight away.
You
can also reverse the process and find out translation of an object
upwards in the hierarchy, so for example finding out object’s,
which is in the root of the scene (world space), translation under
another object which is under multiple objects. In order to do this
you need to connect the queried object’s translation into the
input1 of the vector product node and connect the object’s
worldInverseMatrix, under which you want to virtually move the
queried objects translation space to, into the matrix input of the
vector product node. The output will be the queried object’s
translations as if it would be under the specified object which
matrix you plugged into the vector product.
In
our example scene we could query the greenToruse's translation, which
are currently in worldspace as it is not part of the hierarchy in
which the other belong to, under the orangeSphere, which already
under the purpleCone. Connect the the orange Sphere's
worldInverseMatrix into the vectroProduct node's matrix input slot in
the connection editor. Then connect the greenToruses translation into
the vectorProduct's input1 slot. Make sure the vector product
operation is Point Matrix Product. The output is the translation of
the torus as if it were under the sphere (t:-1.6. -1.1. -5.1).
I hope this will be usefull for some of you =)
Note
about maya matrix maths:
Maya
has a few matrix math nodes that are hidden. The can be created with
createNode command in the script editor and found then in the
outliner if you show all the scene nodes (un-check show only dag
nodes).
These
nodes include:
pointMatrixMult
multMatrix
fourByfourMatrix
passMatrix
addMatrix
holdMatrix