Particles; random rotation while aligning to normals of surface

ParticleNormals_01 ParticleNormals_02

This tutorial will explain how to align particles to the normals of a surface so that they follow the curves of the surface while still having random rotation about the ‘up’ axis.

Create a poly plane and use soft selection to give it some undulations.

Create a poly pyramid with default settings.

Select ‘pPlane1’ and go to Particles > Emit from Object.

In the ‘particleShape1’ node, change the max count to 200.

In the ‘particle1’ node, change the rate to 100,000 and change the Emitter Type to ‘Surface’.

Play the animation to see the particles appear on the surface of the plane.

Select ‘pPyramid1’ and ctrl+select ‘particle1’.

Go to Particles > Instancer (Replacement).

Open the ‘particleShape1’ node in the Attribute Editor.

Under Add Dynamic Attributes, add three general attributes, ‘meshPositionPP’, ‘meshNormalPP’, ‘rotatePP’. Data type: Vector, Attribute Type: Per particle (array)

Make sure that you have the ‘nearestPointOnMesh.mll’ plugin loaded in the Plug-in Manager.

Make a new creation expression. In the Expression Editor, add the following:

//Align instances to normals on mesh
int $id2 = particleShape1.particleId;
vector $particleposition = particleShape1.position;
int $rotX = 1;
int $rotY = 1;
int $rotZ = 1;
float $nrm[] = `nearestPointOnMesh -ip ($particleposition.x) ($particleposition.y) ($particleposition.z) -q -normal pPlaneShape1`;
vector $normalOnMesh = <<($nrm[0]*$rotX), ( $nrm[1]*$rotY), ($nrm[2]*$rotZ)>>;
particleShape1.meshNormalPP = $normalOnMesh;
//Convert normal vector to euler coordinates
float $angBet[] = `angleBetween -euler -v1 1 0 0 -v2 ($normalOnMesh.x) ($normalOnMesh.y) ($normalOnMesh.z)`;

//Set rotation
vector $rotInit = << rand(0,180) , $angBet[1], $angBet[2] >> ;
particleShape1.rotatePP = $rotInit;

 

Now under Instancer (Geomtery Replacement), change the Rotation to ‘rotatePP’.

We’re almost there but the pyramids are facing the wrong way. Select the pyramid, rate by -90 on the Z axis, move the pivot point to the base of the pyramid, move the pyramid to the exact 0,0,0 location and freeze your transformations. You should now be good to go.

 

Leave a Reply

Your email address will not be published. Required fields are marked *