Tutorial 1 of 10
GETTING STARTED
CREATOR NOTEby Morning.star, published with permission
Our purpose here is not to learn all of the possible ways of doing something. Rather it's to learn some straightforward methods that will work in handcoding vrml worlds & objects. We'll cover as much coding as we can, but won't be able to cover everything.
If you complete these tutorials you should be able to create a perfectly good piece of work and even go on to build a whole world. My own approach when it comes to learning anything is that it's better to succeed at something simple but excellent than to produce something inferior but incredibly complex. These tutorials should help you succeed in creating an object you can be proud to share with others. I began learning hand-coding in CT & between the time I spent creating there & now in CTR have hand-coded well over 1000 objects. In fact, if I can learn to hand-code ( & everything I've ever done has been hand-coded ), then anyone can. Promise.
There are a series of 10 tutorials that take you through various aspects of object creation. There are also examples of objects containing relevant coding in the club for you to have a look at. If you have comments or questions, please leave them in the CLUB INBOX rather than attached to the tutorials or on the MESSAGE BOARD. All comments attached to tutorials or left on the MB will be deleted so that the tutorials are easy to access.
WHAT YOU NEED
We'll use the simplest methods & tools available - our purpose is not to explore all the bells & whistles available in terms of text editing or other software. The benefits of using one editor over another are also not the focus here.
- I recommend using Notepad. It's what I use currently & most folks have it on their comps. When you save your file initially, you'll save it as a .txt file. Once that's done, you'll go to the file in its folder & change the .txt file extension to .wrl. Your comp will probably ask you if that's what you want to do. Accept the change. Changing it to a .wrl won't affect the coding. When next you open the file to work on it, the code will display correctly. You just need to remember to use Notepad to open the file each time you want to work on it.
- A hand-held calculator hanging on a rope around your neck :))) just kidding lol ! But seriously, you'll need a calculator to help you do basic math. DON'T PANIC !!! No fancy calculus required - it's just easier not to have to do the thinking yourself - let the machine do it !
- You're going to need some graph paper as well to help you plot the dimensions of your object.
- And finally, you should be able to make your own textures, ie. have a graphics or photo-editing programme to create textures with. And don't let this put you off either - everyone starts making textures sometime. Once you get the hang of it & get some practice in, you'll find them to be half the fun. After all - it's just a plain ole box 'til you put a texture on it :) You'll also need to use one to do your thunbs ... a graphics programme, not a box LOL!
- So that’s what TO do . What's NOT to do ? Any big don’ts ?
**You bet ! Here’s one : DON’T manipulate the text of your code using any kind of font face, font color, font size or any HTML coding at all. Leave it just plain ordinary lettering - the text editor's default will do.**
Here’s another : DON’T forget to look at your work frequently - as in after every little change you make or thing you add & DON'T forget to SAVE AS ! Get in there in 3d at every step along the way & check it out ! If your item must be entered - enter it . If it must be seen - look at it . If it must be clicked - click it . Make sure your work looks like you expect it to & performs exactly as you want it to perform . Be your own crashtest dummy :) And since handcoding is unlike using a programme where you have your creation in front of you in 3D all the time, you can either keep a 2nd 3D window open all the time & refresh it after your changes, or keep opening up a new 3D window each time you do any work in your file. There's an example of a 'gee, I missed that' in one of my objects in the club. Have a look at 'Misery Hill Dining'. See how tiny that one candlestick holder on top of the table is? YIKES !!! So embarassing ! Yep, everyone makes mistakes.
Another biggee : DON’T forget that the 1st world or object you create will probably disappoint you in some way ( as will many others in your building & creating career ) . Don’t sweat it ! There won't likely ever be a piece of work you don't look back on at some point & say "gee I wish I had ..." so be demanding of yourself, but not cruel :)
The most frequent error is misjudging the proportions of a piece & that's really easy to do. Experiment - experience is the best teacher . My first tabletops ended up being much higher than I would have liked in retrospect. Use the measuring sticks I've created ( ask me for a set, there are 3 - a vertical, horizonal & small one with finer markings ). Take some time to drop them & measure parts of your home & clubs as well as other creators' objects. Developing a sense of proportion is a very important building & creating skill - & it's not innate - it's learned ! I've put a copy of each in the club so you know what I'm tallking about.
And finally, none of this is about competing with others . It’s an act of artistic creation - an expression of your creative urges & capabilities . In time, you’ll find your own unique style & increasing level of excellence if you choose to be kind & patient with yourself . Allow yourself the freedom to create & keep working at it . You’ll make mistakes - learn from them rather than permit them to embarrass or discourage you .
Handcoding is EASY once you get the hang of it & best of all - it’s cheap ! It’s a great way to begin learning how to build in 3d . In learning VRML code, you’ll establish a solid foundation of understanding that will stand you in good stead whether you are creating canvasses for your etchings & photos, or complex objects & worlds .
- * * * * * * * * * * * * * * * * * * *
SETTING UP AN OBJECT FILE
All code, VRML & HTML included, begins with a simple ON switch that must be included in order for a browser to recognize what it's reading & present it back to you in the desired form. So here’s the #1 rule of VRML handcoding :
Turn ON your code ! And here’s how you do that :
At the beginning of every object or world you make (not at the beginning of each piece that makes up an object or world) put this on the 1st line:
#VRML V2.0 utf8
What this basically says to a browser is “Heh, use a programme that translates VRML into 3d objects. Use version 2 ”. This is the coding that commences the reading of your script - the button that turns the Blaxxun plugin on. The plugin will translate & a browser will read each line in the script that follows except for ....
Every line that you start with a # which will be avoided by your browser for translation into a 3d object. So you can use the # to leave notes for yourself here & there. For example, when you’re making an object you might want to use notes to mark the places in your code where all of the codes for the table legs are located, or the stools, or the animated objects, or for adding titles over sections of code. The # is a handy tool that will help you not get lost in your own code. Here are some examples of how you might use it :
#1stfloor-rearhousewalls #chairback-spindles #trees
- * * * * * * * * * * * * * * * * * * *
ABOUT BRACKETS
The coding for each piece you create as part of your world will contain a whole lot of brackets of various sorts - { [ } } ( ). Brackets define the boundaries of characteristics as well as the boundary of an entire object or piece of it. Pay careful attention to the use of them - they are VERY specific & NOT interchangeable.
You'll have to be very careful when you're typing or copy/pasting code. You must be ABSOLUTELY ACCURATE ! Handcoding allows for no errors, not even a tiny comma or period’s worth of error. So as you are working your way through these tutorials make certain you copy everything accurately & put everything where it is placed in the examples.
- * * * * * * * * * * * * * * * * * * *
Before I go further, one last attempt at convincing you of the value of learning how to hand-code VRML. What follows is a comparison of the file sizes of a hand-coded box & one produced in a programme ( in this case, Spazz ).
Why am I handcoding instead of just using a programme?
There are some good reasons for learning handcoding even if one intends to continue creating using a programme. File optimization is foremost amongst the very good reasons for learning handcoding. Once you learn how to handcode, you can go over your output from a programme & tighten up the coding, reducing filesize sizes significantly.
To give you an idea of the difference between the coding output of Spazz & that of handcoding, we're going to examine the example of a simple Box. Here's the coding for a very elegant & very simple handcoded Box :
Transform { translation 0 0 0 children [
Shape { appearance Appearance {
material Material { diffuseColor 0.2 0.3 0.2 }}
geometry Box { size 50 0.1 50 }}
]}The filesize for the above Box ( including WorldInfo ) comes in at 255 bytes.
Here is the same Box produced in Spazz :
Transform { translation 0 1 0 children [
DEF dad_GROUND Transform {
children [
DEF GROUND Group {
children [
DEF dad_Box1 Transform {
children [
DEF Box1 Shape {
appearance Appearance {
material DEF Shiny_Purple_mat Material {
ambientIntensity 0.200
shininess 0.100
diffuseColor 0.9176 0.0 0.874
emissiveColor 0.0 0.0 0.0
specularColor 0.9176 0.0 0.874
}
}
geometry Box {
size 2.0 2.0 2.0
}
}
]
}The filesize for this Box ( including WorldInfo ) is 513 bytes - OVER TWICE the filesize of the handcoded version ! Expand this to include all of the pieces of a complex object or world & you can see how incredibly wasteful unedited Spazz files were. Regardless of the programme you use, you can trim off a fair amount of filesize by simply collaping lines together, getting rid of unnecessary DEFs, deleting unnecessary decimal points & zeros, & collapsing brackets.
An edited Spazz file for the above Box might look something like this :
Transform { translation 0 1 0 children [
Shape { appearance Appearance {
material Material { ambientIntensity 0.2 shininess 0.1
diffuseColor 0.9176 0 0.874 emissiveColor 0 0 0
specularColor 0.9176 0 0.874 }}
geometry Box { size 2 2 2 }}
]}Even this much editing would reduce your filesize to almost the same size as the handcoded version. Worth the effort.
Thanks to chiromancer for providing the coding script for the Spazz-produced & handcoded boxes !