Beginning VRML2Hi all,
VRML is an ever growing technology that enables web developers to display 3D objects and environments in a web browser. You’ve probably heard of VRML from the newsteller, that’s why I wanted to make a tutorial to introduce it in a better way.
Through this tutorial you will get to know the basics of VRML and its main components and shapes
the file extension associated with VRML is “.wrl” which is basically a text file with unique structure similar to HTML, to display the 3D objects in your browser you will only need to install relatively small plug-in for your browser –I’ve attached a plug-in
The structure of a typical .wrl file contains three elements:
• File header
• Comments
• Scene graph
Header
The file header looks like this:
Notice that it starts with a ‘#’ and there’s a space between ‘VRML’ and V.2 which indicated the version of VRML you are using, and utf8 indicates the Encoding type that you use which is (UCS Transformation Format and its 8bit)Code:#VRML V.2 utf8
Comments
Comments start with a ‘#’ sign except the first line because it’s the header (ex:# this line is a comment).
Scene Graph
The rest of this tutorial will be about the scene graph.
Scene Graph is a Collection of nodes that draws or describes the shapes that we want to draw and how these shapes appear (lights, textures ….). Each node in a Scene graph may contain zero or more fields and each field can be assigned with values or left blank, I bet you have lost me so lets view a simple example:
There are 54 types of nodes in VRML, Objects of VRML are placed inside a main node that’s called “shape” which contains another 2 nodes (appearance and geometry) , the appearance node that specifies how (not what) the object will be displayed in this example we used a texture with the path to a “.jpg” file.Code:#VRML V2.0 utf8 # You can write this text in a text document and save it as “.wrl” Shape{ appearance Appearance{ texture ImageTexture { url "codecall.JPG" } material Material{} } geometry Box{ size 4 2 2 } }
And the geometry node identifies what object geometry to draw and it has one field (size) that specifies the dimensions of the box (x,y,z)
When you view this .wrl file in your browse it will look like this:
Now let’s take a brief look at the available shapes that we can use:
1. Box
2. Cone
3. Cylinder
4. Sphere
5. Text
-No explanation needed for the box shape we already used it
Cone
-the cone has two fields that we can customize: height and bottom radius
cylinderCode:Shape{ appearance Appearance{ material Material{} } geometry Cone{ height 7 bottomRadius 3.5 } }
-the cylinder has two fields the height and the radius:
SphereCode:geometry Cylinder{ height 3 radius 2 }
-the sphere has one field: the radius
Text
In this one we have 1 field and one node , the first field is the “string” value(s) that we want to write and the node contains various fields related to the font, size and spacing. in the style field we can use bold, italic, bolditalic, or plain (notice that they are all in lowercase).the spacing is the vertical spacing between each string we have.Code:Text{ string [ "CodeCall.Net" , " While(true)" ] fontStyle FontStyle{ style "italic" size 3.0 spacing 1.0 } }
Here is the final output of the previous code:
--------------------------------------------------------------------
Transform Node
-Till now we know how to draw a single shape in one VRML, but we have a problem; if we try to draw more than one shape they will collapse because the are all drawn in the same position , that’s why we will need the “Transform Node”
The Transform node includes the translation (position), rotation and scaling. A typical fields of and transform node can look like this:
The above code X,Y, and Z represent float variables . in the rotation field we specified the direction of the rotation and the angle, for example this line(rotation 0.0 1.0 0.0 .5) will rotate the shape around the y axis for .5 angle (90degree) . The “scale” node will resize the shape according to the values you assign to x,y and z.Code:Transform{ translation X Y Z rotation X Y Z angle scale X Y Z Children[……] }
The children node will contain the shapes that we want to draw, now lets test this node:
Notice we have two Transform nodes, in the first node we inserted two shapes that’s why they collapsed into one we can separate them by making a third Transform node and assigning different position.Code:#VRML V2.0 utf8 Transform{ translation 3.0 4.0 00 rotation 0.0 0.0 1.0 1.0 scale 1.0 0.5 1.0 children[ Shape{ appearance Appearance{ material Material{} } geometry Cylinder{ height 3 radius 2 } } Shape{ appearance Appearance{ material Material{} } geometry Cylinder{ height 8 radius 0.1 } } ] } Transform{ translation -2.0 0.0 00 rotation 0.0 0.0 0.0 0.0 scale 1.0 0.5 1.0 children[ Shape{ appearance Appearance{ material Material{ diffuseColor 0.0 0.5 1.0 specularColor 0.5 1.0 0.0 ambientIntensity 0.5 transparency 0.2 shininess 10 } } geometry Text{ string [ "CodeCall.Net" , " While(true)" ] fontStyle FontStyle{ style "italic" size 3.0 spacing 1.0 } } } ] }
Now lets take a brief look at the Material node, which controls the values of color and lightening and transparency:
• diffuseColor: is the dominant color of the shape and take three values
• specularColor: is a highlight Color
• ambientIntensity: specifies the amount of ambient light (brightening and darkening)
• transparency: takes one float value and ranges from (0.0 to 1.0) 0.0 means its transparent
• shininess: takes one value which determines the highlight size
And here is the final output:
I hope you liked this tutorial, don’t hesitate to ask anything or comment
All the previous .wrl files and plug-in are in the attachments
**sorry for my English
Amr
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
www.amrosama.com | the unholy methods of javascriptCode:eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
Very nice tutorial.
thnx wp
i was starting to worry for not showing up
Last edited by amrosama; 11-02-2008 at 09:32 AM.
Awesome tutorial! +rep
Good Tutorial .. +rep when it allows me to![]()
Haha
its okay i didnt make it for rep points anyway![]()
I haven't read it just yet because I am busy, but a quick scan of it and the outcomes are REALLY good! +rep
Can't +rep ATM
Also, just a note.
GET RID OF IE![]()
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
love is blind brandon
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
www.amrosama.com | the unholy methods of javascriptCode:eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
What does that mean amro?
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
im loyal to internet explorer
but the pc i was using while writing the tutorial had tint processor and ram so i used Ie because it opens fast
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
www.amrosama.com | the unholy methods of javascriptCode:eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks