help needed with particle instancing based on poly normal direction.


#27

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.


#28

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


#29

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.


#30

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!


#31

Just wanted to say a massive thanks to all who contributed to this thread.

Massive help!


#32

Hi everyone,

How do i then offset the particles along the surface normal (and possibly animate it over time)?

Thanks
F


#33

goal offset attribute in particle shape.


#34

can you do that with nparticles the same way?
i do not get the instance normal alignment working…


#35

There’s some great information here, I have something I’ve been trying to do related to this.

I’m trying to create an enormous flock of bats that can be dynamically influenced. One problem I’m having is getting the direction of the individual bats and awareness of the other bats around it.

Anybody have ideas?


#36

Trying to keep this little kick ass thread alive.

I have bugs crawling along skin and I’ve got them rotating around based on the normals which is great. And random Y rotation is easy enough.

I am however trying to figure out how I can get the Y rotation to aim in the direction that the particles are moving.

Any ideas?


#37

Bringing this one back.

Anyone have a solution for the above post.

I’m working on something similar and can’t seem to get the insects to aim in the direction of the velocity and have them orient to the surface normal.


#38

Figured it out like 2 minutes later and thought I’d post the solution in case anyone else needs it.

Aim Direction : Velocity
Aim World Up: goalWorldNormal0PP

With that setup in the instancer, the particles will aim toward their velocity and still be oriented correctly on the surface.


#39

Hey guys,

I don’t know what i’m doing wrong…
I guess that when it comes to scripting I get lost most of the times… :banghead:

Anyways, could someone help me figure out why this is not working for me? All I wanted is for the instances make a kind of grid with crosses, using the sphere as a dome with a cross on each vertex…

I used YDP scene file as a start and copied the expressions…

I uploaded my scene.
please, guys… :slight_smile:
Thanks a lot!!!


#40

Ok…hmm

I managed to constrain the instances to the sphere’s normals. :slight_smile:


#41

ctp,

I’m trying a variation of yours but i can’t seem to get it right! I work with the Z up and thus i’m attempting to modify your code for one with the Z up.

This is the expression that i’m creating:

// sets the orient axis for the instance
particleShape1.aimUp = <<0,0,1>>;

// get surface normal at particle position
vector $particlePos = particleShape1.position;
vector $normal = nearestPointOnMesh -ip ($particlePos.x) ($particlePos.y) ($particlePos.z) -nr -q pPlane1;

// orient the instance
particleShape1.aimDir = $normal;

// random rotation for Z axis
particleShape1.randomRotationZ = rand(360);

//solve each angle, convert to degrees
float $rotX = rad_to_deg( atan2( ($normal.y), ($normal.z) ) );
float $rotY = rad_to_deg( asin( -($normal.x) ) );

// asign random rotation in Z
particleShape1.rotationPP = << $rotX, $rotY, particleShape1.randomRotationZ >>;

any help with this will be greatly appreciated, i’ve attached my file for your reference.

Thanks,

-G


#42

[ should have read the posts above, ignore me]

Acidream = genius.


#43

hey guys

great thread and another resurrection!

so i was mucking around with YourDaftPunks scene (thanks) and stimuli’s post trying to aim the poly planes to a camera in the y axis whilst maintaning the orientation to the surface.

i am trying to replicate a ground cover system in a game engine. don’t ask why, but I am!

i think stimulis solution for aiming would break the surface orientation?

thanks for the informative read guys.

Kev


#44

He can add a custom attribute randomRotation and give and give it this expression :

particleshape1.randomRotation = rand(0,0.360,0)

and map it to the rotation, like that he will get random rotation on all the instances on the Y axis.
the bad thing about doing it with Index is that more indexes in the instances effect the ram during the rendering and slow down a bit the render if the objects instances get pretty big with complicated shader network complicated .
thanks


#45

getting degrees with angleBetween command, and with random X rotation

// getting particle location
vector $p = nParticleShape1.position;

// calculating normal
vector $normal = nearestPointOnMesh -ip ($p.x ) ($p.y) ($p.z) -normal -q pSphere1;

// solving angles
float $angBet[] = angleBetween -euler -v1 1 0 0 -v2 ($normal.x)($normal.y)($normal.z);

// setting rotation with random
nParticleShape1.rotationPP = <<($angBet[0]+rand(180)), $angBet[1], $angBet[2]>>;

here your object for instancing should be heading x direction with its “up”


#46

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.