help needed with particle instancing based on poly normal direction.


#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.