Click in order to post a new topic.  Click in order to post a reply.

member profile | register | search | QuickLinks | help | home
  next oldest topic   next newest topic
»  ZBrushCentral   » ZBrush Forum   » ZScript Lesson II: ISliders

UBBFriend: Email this page to someone!    
Author Topic: ZScript Lesson II: ISliders
davey
MODERATOR
Member # 6

posted January 21, 2002 07:57 PM     Profile for davey   View Gallery for davey     Send New Private Message   Edit/Delete Post
This lesson is the second in an ongoinging series. It's designed to follow ZScript Lesson I: IButtons and Formatting.

Thank you all for the terrific responses to Lesson I. To give people more time to practice and discuss the skills presented in these lessons, Lesson III will be presented in two weeks' time.



In this lesson, you'll create the ZScript shown above. Each line of sliders displays some settings for Tool, Color, Material and Texture, which you can "grab" from the ZBrush interface by pressing the Grab button. Once grabbed, you can edit the settings by adjusting the sliders. Any time you like, you can change the ZBrush palettes to these settings by pressing the Apply button.

In Lesson I, you learned how to create interactive buttons using the IButton command. In this lesson you'll learn how to create and manipulate interactive sliders, using the ISlider command.

1) Examining the ISlider Command
In this section you'll become familiar with the ISlider command and its arguments. If you're already familiar with the ISlider command, you can skip to section 2.

The ISlider command is similar to the IButton command, with a few more arguments that describe the way it slides.

Here are the arguments:


The Slider Text, Popup Info, Commands Group, Initially Disabled and Slider Width arguments are the same as their counterparts in the IButton command, except that the Commands Group executes whenever the slider is moved.

The remaining arguments are simple:

Starting Value is the value displayed in the slider when it's first loaded. Don't be confused -- this isn't the lowest possible number the slider can have -- that argument is the Minimum Value. The Starting Value could be the same as the slider's Minimum Value, Maximum value, or anything inbetween.

Resolution is the amount of each "tick" of the slider -- that is, the smallest amount by which the slider can change. Suppose the Starting Value is 0; a Resolution of 1 means the slider can change to values like 0,1,2,3 and so on. A Resolution of 10 means the slider can change to values like 0,10,20,30 and so on. A Resolution of .05 means the slider can change to values like 0,.05,.10,.15 and so on.

Minimum and Maximum Values are the numbers at the far left and right ends of the slider. Your slider can go from 0 to 10, 1 to 100, -255 to 255, or any two numbers as long as the Minimum Value is less than the Maximum Value.

Here's a typical way you might use the Slider:

[ISlider,"Set The Draw Size",
64, 1, 1, 128,
"This Sets the Draw Size",
[ISet,Draw: Draw Size,[IGet,ZScript:Set The Draw Size]]
]

This slider looks like this:

It has a Starting Value of 64, and goes from 1 to 128 (Minimum and Maximum Values) in increments of 1 (Resolution). When you change it, the Commands Group executes (and the Draw Size is changed to match its value). We'll examine the commands in the Commands Group later.

Notice something about the slider: you can't see the value of the slider unless you hold your cursor over it:

Not only do you see the Popup Text, but the Slider Text moves to the right in the ISlider and the value appears.

You can create the slider so the value is always displayed, by changing its width to allow enough room for the Slider Text and the value. Do this by adjusting the Slider Width argument:

[ISlider,"Set The Draw Size",
64, 1, 1, 128,
"This Sets the Draw Size",
[ISet,Draw: Draw Size,[IGet,ZScript:Set The Draw Size]]
,,200
]

Now, the slider displays its value even when your cursor is not floating over it:


2) Variables and The VarSet Command
You'll work a little backward on this ZScript: you'll first lay out the ISliders and IButtons, then later you'll insert a Commands Groups into each one.

In the next section, you'll create a single line of ISliders and IButtons that looks like this:

You'll need to know the width of each ISlider and IButton. You could meticulously figure out each width, but by planning ahead you can let ZBrush calculate the widths for you.

In the above image, notice that there are two sizes: small and large. The large size is twice the width of the small size. So first, figure out the small size. Count the items in the image, counting once for each small item and twice for each large item, and once for the space between the two IButtons. Your count should be 11:

You'll use a PageSetWidth command to set the page width to 640 (ZBrush's default canvas width, and the only canvas width possible for Demo users). So, the width of each small item is 640 divided by 11.

Use a variable to tell ZBrush that a "small width" is 640/11 (the slash means "divided by"). The command which does this is VarSet.

[VarSet,
Variable Name,
Value
]

The Variable Name can be anything you like, as long as it's spelled with letters and numbers. In this case, call it SmallWidth, so you can remember it easily.
[VarSet,
SmallWidth ,
640/11
]

Variables are extremely useful; you can use them in your ZScripts in any place you'd use a number, and even sometimes where you'd use a word or phrase, or a brushstroke.

Now ZBrush knows that whenever you put the word 'SmallWidth' in a command, it'll use the value of 640 divided by 11.

Create another variable for your large item widths. The large items are twice the size of the small items, and you've already specified a variable for the small widths, so you'll use another VarSet:

[VarSet,
LargeWidth ,
SmallWidth * 2
]

The asterisk (*) means "multiplied by".

So far, your ZScript looks like this (with the VarSets condensed to one line each):

[PageSetWidth,640]
[VarSet, SmallWidth, 640/11]
[VarSet, LargeWidth, SmallWidth * 2]

One thing you should know: the two VarSet commands must appear in this order. Why? Because the second VarSet command uses a variable you've already created, SmallWidth. If it hadn't already been created, ZBrush wouldn't know what value to use for SmallWidth, and you'd get an error message when you loaded the ZScript.


3) Laying It Out, and Comments
Now that you've got the widths figured out, you can lay out the first line of ISliders and IButtons.

As I mentioned before, you'll work a little backward: you'll lay them out first, and later insert the Commands Groups into each one. To help you find the place where each Command Group goes, you'll insert a Comment.

Comments are not really commands; they're simply notes to yourself or other "ZCoders". One way to write Comments is with a double-slash:

[IButton,Button,Popup,
// Commands Group will go here
]

Comments can go anywhere, inside or outside ZScript commands. ZBrush completely ignores everything after the //, up through the end of the line. When the ZScript is loaded, Comments are not displayed.

In this case, you'll place a Comment into each ISlider and IButton, so you can easily find where to insert the Commands Groups later.

Start with the first ISlider which displays the Tool Item Info number.

Decide on the arguments:
Slider Text = "Tool"
Starting Value = let's make it 1.
Resolution = You know the Tool Item Info numbers are 1,2,3, etc., so this should be 1.
Minimum Value = 0 (smallest possible Tool Item Info number)
Maximum Value = let's make it 38, the largest Tool Item Info number in the Tool Palette if no tools have been loaded. But we'll take another look at this later...
Popup Info = "Tool Item Info Number"
Commands Group = for now, it'll be a Comment: // Commands Group goes here
Initially Disabled? = empty
Slider Width = the variable, SmallWidth.

Plug these arguments into the ISlider command (some arguments are placed together on one line):

[ISlider,Tool,
1, 1, 0, 38,
"Tool Item Info Number",
// Commands Group goes here
,
, SmallWidth
]

Notice something important: where I've put the Comment, I've put the comma on the next line. You might be tempted to put the comma right after the Comment ( // Commands Group goes here, ) but remember, everything after the double slash (//) is ignored -- so this would mean even the comma was ignored.

Note: In some of these ISliders, you won't replace the Comments with Commands Groups, but that's okay -- the Comments won't change the way they work.

Now for the three Color components: Red, Green and Blue. Each can go from 0 to 255, in increments of 1 (Resolution). For each, start with a value of, let's say, 128.

[ISlider,R,
128, 1, 0, 255,
"Red Component",
// Commands Group goes here
,
, SmallWidth
]

[ISlider,G,
128, 1, 0, 255,
"Green Component",
// Commands Group goes here
,
, SmallWidth
]

[ISlider,B,
128, 1, 0, 255,
"Blue Component",
// Commands Group goes here
,
, SmallWidth
]


Same for the Material ISlider, but this time use the LargeWidth variable. The Material palette can go from 0 to 65; use a Starting Value of 1:
[ISlider,Material,
1, 1, 0, 65,
"Material Item Info Number",
// Commands Group goes here
,
, LargeWidth
]

Now the Texture ISlider. Similar to the Tool palette, the Texture palette starts with items from 0 to 44, but can be expanded. So use 44 as the maximum, but we'll take another look at this later...
[ISlider,Texture,
0, 1, 0, 44,
"Texture Item Info Number",
// Commands Group goes here
,
, LargeWidth
]

Now for the Grab IButton. This button will examine the various ZBrush palettes, and put those (current) values into these ZScripted ISliders. Again, use a Comment to tell yourself where the Commands Group will be placed later:
[IButton,Grab,"Grab Current Values",
// Commands Group goes here
,
, SmallWidth
]

Move the "Pen" forward one SmallWidth:
[PenMove, SmallWidth]

Finally, the Apply IButton, which will do the opposite of the Grab IButton: take the value of each ZScripted ISlider, and place that value into the appropriate ZBrush palette.
[IButton,Apply,"Apply These Values",
// Commands Group goes here
,
, SmallWidth
]


4) Expandable Sliders: IGetMax and ISetMax
In the last section I promised we'd "take another look" at the Maximum Values of the Tool and Texture ISliders.

Wouldn't it be nice if the Tool ISlider first checked how many items were in the Tool palette, and adjusted itself to match that number?

The command which does this is IGetMax:

[IGetMax,Interface Item Path ]

In this case:
[IGetMax,Tool:Item Info]

In your ZScript, go back to the Tool ISlider and replace the Maximum Value (38) with this IGetMax command:
[ISlider,Tool,
1, 1, 0, [IGetMax,Tool:Item Info],
"Tool Item Info Number",
// Commands Group goes here
,
, SmallWidth
]

Do the same for the Texture ISlider:
[ISlider,Texture,
0, 1, 0, [IGetMax,Texture:Item Info],
"Texture Item Info Number",
// Commands Group goes here
,
, LargeWidth
]

That works perfectly, the first time the ZScript is loaded. But what if you change the number of tools or textures afterward?

You can use the ISetMax command to change the Maximum Value of any ISlider you create.

[ISetMax,ZScript:ISlider name, Value ]

Note: you cannot use ISetMax on ZBrush interface items, only the ISliders you create in your ZScripts.

You'll use this command so that each time the Tool and Texture ISliders are changed, they examine the Tool and Texture palettes to see if there's a new number of items. Unfortunately, this will have to be done after the slider is changed. This means, once you've loaded a tool, the Tool ISlider won't "know" it's there until after the first time you move the ISlider.

For the ISetMax's value, you can use another IGetMax:

[ISetMax,ZScript:Tool,[IGetMax,Tool:ItemInfo]]

Find the Comment in the Tool ISlider and replace it:
[ISlider,Tool,
1, 1, 0, [IGetMax,Tool:Item Info],
"Tool Item Info Number",
[ISetMax,ZScript:Tool,[IGetMax,Tool:ItemInfo]]
,
, SmallWidth
]

This works well, but what if there are more than one sliders called "Tool"? There's another, even simpler way to write the ISetMax command, which I'll explain in the next section.


5) A Neat Feature
In the last section you learned that interface item path to any ZScript IButton or ISlider is 'ZScript: Item Name '.

This could get confusing, especially if there are two or more ISliders or IButtons with the same name.

In the case of the Tool ISlider, you entered 'ZScript:Tool' as the interface item path (within the ISetMax command). You can replace that entire phrase 'ZScript:Tool' with the number 0. This is a special way to tell any IButton or ISlider that it's referring to itself. In this case:

[ISetMax,0,[IGetMax,Tool:ItemInfo]]

So the Tool ISlider looks like this:
[ISlider,Tool,
1, 1, 0, [IGetMax,Tool:Item Info],
"Tool Item Info Number",
[ISetMax,0,[IGetMax,Tool:ItemInfo]]
,
, SmallWidth
]

What does the number 0 mean? It means "find the interface item that's 'this many' away from this ISlider". So you could enter a 1, and it would find the next ISlider or IButton, 2 for the one after that, and so on. Or you could enter -1 to find the previous ISlider or IButton, -2 for the one before that, and so on.

Don't be confused: by "next" and "previous" I mean the next and previous ISlider or IButton in your ZScript text file, even though you may use PenMove commands to place it elsewhere in the ZScript window.

This number can be any number between -99 to 99. You can use this feature on any ZScript command that uses an Interface Item Path, to find other ZScript items.

So, with the Tool ISlider modified, do the same for the Texture ISlider:

[ISlider,Texture,
0, 1, 0, [IGetMax,Texture:Item Info],
"Texture Item Info Number",
[ISetMax,0,[IGetMax,Texture:ItemInfo]]
,
, LargeWidth
]

We'll use this "neat feature" again in the next section, when we write the Commands Groups for the Grab and Apply IButtons.


6) Setting the Values: the ISet Command
Now you'll create the Commands Groups for the two IButtons. Each of them will use the ISet command:
[ISet, Interface Item Path ,
New Value
]

Note: unlike the ISetMax command, you can use ISet on any ZBrush or ZScript interface item.

First, the Grab IButton. This IButton "grabs" information from various ZBrush palettes, and changes the ISliders in this ZScript to match. For each ISlider, you'll read the corresponding palette item with an IGet command, and set the ISlider with an ISet command.

Take another look at the layout of your ZScript items:

Notice the Tool ISlider is 6 items away from the Grab IButton. So, to tell the Grab IButton to find the Tool ISlider, you'll use the number -6 (that's 6 items previous).

[ISet,-6,[IGet,Tool:Item Info]]

That takes care of the first command in this Commands Group.
The next three are for the Red, Green and Blue ISliders:
[ISet,-5,[IGet,color:r]]
[ISet,-4,[IGet,color:g]]
[ISet,-3,[IGet,color:b]]

Next are the Material and Texture ISliders:
[ISet,-2,[IGet,Material:Item Info]]
[ISet,-1,[IGet,Texture:Item Info]]

Find the Comment inside your Grab IButton and replace it with these commands:
[IButton,Grab,"Grab Current Values",
[ISet,-6,[IGet,Tool:Item Info]]
[ISet,-5,[IGet,Color:R]]
[ISet,-4,[IGet,Color:G]]
[ISet,-3,[IGet,Color:B]]
[ISet,-2,[IGet,Material:Item Info]]
[ISet,-1,[IGet,Texture:Item Info]]
,
, SmallWidth
]

Now for the Apply IButton. This time, the Tool ISlider is -7 items away, so start there:
[ISet,Tool:Item Info,[IGet,-7]]

Do the same for the rest of the ISliders:
[ISet,Color:R,[IGet,-6]]
[ISet,Color:G,[IGet,-5]]
[ISet,Color:B,[IGet,-4]]
[ISet,Material:Item Info,[IGet,-3]]
[ISet,Texture:Item Info,[IGet,-2]]

Now you have a functioning ZScript that stores certain settings which you can recall later.

To review, the entire ZScript should look like this:

[PageSetWidth,640]
[VarSet, SmallWidth, 640/11]
[VarSet, LargeWidth, SmallWidth * 2]

[ISlider,Tool,
1, 1, 0, [IGetMax,Tool:Item Info],
"Tool Item Info Number",
[ISetMax,0,[IGetMax,Tool:ItemInfo]]
,
, SmallWidth
]

[ISlider,R,
128, 1, 0, 255,
"Red Component",
// Commands Group goes here
,
, SmallWidth
]

[ISlider,G,
128, 1, 0, 255,
"Green Component",
// Commands Group goes here
,
, SmallWidth
]

[ISlider,B,
128, 1, 0, 255,
"Blue Component",
// Commands Group goes here
,
, SmallWidth
]

[ISlider,Material,
1, 1, 0, 65,
"Material Item Info Number",
// Commands Group goes here
,
, LargeWidth
]

[ISlider,Texture,
0, 1, 0, [IGetMax,Texture:Item Info],
"Texture Item Info Number",
[ISetMax,0,[IGetMax,Texture:ItemInfo]]
,
, LargeWidth
]

[IButton,Grab,"Grab Current Values",
[ISet,-6,[IGet,Tool:Item Info]]
[ISet,-5,[IGet,Color:R]]
[ISet,-4,[IGet,Color:G]]
[ISet,-3,[IGet,Color:B]]
[ISet,-2,[IGet,Material:Item Info]]
[ISet,-1,[IGet,Texture:Item Info]]
,
, SmallWidth
]

[IButton,Apply,"Apply These Values",
[ISet,Tool:Item Info,[IGet,-7]]
[ISet,Color:R,[IGet,-6]]
[ISet,Color:G,[IGet,-5]]
[ISet,Color:B,[IGet,-4]]
[ISet,Material:Item Info,[IGet,-3]]
[ISet,Texture:Item Info,[IGet,-2]]
,
, SmallWidth
]

Now, how about adding more lines so you can store a number of settings? That's easy. Add a PenMoveDown command (can also be written simply [PD]), then copy and paste all the ISliders and IButtons. Since you used the "neat feature" for finding other ZScript items, each Grab and Apply IButton will work properly for the line of ISliders next to it.


Exercises
To get a little more practice, try these challenges on your own:

Try adding a second line of ISliders which record more information such as Draw Size, Alpha:Item Info, RGB Intensity and ZIntensity.

Modify the commands within the Grab and Apply IButtons, so that the sliders on each line are only grabbed/applied, if the corresponding Tool, Color, Material and Texture buttons in the Marker palette are pressed.

Feel free to post your results in this thread.

Happy ZScripting!
dave




Next lesson:
Lesson III: CanvasStroke and Loops

Posts: 351 | From: California | Registered: Apr 2001  |  IP: Logged
JohnArtbox

Member # 355

posted January 21, 2002 09:20 PM     Profile for JohnArtbox   View Gallery for JohnArtbox     Send New Private Message   Edit/Delete Post
Doh! I just spent a few hours trying to puzzle sliders out(non-programmer).
I've never even bothered with scripts before because of the learning curve. Now I'm having more fun than a monkey in a madhouse.
John

Posts: 85 | From: Australia | Registered: May 2001  |  IP: Logged
upham
••••••••
Member # 40

posted January 21, 2002 09:46 PM     Profile for upham   View Gallery for upham     Send New Private Message   Edit/Delete Post
Your post is pumping out through my printer as I type!!!
Thanks Davey!!!!
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
dr. jjwow
•••••••
Member # 280

posted January 22, 2002 01:46 AM     Profile for dr. jjwow   View Gallery for dr. jjwow     Send New Private Message   Edit/Delete Post
hi davey i want to let you know that im enjoing these classes and so far ive learned alot.. keep them coming and when i can find the time to actually make a zsript i will.. i would also like to know if you plan to make this into a pdf file for easier printing...

________________

"if you look back you might step in a hole ahead of you, so dont look back"
Come and join me


Posts: 3679 | From: vancouver | Registered: May 2001  |  IP: Logged
DLee
•••••••••
Member # 1177

posted January 22, 2002 12:04 PM     Profile for DLee   View Gallery for DLee     Send New Private Message   Edit/Delete Post
Thank you very much. Somehow I missed 1 so got to go back and read that one to.

________________

D. Lee

Z page
http://www3.telus.net/public/dlee56/art/
Homepage
http://www3.telus.net/public/dlee56


Posts: 884 | From: B.C Canada | Registered: Nov 2001  |  IP: Logged
s o u t h e r n

Member # 46

posted January 22, 2002 12:07 PM     Profile for s o u t h e r n   View Gallery for s o u t h e r n     Send New Private Message   Edit/Delete Post
Dave, you are an un-sung hero where I live so here I am singing about you. Very cool tutorial and just as Upham said, I hear the hum of a HP printer head cranking out yer stuff.

Well done. Very clear for non-code heads like me.

Glen


Posts: 1028 | From: UK, Northwest | Registered: Apr 2001  |  IP: Logged
Muvlo
•••
Member # 61

posted January 22, 2002 02:33 PM     Profile for Muvlo   View Gallery for Muvlo     Send New Private Message   Edit/Delete Post
Good one! Lots of fun to read, and again you help me to understand commands that I say "Why in the world..." about. Thanks!

________________

Law must retain useful ways to break with traditional forms because nothing is more certain than that the forms of Law remain when all justice is gone.
--Gowachin aphorism
The Dosadi Experiment, Frank Herbert


Posts: 2218 | From: Seitch Tabr | Registered: Apr 2001  |  IP: Logged
davey
MODERATOR
Member # 6

posted January 28, 2002 02:45 PM     Profile for davey   View Gallery for davey     Send New Private Message   Edit/Delete Post
I'm really glad these lessons can be of some help

Thanks,
dave


Posts: 351 | From: California | Registered: Apr 2001  |  IP: Logged

All times are Pacific Time  

Click in order to post a new topic.  Click in order to post a reply. Close Topic    Move Topic    Delete Topic next oldest topic   next newest topic
Hop To:

Contact Us | Pixologic Home Page

Powered by Infopop Corporation
Ultimate Bulletin Board 6.04a