help needed with particle instancing based on poly normal direction.

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  03 March 2010
Easy solution

Well, mad props to YourDaftPunk for giving me exactly what I'm looking to do.

I tried ctp's method, before reading his comment, and it got me close to what i need, but not quite there. The rotations are inflexible.

To answer the question asked by recent posters, to add random rotate Y values to the arrows,
  1. Create a new PP Attribute, call it randomRotY (an arbitrary name).
  2. Add the following expression to your existing expressions:
    particleShape1.randomRotY = <<0,rand(0,359),0>>;
  3. Last, in the particle shape node, go to the Instancer (Geo Replacement) section and for Rotation, select randomRotY. Rewind and play your scene.

Once again, mad props to YDP for the closestPointOnMesh solution... just the ticket! Particle leaves on trees, here I come!

Last edited by stimuli : 03 March 2010 at 06:53 PM.
 
  06 June 2010
Since we all are on the topic of per particle rotation.
The random rotation is rather easy, I was wondering how can we make a per particle instance rotate based on a position of the locator. So if the locator position changes, so does the rotation of the per particle instance. Any ideas how to do that ?
 
  06 June 2010
There's a Instancer option called Aim Position that does exactly that.

Your geo to be instanced:

  1. Must be facing/aiming down positive X
  2. Must be grouped - we will instance the group.

Create a cube, it's name should be pCube1. Move it somewhere (don't Freeze Transforms!). The particles will aim towards pCube1.

Make some Particles. I used the Particle Tool and just clicked all around the cube.

Create a PP Attribute called AimHere (arbitrary name) for your particles. It must be Vector, and Per Particle.

Right-click your PP AimHere Attribute and choose runtime expression. This executes expressions every frame, as opposed to once before the scene plays aka initial state. Before or After Dynamics is up to you.

Your expression:
particleShape1.AimHere = <<pCube1.translateX, pCube1.translateY, pCube1.translateZ>>;


Now Particles->Instancer (Replacement) the group (not the geo!). For Aim Position, choose AimHere.
I hid the group I instanced from. If I hid the geo as opposed to the group, all instances disappeared.

Move the cube around.


consult Maya's Help for more info: http://download.autodesk.com/us/may...umber=d0e404402



Last edited by stimuli : 06 June 2010 at 02:41 PM.
 
  08 August 2010
This thread has been great! So i'm dusting off my Maya particles knowledge and have gotten stuck. I'm using Maya 2009 nParticles. Right now I am shooting nParticles with instanced geometry at a deforming surface via goal weights. I need the instanced geo to orient with the deforming surface face normals

In an effort to do use I'm working off YourDaftPunk's example scene. I have tried to recreate it, but have issues with the aimUp and aimDir. I cannot find then in the pp attributes, and maya won't let me create them. I'm sort of lost on this at the moment.

Any advice would be great.
 
  08 August 2010
Originally Posted by DCWarner: This thread has been great! So i'm dusting off my Maya particles knowledge and have gotten stuck. I'm using Maya 2009 nParticles. Right now I am shooting nParticles with instanced geometry at a deforming surface via goal weights. I need the instanced geo to orient with the deforming surface face normals

In an effort to do use I'm working off YourDaftPunk's example scene. I have tried to recreate it, but have issues with the aimUp and aimDir. I cannot find then in the pp attributes, and maya won't let me create them. I'm sort of lost on this at the moment.

Any advice would be great.


These attributes are located on the particle shape node, Look for the "Instancer (Geometry Replacement) Tab, in the "Rotation Options" section
__________________

 
  08 August 2010
I'm not finding it. In the instancer section i see Aim Direction and Aim Axis, calling upon aimUp and aimDir respectively. In YourDaftPunk's scene there are two Per Particle(Array) Attributes, Aim Up and Aim Dir, which are referred to as aimUp and aimDir in the expression editor. I can't find them in the particle attribute list, nor does it seem i can add them as custom Per Particle attribis...
 
  08 August 2010
UGH! SO DUMB! I guess this happens when we stare at the screen for too long! Forgot to turn per-particle on! Well, i have the variables working, but not getting the behavior i want yet...
 
  08 August 2010
Originally Posted by DCWarner: UGH! SO DUMB! I guess this happens when we stare at the screen for too long! Forgot to turn per-particle on! Well, i have the variables working, but not getting the behavior i want yet...

ok. cool. I was going to say, "Wait why can't you add them?"

Glad you solved it
__________________

 
  08 August 2010
So far so good. Using the solution outlined by YDP, has anyone been able to generate random rotations about the normal vector? Stimuli's solution breaks all other rotations, and since i'm attaching instanced objects to a deforming sphere, I have to keep aligned with the surface normal.
 
  08 August 2010
I tried doing a mix between YDP's solution and the vector2rot script mentioned by Derek Wolfe.
Occasionally I was getting some very abrupt changes in aim direction when using the closestPointOnMesh node, especially on a deforming mesh.
So I tried comparing results with the nearestPointOnMesh command, and using the same input position here's what I got, :

normal from closestPointOnMesh
// Result: -0.323307 0.709912 -0.625698 //

normal from nearestPointOnMesh
// Result: -0.33909 0.776836 -0.530607 //


Odd!

Anyway, using the command nearestPointOnMesh (remember to first load the plugin nearestPointOnMesh.mll) here's a way to align particle instances to surface normals and having a random rotation around the alignment axis. In this case I'm aligning the instances X-axis, so the original instance object should be pointing along the X-axis on the grid (with transforms frozen) for this to look right.

add two custom per particle attr's:
rotationPP (vector)
randomRotationX (float)


in the instancer section of the particleShape tab, go to Rotation Options and set Rotation to be rotationPP.

Creation expression:
// random start position
   particleShape1.goalU = rand(0.1,0.9);
   particleShape1.goalV = rand(0.1,0.9);
   
   //random rotation for X axis
   particleShape1.randomRotationX = rand(180);
   


Runtime expression:
// define a variable with the particle position
   vector $p = particleShape1.position;
   
   // get surface normal at particle position
   vector $normal = `nearestPointOnMesh -ip ($p.x) ($p.y) ($p.z) -normal -q pPlane1`;
   
   // define worldUp
   vector $worldUp = <<0,1,0>>;
   
   // calculate normalized directions by which to align the y and z axis of the instance object
   vector $directionOfZaxis = unit(cross( $normal, $worldUp ));
   vector $directionOfYaxis = unit(cross( $directionOfZaxis, $normal ));
   
   // solve each angle, result in degrees
   float $rotZ = rad_to_deg(( atan2( ($normal.y), ($normal.x) ) ));
   float $rotY = rad_to_deg(( asin( -($normal.z) ) ));
   
   // feed result into the rotationPP attribute
   particleShape1.rotationPP = << particleShape1.randomRotationX, $rotY, $rotZ >>;
   


Optionally you can add the runtime expressions in the creation too.
Also, notice the "pPlane1", which should be corrected to match the name your poly object.

Last edited by ctp : 08 August 2010 at 04:56 PM. Reason: typo
 
  08 August 2010
... I just noticed I'd pasted some lines in there that were not needed for this case.
So these lines are redundant, as you might have noticed too


 // calculate normalized directions by which to align the y and z axis of the instance object
 vector $directionOfZaxis = unit(cross( $normal, $worldUp ));
 vector $directionOfYaxis = unit(cross( $directionOfZaxis, $normal ));
 


Cheers.
 
  08 August 2010
Ah CTP!

You beat me to it. After stepping away for a few day I just started to dissect the commands and vector math.

I created a script similar to yours, no need to post it. The only difference was that i used closetPointOnMesh. I didn't experience the abrupt changes in direction you did, and the behavior seemed better.

Glad you posted your solution!

DCW

Oh!! What i think helps with the with this script and the deforming surface is to create a geoCache of the surface.
 
  08 August 2010
This thread might be dug up a few times in searches later on, so I thought it would be worth putting an extra note in here...

If you want the Y-axis of the instance object to align with the surface normal, it will work with these lines:

float $rotX = rad_to_deg( atan2( ($normal.z), ($normal.y) ) );
float $rotZ = rad_to_deg( asin( -($normal.x) ) );

You can then assign a random rotation to the Y-axis.

NOTE: In this case, rotation order must be set to YXZ, on the instancer node.

C

Last edited by ctp : 08 August 2010 at 10:24 AM.
 
  08 August 2010
Originally Posted by bigbossfr: Up for my question.


Is this what you mean?

In your particles go to add dynamic attribute > general. Give it a name(like particle_rotate), make sure its a vector (for x,y,z), and check per particle array.

Rightclick your new attribute and runtime expressions before dynamics and type this in :

nameofparticlesParticleShape.particle_rotate = rand (<<0,0,0>>,<<360,360,360>>) ;

What this line does is bascially give them a random rotation of 0 and 360 degrees in x y z. You could ofc if you just wanted it to be in one angle change it to 0,360,360 or something.
Then under rotation options choose particle_rotate.

Remember tho that the will randomly rotate every single frame now, if you just want to create some randomness and have your geometry be still, you can scrub in the timeline untill you find a frame youre happy with and then just put // in front of the expression or delete it.
 
  01 January 2011
glad this thread is still open - consider me subscribed - I'm trying to run through some of the examples and get my head around the expressions!
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 02:27 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.