Você está na página 1de 5

Easy Examples in VRML

Pgina 1 de 5

Basic VRML and Easy Examples


*text adapted from an original by Randy Appleton

Info
This is a basic short introductory text. Full VRML 2 details can be found on the Annotated VRML 97 Reference Manual (http://accad.osu.edu/~pgerstma/class/vnv/resources/info/AnnotatedVrmlRef/Book.html) VRML code editors Like HTML, VRML files are plain* text files (with the extension .wrl) edited by any code editor (even the very basic ms windows notepad). (*) wrl files can optionally be compressed in gzip (keeping the wrl extension) since most VRML/X3D viewers/plugins can uncompress them, on the fly. Some free compressors, like 7-Zip, can uncompress/compress in gzip format. Specialized VRML editors like VRMLPad can also compress/uncompress VRML files. VRML Basics The basic idea is to make a text file describing the world you want. The text file will consist of one header, and then definitions and nodes. All comments in VRML start with a '#'. VRML is case sensitive, so get the capitalization right! The header MUST look like this, and must be on the VERY FIRST LINE. #VRML V2.0 utf8

VRML Nodes
A VRML world is just a set of nodes. Each node will have a type, scale, rotation, translation, color, texture, and some others. There will often be useful defaults for all these properties. Nodes have four basic types: infomational, grouping, shape, and transformational. An informational node just carries comments by the author. A grouping node makes many other nodes into one node for easy processing. A shape node is basic shape, like box, sphere, etc. A transformational nodes gives all child nodes a common property, for example scale or color.

VRML Axes and Rotations


Remember that VRML uses the following axes system ... Rotations in VRML work by the right-hand rule. If you imagine wrapping your hand around one of the axes, with your thumb pointing in the positive direction, the direction of positive rotation is the same as the direction that your fingers wrap around in. If you want to rotate an object 90 degrees away from you around the X axis, you would use a 90 degree negative rotation. All rotations are measured in radians not degrees. Here is an easy conversion chart ...

Degrees 0 45 90 135 180 225 270 315 360 Radians 0 0.78 1.57 2.36 3.14 3.93 4.71 5.5 6.28

http://www.odisseia.univ-ab.pt/vrml/tutorials/basic/vrml-coding.htm

03-11-2012

Easy Examples in VRML

Pgina 2 de 5

Translation Nodes
A translation nodes changes the shape, size, and/or position of any child nodes. The 'translation' attribute tells where to move along the X, Y, and Z axes. The 'rotation' attribute tells an axis to rotate about, and how much to spin. The 'scale' attribute tells how big the thing should grow in the X, Y, and Z axes. Remember that ORDER MATTERS (translate then rotate is not the same as rotate then translate). An example is shown below. Notice the ordering of the operations.
Transform { scale 2 1 2 rotation 0 1 0 0.78 translation 1 1 1 children [ USE FBOX ]

Material Nodes
A material node describes the appearance of any child nodes. A material node can have up to six attributes: Name Description Arguments A Color diffuseColor The normal colour of the object. Triple A Color specularColor The colour of highlights on shiny objects. Triple The object 'glows' with a light of it's own of this colour. It doesn't A Color emissiveColor cast light on any other objects though. Triple ambientIntensity The amount of ambient light that the object reflects. Scale 0 ... 1 shininess How reflective the object is. Scale 0 ... 1 How transparent the object is. Note, some browsers will not transparency Scale 0 ... 1 support partly-transparent objects. An Example of a semi-transparent green box looks like this...
Shape { appearance Appearance { material Material { diffuseColor 0 0.5 0 emissiveColor 0 0.8 0 transparency 0.5 } } geometry Box { } }

ImageTexture and MovieTexture Nodes


An imageTexture node makes all of it's children have a specific picture for a background. Basically, you just tell it the URL, and wether to tile the picture horizontally and vertically. The standard says only JPG files can be used, but the Cosmo player can also use GIFs. A movieTexture node shows an MPEG movie on the surface. It has all the attributes above, plus 'speed' and 'loop'. MovieTexture can be unreliable, so be warned.

http://www.odisseia.univ-ab.pt/vrml/tutorials/basic/vrml-coding.htm

03-11-2012

Easy Examples in VRML

Pgina 3 de 5

Appearance { texture ImageTexture { url "brick.jpg" repeatS TRUE repeatT TRUE } }

Appearance { texture MovieTexture { url "random.mpg" repeatS TRUE repeatT TRUE speed 2 loop true } }

Summary So Far
You've gotten all of this if you can make this scene. The balloon JPG is balloons.jpg .

Shape Nodes
Box, Cone, Sphere and Cylinder are known as "primitive solids" or primitive shapes.

The basic vrml shapes include the primitive solids and other. geometry Box { size 5.5 3.75 1.0 } geometry Cone { bottomRadius 5 height 10 side TRUE #this isn't actually needed bottom FALSE } geometry Sphere { radius 10,000,000 } geometry Cylinder { radius 0.5 height 10 top FALSE bottom TRUE side TRUE } ElevationGrid { xDimension 6 zDimension 6 height [1.5, 1, 0.5, 0.5, 1, 1.5, 1, 0.5, 0.25, 0.25, 0.5, 1, 0.5, 0.25, 0, 0, 0.25, 0.5, 0.5, 0.25, 0, 0, 0.25, 0.5, 1, 0.5, 0.25, 0.25, 0.5, 1, 1.5, 1, 0.5, 0.5, 1, 1.5] xSpacing 5.0 zSpacing 5.0 }

geometry Text { string ["Hello", "World"] fontStyle USE HELLOFONT maxExtent 5 length [3, 3] }

Easy Example VRML Files


http://www.odisseia.univ-ab.pt/vrml/tutorials/basic/vrml-coding.htm 03-11-2012

Easy Examples in VRML

Pgina 4 de 5

#VRML V2.0 utf8 Shape { appearance Appearance { material Material { } } geometry Box { } } DEF FBOX Shape { appearance Appearance { material Material { } } geometry Box { } } USE FBOX #VRML V2.0 utf8 DEF FBOX Shape { appearance Appearance { material Material { } } geometry Box { } } Transform { scale 2 0.5 2 rotation 0 1 0 0.78 translation 0 -1.5 0 children [ USE FBOX ] } #VRML V2.0 utf8 Shape { appearance Appearance { material Material { diffuseColor 0 0.5 0 emissiveColor 0 0.8 0

A Simple Box

Reuse Demo Can you find the bug in this file?

Transform Example

Semi-transparent Green Box


transparency 0.5 } } geometry Box { } } #VRML V2.0 utf8 Shape { appearance Appearance { texture ImageTexture { url "balloons.jpg"

http://www.odisseia.univ-ab.pt/vrml/tutorials/basic/vrml-coding.htm

03-11-2012

Easy Examples in VRML

Pgina 5 de 5

repeatS TRUE repeatT TRUE } } geometry Box { } }

Texture Demo

Atividade Formativa
Usando as formas primitivas (primitive shapes) e outras crie os seguintes objetos e exiba-os no Frum:

um carro bsico (pode ser parecido aos brinquedos de madeira: exemplo carro de madeira aqui) Uma casa bsica, muito simples (pode tambm ser como um brinquedo de madeira) Um boneco de neve Faa outros objetos sua escolha,

Nota: comece por criar objetos simples/toscos, mas depois no se coiba e melhore-os; pode at adicionar texturas

http://www.odisseia.univ-ab.pt/vrml/tutorials/basic/vrml-coding.htm

03-11-2012

Você também pode gostar