help needed with particle instancing based on poly normal direction.


#1

Hi there

I’m having difficulty getting the particle instancer to behave a certain way. In a nutshell what I want to do is emit particles with instanced poly planes that face the same direction as the poly normals that they are emitted from.

and I am stuck! haha
Here is an image of what it looks like at the moment.

All I want is to be able to have those instanced planes to be facing outward from birth.

here is the above scene: http://www.eye-for-complexity.com/Misc/HelpInstance.zip
I would appreciate it if anyone could help me.


#2

place a locator at the centre of your sphere and put this code in creation and runtime

vector $pos = worldPosition;
$px = $pos.x;
$py = $pos.y;
$pz = $pos.z;
//now make a custom vector att (aimDir)
aimDir = <<$px,$py,$pz>>;

and plug that into the aim direction of your instancer. As long as your sphere doesnt deform or translate without the the locator your good to go.

good luck


#3

Thanks mandark for the quick reply, It hadnt occured to me to make them aim at a locator ahha… but its not working quite how I want it to. the instances stay the way they were and if i move the locator up a bit they rotate 90 degrees which happens with aim constraints when they arent set up right I think.

Is there a way that I could find the direction of the polygon normal and plug that into the instancer rotation? so its not dependent on aiming and I could make it work on any shaped object.

Thanks


#4

Maya has a closestPointOnMesh node that can also return the closest normal. I did a test with a particle expression that queries the cPOM node and sets a per particle attribute to orient the instance based on the normal:

scene file

Seems to animate nicely and your geometry can be any shape.
-shawn


#5

Here’s yet another option… :slight_smile:

First make sure you have “Need Parent UV” ticked in your Basic Emitter Attributes.

Then make the sphere a goal for the particles. Make sure the goal weight is NOT zero (use 1.0 if you want them to stick to an animated surface)

Select the particle object. Look in the Attribute Editor, find the particleShape node/tab. Look in the section called “Per Particle (Array) Attributes” for the following attributes:

Parent U, Parent V, Goal U, and Goal V.

If they are not there, you need to add them - you do this in the section just below, called “Add Dynamic Attributes”, hit the “General” button. You will find them in the “particle” tab.

Enter a Creation Expression for the particles (right-click on one of the Per Particle attributes and select “Creation Expression…”. This opens the Expression Editor.) Type in the following:

goalU = parentU;
goalV = parentV;

and hit the “Create” button in the Expression Editor.

In the Attribute Editor, on the particleShape node, look for “Goal Weights and Objects”. Hit the button “Create GoalWorldNormal 0 PP”.

In the “Instancer (Geometry Replacement)” section, set the “Aim Direction” to be GoalWorldNormal0PP.

(In short, you have now made the particles aware of their place of birth on the object, in terms of U and V coordinates. These coords are then set to be their birth goal, and is then used to read the normal from the object. And you then feed this to the instancer.)

Now, this is more specific to the scene you had already made…

  • you had Rotation Type (in the Instancer section) set to “Force”. Set it to “None” as is the default.

  • select the polyPlane (the object you use for instancing).

  • in the channel box, enter -90 for Rotation Z.

  • Freeze Transformations (if your polyPlane is not at the origin of the scene, then you will want to use the option to only freeze rotations)

The polyPlane’s object X-axis is now pointing same direction as the normal of the polyPlane, and it will align as you described.

Note: you can hide your instance object, so you don’t have to move it away from the scene origin. Making the original instance object invisible will not affect rendering of the particle instances.


#6

“YourDaftPunk” and “ctp”, thanks so much, I tried out both of your techniques and they work great!!.

exactly what I wanted to achieve,
Thanks!!!


#7

my bad the expression should have had the locator name in it too lol. Im glad you found a solution that worked.


#8

I’ve also seen this done with follicles. Cool script!


#9

Hi,
Just a question : how can i give a random rotation on all instancer ? (with the YourDaftPunk scene for example).

I tried a random vector in the “rotation” in the instancer, it isn’t work.

Thank.


#10

Hi everyone… I also have a question about this subject:

I created a particle grid with simple cubes instanced, and aplied a white shader to a face of the cube, and a black shader to the opposing side, then I made the particles collide with a plane with a sine deformer, and made the point in wich they collide the particle’s goal position, and used ctp’s method to make the instances get the poly normal direction.

So… what I got so far is a bunch of particles that sticks to a plane and get a nice curvy form (from the sine deformer). the trick however is that I need to animate the rotation of that instance based on its position to a locator, so… when the locator is close to the particle the instance is rotated 0 degrees showing the white face, and when is far away… the instance rotates 180 degrees to show the black face of the cube… the problem is: I can’t get the curvy shape (wich I get setting “aim direction” to goalWorldNormal0pp) and the control of the rotation (using a custom atribute called “RotationPP” conected to Rotation), kind of like one overrides the other or something.

I’m now realizing that my question is basically the same as bigbossfr’s… so… I’m sorry for that extra words… basically what I want to know is if there is a way to add rotation to a instance… and still conserve all the normal aiming goodnes… kind off…

here’s my scene if anyone cares to take a look (maya2010, but an ascii file is included)
http://rapidshare.com/files/290469550/ParticleInstancingMaya2010.zip.html

Thank you everyone…
ps. English is obviusly not my first languaje and therefore is kind of bad…so I have to use a lot of words to try to understand myself… sorry about that


#11

Up for my question.


#12

I found this thread, which helped me a lot (YourDaftPunk’s methode, that is).
But I too need a way to give the instances a random rotation (still they have to be perpendicular to the surface but with random rotation along the arrow’s length axis).
Old thread reanimated ;o)


#13

gotta love the undead threads

duplicate your instanced geo a couple of times and rotate them randomly in y.
freeze all transforms
instance with indexPP set to rand( 0 , numOfInstances+1 )

its kind of a cheat because the idea is to just make a connection instead of duplicating and making your scene bigger. but sometimes getting it done is more important than doing it “properly”
Just like when someone hands you a scene file with an outliner thats 5000 pages long of unnamed nodes and you dump in a new group named “screwYouUnorganizedJerk”
…or maybe its just me. haha :applause:


#14

Thanks mthorson,

if I don’t find a more elegant way that’s certainly a possibility.
Thing is, I already have at least 10 different objects that are distributed randomly with the indexPP method. I would have to duplicate all of them several times and rotate them, which would give me loads of objects…


#15

There is a scrpt called vector2rot, use it to get the rotations, then add a random value to the y rotation.


#16

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,

[ol]
[li]Create a new PP Attribute, call it randomRotY (an arbitrary name).[/li][li] Add the following expression to your existing expressions: [/li]```
particleShape1.randomRotY = <<0,rand(0,359),0>>;


[li] Last, in the particle shape node, go to the [i]Instancer (Geo Replacement) [/i]section and for [i]Rotation[/i], select randomRotY. Rewind and play your scene.[/li][/ol]   [img]http://stimuli.ca/random/20100312/randomYParticles.jpg[/img]
 Once again, mad props to YDP for the closestPointOnMesh solution... just the ticket! Particle leaves on trees, here I come!

#17

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 ?


#18

There’s a Instancer option called Aim Position that does exactly that.

Your geo to be instanced:

[ol]
[li]Must be facing/aiming down positive X[/li][li]Must be grouped - we will instance the group.[/li][/ol]

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 [b]Particle Tool[/b] and just clicked all around the cube.

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

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

Your expression:
particleShape1.AimHere = <<pCube1.translateX, pCube1.translateY, pCube1.translateZ>>;
Now [i]Particles-&gt;Instancer (Replacement)[/i] the [b]group[/b] (not the geo!). For Aim Position, choose [i]AimHere[/i].
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/maya/2011help/index.html?url=./files/Particles_Instance_geometry_to_particles_single_and_animated.htm,topicNumber=d0e404402



#19

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.


#20

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