[sectionBegin," Stencils ",0,"ZScript Primer (Press to expand this section)",
	[varDef,zbPrimerTempOpenSN][varDef,zbInitDocSavedSN,0][varDef,zbInitSavedDocSN,""]
	[iPress,7442]
	[if,(zbPrimerTempOpenSN),
		[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,zbInitSavedDocSN,[fileNameGetLastUsed]]
					[varSet,zbInitDocSavedSN,1]
				] // end if (user saves)
			] // end if (save enabled)
			[Note,"One moment please...",,2]
			[iKeyPress,13,[iReset]]
			[varSet,zbPrimerTempOpenSN,1]
		, // else (user won't reset)
			[iUnPress,0][exit]
		] // end if (wanna reset?)
	] // end if PrimerTemp
	[Note,"This primer describes the Stencil Palette, which provides ways to mask all ZBrush painting and sculpting actions with a selected stencil.",stencil:,-1]
	[Note,"\n\n\C909090(Click to continue)\Cc0c0c0",,0]
] // end sectionBegin
[pd][paintBackSliver,2,40,40,40][pd]
[pd]
The [buttonFind,stencil:,"Stencil palette"] provides ways to mask all ZBrush painting and sculpting actions with a selected stencil. Any image can be used as a stencil; as you'll see in this primer, images are assigned by converting them to [buttonFind,alpha:,Alphas] first.

For comparison's sake, begin by painting a simple image with no stencil applied. [iButton,"Click here","Paint a simple image",
	[routineCall,zbPrimerStencilInit]
	[routineCall,zbPrimerStencilGlaze]
] // end iButton
to paint this image. FYI, you're looking at a deformed sphere drawn on the canvas, with paint applied using the [buttonFind,tool:bumpbrush,"Bump Brush"].

Now look at the same image with the default stencil applied. Clicking [buttonFind,stencil:stencilon,"Stencil On"] displays the default french curve [iButton,"show me","Show the default stencil",
	[iKeyPress,13,[iReset,6]]
	[iPress,stencil:stencilon]
	[iPress,stencil:elv]
	[iUnpress,stencil:wrapmode]
]. // end iButton
[pd]
Watch what happens when you paint the same simple image as before [iButton,"show me","Paint with the stencil on",
	[routineCall,zbPrimerStencilInit]
	[iPress,stencil:stencilon][iUnPress,stencil:wrapmode][iPress,stencil:show]
	[routineCall,zbPrimerStencilGlaze]
	[iUnPress,stencil:show]
]: // end iButton
the paint is not applied inside the french curve. You can also [buttonFind,stencil:inverse,"invert"] the stencil so the paint is only applied inside the french curve, and the rest of the canvas is masked from painting [iButton,"show me","Paint with the stencil on",
	[routineCall,zbPrimerStencilInit]
	[iPress,stencil:stencilon][iUnpress,stencil:wrapmode][iPress,stencil:show]
	[iPress,stencil:inverse]
	[routineCall,zbPrimerStencilGlaze]
	[iPress,stencil:inverse]
	[iUnPress,stencil:show]
]. // end iButton
[pd]
You can also transform the stencil in numerous ways by using a unique "coin controller". You can display the coin controller by pressing the spacebar [iButton,"show me","Briefly show the coin controller",
	[iUnPress,stencil:stencilon]
	[iPress,layer:modifiers:clear]
	[iPress,stencil:stencilon]
	[iKeyPress," ",[delay,2],320,240]
]. // end iButton
The coin controller is centered wherever your cursor is located when you press the spacebar.

Remember that the spacebar is also used to pan the canvas inside the document window. After pressing the spacebar, a click-drag anywhere on the coin controller transforms the stencil; a click-drag anywhere not on the coin controller pans the canvas.

Any [buttonFind,28701,"Alpha"] can be used as a stencil by clicking the [buttonFind,alpha:makestencil,"Make Stencil"] button [iButton,"show me","Make a stencil out of an alpha",
	[iUnPress,stencil:stencilon]
	[iSet,alpha:itemInfo,23]
	[iSet,alpha:alphablur,8]
	[iPress,alpha:makestencil]
	[iPress,stencil:vert]
	[iPress,stencil:elv]
	[iPress,stencil:elv]
	[iPress,stencil:show]
]. // end iButton
The stencil is sensitive to the [buttonFind,alpha:alphablur,"Alpha Blur"] and [buttonFind,alpha:alphanoise,"Alpha Noise"] sliders; you should adjust these before applying an Alpha as a stencil.

Notice how the stencil is displayed as lines of varying thicknesses. This is called an [buttonFind,stencil:elv,"Elevation"] view, and is similar to cartographers' elevation maps showing variations in altitude. You can get a better idea of how the stencil is applied by turning off Elevation view [iButton,"show me","Briefly turn off Elevation View",
	[iUnPress,stencil:elv]
	[delay,2]
	[iPress,stencil:elv]
]. // end iButton
If the white lines are difficult to see while working, you can change the color by clicking any of the [buttonFind,stencil:red,"R"], [buttonFind,stencil:green,"G"] and [buttonFind,stencil:blue,"B"] buttons. And, of course, you can [buttonFind,stencil:show,"Hide"] the stencil altogether while it is still turned on.

Any [buttonFind,28601,"Texture"] can be used as a stencil by converting it to an Alpha first. Click the [buttonFind,texture:makealpha,"Make Alpha"] button to convert it [iButton,"show me","Convert a texture to a stencil",
	[iSet,texture:itemInfo,32]
	[iPress,texture:makealpha]
	[iSet,alpha:alphablur,0]
	[iSet,alpha:alphanoise,0]
	[iPress,alpha:makestencil]
	[iPress,stencil:stencilon]
	[iPress,stencil:stretch]
	[iPress,stencil:inverse]
	[iPress,stencil:show]
]. // end iButton
[pd]
One of the most powerful features of the Stencil is [buttonFind,stencil:wrapmode,"Wrap Mode"]. When Wrap Mode is activated, the stencil is no longer like a rigid cardboard cutout, but like a fabric cutout that wraps onto the contours of your painting [iButton,"show me","Show how a stencil works in Wrap Mode",
	[routineCall,zbPrimerStencilInit]
	[iPress,stencil:stencilon]
	[iPress,stencil:wrapmode]
	[iPress,stencil:horiz]
	[routineCall,zbPrimerStencilGlaze]
	[iUnPress,stencil:stencilon]
]. // end iButton
The coin controller still transforms it, and the stencil wraps after each transformation.

[routineDef,zbPrimerStencilInit,
	[iUnPress,stencil:stencilOn]
	[iPress,layer:modifiers:clear]
	[ISet,tool:itemInfo,8]
	[iSet,tool:modifiers:initialize:hdivide,9]
	[iSet,tool:modifiers:initialize:vdivide,5]
	[iUnPress,tool:modifiers:sh]
	[iUnPress,tool:modifiers:sv]
	[iColorSet,255,80,80]
	[iSet,material:itemInfo,2]
	[iSet,texture:itemInfo,0]
	[CanvasClick,320,240,320,255]
	[TransformSet,320,240,0,180,180,180,0,0,0]
] // end routine

[routineDef,zbprimerStencilGlaze,
	[IColorSet,255,225,255]
	[IPress,TOOL:BumpBrush]
	[iSet,draw:rgbIntensity,100][iSet,draw:zintensity,80]
	[iSet,alpha:itemInfo,1]
	[CanvasStroke,(ZObjStrokeV02n155=
YH136VD4p1H133VD4p98H132VD4p9BH12FVD4p9EH12BVD6pA1H128VD7pA4H123VDCpA7H122VDEpA9H120VE2pACH11FVE6pAEH120VEEpB0H121VF3pB3H124VF7pB6H128VFEpB9H130V102pBDH13BV104pC2H14AV102pC6H150VFFpCAH15AVF6pCEH15EVEEpD0H160VE4pD4H15FVDCpD7H15CVD4pDAH158VCDpDBH153VC7pDDH14DVC2pDEH146VC0pDFXH13BVC0YH12FVC1pE0XH125VC1YH11AVC4pDFH110VCBpDEH103VD6pDDHFCVE0pDCHF8VEBpDBHF6VFApDCHF8V105pDDXHFEV111YH109V11CpDFH114V124pE2H120V129pE5H131V12CpE8H140V12CpEBH14DV12BpEDH15DV122pEFH16AV11ApF1H178V10DpF2H180VFEpF4H181VEDpF7H181VD7pF9H17FVC8pFBH17BVBDpFDXH175VB1YH16DVAApFEH163VA4pFFXH159VA1YH150V9FMXH146V9FH13BV9FH128V9FYH112VA7pFFH109VB0pFDH100VBBpFCHF6VC8pFBHF2VD3pFAXHEAVE3YHE7VECpF9XHE4VFBYHE3V107pF8XHE8V119YHF2V127pF9H107V136pF8H120V144pF7XH135V14CH14DV155H162V157YH16FV155pF8H185V149pF9H192V13DpFAH19EV12ApFBH1A7V114pFCH1ADVFEpFDH1ADVF0pFEXH1AAVDBYH1A4VCApFFXH19EVBBYH195VA9MXH18CV9EH17EV8FH170V87H161V80H14EV7EH144V7DH134V7DH128V7FH121V80H10FV88H100V91HECVA2HDCVB3HCEVC5YHC7VD4pFFXHBFVEBYHBAV101pFEHBAV110pFDXHBEV124YHC9V138pFCHD5V145pFBXHE5V154
HFEV161H10FV168YH122V16FpFCXH133V174H141V177YH152V17ApFDH161V178pFEXH16EV174YH17EV16ApFFXH195V15AYH1A3V14DMXH1B3V13AH1C4V124H1C9V119H1CEV108H1D3VF4H1D4VE5H1D0VD1H1CBVBEH1C5VABH1BDV98H1B4V8DH1A7V83H197V79H18BV73H176V6CH163V67H151V62H144V5FH135V5DH12CV5EH125V5FH116V62H106V6AHF6V74HECV7DHE2V87HD8V93HC9VA4HC3VAFHBDVC0HB9VD6HB0VEFHABV102YHA9V126pEFHAAV131p78)]
] // end routine


[iButton," Return to your original (saved) document ","Return to your original file",
	[fileNameSetNext,[var,zbInitSavedDocSN]]
	[if,[isEnabled,document:save],
		[iKeyPress,'N',[iPress,document:open]]
	, // else nothing to save
		[iPress,document:open]
	] // end if
	[varSet,zbInitSavedDocSN,""]
	[varSet,zbInitDocSavedSN,0]
	[varSet,zbPrimerTempOpenSN,0]
] // end iButton
[pd][pd][paintBackSliver,2,40,40,40][pd][sectionEnd] // primer
