PDA

View Full Version : Particles scripting problem... help?


cmurder
03-05-2007, 07:06 AM
Hi, I'm trying to write a script that makes an object have the exact same position as a particle that is moving. The reason I'm not just using a particle instancer for the object is: I want to make a bunch of hairs flying off of an object. The plan is to make a bunch of nurbs planes with hairs that will be following the motion of the particle system. It doesn't seem like I can use an instancer for this because the hairs won't have individual dynamics.

Anyway, here's the script I wrote to try to get 2 different spheres to follow the position of a particle using worldPosition and Position:

global proc whatever() {
float $thepos[] = `getParticleAttr -at position -array true particleShape1.pt[0]`;
setAttr pSphere3.tx $thepos[0];
setAttr pSphere3.ty $thepos[1];
setAttr pSphere3.tz $thepos[2];
float $thepos2[] = `getParticleAttr -at worldPosition -array true particleShape1.pt[0]`;
setAttr pSphere4.tx $thepos2[0];
setAttr pSphere4.ty $thepos2[1];
setAttr pSphere4.tz $thepos2[2];
};

The outcome isn't what I would expect, as neither sphere has the same position as the particle[0].... there seems to be some sort of offset or they are using a different coordinate system.

Any thoughts? Thanks very much!

dr.rastaman
03-05-2007, 08:25 AM
The problem is, that
getParticleAttr -at position -array true particleShape1.pt[0]
lways returns the centroid of your particle-object, not the position of the individual particle.
You can try it like this:

float $positions[]='getAttr particleShape1.position';
//that gives you an array that holds the World-Position-Data for all particles
setAttr pSphere1.translate ($positions[0]) ($positions[1]) ($positions[2]);
setAttr pSphere2.translate ($positions[3]) ($positions[4]) ($positions[5]);

The reltionship between the x,y,z-values and the particleID is as follows:

x-Value: particleID*3;
y-value: particleID*3+1
z-value: particleID*3+2;

Hope it helps...

cmurder
03-05-2007, 08:50 AM
Hi, thanks for your help but it doesn't seem to be working. I don't think it is returning the value of the centroid... I've checked the values and it is different for every particle. Also the values the particle returns for worldposition and postion are different if you move the system around. Here is my scene file if you have a second to check it out:

http://www.me-vs-you.com/spheretest.mb

Thanks again for any advice!

YY3010966
03-05-2007, 02:34 PM
hi guys
i think i'll give you the mel this time tomorrow if there is no suddenness.
it complete automatism

so,be waiting please!:D

MikeRhone
03-05-2007, 10:45 PM
Im not sure quite what yo are trying for, but have you looked into the very popular unInstancer script (http://www.highend3d.com/maya/downloads/plugins/dynamics/Uninstancer-4331.html) ?

cmurder
03-06-2007, 03:31 AM
Oh nice tip... I'll check that out. Essentially I wanted to extract particle location data to be used to drive location of geometry... unfortunately even though the numbers match up, the physical location does not.

Thanks for the tip!

YY3010966
03-06-2007, 12:58 PM
hi there ;
i think i have finished what you want .:)

there are the scene and the mel .

In the scene ,there is a particle only,excute the mel , there are four functions.
u can try it .
any bug let me know,3Q!!
and hope can help !
bye.

cmurder
03-06-2007, 06:49 PM
Thanks, it looks like that works exactly like it should. I guess the difference is this line:

float $pos[]=`pointPosition -l particleShape1.pt[$i]`;

I didn't know about the pointPosition attribute... strange how that works but worldPosition does not.

Thanks again!

YY3010966
03-07-2007, 12:38 PM
hi, u are welcome.

the pointPosition command can get the position of points expediently,like particles,CV,etc....

i think the worldPosition can achieve it also,but i dont try it .

u can modify my mel and try it out youself :) .

any question ,let me know. and me ,too! help each other!

good luck !

Als
03-07-2007, 08:57 PM
getAttr per particle works too, but for some reason you need to select that particle to make it work... Weird, but it works.


Als

CGTalk Moderation
03-07-2007, 08:57 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.