Tuesday, 24 January 2012

Hedge Tutorial

One day Robert decided he needed to do some R&D for an upcoming project, and started making a hedge in Maya. Methods such as paint effects hadn't worked, and modelling the whole thing would be a long and cumbersome task, so he elected to use particle systems.
As he sat down at his desk, Robert turned slowly to his cat, and screamed 'Damn! If only I knew how to do the following!:
-Create a hedge within Maya, using particle systems and instanced geometry!
-How to create basic expressions to make instanced geometry rotate randomly!'

''I know!' he blasted as the cat ran away, 'I will find these details out, and post them online with simple instructions and screenshots so others may learn from my errors!'
Robert banged his fist on the table with determination. 'Let's make this hedge! Right after I get some coffee and check my facebook!'

An hour later, Robert began his daunting challenge.

The first thing Robert knew he must do was to create a cube in maya, a block out of the hedge's shape. He made a poly cube, and decided that 10 subdivisions would be sufficient to shape it thusly:

As he worked, his phone rang. It was his grandmother.
'Are you creating a poly cube in maya to make a hedge, dear?' she asked.
'Why yes granny, I am!'
'Oh good. Be sure to delete any unnecessary faces, such as the ones on the bottom and at the back, to decrease render times later!', his gran replied; she hang up. Robert thought this was an excellent idea, and complied.
After a full 2 minutes of work, Robert was fed up of using maya, and decided to go on google and find a suitable leaf image which he could adapt into a texture map.

Robert promptly loaded a suitable image into Photoshop, and created an alpha channel for the leaf. As he was completing this process, his cat returned to the room. As he stared into the cat's eyes, he could sense the cats thoughts...
'Save the image file as a .tga... With alpha channels... 32 bits... Compress', the cat said, telepathically.

Robert thought this counsel was nonsense, but his fear had made him pliable, and he proceeded as the cat had ordered:

He loaded his texture map into maya and applied it to a plane, the approximate size of a leaf in relation to his hedge. He was delighted with the result:

Now that Robert had both his leaf and his hedge model ready, he knew his destiny was about to begin. He was going to make the particle system that would drive the random geometry, which would later become leaves.

Robert selected his basic hedge model, then clicked the 'Particles>Emit from object' options box. He then made sure to select 'surface' as his Emitter type. After slowly contemplating the beauty of fallen leaves idling and dancing in the wind, he decided that he did not want his leaves moving for this at all, so set his speed to 0, and clicked 'create'. 

Following this, Robert had his leaf plane selected, when he happened upon the 'Instancer (Replacement)' options tab. He chose the default options without hesitation.

'Oh Happy Day!' Robert cried. And he cried again, when he discovered that the default settings would not randomise his leaves at all:

As he sat in despair a magical unicorn, with the head of a T-Rex suddenly appeared next to him, in a vision of rainbows and purple smoke.
'You must create a custom expression to randomise the leaves rotations' ,the unicorn whispered, before conveying the necessary expressions to Rob via telepathy; then disappeared to whence he came.

'Why have Autodesk not thought to make this easier!' he lambasted, 'Surely this is a common occurence, befitting of a tool in a future maya update!'. The cat nodded, sanctifying his grievance. With a heavy heart, Robert opened up the attribute editor for his particle system, and clicked the 'General' button in the 'Add Dynamic Attributes tab, and naked his new attribute 'rotPP':

With the 'creation' option selected, he input the following:
particleShape1.rotPP = rand (0,360);
And with 'runtime before dynamics' chosen, he did also type:
particleShape1.rotPP += 0.001;

This gave the attribute a random value, from 0 to 360, and would vary it per particle, just as the T-Rex-headed unicorn had prophesied. He knew that once he deleted his current instance via the Outliner tab, he could create a new instance, as he had before, and choose his new 'rotPP' expression as it's rotation value.

Voila! His masterpiece was almost complete, Robert knew. All he had to do now was tweak his particle/emitter settings to get a suitable volume of leaves, and break the connection to the particles 'Current Time' attribute, until he discovered a better way to 'freeze' his leaves or convert them to polygons.

Jealous of his success, the cat climbed onto Robert's desk to have a look. As he espied Rob's amazing work the cat's eyes bulged and glowed, as if some ancient knowledge long hidden in his mind was creeping out from the darkness.

'Not bad' Robert chuckled to himself, drunk with his success. 'It's far from perfect, but for R&D/tutorial purposes, I'd say our work is done!'

To his astonishment, His cat started rising slowly from the desk, knocking his keyboard to the floor, and turned towards him, as if compelled by some supernatural force...

'I hope that if anyone appreciates this tutorial, or has any further tips, that they comment on this blog post', the cat screeched...


  1. Lol very entertaining tutorial Ol, i would love to see more tutorials in the future :)

  2. Thanks, but I spent ages trying to figure out why the expression editor doesn't appear when clicking 'General' under 'Add Dynamic Attributes' in particleShape1's attribute editor, as your pics imply. You neglected this step :)

    You needa tell people how to use the Add Attribute window, and *then* how to open the Expression Editor :)

    Bit hard for us expression noobs to follow otherwise, hehe.

  3. Hey,
    nothing happens when I complete this step,
    "Following this, Robert had his leaf plane selected, when he happened upon the 'Instancer (Replacement)' options tab. He chose the default options without hesitation."
    hmm I can't figure out what is up/why it won't work for me...Too bad because I would like to make some hedges :-D

    Thank you for the tutorial. Maybe you could put some more details in to help n00bs like me n the dude who commented before..