Author
|
Topic: ZScript Lesson I: IButtons and
Formatting |
davey •MODERATOR
Member # 6
|
posted January 14, 2002 01:14 PM
Welcome to ZScripts 101!
You're on your way to harnessing the awesome power of
ZScripts. In many ways, ZScripts resemble complex computer
programming languages -- but you don't have to be a programmer
to take advantage of them. All you need is ZBrush v1.23b or
later, a text editor, and an imagination.
Some notes about this ZScript lesson:
Perhaps you've opened some of the ZScripts included with
ZBrush, and become overwhelmed by the technological, codelike
nature of the ZScript commands. In these lessons I'm hoping to
de-mystify them -- if you finish today's lesson and you're
still as confused as ever, I haven't done my job.
I can appreciate that each of you has a different level of
computer experience; some of you are well familiar with other
computer codes and languages (such as HTML, JavaScript,
Commodore 64 Basic ). Others have only recently learned how to turn on
a computer. It's a challenging task, but I'll try to make
these lessons easy enough for novice users to follow, yet
instructive enough for advanced users.
Before following this lesson, you should:
have a pretty fair knowledge of how ZBrush
works
familiarize yourself with the basic structure of
ZScripts -- I highly recommend reading the Composition page of
the tutorial "Creating ZScript Tutorials".
You'll want to bookmark this link: ZScript Command Reference. It's got all the
ZScript commands categorized by function, with lots of helpful
notes and tips. Novice
Users: Don't feel you need to understand everything
you read in the ZScript Command Reference. For now, browse the
categories, so you get a good idea of what kinds of tasks are
possible in the ZScript command set. Advanced Users: If you've been
tinkering with your own ZScripts, or you're too impatient to
wade through this lesson, there's lots of useful information
in the ZScript Command Reference to help you write your own.
As needed, you can return to the Reference and browse through
the Index for tips on accomplishing various tasks.
In this lesson, you'll create the ZScript shown above.
Each button selects a color; if there is an active 3D object
in Edit mode, each button also creates a new texture filled
with that color. Then you'll learn some of the
display/formatting commands that give your ZScript some visual
appeal.
1) Examining the IButton
Command In this section you'll become familiar
with the IButton command, the real workhorse of any
ZScript. If you're already familiar with the IButton
command, you can skip to section 2.
First, examine the IButton command. The
IButton command can be given several pieces of
information (called arguments) separated by commas. Not all
arguments need to be typed; if they're missing, ZBrush assumes
each argument has a certain (default) value.
In this example, each argument is displayed with a
different color so you can tell them apart. Also, in this and
other examples in this lesson, each argument is placed on a
separate line, with some of the lines indented. Again, this is
just done to avoid confusion; you may choose to structure the
text in your ZScripts differently.
The reason ZBrush knows which argument is which is that
they're separated by commas. Here's a typical way you might
type the IButton command:
[IButton,"Select the SimpleBrush","This
button selects the Simple Brush",
[IPress,Tool:SimpleBrush] ] | This
button looks like this:
If you float your cursor over the button, the popup
appears:
... and if you click this button, the command
[IPress,Tool:SimpleBrush] is executed, meaning the
SimpleBrush is selected in the Tool palette.
But what about the last three arguments? You can leave them
out completely, and ZBrush assumes you want to have certain
default values assigned. If you're curious, here are the
default values:
Initially Disabled? = No. Button Width = A little wider
than the Button Text. Hotkey = no hotkey.
If you want to provide one argument, but not the arguments
before it, simply type enough commas to separate them. For
instance, suppose you want to assign the hotkey 'B' to this
button:
[IButton,"Select the SimpleBrush","This
button selects the Simple Brush",
[IPress,Tool:SimpleBrush]
, , ,
'B' ] |
2) The IColorSet
Command In this section, you'll create a button
that changes the ZBrush Main Color.
The ZScript command that changes the ZBrush main color is
IColorSet. The way it's written is
[IColorSet, red, green,
blue] | To
set the color, simply replace IColorSet's arguments with the
red, green and blue components of the color. These can be
determined by picking your color in ZBrush's Color palette,
and reading the R, G and B sliders.
Let's start with a red that is R=255, G=0, B=0:
Place
the command inside an IButton:
[IButton,"Red","Pick a Red Color",
[IColorSet, 255, 0,
0] ] | Now
you have a working button that changes the ZBrush main color
to red. To add a finishing touch, set a HotKey for this button
-- let's make it SHIFT+ALT+'R' for 'Red' -- so whenever you
press the HotKey, the color changes to Red.
[IButton,"Red","Pick a Red Color",
[IColorSet, 255, 0, 0]
, , ,
SHIFT+ALT+'R' ] | (Note
to Mac users: the ALT key and OPT key can be used
interchangeably).
3) The If, IGet and IPress
Commands Here's the plan for this section: Check
if there's an active 3D object in Edit mode. If there is,
press the New button in the Texture:Inventory palette:
How do you check if there's an active object in Edit mode?
The easiest way is to check if the Edit Object button, in the
Transform palette, is pressed:
The IGet command checks any ZBrush interface item.
If the interface item is a slider, IGet yields the
numeric setting of the slider; if it's a button, IGet
yields 1 if it's pressed, 0 if it's unpressed.
The IGet command is written like this:
[IGet,Interface Item
Path] | Substitute
the Edit Object button path:
[IGet,Transform:Edit
Object] | If
this equals 1, you know the Edit Object button is pressed. But
what do you do with that information? You need to execute one
set of commands if the Edit Object button is pressed, another
if it's not pressed.
That's where the If command comes in. The If
command is written like this:
[If,
something is true or false ,
commands to execute if true... ,
commands to execute if
false... ] | In
this case, you don't want to do anything if the Edit Mode
button is unpressed. So the third argument, the commands to
execute if false, will be empty.
To press a button, use the IPress command. The
IPress command is simply written
[IPress,Interface Item
Path] | So
put these three elements together. In plain English, you'd
say, "If the Edit Button is pressed (equals 1), press the New
Texture button." In ZScript-ese, you'd say
[If,
[IGet,Transform:Edit Object] = 1 ,
[IPress,Texture:Inventory:New] ] | Put
this inside the button you created earlier, and you get:
[IButton,"Red","Pick a Red Color",
[IColorSet, 255, 0, 0]
[If, [IGet,Transform:Edit Object] = 1 ,
[IPress,Texture:Inventory:New]
]
,,,SHIFT+ALT+'R' ] | Now
that you have a Red button, copy and paste the whole
IButton, to create a Yellow, Green and Blue button. Of
course, you'll want to put different arguments into the
different IColorSet commands, as well as change the
names of the buttons and the hotkeys.
When you're finished, try out your ZScript -- save it as
"MyZScript.txt", and load it into ZBrush (using the
ZScript:Inventory:Load button). It should look like
this:
4) Creating the
Graphics Use ZBrush to create the individual box
graphics for the ZScript.
Start with a blank black canvas. Select a Cube3D, change
the color to white, and select the Bumpy Metal material. Draw
it anywhere on the canvas, press the Transform:Rotate button,
and hold the Shift key while dragging inside the Canvas Gyro
to make it perfectly level:
Press the Transform:Scale button, and open the
Transform:Info sub-palette. In each of the sliders, type
40:
The number 40 means that from the center of the cube to
each of the sides, the distance is 40 pixels. That means this
cube has a width and height of 80 pixels.
Mark it (Transform:Mark).
Now, select a Sphere3D. Change the color to red, and press
the Draw:ZSUB button. Draw the sphere on top of the cube,
using the marker for placement:
Now, select the MRGBZGrabber, and make sure Shaded RGB and
Auto Crop are pressed:
Grab it by clicking inside and dragging so the white
rectangle completely surrounds the box:
Your Texture palette should now look like this:
Now, press Undo to remove the red sphere, change the color
to Yellow, and draw another sphere. Grab it and do the same
for Green and Blue.
You've created all four graphics needed for your ZScript.
Select each in the Texture Palette. Notice that the
Texture:Inventory sub-palette tells you each graphic's width
and height:
Select each texture, and export each by pressing the
Texture:Inventory:Export button. Name the files 'RedBox.psd',
'YellowBox.psd', 'GreenBox.psd' and 'BlueBox.psd', and be sure
to save each image in the same folder as your ZScript
resides.
Note for Demo users: You
can't Export from the Demo version, so here are the four
graphic files for download. Right-click to download each
file: RedBox.psd YellowBox.psd GreenBox.psd BlueBox.psd
The box graphics are now ready to display in your ZScript.
5) Formatting the
ZScript First, you'll want to display the box
graphics you just created inside your ZScript. The command for
displaying images is
[Image, Filename,
Alignment (0=center, 1=left, 2=right),
Resized
width ] | For
this lesson, you'll want to left-align the images, and you
won't need to resize them (omit the third argument). So
beginning with the red box, the command looks like this:
[Image, RedBox.psd,
1 ] | The
'1' looks a little funny floating on it's own, so why not put
everything on one line?
When
formatting your ZScripts, it's helpful to think of an
invisible "pen" that "writes" every item in the ZScript
window. For the Image command, the "pen" displays the
image, then moves to the top right edge of the image.
This means, to set the box graphics next to each other, you
only need to repeat the Image command once for each
box, one command appearing after another:
[Image, RedBox.psd,1] [Image,
YellowBox.psd,1] [Image, GreenBox.psd,1] [Image,
BlueBox.psd,1] | After
the "pen" has displayed all four images, ask yourself, where
is the "pen" now? It's at the top right edge of the blue
box:
Notice something interesting: The black background from the
ZBrush canvas doesn't appear where the corners of the boxes
are. That's because, in any image you display in the ZScript
window, if the upper-leftmost pixel is solid black (color
red=0, green=0, blue=0), any black pixel becomes transparent.
If you want to display a black color, simply paint the
upper-leftmost pixel with an almost-black color, say
red=1,green=1,blue=1.
Now, where to put the IButtons you created earlier?
You'll want to move the "pen" down 80 pixels, because the
height of each box is 80 pixels. You'll also want to move the
pen to the left edge of the page, because that's where all
four boxes start.
The convenient command for moving the "pen" to the left
edge of the page is
...
and it has no arguments at all.
The command for moving the "pen" a certain number of pixels
is
[PenMove,
horizontal distance ,
vertical
distance ] | Since
PenMoveLeft takes care of our horizontal placement, you
can omit the first argument, and use PenMove to move
the "pen" down 80 pixels. Putting the two together, it looks
like this:
[PenMoveLeft] [PenMove,,80] | What
if you wanted to move the "pen" up instead of down? You'd type
-80 instead of 80. Any negative number means "move up", any
positive number means "move down". For horizontal movement, a
negative number means "move left", and a positive number means
"move right".
After the pen movements, place the four buttons you
created. Your ZScript now looks like this:
[Image, RedBox.psd,1] [Image,
YellowBox.psd,1] [Image, GreenBox.psd,1] [Image,
BlueBox.psd,1]
[PenMoveLeft] [PenMove,,80]
[IButton,"Red","Pick a Red Color",
[IColorSet, 255, 0, 0]
[If, [IGet,Transform:Edit Object] = 1 ,
[IPress,Texture:Inventory:New]
]
,,,SHIFT+ALT+'R' ] [IButton,"Yellow","Pick a
Yellow Color",
[IColorSet, 255, 255, 0]
[If, [IGet,Transform:Edit Object] = 1 ,
[IPress,Texture:Inventory:New]
]
,,,SHIFT+ALT+'Y' ] [IButton,"Green","Pick a
Green Color",
[IColorSet, 0, 255, 0]
[If, [IGet,Transform:Edit Object] = 1 ,
[IPress,Texture:Inventory:New]
]
,,,SHIFT+ALT+'G' ] [IButton,"Blue","Pick a Blue
Color",
[IColorSet, 0, 0, 255]
[If, [IGet,Transform:Edit Object] = 1 ,
[IPress,Texture:Inventory:New]
]
,,,SHIFT+ALT+'B' ] |
If you load it into ZBrush, it looks like this:
Uh-oh. The buttons aren't aligned with the graphics. What
now?
Remember that the IButton command has an argument
that sets the ButtonWidth. It's the argument right before the
HotKey.
Since you know that each box graphic has a width of 80, you
can set the width of each IButton to match. For
example, edit the Red button to look like this:
[IButton,"Red","Pick a Red Color",
[IColorSet, 255, 0, 0]
[If, [IGet,Transform:Edit Object] = 1 ,
[IPress,Texture:Inventory:New]
]
,,80,SHIFT+ALT+'R' ] | Do
the same for the other three buttons, and they should align
perfectly.
One more thing: why not center the whole ZScript in the
ZScript window? You could go through the tedious task of
moving the "pen" to the center, moving to the left a certain
number of pixels, etc. But the easier way is to use the
PageSetWidth command:
[PageSetWidth, Preferred
Width] | PageSetWidth
not only sets the width of the page, it moves the left and
right margins inward so the whole page is centered in the
window.
So how wide should the page be? Are you going to have to
dig the calculator out of the desk drawer? No. ZBrush can do
the math for you.
Instead of entering a number for the Preferred Width,
you're going to enter a numeric expression. This tells ZBrush
how to calculate a number, and you don't have to know the
answer yourself.
You know the width of each button (80) and you know there
are four buttons. So you need to tell ZBrush that the Page
Width is 4 times 80. Just to give ZBrush a little breathing
room, add one more pixel. In ZScript-ese that's:
FYI, the add, subtract, multiply and divide symbols are: +
(plus sign, add), - (hyphen, subtract), * (asterisk,
multiply), / (slash, divide).
Place the PageSetWidth command at the top of your
ZScript. You're done!
The final ZScript looks like this:
[PageSetWidth, 4*80+1]
[Image, RedBox.psd,1] [Image,
YellowBox.psd,1] [Image, GreenBox.psd,1] [Image,
BlueBox.psd,1]
[PenMoveLeft] [PenMove,,80]
[IButton,"Red","Pick a Red Color",
[IColorSet, 255, 0, 0]
[If, [IGet,Transform:Edit Object] = 1 ,
[IPress,Texture:Inventory:New]
]
,,80,SHIFT+ALT+'R' ] [IButton,"Yellow","Pick a
Yellow Color",
[IColorSet, 255, 255, 0]
[If, [IGet,Transform:Edit Object] = 1 ,
[IPress,Texture:Inventory:New]
]
,,80,SHIFT+ALT+'Y' ] [IButton,"Green","Pick a
Green Color",
[IColorSet, 0, 255, 0]
[If, [IGet,Transform:Edit Object] = 1 ,
[IPress,Texture:Inventory:New]
]
,,80,SHIFT+ALT+'G' ] [IButton,"Blue","Pick a
Blue Color",
[IColorSet, 0, 0, 255]
[If, [IGet,Transform:Edit Object] = 1 ,
[IPress,Texture:Inventory:New]
]
,,80,SHIFT+ALT+'B' ] |
Exercises To
get a little more practice, try these challenges on your own:
Create a button that sets the color to its
Color-Wheel Complement (the color on the opposite side of the
color wheel). Hint: a color's complement can be determined by
taking the red, blue, and green components and subtracting
each from 255.
Create a painter's palette with different color
swatches located on it. Here's a blank palette to get you
started:
Right-click here to download the PSD
file. Hint: You can display one image, then use
PenMove commands to move on top of it, and display
another image.
Feel free to post your results in this thread.
Happy ZScripting! dave
Next lessons: Lesson II: ISliders Lesson III: CanvasStroke and Loops Lesson IV: TransformSet and CanvasClick
Posts:
351 | From: California | Registered: Apr
2001 | IP: Logged
| |
upham •••••••• Member # 40
|
posted January 14, 2002 01:35 PM
Man, I've
been waiting for this thread for ages!! You must of worn your
fingers to the bone writing all this and the Pixologic
webpages! Thanks Davey!  Gotta hit the ZScript books! Study
study! Upham
________________
NEW TO ZBRUSH??? Check out these helpful links... PIXOLOGIC HOME
PAGE! **Reading** *ZBrush Central Quicklinks*, *ZBrush 250 page manual!*, *ZAcademy_PDF_Color-6.7meg, *ZBrushCentral Modeling ver 1.23b- 7meg,
* **Resorces** Southern Graphics, ZPlace,The Aurickle, RoboTalk ZBrush Galleries Juandel's ZBrush Gallery, Renderosity ZBrush Art Gallery, 3D Commune ZBrush Forum, Upham's ZLand 4
newbies, Ken B's Brilliant-Creations
Posts:
780 | From: New Zealand | Registered: Apr
2001 | IP: Logged
| |
|
|
aurick •MODERATOR
Member # 348
|
posted January 14, 2002 06:01 PM
Rock on!
PageSetWidth was exactly what I've been wanting to know.
Thank you for taking the time to put this together. It's
very clear, and I can't imagine it giving anyone difficulty.
________________
Matthew _ _ ______________ _ _ Moderator
Pixologic, Inc. http://www.zbrush.com/ http://www.zbrushcentral.com/
Posts:
4375 | From: Las Vegas, NV | Registered: May
2001 | IP: Logged
| |
|
|
|
|
|
WingedOne
•••••••
Member # 48
|
posted January 17, 2002 10:00 AM
Thanks for
the tutorial and an idea just came to me. I created a ZScript
folder on my PocketPC and will save the ZScript command
reference to my PocketPC as well and then I can work on
ZScripts on the go!
I'm looking forward to more upcoming lessons.
I'd be interested in seeing scripts demonstrating the use
of math functions to generate images (tan, cosin, sin, abs,
etc.) and the uses of the pixolpick command.
________________
"Don't be mean. Don't be mean... 'cause... No matter where
you go... there you are." - Buckaroo Banzai
Posts:
1661 | From: Monster Island | Registered: Apr
2001 | IP: Logged
| |
s o u t h e r n
•
Member # 46
|
posted January 17, 2002 10:07 AM
Hey Winged
one....SNAP...
I wrote some of my QUICK-DEFORMER on my HP
JORNADA....Really hard but really cool!!!
Glen
...and I have the command reference and Daveys tuts saved
on my Compact Flash card (Along with the latest Steriophonics
album in MP3)
Posts:
1028 | From: UK, Northwest | Registered: Apr
2001 | IP: Logged
| |
| |