View Full Version : API: set particle position
meagane 12-23-2008, 12:26 PM I read various threads about how to connect to the particle node position attribute.
Although it is a vectorArray it cannot be connected by a appropirate node output attribute which is made of MVectorArray data (pointed to by a MObject).
As I`m still totally unclear about how to get data into that position attribute,
can anyone tell me about that?
A general solution about how to change the particles position via API would also be fine.
many thanks!
|
|
meagane
01-05-2009, 01:03 PM
ok, just one more try...
nobody out there who might have an answer?
heellloooooooooooo................:wavey:
AndersEgleus
01-06-2009, 04:14 PM
What exactly is it that you want to connect to the position?
meagane
01-07-2009, 11:41 AM
its just positional data (xyz)...
Robert Bateman
01-07-2009, 01:19 PM
This sounds like there may be danger ahead, anyhow...
I don't think it's possible with a field node (since that's just supposed to compute a force) - and position isn't marked as an output afaik.
IIRC, it should be possible with an MItGeometry iterator if that's part of an MPxCommand for a single 1 shot initialisation of the data.
If you want to modify the particle positions every update, then i think the only option is to implement an MPxDeformer node.
I could of course be very wrong.
meagane
01-07-2009, 02:14 PM
would it work otherwise if its the translate data?
Robert Bateman
01-07-2009, 04:21 PM
would it work otherwise if its the translate data?
of what ???
AndersEgleus
01-07-2009, 06:37 PM
its just positional data (xyz)...Yes, but I mean where is the data coming from? Is it stored in an array attribute of another node, or in the translate attributes of several other nodes, or in an ascii/binary file? This is crucial information since there are so many ways to solve the same problem.
meagane
01-07-2009, 06:38 PM
of what ???
the translate attribute of a transform (or from a custom node which gives the extracted translate of the worldMatrix attribute of the transform)
Yes, but I mean where is the data coming from? Is it stored in an array attribute of another node, or in the translate attributes of several other nodes, or in an ascii/binary file? This is crucial information since there are so many ways to solve the same problem.
okay,
its just that I read some earlier threads about that and came to the conclusion that there seems to be no easy or "good" way of getting the particle shape accept the data.
So, actually I will have to get the data in the node from
a. ascii files and
b. from the translate of several transforms
I may have misunderstood the other threads and it may be only a problem if the data come from a file and in case of the translate from a transform I will simply have to make a vector array of the data and connect them to the position attribute of the particle
AndersEgleus
01-07-2009, 07:07 PM
Sorry, didn't see you said it's another node with vectorArray data you want to connect from.
One way to do it is to assign the values through the particle expressions -
particleShape1.position = otherNode.theVectorArrayAttribute
This will assign theVectorArrayAttribute [0] to position [0]. If the other array is shorter, It seems that it wraps the index (e.g. if there are 30 particles, but only 15 array elements in the other node, theVectorArrayAttribute [0] will be assigned to position [15] etc).
If you want to do it using the api, I'd recommend using fields, you could check the current position, mass and velocity of the particle through the force's input data, and calculate a force that's exactly big enough to push the particle to the desired position. This would of course assume no other fields are affecting the particles.
AndersEgleus
01-07-2009, 07:31 PM
Ok, I replied before reading your answer, lol.
a. ascii files
Mel way: You could create a (non-particle) expression which reads the ascii data from a file, store that data in a global vector array, and have the particle expression read the global vector array and assign it to position, like so
expression1:
global vector $posData [];
$posData = readTheDataFromFile ();
particle expression:
global vector $posData [];
position = $posData [paricleId]; //provided the data is indexed according to the particleId's
b. from the translate of several transforms
Mel way: you could write a script which takes each of the transform and parent constrains another transform to it (if it's not parented to the scene root) to get the world position, then create the particle expression as a string which looks like this:
int $id = particleId;
switch ($id)
{
case 0:
position = <<object0.tx, object0.ty, object0.tz>>;
break;
case 1:
position = <<object1.tx, object1.ty, object1.tz>>;
break;
// ... etc
}
but this gets ridiculous if you have many particles.
API way: In both cases, you could code a node which either reads the ascii file from disk or takes an array of translations (or world matrices) as input and outputs a vector array to use with my first suggestion in the last post, or code a field which takes the same kind of input, to use with my second suggestion.
Or do what Robert suggested.
Good luck!
Robert Bateman
01-08-2009, 02:59 PM
or alternatively write the positions into a particle data cache file. search the maya docs for pdc file format.
CGTalk Moderation
01-08-2009, 02:59 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.