So I wanted to visualise a field in maya, as I needed to know what it was looking like, and I found a pretty simple way to do it.
Create a 3D fluid container:
Dynamics > Fluid Effects > Create 3D Container
Connect your field to the container:
Window > Relationship Editors > Dynamic Relationships
In the fluid container, turn on velocity draw:
Display > Velocity Draw
Feel free to change the options, increase the resolution of the container if you need more fidelity.
So I ended up with a few issues when attempting to set the keyframe on an object using the layout specified in the python command, I was trying to do something like:
cmds.setKeyframe("pCube1", value=True, attribute="visibility")
However as I was using instancing, this would also keyframe the visibility on the pCubeShape1 which I didn’t want, even if I explicitly passed in only the name of the transform, to avoid this you need to pass in the transform name and the attribute in the same go, so something along the lines of:
and this should only change it on the transform.
So I found a great little script here that will randomise the vertex positions in all the axis depending on how much you want it to, check it out below!
$mySelection = `ls- sl`;
$myVerts = `getVerts`; // this command grabs all the vertices of selected objects and put into a string array
for ($vert in $myVerts)
float $min = -50;
float $max = 50;
float $randNumX = rand( $min , $max );
float $randNumY = rand( $min , $max );
float $randNumZ = rand( $min , $max );
select -r $vert ;
move -r $randNumX $randNumY $randNumZ ;
select -r $mySelection; // return to previously selected objects
So it’s a bit of an odd one, but I needed to be able to calculate the RGB value of the colour at certain points on the mesh, and at first this seemed a bit tricky, but using the cloestPointOnMesh node and the colorAtPoint command I was able to use a locator and easily connect it up to give me the result I needed, hopefully it will help you out too.
// Select mesh
$mesh = `ls -sl`;
// Select locator
$locator = `ls -sl`;
//Name of the texture
string $texture = "noise1";
//Calculates the position of the locator.
float $position = `xform -worldSpace -query -translation $loc`;
//Calcualtes the closest point on the mesh to the locator.
float $uv  = `closestPointOnMesh -ip $position $position $position -q -u -v $mesh`;
//Calculates the RGB colour of the texture at the point
float $rgb  = `colorAtPoint -o RGB -u $uv -v $uv $texture`;
Here is a little script I found from here, that allows you to query the amount of points (or cv’s) on a curve, where curveShape1 is the name of the curve you have created.
string $curve = "curveShape1";
int $numSpans = `getAttr ( $curve + ".spans" )`;
int $degree = `getAttr ( $curve + ".degree" )`;
int $form = `getAttr ( $curve + ".form" )`;
int $numCVs = $numSpans + $degree;
// Adjust for periodic curve:
if ( $form == 2 ) $numCVs -= $degree;
I then used this to be able to spread the cv’s along the y axis, where ‘curve1’ is the name of your curve.
for ($i = 0; $i < $numCVs; ++$i )
vector $low = `pointPosition -w curve1.cv`;
vector $high = `pointPosition -w curve1.cv[$numCVs-1]`;
float $gap = ($high.y - $low.y)/($numCVs-1);
vector $pos = `pointPosition -w curve1.cv[$i]`;
$var = $lowNew.y + $i*$gap;
move -y $var;