[sectionBegin," Masking ",0,"ZScript Primer (Press to expand this section)",
	[varDef,zbPrimerTempOpenMK][varDef,zbInitDocSavedMK,0][varDef,zbInitSavedDocMK,""]
	[iPress,7442]
	[if,(zbPrimerTempOpenMK),
		[iKeyPress,'N',[iPress,document:newdocument]]
	, // else
		[if,[messageYesNo,"OK to clear all customized tools, lights and materials?","DOCUMENT MUST BE CLEARED BEFORE PROCEEDING..."],
			[if,[isEnabled,document:save],
				[if,[messageYesno,"Would you like to save this document before proceeding?","Document has not been saved."],
					[iPress,document:saveas]
					[varSet,zbInitSavedDocMK,[fileNameGetLastUsed]]
					[varSet,zbInitDocSavedMK,1]
				] // end if (user saves)
			] // end if (save enabled)
			[Note,"One moment please...",,2]
			[iKeyPress,13,[iReset]]
			[varSet,zbPrimerTempOpenMK,1]
		, // else (user won't reset)
			[iUnPress,0][exit]
		] // end if (wanna reset?)
	] // end if PrimerTemp
	[iPress,tool:sphere3d]
	[Note,"This primer describes the process of Masking: an innovative feature which enables you to create unique effects when sculpting 3D objects.",tool:modifiers:selection:,-1]
	[Note,"\n\n\C909090(Click to continue)\Cc0c0c0",,0]
] // end sectionBegin
[pd][paintBackSliver,2,40,40,40][pd]
Masking is an innovative feature of ZBrush which enables you to create unique effects when sculpting 3D objects. 

[iButton,"Click here","See an example of masking",
	[routineCall,zbPrimerMaskInit]
	[iSet,tool:modifiers:selection:sel,8]
	[iSet,tool:modifiers:selection:skp,0]
	[iPress,tool:modifiers:selection:maskall]
	[iPress,tool:modifiers:selection:row]
	
] // end iButton
to draw a sphere and apply a simple mask. Notice the dark bands -- these are masked areas, and any editing using the [iButton,"sculpting tools","Show the sculpting tools",
	[iShow,transform:drawpointer,1]
	[iShow,transform:move,1]
	[iShow,transform:scale,1]
] // end iButton
or [iButton,"deformation sliders","Show the Deformation Sliders",
	[iShow,tool:modifiers:deformation:,1]
] // end iButton
will be ignored in these areas. The light, un-masked areas are said to be "selected".

[IButton,"Click here","See a simple transformation",
	[iSet,tool:modifiers:deformation:inflat,45]
] // end iButton
to see how a simple deformation (the [buttonFind,tool:modifiers:deformation:inflat,"Inflate slider"]) acts on this masked object. Notice that the masked areas are "protected" from any deformation.

Masks can be more than simply black-and-white patterns. If a mask is applied over an area at, say, 50%, any deformation will act on that area with 50% intensity.

Masking requires that you are working with a 3D object in [buttonFind,transform:editobject,"Edit Mode"].

The modifiers for applied masks are in the [buttonFind,tool:modifiers:selection:,Selection] sub-palette of the Tools palette. Using these modifiers you can [buttonFind,tool:modifiers:selection:inverseselection,Invert] the mask, so what is currently masked becomes selected and vice-versa; [buttonFind,tool:modifiers:selection:maskall,"Mask All"], [buttonFind,tool:modifiers:selection:clear,Clear] the mask entirely, set the [buttonFind,tool:modifiers:selection:intensityvalue,"Mask Intensity"], [buttonFind,tool:modifiers:selection:blend,"Blend Amount"] which determines how strongly a new mask "mixes" with an old one, and do numerous other things discussed below.

There are several ways you can apply masks to an object: [FontSetSizeMedium]([PenMove,4])[PenMove,-15,6][FontSetSizeSmall]1[PenMove,5,-6][FontSetSizeMedium] painting it directly onto the surface, [FontSetSizeMedium]([PenMove,4])[PenMove,-15,6][FontSetSizeSmall]2[PenMove,5,-6][FontSetSizeMedium] applying an [buttonFind,alpha:,Alpha] onto the entire object, [FontSetSizeMedium]([PenMove,4])[PenMove,-15,6][FontSetSizeSmall]3[PenMove,5,-6][FontSetSizeMedium] applying an Alpha onto a selected portion of the object, [FontSetSizeMedium]([PenMove,4])[PenMove,-15,6][FontSetSizeSmall]4[PenMove,5,-6][FontSetSizeMedium] using color attributes from an applied [buttonFind,texture:,Texture] as a mask, and [FontSetSizeMedium]([PenMove,4])[PenMove,-15,6][FontSetSizeSmall]5[PenMove,5,-6][FontSetSizeMedium] masking rows and columns mathematically.

1. Painting directly: Using the [buttonFind,transform:drawpointer,"draw pointer"], you can hold the 'Ctrl' key while dragging on the surface of the object to paint the mask [iButton,"show me","Show an example of painting a mask directly",
	[routineCall,zbPrimerMaskInit]
	[transformSet,320,240,-300,150,150,150,90,0,0]
	[iSet,draw:drawSize,24]
	[iSet,tool:modifiers:selection:intensityvalue,100]
	[iSet,tool:modifiers:selection:blend,100]
	//[varSet,zbPrimerMaskTabletEnabled,[iGet,tablet:usetablet]] // 1.22f bug workaround
	//[varSet,zbPrimerShowActEnabled,[iGet,zscript:showactions]]
	//[iUnPress,zscript:showactions]
	//[iUnPress,tablet:usetablet]
	[iKeyPress,CTRL,[canvasStroke,(ZObjStrokeV01n190x3=H388V188P0H388V188P1H360V162P1H360V161P1H359V161P1H357V160P1H354V159P1H353V158P1H353V157P1H351V156P1H349V155P1H345V153P1H344V152P1H343V151P1H342V150P1H340V150P1H339V150P1H339V149P1H337V149P1H336V148P1H334V148P1H332V148P1H330V147P1H325V146P1H323V146P1H319V145P1H317V145P1H314V145P1H311V145P1H308V145P1H304V145P1H302V145P1H298V145P1H295V145P1H292V146P1H286V146P1H283V149P1H281V149P1H279V150P1H278V151P1H276V151P1H273V153P1H271V154P1H269V155P1H267V158P1H265V159P1H264V161P1H262V163P1H261V164P1H260V166P1H258V167P1H257V170P1H254V171P1H253V172P1H252V174P1H251V175P1H249V176P1H248V178P1H246V180P1H244V182P1H243V184P1H242V186P1H241V187P1H240V189P1H239V191P1H237V193P1H237V196P1H235V198P1H235V201P1H232V203P1H232V206P1H231V212P1H230V214P1H230V217P1H230V219P1H230V221P1H230V225P1H230V227P1H230V230P1H230V232P1H230V234P1H230V236P1H230V238P1H230V241P1H230V244P1H230V247P1H231V250P1H231V252P1H232V255P1H232V258P1H234V262P1H235V264P1H235V266P1H235V268P1H236V269P1H237V272P1H237V275P1H239V277P1H240V281P1H242V284P1H244V287P1
H246V289P1H248V293P1H250V295P1H252V297P1H254V299P1H256V301P1H262V306P1H265V309P1H270V312P1H273V313P1H278V315P1H281V317P1H285V318P1H289V319P1H292V321P1H295V322P1H298V324P1H303V325P1H308V326P1H312V326P1H316V327P1H320V327P1H325V328P1H328V328P1H331V328P1H333V327P1H335V327P1H338V327P1H341V326P1H344V326P1H348V325P1H350V325P1H353V324P1H355V324P1H358V322P1H361V319P1H366V318P1H368V316P1H370V315P1H372V314P1H374V312P1H376V311P1H378V309P1H379V307P1H383V304P1H385V302P1H387V300P1H389V297P1H390V295P1H391V293P1H392V290P1H393V289P1H395V286P1H397V284P1H398V280P1H400V276P1H400V273P1H400V270P1H401V268P1H401V265P1H402V261P1H402V259P1H403V257P1H403V255P1H403V252P1H403V250P1H403V247P1H403V245P1H403V243P1H403V241P1H403V239P1H403V235P1H403V233P1H403V231P1H403V229P1H403V227P1H403V225P1H402V223P1H402V219P1H401V215P1H400V213P1H399V210P1H397V207P1H394V202P1H392V198P1H390V193P1H389V191P1H387V188P1H387V188P1)]]
	[iSet,tool:modifiers:deformation:inflat,35]
	//[if,zbPrimerMaskTabletEnabled,[iPress,tablet:useTablet]]
	//[if,zbPrimerShowActEnabled,[iPress,zscript:showactions]]
]. // end iButton
The intensity of the mask is determined by two sliders: [buttonFind,draw:rgbintensity,"RGB Intensity"] and [buttonFind,tool:modifiers:selection:intensityvalue,"Mask Intensity"]. You can change the softness of the Draw Pointer strokes, and add noise, by using the [buttonFind,transform:modifiers:,"Transform modifiers"].

2. Applying an Alpha to the entire object: This is done simply by pressing the [buttonFind,tool:modifiers:selection:fromalphaintensity,Alp] button with any Alpha chosen [iButton,"show me","Show an example of applying a mask from an alpha",
	[routineCall,zbPrimerMaskInit]
	[transformSet,320,240,-300,150,150,150,90,0,0]
	[iSet,alpha:itemInfo,7]
	[iSet,alpha:alphablur,0][iSet,alpha:alphanoise,0]
	[iPress,tool:modifiers:selection:fromAlphaIntensity]
	[iSet,tool:modifiers:deformation:inflat,59]
]. // end iButton
The applied alpha is sensitive to the [buttonFind,alpha:alphablur,"Alpha Blur"] and [buttonFind,alpha:alphanoise,"Alpha Noise"] sliders.

3. Applying an Alpha to a selected area: This is done with the [buttonFind,transform:move,Move] tool selected (while in Edit mode). Hold the 'Ctrl' key while dragging a rectangular area over some or all of the object [iButton,"show me","Show an example of applying an Alpha to a selected area",
	[routineCall,zbPrimerMaskInit]
	[transformSet,320,240,-300,150,150,150,90,0,0]
	[iSet,alpha:itemInfo,7]
	[iSet,alpha:alphablur,0][iSet,alpha:alphanoise,0]
	[iPress,transform:move]
	[iKeyPress,CTRL,[canvasClick,160,90,500,400]]
	[iSet,tool:modifiers:deformation:inflat,59]
]. // end iButton
The chosen Alpha is stretched to fit the dragged rectangle, and projected onto the area selected (that is, projected as if it were "beamed" onto the surface with a slide projector, distorting accordingly). Again, the applied alpha is sensitive to the [buttonFind,alpha:alphablur,"Alpha Blur"] and [buttonFind,alpha:alphanoise,"Alpha Noise"] sliders. When applied in this manner, the alpha is image-reversed -- dark portions become light (selected) and light portions become dark (masked). Also, the front and back portions of the 3D object are masked at the same time, as if the alpha extended all the way through it [iButton,"show me","Show the backside of this 3D object",
	[varSet,zbPrimerLoopIndex,0]
	[loop,10,
		[varAdd,zbPrimerLoopIndex,18]
		[transformSet,320,240,-300,150,150,150,90,0,zbPrimerLoopIndex]
		[delay,.15]
	] // end loop
]. // end iButton
[pd]
4. Using color attributes from an applied Texture: When a texture is chosen, you can apply attributes of the texture's colors as a mask. These attributes are [buttonFind,tool:modifiers:selection:int,Intensity] (darkness or brightness of colors), [buttonFind,tool:modifiers:selection:hue,Hue] (in the color spectrum, red-orange is fully masked, and violet-red is fully unmasked), and [buttonFind,tool:modifiers:selection:sat,Saturation] (the saturation of each color).

For example, [iButton,"click here","Show an example of applying Texture Hue as a mask",
	[routineCall,zbPrimerMaskInit]
	[transformSet,320,240,-300,150,150,150,0,0,0]
	[iSet,texture:itemInfo,41]
] // end iButton
to draw a sphere with a [buttonFind,28601,"spectrum texture"] applied. Pressing the [buttonFind,tool:modifiers:selection:hue,Hue] button converts hues (the red, orange, yellow, green, blue, violet spectrum) to corresponding mask values [iButton,"show me","Use Hue values as a mask",
	[iPress,tool:modifiers:selection:hue]
	[iSet,texture:itemInfo,0]
	[iSet,tool:modifiers:deformation:inflat,99]
]. // end iButton
[pd]
5. Masking rows and columns mathematically: This is probably the least-often used method of applying a mask, but it's sometimes useful. This method uses the [buttonFind,tool:modifiers:selection:row,Row], [buttonFind,tool:modifiers:selection:col,Column] and [buttonFind,tool:modifiers:selection:grd,Grid] buttons, and the [buttonFind,tool:modifiers:selection:selectcount,Select] and [buttonFind,tool:modifiers:selection:skipcount,Skip] sliders. In ZBrush, 3D tools are made up of many rectangles arranged in a grid, and row/column masking is a way of selectively masking rows and columns of these rectangles.

For example, [iButton,"click here","Show an example of row/column masking",
	[routineCall,zbPrimerMaskInit]
	[iSet,tool:modifiers:initialize:hdivide,24]
	[iSet,tool:modifiers:initialize:vdivide,24]
	[iUnPress,tool:modifiers:sh]
	[iUnPress,tool:modifiers:sv]
] // end iButton
to draw a sphere and turn off smoothing so you can see the rectangles more clearly. Suppose you wish to mask every fourth row of rectangles. To do this, press [buttonPress,tool:modifiers:selection:maskall,"Mask All"], set [buttonSet,tool:modifiers:selection:Sel,3,Select] to 3 (the number of rows to un-mask) and [buttonSet,tool:modifiers:selection:skp,1,Skip] to 1 (the number of rows to leave masked), and press [buttonPress,tool:modifiers:selection:row,Row]. You can selectively mask [buttonFind,tool:modifiers:selection:col,Columns] in the same manner, or create a checkerboard mask by pressing [buttonFind,tool:modifiers:selection:grd,Grid]. A value of 0 in the [buttonFind,tool:modifiers:selection:skp,Skip] slider causes the Skip value to be the same as the Select value.

Note: Imported 3D objects cannot be masked using row/column masking.

A bonus feature of masking is [buttonFind,tool:modifiers:selection:hidept,"Hide Points"]. Pressing this button makes any un-masked areas of the object transparent [iButton,"show me","Hide Unmasked",
	[iPress,tool:modifiers:selection:hidept]
	[iUnPress,tool:modifiers:selection:viewmask]
]. // end iButton
To restore hidden points, press [buttonFind,tool:modifiers:selection:showpt,"Show Points"].

[iButton," Return to your original (saved) document ","Return to your original file",
	[fileNameSetNext,zbInitSavedDocMK]
	[if,[isEnabled,document:save],
		[iKeyPress,'N',[iPress,document:open]]
	, // else nothing to save
		[iPress,document:open]
	] // end if
	[varSet,zbInitSavedDocMK,""]
	[varSet,zbInitDocSavedMK,0]
	[varSet,zbPrimerTempOpenMK,0]
] // end iButton

[routineDef,zbPrimerMaskInit,
	[iUnPress,transform:editobject]
	[iPress,transform:drawpointer]
	[iPress,layer:modifiers:clear]
	[iPress,tool:sphere3d]
	[iSet,material:itemInfo,6]
	[iSet,texture:itemInfo,0]
	[iColorSet,255,230,120]
	[canvasClick,320,240,320,250]
	[transformSet,320,240,-300,150,150,150,50,20,0]
	[iPress,transform:editobject]
] // end routine
[pd][pd][paintBackSliver,2,40,40,40][pd][sectionEnd] // end of Masking
