View Full Version : Duncan.. Question about instancing!
azshall 01-21-2006, 06:47 PM Hey Duncan ... Is there a way to query whats going on with the Instancer? ...
To break down what exactly I mean, when I graph the 'instancer1' node in the hypershade I can see all of my objects feeding into it. No matter how I seem to query it, all I get is an exact same matrix of integers (ie, 1 0 0 1 0 1 1 0 0 1 0) etc .. to that effect. I'm curious if there is a way to actually query each frame of world space where the instanced objects are and bake the object(s) into keyframes. If not that, at least be able to successfully query the said objects.
Is this even possible? The instancer just seems to be such an elusive node that you can't really muck with unless its actual expressions for particles, etc... Which I'm already doing, but I want to try and break it down and take it further than that ...
Thanks ..
Seth
|
|
panand
01-22-2006, 02:34 AM
you can query using the instancer command, for example:
$instancerNode = "instancer1";
$partShape = `instancer -q -pds $instancerNode`;
$count = `particle -q -ct "particleShape1"`;
$numObjects=2;
for ($i=0; $i<$numObjects; $i++)
{
$obj = `instancer -index $i -q -obj $instancerNode`;
print ("object "+$i+":"+$obj[0]+"\n");
}
Hey Duncan ... Is there a way to query whats going on with the Instancer? ...
To break down what exactly I mean, when I graph the 'instancer1' node in the hypershade I can see all of my objects feeding into it. No matter how I seem to query it, all I get is an exact same matrix of integers (ie, 1 0 0 1 0 1 1 0 0 1 0) etc .. to that effect. I'm curious if there is a way to actually query each frame of world space where the instanced objects are and bake the object(s) into keyframes. If not that, at least be able to successfully query the said objects.
Is this even possible? The instancer just seems to be such an elusive node that you can't really muck with unless its actual expressions for particles, etc... Which I'm already doing, but I want to try and break it down and take it further than that ...
Thanks ..
Seth
frogspasm
01-22-2006, 09:24 PM
Panand.... That doesn't seem to work.
The only thing you queried there is the name of the particle system, and the name of the object being instanced. Try querying anything else and you get nothing...
instancer -index 0 -q -obj -q -objectPosition instancer1; Maybe I'm not getting the syntax correct, but it's not working for me.
It looks like you can query the values that are assigned to the instancer with:
getAttr particleShape1.instanceData[0].instanceAttributeMapping;
// Result: age age position worldPosition id particleId aimDirection velocity aimAxis aimUpAxis acceleration//
It returns the string for whatever values are mapped to the instancer from the particle attributes, ie:
age = age
postion = worldPosition
id = particleId
aimDirection = velocity
aimAxis = 0 (not sure why this value comes up when I haven't mapped it)
aimUpAxis = acceleration
You would then have to query those attributes for each particle in your system:
getParticleAttr -at worldPosition particleShape1.pt[1];
getParticleAttr -at velocity particleShape1.pt[1];
getParticleAttr -at acceleration particleShape1.pt[1];
etc.
Then you have to figure out the rotation values for all your instances form that.
( I guess that's what you are doing now, azshall)
It seems bit of a pain in the ass, though, because the instanceAttributeMapping array changes depending on what you have controlling the instance attributes...
It'd be nice to just be able to get rotational values directly.
Mike D.
Grrr, Arrgh!
azshall
01-24-2006, 05:19 PM
I had already tried what panand suggested before writing the email, It doesn't get me much.
Graphing the objects and seeing that they're actually instanced in, and trying to query those, does not give me much.
You definately seem to have the right approach, or beginnings, but ... There needs to be a way to just open it up and look into it. Its silly that its so locked down.
az
Duncan
01-24-2006, 10:09 PM
As far as I can tell it is currently impossible in mel to get the rotations for instanced particles short of computing this yourself from the particle velocities combined with the various instancer attributes. The particle instancer command currently is broken when in query mode (bug 178009). If this is important for you please report it to alias support.
I think you can still get the values by writing a plugin. Check out the API class:
MItInstancer
Duncan
Sanctuary
08-11-2006, 08:05 AM
particles are points => they don`t have rotations. Instead define customs PP attrs which control the instanced object rotation/scale/etc
string $instancerNode = "instancer1";
string $partShape = `instancer -q -pds $instancerNode`;
int $numObjs = `getAttr ($instancerNode + ".ic")`;
for ($i=0; $i<$numObjs; $i++)
{
vector $posPP = `particle -at "position" -order $i -q $partShape`;
// i know this because i`m feeding it to the intancer from particleObject
vector $rotPP = `particle -at "x_rotPP" -order $i -q $partShape`;
// i know this because i`m feeding it to the intancer from particleObject
vector $scalePP = `particle -at "x_scalePP" -order $i -q $partShape`;
float $indexPP[] = `particle -at "x_indexPP" -order $i -q $partShape`;
$obj = `instancer -index $indexPP[0] -q -obj $instancerNode`;
// print ($i + "> " + $obj[0] + " > " + $posPP + "\n");
select -cl;
string $newObj[] = `duplicate $obj[0]`;
move -a -ws ($posPP.x) ($posPP.y) ($posPP.z) $newObj[0];
rotate -a -ws ($rotPP.x) ($rotPP.y) ($rotPP.z) $newObj[0];
scale -a ($scalePP.x) ($scalePP.y) ($scalePP.z) $newObj[0];
}
Sanctuary
08-11-2006, 08:07 AM
here`s my code to quickly define some basic PP attr and expr for particles
string $objs[] = `ls -sl -type "transform"`;
for ($obj in $objs)
{
string $particleObj[] = `listRelatives -type "particle" -fullPath $obj`;
if (!`attributeExists "x_indexPP" $particleObj[0]`) {
addAttr -ln x_indexPP -keyable true -dt doubleArray $particleObj[0]; }
if (!`attributeExists "x_scalePP" $particleObj[0]`) {
addAttr -ln x_scalePP -keyable true -dt vectorArray $particleObj[0]; }
if (!`attributeExists "x_rotPP" $particleObj[0]`) {
addAttr -ln x_rotPP -keyable true -dt vectorArray $particleObj[0]; }
string $creation = `dynExpression -q -c $particleObj[0]`;
$creation = "x_indexPP = trunc( rand(0,9) );\r\nx_scalePP = rand(0.5,0.8);\r\nx_rotPP = rand(360);\r\n\r\n" + $creation;
dynExpression -s $creation -c $particleObj[0];
string $runtime = `dynExpression -q -rbd $particleObj[0]`;
$runtime = "x_rotPP += rand( 0.001, 0.01 );\r\n\r\n" + $runtime;
dynExpression -s $runtime -rbd $particleObj[0];
}
azshall
08-11-2006, 02:57 PM
Ahhh... Very nice approach... I'll give this a shot!
az
n0$feratu_037
09-05-2006, 08:50 AM
There is another way of getting particle rotation,but it involves some scripting
you can put this script in your scripts dir:
// vector2rot.mel
// script for converting vector into worldspace rotations.
// adrian@kolektiv.com (http://forums.cgsociety.org/adrian@kolektiv.com) Jun 20/04
// AWGUA Maya Seminar August 2004
// Description: An essential script for converting velocity and up vectors into
// Euler rotations.
// NOTE: If you're using this for particle instancing, make sure to convert rotational
// values in degrees to radians *twice*, due to a little legacy bug. Like this:
// vector $direction = worldVelocity;
// vector $up = normalPP;
// float $rot[] = `vector2rot $direction $up`;
// float $rotX = deg_to_rad( deg_to_rad( $rot[0] ) );
// float $rotY = deg_to_rad( deg_to_rad( $rot[1] ) );
// float $rotZ = deg_to_rad( deg_to_rad( $rot[2] ) );
// Special thanks goes out to Steve Hwan for providing the guts, I just Maya-nized it.
////
// main proc
global proc float[] vector2rot( vector $direction, vector $up ) {
// normalize vectors first
$direction = unit( $direction );
$up = unit( $up );
// calculate the side vector
vector $sideVec = cross( $up, $direction );
vector $upVec = cross( $direction, $sideVec );
float $cosY = sqrt( ($sideVec.x)*($sideVec.x) + ($sideVec.y)*($sideVec.y) );
// solve each angle
float $rotZ = atan2( ($sideVec.y), ($sideVec.x) );
float $rotY = atan2( -($sideVec.z), ( (($sideVec.x)+($sideVec.y)) / (cos( $rotZ ) + sin( $rotZ ) ) ) );
float $rotX = atan2( ($upVec.z), ($direction.z) );
// convert to degrees
$rotX = rad_to_deg( $rotX );
$rotY = rad_to_deg( $rotY );
$rotZ = rad_to_deg( $rotZ );
// return x,y,z rotations
return { $rotX, $rotY, $rotZ };
} // vector2rot
and then in your expression put something like this:
float $aimPP[]=`getParticleAttr -at velocity Flow_particle.pt[1]`;//get velocity
vector $direction = (<<($aimPP[0]),($aimPP[1]),($aimPP[2])>>);//define direction vector
vector $up = <<0,1,0>>;//define up vector
float $rot[] = `vector2rot $direction $up`;//use the script to get rotation values
rotateX = $rot[0] ;//assign the values to the obj
rotateY = $rot[1] ;
rotateZ = $rot[2] ;
I used this approach to attach objects (duplicates) to particles,and drive rotation from particle rotation,hope it helps.
CGTalk Moderation
09-05-2006, 08:50 AM
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.