View Full Version : mel needed for clusters of a curve to follow the particles
glassfairy
09-09-2010, 08:12 PM
plz someone help me with mel code i need to get
clusters of a curve to follow the particles so i can make a rope ...
plz see http://www.digitaltutors.com/forum/showthread.php?22043-ncloth-parts-of-chain-interpenetrating&p=78047 to know what i m looking for specifically
glassfairy
09-11-2010, 10:26 PM
comeon 48 views and not single reply?
gutterFish
09-12-2010, 03:21 AM
Hi, so I looked over what dule wrote and its out of my league but heres what I do understand. A cluster was created for each cv on the curve (I think dule gave instructions on building the curve earlier in the thread). Creating the clusters was probably an iteration of some sort i.e query the cv's in the curve and then for ($eachCV in $querydCVs){cluster;}
then it gets away from me. What I can gather is the world space position of each particle was evaluated constantly (every frame maybe? but i dont get how the particles were already being made to move like a rope??) then maybe a custom ppAttribute was created and a script plugged into it that somehow pinned the transform nodes of each cluster to the earlier queried world position
of each particle. Im not advanced enough know offhand how that script would go. I imagine many many hours of pouring over the command and node
reference documentation and digging through mayas native mel scripts.
The whole thing sounds very advanced to me. Even if on an individual basis I knew how to do each of the things needed to be done. Just the thought of putting them all together in the correct sybtax. The video posted of the ropes animation is way cool. Maybe something similar could be achieved springs or soft bodies? It depends of course on what exactly you need to achieve.
heres a video for that
http://www.youtube.com/watch?v=7GD_4KG8O2o
there were many tutorials on creating dynamic rope in maya by the way when I googles it.
glassfairy
09-12-2010, 01:19 PM
i had already tried those...not giving the look and doesnt deform properly
gutterFish
09-12-2010, 02:49 PM
well try breaking the problem into smaller parts. take each part on individually then work on putting them all together. Try doing it manually in the viewport with echo all commands on and see what you can learn. Sometimes digging through mayas native scripts and command/node reference materials is necessary and lots of toying with flags and syntax. But this requires some basic knowledge about mel and how to use the command and node reference docs The point is again tackling one problem at a time. Figuring out what you need to know in the order you need to know it in order to move on to the next problem.
.
gutterFish
09-12-2010, 04:58 PM
here's the code for querying the world position of every particle in your particle object
/////////////////////////////////////////////////////////////////
int $particleCount=`particle -q -count particleShape1`;
for($x=0;$x<$particleCount;$x++)
{
vector $ppPosition[] =`getParticleAttr -at worldPosition particleShape1.pt[$x]`;
print $ppPosition;
}
//////////////////////////////////////////////////////////////////////////////
//That final "print" command doesnt need to be there its just for visual feedback that the code is working
//
need to find a way to have it eval. every frame.
chrisg
09-12-2010, 07:13 PM
A possible way to make it evaluate at every frame is to put it into an expression.
gutterFish
09-12-2010, 07:57 PM
what just plug it into the ppPosition slot? Just the way it is?
gutterFish
09-13-2010, 11:12 AM
Hey bravo, my goal (hehe, its my goal now). My goal is to use the vector data to set the world position of some cluster handles. Ive played with tring to constrain the cluster handles to the particles but I havent been able to (yet). The thing about using the data to set the clusterhandles pos. is that the command im using returns something like this (1.0023 0.0044 3.1543 0 0 0)
(1.0023 0.0044 3.1543 0 0 0)
(1.0023 0.0044 3.1543 0 0 0)
im assuming, going by the component editor that the 0 0 0 is a velocity vector I dont know why its there I didnt ask for it. :)
So I guess I could do something like set cluster?Handle world position to $vVector[0]
set cluster?Handle world position to $vVector[1] ..ect.. Thats in english of course not mel.
It seems to work but I cant find the flag for setting the position relative to origin. Ive messed with setAttr, move and xform but no luck.
Soooo... what im thinking about right now is a.) how to use the vector data to set the position of another transform node
b.) how to do it totally dynamically (i.e. on the fly variables)
Why am I trying to do this???? I love a nice puzzle :)
glassfairy
09-13-2010, 04:37 PM
ok i tried this code it give me error on the print line y so?
int $particleCount=`particle -q -count particleShape1`;
for($x=0;$x<$particleCount;$x++)
{
vector $ppPosition[] =`getParticleAttr -at worldPosition particleShape1.pt[$x]`;
print $ppPosition[].y;
}
gutterFish
09-13-2010, 05:09 PM
because of the "[].y"
each member of this array is the entire vector position (x,y and z) plus what I believe is velocity information as I posted above.
you could print a single vector of whichever particle you want by inserting an integer between 0 and (one less than the total value of $particleCount) between the brackets.
example: print $ppPosition[3]; /// that would return the vector position of the fourth particle in your particleShape.
WHen I have more time I will try to work out how to feed that vector to the cluster transform node.
Off the top of my I suppose each member of $ppPosition could be placed into its own variable then you use that value whenever.
the ".y" you put at the end means nothing to maya. the numbers returned are just numbers, they have no meaning other than that.
They need to be isolated and then used as arguments for other attributes.
or maybe you just used incorrect syntax?
Im a newbie at MEL
edit: also if your using nParticles it maybe different
The way I did it before was to have all the clusters stored in an array in such a way that the 1st cluster, that is position where the first particle is, would be stored as the 1st variable in the array.
Now you take your particles, attach an expression to them, and make sure it evaluates "before dynamics" so it keeps updating regulary(if I remember right).
The code itself would be simple, something like:
int $parID = nParticleShape1.particleId; //current particle ID
float $pos[] = nParticleShape1.worldPosition; //particle world position
move -rpr -ws $pos[0] $pos[1] $pos[2] $ArrayName[$parID]; //moves the cluster(of number ID) to world position of the particle the expression is playing with atm
Particle expressions seem to execute once for every single particle in your chain (each and every frame), and the only thing that changes is the ID (nParticleShape1.particleId) of the actual individual particle that the expression is manipulating at the moment.
glassfairy
09-14-2010, 06:14 AM
ok i got it done!!! tht too without clusters
here's the code
int $particleCount = `particle -q -count nParticleShape1`;
for ($n=0; $n<$particleCount; $n++)
{
float $pos[] = `getParticleAttr -at worldPosition nParticleShape1.pt[$n]`;
move -rpr -ws $pos[0] $pos[1] $pos[2] circle.cv[$n];
}
thanx to everyone especially gutterfish and dule!