Sunteți pe pagina 1din 61

Title of Seminar: Digital Hair Presenter: Sergey Tsyptsyn

0. Long waiting for Hair before Maya 6.x


Before Maya 6 there was a lot of tricks to simulate behavior and look of the Hair. People tried to do their best with Paint Effects, softbodies and particles, surface texturing. Even cloth dynamics was involved to simulate motion of Hair clumps. At the second part of this Master Class I will show some ways to save previously created fake Hair and convert them to new real Hair system. Current implementation of Hair system has real MAYA nature inside. If you have some experience with particle dynamics you can start to work with Maya Hair without any problem. I suggest to keep one thing in mind working with Hair:

Hair is Particles
I am going to prove that during this MC.

I. Understanding MAYA Hair


Like Particles Hair is Complex object. On the one hand it should be considered as one, whole object, especially from rendering side. On the other hand it consists of number of curves defining the shape and motion of this whole object. Experience with Rigid Body Dynamics, Particles, Cloth, Fluids makes learning Maya Hair just a game. Hair is not long Fur, Hair is Particles. Fur can be considered as a kind of procedural texture with corresponding behavior. Hair has different nature. Therefore everything you know about particles can be and should be used with Hair. You can consider Maya Hair as good soft bodies with particles and non-stretched springs. It is most safe and adequate way to think about Hair. If you have strong allergy to dust and particles you can think of Hair as a chain of rigid cylinders with nail constraints. All rules of particle dynamics must be kept in mind: playback speed=play every frame, play only forward and so on. One basic rule: Fast movements real problems. Hair is not usual object it is complex, intricate, heavy, capricious and crazy.

As well as for particles Hair has Double Nature dynamic curves and visualized curves. For particles there are several Render Types. For Hair there are several Render Ways. These ways depend on you goals and you favorite Render Engine.

II. Growing good Hair


Lets create some Hair. Open file 1_headBadUV.ma

The main condition for successful Hair creation is good UV-mapping on the target surface. Good means not only non-overlapped, but also normalized. Select head mesh and try to create default Hair: Hair=>Create Hair. You will see strange bunch of clumps on the right side of head. Check UV-mapping on the mesh. Select head and open Window=>UV Texture Editor.

As you can see the UVs are perfect but not located in [0,1] region.

Normalize UVs by doing Polygons=>Normalize UV at UV Texture Editor

As you can see Hair is now non-uniformly covers entire mesh. Always check UV-mapping on target surface. Otherwise you will get strange surprises, especially during Hair painting.

Hair needs good UVs!


Although Hair is relocated during UVs tweaking it is better to recreate Hair system after UVs editing, because new follicles will not be created at the areas where UVs were not defined before editing. Obviously, for NURBS surfaces there is absolutely no problem with UVmapping. Hint. It is good idea to make one NURBS-patch for Hair creation. Later you can parent this patch to your head model. If head is deformable you can use wrap-deformer to deform this patch with head. It is not good idea to land hair to entire surface, because it will be too much depilation job to keep only needed area hairy. Therefore Hair Painting is good option. Select Hair and delete Hair System: Hair=>Delete Entire Hair System. Select head mesh and open Option Box for Paint Hair Tool. Set the following values:

U: Follicle Density=40; U: Follicle Density=20; Hair Length=10; Output=NURBS Curves;

Hint. You can compensate non-uniform parameterization or UV-mapping with different Follicle Density values. Hint. If you are not going to make heavy Hair set Output=NURBS Curves for initial setup. It always possible to add Paint Effects Brush to Hair curves later. During painting look at the symmetry line (potential parting location) and see that follicles are not sitting on the central line.

Undo all painting and go to Script Editor and set following variable
optionVar -intValue createHairMaxDensity 101;

Try again and check the symmetry. Why 101? By default painting is applied on the 100x100 grid. If you want to have row or columns of follicles exactly at the middle of grid you need to set size if the grid to odd values, like 101. Note. Try to create simple nurbs-plane and play with painting follicles on it. Set U/V Density to 4 then compare result of painting (or flooding) with createHairMaxDensity=100 and
createHairMaxDensity=101.

Paint Hair everywhere you think it should be. Do not worry about extra or unnecessary follicles. Do not waste your time for deletion these follicles. We will remove them later.

Quit the Paint Hair Tool and save scene. This scene saved as 2_headPainted.ma Now we need to remove unnecessary follicles. As long as you are already familiar with Maya Fur, you know that a good way to do this is attribute map. We are going to take file texture and keep only those follicles that are in the dark area of surfaces (black area used for better visualization only, you can easily modify process to use white area as a mask). Texture is already here. Switch to textured view. Uncommon name of texture is file1.

Small script can be used to sample color under each follicle and remove follicle if the color is not black. Select hairSystem1 and execute following script.
string $texture = "file1"; // converting selection to follicles convertHairSelection "follicles"; // list of follicles string $list[] = `ls -sl`; string $it; // for each follicle for ($it in $list) { // get UV-position float $u = `getAttr ($it+".parameterU")`; float $v = `getAttr ($it+".parameterV")`; // get color at point on surface under follicle float $col[] = `colorAtPoint -o RGB -u $u -v $v $texture `; // delete follicle and its curve if red channel is white if($col[0]>0.5) delete (`listConnections -t "nurbsCurve" $it`) $it (`listTransforms $it`); }

You can see shaved head now.

You can create this baldness-texture using your favorite method of texturing. This texture is extremely useful not only for creation process. It can be used for many purposes during hair setup. You will see that later.

Baldness texture is a must!


Now you can check behavior and stiffness of Hair. Play animation and look at very stiff Hair. Select hairSystem1 and set Stiffness=0.03. Note. In Maya 7 there is built-in support for baldness texures.

III. Stiffness is the problem


For dynamic simulation the main problem is high velocities. The dynamics systems with very high frequencies are call stiff systems. Therefore you should avoid very high values for the real stiffness attributes. To calculate high-frequency motion Iteration attribute should be set with very large values (above 100), which slows down performance significantly.

There are some ways to make fake stiffness for Hair. First of all, keep the number of CVs low for current curves. You can set it during creation or tweak it later with Sample Density attribute on follicles. To smooth the visual (not computed) shape of curves the subSegments attribute can be used later. High Damp values (above 100) can be used sometimes to simulate rigid behavior. Rest curves is very flexible way to make fake stiffness. They work in conjunction with stiffness attribute and allow to freeze Hair. Using constraints applied to whole Hair system can be used to fasten Hair around some fixed position. Creating several constraints with Point Method=U Parameter helps fix Hair along length. These constraints can parented to head model. In Maya 7 there is new and very useful attributes Start Curve Attract for Hair system. It makes start curves a goal for current curves and control the amount of attraction to start curves. To make Hair stiff you need now only save current shape as start curves and set Start Curve Attract to large enough values. Value of 1 means full attraction. In our case stiffness is not an issue, but I keep number of CVs low for making further styling easier.

IV. Styling the Hair


Styling is trickiest part of Hair setup. Hair object is so complex that it is very difficult to find the way to simulate real hand-made styling. There is no substitution for real hands. You can use some techniques. First and main one is manual hand modeling with start curves. There are some useful operations, like lock length and selecting end CVs of all start curves. You can apply deformers to all start curves and shape these curves as whole object. But unfortunately you can not lock length during deformation. Interactive playback and simulation can be used to control the behavior of Hair. Dynamic fields help to make common shape. Hair constraints can be used like real hand during Interactive playback. It is rather time consuming method, but if you like computer games this is for you. As long as you get desired Hair shape you can save it as initial state with Set Start From Current operation. If you have already library of adjusted Paint Effects Hair and have huge experience of styling Hair with brush attributes, you can convert your strokes to curves and make them dynamic for further animation. In Maya 7 you can convert Paint Effects tubes to nurbs curves. Then you can make that curves dynamic and use Hair dynamics and shading to make Hair animation.

Another way is particle emitting from surface and converting their trajectories to dynamic curves. I will go for it later. Now we will use main manual method with saving initial state of simulated curves. But before doing any changes and simulations it is very important to setup collisions. Since Hair is Particles it can be collided with surfaces. It is really important to do this at the beginning because some curves can penetrate surface during simulation. After saving initial state and creating collisions these curves will be blocked inside the surface or jumped up.

Collisions should be set before styling


Try to use Collide Sphere and Collide Cube constraints instead of using Make Collide operation. This type of collision is calculated much more quickly and precisely than collisions with real surfaces. You can create several Collide Spheres and Cubes and place them inside you model to make fake but fast and precise collisions. Select hairSystem1 and use Hair=>Convert Selection=>to Follicles for selecting all follicles. Then run Hair=>Create Constraint=>Collide Sphere.

New spherical object appears inside the head. Move and scale it to fit the shape of head model. scale = 5.0; 4.8; 6.3

translate = 0.0; 8.2; 2.9

It is good idea to save scene before manual tweaking of start curves, because Undo does not work for editing length locked curves. This stage is saved as 3_headCollisionSetup.ma

V. Symmetry Tricks
If your model has symmetry plane you can save some time by instancing half a Hair and use only half of the curves to make initial styling. Our Hair is symmetrical. This might be important if you want to make parting in the middle. Now go to Front view and select all follicles and curves on the right side of head (exclude hairConstraint1 from selection).

Delete them. Now select all current curves (not follicles!) except central row. Duplicate them as instances.

Group duplicated instances. Set scaleX=-1 for new group.

For easier selecting it later parent the group to world: Edit=>Unparent. Play animation. Frame rate is almost doubled with this trick and will be more noticeable on heavy scenes. File saved as 4_headInstancedHair.ma

VI. Manual Styling


It is very useful to keep number of CVs for start curves as low as possible for easy manual modeling. Note that start curves have first degree because the only positions of their CVs are important. You can apply all editing curves operations, including Rebuild Curves, to start curves. Go to first frame, select hairSystem1 and run Hair=>Convert Selection=>to Start Curves End CVs. Press l key to lock curves length and move selected CVs back (negative Z-direction).

Switch to Scale Tool, Press Insert and move pivot back, out of curves end. Press Insert again. Check the position of pivot from Top view.

Press l key to lock curves length and scale down selected CVs.

If your hand falters there are is no way to undo. You need to open saved scene and try again. It is also very important to move and scale only with one continuous mouse move. You can edit not only end CVs, press arrows key to select any inner row of curve CVs. Remember that you can only edit start or rest curves, not current ones. Scene is saved as 4_headManualStyling.ma

bclark 6/29/05 10:41 AM


Deleted: no

bclark 6/29/05 10:41 AM


Deleted: cancel these weakness

VII. Dynamic Styling


Play animation and look how current curves jump. They are too stiff because small number of simulated CVs. Increase this number. Select hairSystem1 and run Hair=>Convert Selection=>to Follicles. Open Channel Box and set Sample Density=3 for all follicles. It makes all current curves more flexible and less stiff. Play animation and see non-stiff curves falling. The only one thing needs to be corrected. Base of curves tried to keep normal direction relatively to surface. Sometimes it may be good, but now it is better to style current curves to follow the direction of start curves around base.

If all follicles are still selected go to Channel Box and set Start Direction=Start Curve Base. Until you are not using Interactive Playback it is better to do all attributes changing at start frame of simulation. Now curves are falling better but look weak-willed. Some volume or airiness is needed. Select hairSystem1 and set Stiffness=0.3. Play animation. Look at shape of Hair.
bclark 6/29/05 10:48 AM
Deleted: a

You can also improve volume of Hair with editing Stiffness Scale attribute directly during the animation playback.

While playing back animation set Iteration=8 for hairSystem1. Hair starts to be more stiff. Set Iterations back to 4. It is no need to increase it. It is always necessary to compensate increasing Iterations with decreasing Stiffness attribute. If you double Iteration, you need to halve the Stiffness. Try to adjust Iterations first and do not change it later. It is time to save current position of Hair as initial state. Since Hair is Particle, it has Initial State and this state is saved at start curves. Play animation from start to frame 500. Stop it. Select hairSystem1 and run Hair=>Convert Selection=>to Follicles. Save Initial State of Hair with Hair=>Set Start Position=>from Current.

Play animation from start, expecting no movement. But Hair starts to become longer and fall down like spaghetti. What happens? This is the result of setting Sample Density=3. When we set start position from current, start curves inherited CVs of current curves and become three times denser. But Sample Density keeps the old value of 3. So new current curves become three times denser than new start curves and nine(!) times denser than old start curves. That is why they start to be so flexible. Always check Sample Density for all follicles just after saving current position at start curves! Go to start frame. Select hairSystem1 and run Hair=>Convert Selection=>to Follicles. Go to Channel Box and set Sample Density=1 for all current curves. Play animation. Next trick is to make Hair longer after dynamic styling, not before. It saves time and make initial setup much easier. To scale existing simulated Hair we use the following extreme method: extending start curves.

Select hairSystem1, then use Hair=>Convert Selection=>to Start Curves, to select all start curves. Open Option Box for Edit Curves=>Extend=>Extend Curves. Set Extension Type=Extrapolate, Distance=10, and press Extend. Play animation. Do not forget to switch to displaying current curves, not start ones.

Note. If you have rest curves already created, you should do Hair=>Set Rest Position=>from Start immediately after extending start curves or extend rest curves the same way. Again, play animation until curves stop moving and do Hair=>Set Start Position=>from Current for all follicles.

VII. Fixing with rest curves


But at the beginning of animation there is small jump, which couldnt be avoided with saving initial state of Hair. The only way to eliminate this that I know is using rest curves. Select all follicles and run Hair=>Set Rest Position=>from Start.

Play animation until curves stop moving and do Hair=>Set Start Position=>from Current for all follicles again. Now, after rewinding to start frame Hair doesnt move at all. Hint. Save scene at start frame of simulation. This file is saved as 6_headDynamicStyling.ma.

IX. Visualizations
Now it is time to make first render tests to check density of follicles. To enable PFX rendering we need to apply brush to current curves. Select hairSystem1 and run Hair=>Assign Paint Effects Brush to Hair. Oops. Instances curve didnt get pfx-clumps!

For test purposes you can duplicate pfxHair1 node as instance and set scaleX=-1 for it.

Create key light, (directionaLight: rotate=-10; 10; 0; Intencity=1.4) and fill light, pointLight: translate=15; 5; 5; Intencity=0.5). Note that there is new brush node in the Attribute Editor. If you want to render regular Hair you can just delete it. But if you want to give Hair some exotic look with complex pfxbrushes you need keep in mind some details about relations between this brush node and hairSystem attributes. Width of brush is overridden by Hair Width. Most of brush shading attributes (Color1, Specular Color, Specular Power, Translucence) also are overridden by hairSystems ones. For example, select hairSystem1 and set Hair Per Clump=20; Sub Segments=1; Clump With=1 and Hair Width=0.1;. Select brush associated with pfxHair1 and go to Texturing section of Attribute Editor. Turn on Map Color and Map Opacity. Set Texture Type=File. For Image Name use bubble.iff from brushImages folder of your Maya location. Do not forget to set RepeatU=40. Disconnect file1 texture from Lambert1 and make test Render.

Look how color specified in hairSystem1 influences final color of bubbles. File is saved as 7_headPFXbrush.ma For returning to regular Hair just delete brush node. Set back Hair Width=0.01.

Render it.

It still works with symmetrical fakes but density of follicles is not enough to cover the gaps.

X. Removing symmetry fakes


For increasing density of existing and styled curves the passive follicles is good option. Now it is time to remove fakes, and create extra passive follicles. For better feedback hide strokes. Camera menu=>Show=>Strokes. Select duplicated pfxHair2 and delete it. Then delete group1 with instanced current curves. To create real symmetrical dynamic curves we will use similar trick as with instances. Select hairSystem1, then run Hair=>Convert Selection=>to Start Curves. Unselect start curves form central row.

Duplicate selected curves with default options (not as instances). Run the following command at Script Editor to mirror start curves to another side.
scale -p 0 0 0 -r -1 1 1;

Use Freeze Transformations to remove negative scale. The most simple way to add new dynamic curves to existing Hair system is to make selected curves dynamic then assign existing Hair system to them and set necessary attributes for new follicles. These new follicles can be then parented to head model. But in this case new follicles will not be attached to surface and their U/V parameter values will be zero. Another issue is lost connection to constraints. All these issues resolved by semi-intensive scripting. Fortunately Hair system consists of only two or three types of nodes. And working with Hair with MEL is question of establishing necessary connections. If duplicated curves are selected add head surface to selection and run MEL-script called landCurves. Note. For Maya 6.5 you need to have closestPointOnMesh.mll. It is included in BonusPack for Maya.

Just press the button and see new follicles landed on the head. These new follicles have the same attribute values as old ones and are connected to collision constraint. Play the animation. Look at non-symmetrical shape.

We have lost dynamic symmetry because we did not recreate rest curves for new duplicated curves. Do it now. Select all follicles and do Hair=>Set Rest Positions=>from Start. But why does Hair is jumping again? We changed Hair Clump Width, collisions are sensitive to this attribute. It is really not good. Because we are going to adjust Hair Clump Width many times for rendering, but our dynamic styling will be destroyed by this.

Fortunately it is additional Collision Width Offset attribute which can be used to compensate changes in Hair Clump Width. Go to Attribute Editor for hairSystem1 and set simple expression for Collision Width Offset

hairSystemShape1.collideWidthOffset=0.35-hairSystemShape1.clumpWidth

This will keep effective collision distance almost independent on Hair Clump Width. You can change Hair Clump Width during animation and see minimal changes in the shape of Hair. Now it is possible to adjust Hair Clump Width without destroying simulation. Set Hair Clump Width to 0.4. Note. You can add also Hair Width compensation in this expression. File is saved as 8_headDuplicatedStartCurves.ma

XI. Increasing density


We created very low-resolution grid for initial Hair setup for better interactive performance. We can make it denser with painting passive follicles between existing ones. Select head then take Paint Hair Tool. Set Paint Mode=Create Passive Follicles. Double density values for painting: Follicle Density U=80, Follicle Density V=40. Paint over the surface. Do not take care of being inside Hair area. We will delete unnecessary follicles later with the script. (You can even flood surface with passive follicles, if you processor allows you to do that). Select hairSystem1 and execute baldness script again.
string $texture = "file1"; // converting selection to follicles convertHairSelection "follicles"; // list of follicles string $list[] = `ls -sl`; string $it; // for each follicle for ($it in $list) { // get UV-position float $u = `getAttr ($it+".parameterU")`; float $v = `getAttr ($it+".parameterV")`; // get color at point on surface under follicle float $col[] = `colorAtPoint -o RGB -u $u -v $v

file1`;

// delete follicle and its curve if red channel is white if($col[0]>0.5) delete (`listConnections -t "nurbsCurve" $it`) $it (`listTransforms $it`); }

Take a look for strange spacing between follicles. As mentioned above painting is performed on 101x101 grid. Positions of follicles painted with different U/V density values can differ from each other. Note. To guarantee coincidence of follicle positions in our example you can set
optionVar -intValue createHairMaxDensity 81;

if you not going to paint with more then 80x80 grid. You can also use 161 value, but this will slow down painting. And you must do it before first painting. If you change createHairMaxDensity between paintings you can get error with creating follicles. Render image (Hair Per Clump=20; Sub Segments=1; Clump Width=0.4).

Set Display Quality to 10 or hide strokes from view. To increase density exactly on the border of Hair area you can use some tricks.

XII. Density tricks


Most direct way is to double Follicle Density V to 80 and paint passive follicle only near the border.

More intelligent method is based on drawing border curve and land passive follicles to the closest points on surface. For example you can sample this curve with 40 steps and create 40 follicles closest to curves samples. More fake way is to render Hair border area with pretty large hair per clump value and then use this image as patch-texture under Hair. (Use perspective projection and converting to solid texture).

You can use baldness-texture as a mask for this image.

Adding some noise especially near the base can help to make fake density. Shadowing provides effects of extra volume and density. File saves as 9_headPassiveFill.ma

XIII. Shadowing
Set Clump Width=0.25 and Hair Width = 0.005 to male Hair more intelligent. Set Hair Per Clump=50. Go to Shading section. Set Specular Color about 0.5 and make hard specular: Specular Power=10. Select directionalLight1 and turn on Use Dmap Shadows. Paint Effects strokes are not surfaces and you can not use Use Mid Dist Dmap option for them. Turn it off. To get good shadows from thin Hair we need to use high shadow map resolution: Dmap Resolution=2048. Do not use black Shadow Color, make dark grey. Render it.

See shadows artifacts on surface. We need to set shadow offset from surfaces in case of not using Mid Dist Dmap. Set Dmap Bias=0.1.

Add blur to shadows: Dmap Filter Size=5.

Note. It should be at least one surface casting shadows inside light area. You can not shadow the Hair without shadowing a piece of geometry for given light. Look at strange light border at the middle of Hair. We need to adjust shadows map focus manually.

Select directionalLight1 and turn off Dmap Auto Focus. Set Dmap Width Focus=35 to define the area for shadow generation. For making better look of Hair tips the Thining attribute is very useful. Set it to 0.5.

Also by default Hair Clumps are thinner close to tips. But in case of dry and clean Hair it is better to edit Clump Width Scale to make clumps wider.

Do not forget to set high anti-aliasing quality for Hair. Open Render Global. Go to Maya Software tab open section Paint Effects Rendering Options. Turn on Oversample and Oversample Post Filter.

Render it.

Scene saved as 9a_headShadowed.ma You can add curl or noise displacements to Hair to get more dirty look.

XIV. Some tricks


Cut Hair
If you want to make some extreme cuts to make sharp edges you can use following method. Go to Side view and create simple curve.

Before making cut you need to be sure that ALL follicles have start curves (some passive follicles may have not). Go to first frame and make Set Start Position=>From Current for all follicles. Select all start curves (Convert Selection=>to Start Curves) then select created curve. Open Option Box for Edit Curves=>Cut Curves. Set Find Intersections=In 2D and 3D and Cut=Using Last Curve.

Make cut and delete all ends (Use Outlines for easy selecting cuts).

Swith to current positions and play animation. If the Hair starts to lengthen select all follicles and set Rest Pose=Same as Start in Channel Box. It will fix the problem.

Do not forget to check Thinning attribute in that case.

Attribute maps
We already used baldness texture for deleting unnecessary follicles. This scripting method can be used for modifying almost any follicles attributes according to textures. Moreover if you have some textures used for Fur Attribute Maps you can reuse them for Hair. For example if you have Color Map texture you can sample color value using UV from follicle and assign this color to follicle clump. Create or load any texture (Create ramp1 for this example). Select hairSystem, then go to Script Editor and run the following script.
string $texture = "ramp1"; // converting selection to follicles convertHairSelection "follicles"; // list of follicles string $list[] = `ls -sl`; string $it; // for each follicle for ($it in $list) { // get UV-position float $u = `getAttr ($it+".parameterU")`; float $v = `getAttr ($it+".parameterV")`; // get color at point on surface under follicle float $col[] = `colorAtPoint -o RGB -u $u -v $v $texture `; // set color setAttr ($it+".color") -type double3 ($col[0]) ($col[1]) ($col[2]); // set full blend from clump setAttr ($it+".colorBlend") 1;

You can use this method for mapping follicles with textures or making more manipulations according to color or alpha values from maps.

Close-ups
If you need to be close to Hair border you may need extra follicles to make dense hence of follicles to cover the gaps between existing follicles. You can draw border curve and land passive follicles to the closest points on surface. Of course it needs some scripting.

Load the file 9d_headCloseUp.ma or create curve near the Hair border. Select borderCurve AND head surface then run script
passiveFolliclesFromCurve

Set Number of follicles=100 and create passive follicles from selected curve. Follicles are created on the surface at positions closest to curve samples.

Multistreaks also can help with close-ups.

Tweaking cached systems


If sometimes you want to tweak Hair positions after simulating and caching there is a way to use two Hair systems and blendshape hack. First Hair system should be used only for dynamic simulations and should use nurbs curves as output. Second system will be used only for visualization and can have pfx output. This second system can have Simulation Method=Static, therefore current positions will always follow start curves. Trick is to use current curves from first system as target blend shapes for second system start curves, used as base blend shapes. It is the question of accurate selecting. Open 9e_headCached.ma file. If cache is lost recache Hair system. There are some ways to duplicate Hair system. You can duplicate start curves and make them dynamic or use landCurves.mel script to land duplicates to the same surface. Or you can reimport Hair system into the same scene to have two identical Hair systems. We will use simplest way. Select hairSystem1 and convert selection to start curves. Duplicate selected curves with default options. Unparent them (Edit=>Parent). Just in case. Make them dynamic: Hair=>Make Selected Curves Dynamic Select hairSystem2OutputCurves group and delete it, to remove nurbs output from second Hair system. Select hairSystem2 and assign pfxHair node: Hair=>Assign Paint Effects Brush to Hair. Check the visibility of strokes in camera view. For hairSystem2 set Simulation Method=Static to freeze current positions of second Hair system. Now be careful. Select hairSystem2 and convert selection to start curves. It makes them visible not only in camera view but also at Outliner. Select hairSystem1 and set Hair=>Display=>Current Position. It makes nurbs curves for first Hair system visible not only in camera view but also at Outliner. Select group hairSystem1OutputCurves (Group, not curves themselves). Add hairSystem2Follicles group to selection.

Open Option Box for Create BlendShape command and set Origin=World. Create blend shapes. MAYA will be smart enough to parse groups into individual curves and to make proper blending. Now you can hide hairSystem1Follicles and hairSystem1OutputCurves groups to make first Hair system invisible. Select blendshape node (or select any start curve from second Hair system) and change Weight attribute to 1. Look at pfx-shapes blending. You can do some interesting effects with this trick. One can animate blendshaping and force or decrease simulating. Values more than 1 for blend weight can be used for exaggerate simulation.

You can also apply any deformers or tweaks to the start curves of second Hair system. This allows you to make additional manual styling after simulating and even caching.

Start curves of second system define shape of Hair. Shading is defined by hairSystem2 attributes. But dynamic simulation inherited from first Hair system. BlendShape node is the connection between to Hair systems.

Flying Hair
Similar method can be used to make Hair fly from one object to another or to any destination. Open 9e_headTwoHeads.ma file. It contains two similar Hair systems (I just imported scene to itself with no name spacing, it is important). Again, second Hair system is Static and used only for visualization. First one has simulated and cached animation on it (but it is not necessary to cache in this case). The idea is to take start curves from second Hair system, make them soft and then use current curves of first Hair system as goals for these particles. First make start curves soft. Select second__hairSystem1 and convert selection to start curves. Run Soft/Rigid Bodies=>Make Soft Body (Duplicate, Make Original Soft; Hide NonSoft=On; Make Non-Soft a Goal, Weight=0).

New soft body curves appear in Outliner as second__curves*.

It makes easier to select them later. Now it is necessary to make current curves from first Hair system a goals for particles. One by one. Two lines of scripting can help. As long as all soft curves are selected go to Script Editor and run the command $soft=`ls sl`; Then select all current curves from first Hair system: open hairSystem1OutputCurves group and select all children. Go to Script Editor and run the command $goal=`ls sl`; Then run goal command for lists for ($i=0; $i<size($soft); $i++) goal -w 0.5 -utr 0 -g $goal[$i] $soft[$i]; Play animation.

Hide hairSystem1Follicles and hairSystem1OutputCurves groups to remove first Hair system output. You can manage you particles to fly more sophisticated way, using you particle experience. For easy selecting all particle objects in this scene you can you select "*Particle"; command or you can select all soft body curves from Outliner then press down arrow on keyboard and then right arrow key. Once particle are selected use Channel Box to edit attributes or use following commands to create or edit particle expressions for all soft bodies. $soft=`ls -sl`; for ($i=0; $i<size($soft); $i++) dynExpression -s "goalPP = rand(.5, 1.4);" -rbd $soft[$i]; You can animate goal weights of all particles to push them toward new goal or return them back to original positions. To make them fly like snakes use following command for selected particle objects $soft=`ls -sl`; for ($i=0; $i<size($soft); $i++) dynExpression -s "goalPP = 1.-0.3*id/count;" -rbd $soft[$i]; You can even collide particles with head surface. At the end of animation flying curves move with the rest of simulated dynamics for first Hair system. And you can merge flying animation with real Hair dynamics.

XV. Hardcore tricks


Particle growing
There is one simple problem. When you create Hair system legally start curves are straight. But sometimes one may want to create Hair system already shaped. As long as Hair is Particles why dont we use particles to grow initial shape of Hair? Create point emitter. Go to frame 10 and set Rate=100 and set key on it. Go to frame 11 and set Rate=0 and set key on it. We are going to convert particle trajectories to curves. Make Creation Expression:
vector $p = position; curve -d 1 -p ($p.x) ($p.y) ($p.z) -n ("traj"+int(id));

This will create one-point curve for each particle on creation . Add Runtime Expression
vector $p = position; curve -p ($p.x) ($p.y) ($p.z) -a ("traj"+int(id));

This will add new point to already created trajectories for each particle at every frame. To remove all trajectories at first frame create simple (not particle) expression: if(frame==1) delete traj*; Play animation. Look at growing paths.

Be sure that initial animation frame is 1. Otherwise change last expression. Be also sure that no other objects in scene are or will be named with traj* prefix. It is also better to set Undo Queue Size to 50 or to other finite number to prevent memory leaks. If there will be a lot of particles playback speed will be slow down by curves updating. We can change expressions to draw particles not for every particle but only for some.

Good idea is to add two attributes to particle object and use them in expression. Add two attributes to particle1: everyId and everyFrame (integer, default=1).

Change expressions to draw curves only for Nth particle and only for Nth frame. Creation expression:
if(id%particle1.everyId==0) { vector $p = particleShape1.position;

curve -d 1 -p ($p.x) ($p.y) ($p.z) -n ("traj"+int(id)); }

Runtime expression:
if(id%particle1.everyId==0 && frame%particle1.everyFrame==0) { vector $p = particleShape1.position;

curve -p ($p.x) ($p.y) ($p.z) -a ("traj"+int(id)); }

Play with added attributes and see the result. These three expressions allow to grow curves from surfaces and control the shape of curves with dynamic fields, collisions, goal etc. We can add surface emission to the head model. We also can use textures to control rate and areas of emission.

Open 9x2_ParticleHair.ma.

There is nurbs-surface emitting particles. Particles have expressions to build trajectories.

There are two radial fields driving particles. You can also use textures to emit particles from specific areas. Play animation. You can add turbulence or other dynamic controls to change particle motion. Select hairParticles. Set LOD_P=1 to draw every curve from particles path. You can select emitter and set tessellationFactor=2000 for geoConnector1 node to improve randomization across emitting surface. Play 150 frames of animation. Delete expression1 to save life of curves. (use delete expression1 command for example). You can also export created curves into separate file. Delete particles, radial fields and emitter to clear scene. Select all curves from groupTrj group. Make them dynamic: Hair=>Make Selected Curve Dynamic. For created Hair system set Simulation Method=Static. If you want add dynamics to the curves do not forget to release curve tips and make them stiff enough. Add transform (or other) constraint to the root of bunch to keep Hair together. Delete hairSystem1OutputCurves group to save memory. Select hairSystem and add pfx brush to it for visualization. Set Hair per Clump=25; Clump Width=0.2; Hair Width=0.05, Sub Segments=1. Adjust shading attributes and render.

Surface styling
Looking on some hair styles you can notice that in makes sense use curve from surfaces because Hair seems belonging (or touching) to invisible surfaces. One approach is making surface(s), then duplicate isoparms or other surface curves and make these curves dynamic. As long as history will be on start Hair curves can be edited with surface deformation. But looking at typical Hair you can imagine that curves grow from one (source) surface and are attracted (or aligned) to another surface (target). To realize this approach small plugin was written. Go to Plugin Manager and load hairStyler plugin. Do not forget to put AEhairStylerTemplate.mel to your script folder.

Open 9x3_SurfaceHairStart.ma There are two additional surfaces: Source and Target. Hair is to be grown from Source and attracted to Tartget.

This plugin provides special node (hairStyler) representing Hair grid. Attributes of this node allow to control direction of growth and attraction. Select Source and Target surfaces. Press down arrow to select their shapes. Open Connection Editor and load selection to left side. Go to Script Editor and run command: createNode hairStyler Load created hairStyler1 object to right side of Connection Editor. Connect WorldSpace attribute of SourceShape to SourceSurface of hairStyler1.

Connect WorldSpace attribute of TargetShape to TargetSurface of hairStyler1.

Select transform1 at Outliner and go Attribute Editor. Look at attributes of new node and Hair grid on the screen.

At hairStyler1 tab turn on Swap TargetUV checkbox to eliminate Hair crossing due to different surface directions.

Set Inclination attributes to adjust direction of growth.

Setting Target Inclination N to zero means full aligning of Hair ends to target surface. U and V Inclinations control directions along surface. Inclination N controls direction perpendicular to surface.

You can also control shape along Hair with Tension attribute.

To get symmetrical shape you can select Styler object and duplicate it as Instance with ScaleX=-1.

Play with attributes of hairStyler node and shape of target surface. For example scale down target surface.

Then select lower row of control points and move it out.

You can use baldness maps with growMap attribute (use full path to iff-texture file).

Set U and V capacity for hairStyler1 node to 10. To convert grid curves to normal ones use simple script:
int $i; int $count = `getAttr hairStyler1.uCapacity`*`getAttr hairStyler1.uCapacity`; string $name = "gridCurves"; for($i=0; $i<$count; $i++) { createNode -s "nurbsCurve" -n ($name+$i); connectAttr -f hairStyler1.curves[$i] (($name+$i+".create")); if( `getAttr ($name+$i+".spans")` < 1) delete (listTransforms($name+$i)); }

Hide grid curves (Show=>Locators) and look at created Nurbs curves. You can make them dynamics or use landCurves script to connect them to head model. Then you can use Hair dynamics for further adjustments of initially styled Hair. Look at 9x3_SurfaceHairTemplate.ma for more example.

Hair visualization
By now there are many ways to visualize Hair. As long as Hair is very complex and heavy object Paint Effects Renderer is fastest option. Also you can use Mental Ray for Maya to render Hair. Version 7 has Hair support including all raytracing features.

There are also interesting plugins for Hair and Pfx rendering with Mental Ray. They are called MR_hairSystem and MR_pfxBrush and provides geometry shader for Mental Ray (www.provide3d.com).

Renderman for Maya support MAYA Hair seamlessly. You need only set Pixel Samples values high enough to get good antialiasing quality for thin Hair. Nice Deep Shadows feature provides excellent shading.

Another option is Fur Renderer. In Maya 7 you can use Hair curves as attractors for Fur system. Therefore you can make Fur as long as you need and then apply your Hair styling as attractor set for Fur. If you have libraries or presets for Fur looks they can be reused, including attribute maps, shading attributes, density values etc.

Above these superphotohyperrealistic methods of rendering there is an interesting way to visualize Hair with non-photorealistic way. Instead if Mental Ray or Prman render engines one can use Painter software as NPR render engine. Painter has similar concept as Paint Effects: strokes and brushes. It also has scripting features which allow to read strokes data from text file. Semi-simple MEL script can be written to export Hair segments data from MAYA to text file. pfxStrokes command is an easy way to do it with minimal efforts. Open 9x4_headPainter.ma file. Select pfxHair1 node and run hairToPainter script. Select file for output data and wait for Done message. Open Painter application. Create new 640x480 image. Import script from text file created by Maya. On Scripts pulldown menu select Playback Script

Push Import button and select text file with data from Maya.

Give it name, for example hair.

Push Done button.

Select hair name at the list of available scripts.

Now select any brush, for example Artist=>Impressionist.

Set Opacity=10%, Size=1.0, Min Size=0.

Play hair script.

This technique can be extended to render not only Hair objects but any curves from MAYA. One need only make selected curves dynamic and assign them brush. Created pfxHair node can be exported with hairToPainter script and rendered with Painter.

S-ar putea să vă placă și