[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,( 
 )]]
	[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
