

























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


























































A Course Module by West Virginia University for the SEPSCoR Project Frances L. Van Scoy Eric Martino Young Oh Jeremy Jarrells Chris Coleman April 24, 2000 draft
Advantages of VRML VRML (Virtual Reality Modeling Language) is a language for constructing 3-d models. These models man include animations and sounds and allow interaction with users. Two major advantages of using VRML are: (1) models are represented in ascii text files whose format is well-documented (2) models can be built using any text editor and viewed using a free plug-in to a web browser This means that we can build VRML models without buying additional software and hardware. However, many commercial modeling packages are able to import and export VRML models, allowing users to build more complex models than could be easily built from scratch using only a text editor. VRML files On most systems a VRML file must end with extension .wrl For the version of VRML taught in this course, the first line of the VRML file must be #VRML V2.0 utf A Simple Example Here is a simple example of VRML code to model a yellow cylinder. #VRML V2.0 utf Shape{ appearance Appearance { material Material { diffuseColor 1 1 0 } } geometry Cylinder { bottom TRUE
height 2 radius 1 side TRUE top TRUE } } Examples of More Complex Models Some examples of more complex VRML models are available on-line at: http://web3d.about.com/compute/web3d/msubmenu2.htm Additional Information Information on the history of VRML, documentation of the language, and sites for downloading plug-ins are available at: http://www.vrml.org http://www.sdsc.edu/vrml Overview of This Course Module This Course Module is in 12 parts. This Introduction (1) Simple Objects (2) Translation, Rotation, and Scaling (3) Colors and Other Material Properties (4) Extrusions (5) Prototypes (6) Viewpoints and Texture Maps (7) Animation (8) Interaction and Sound (9) Scripting
A VRML file contains a set of nodes. In this chapter we look at Shape nodes, which are used to model 3-d objects. In particular, we'll learn how to build boxes, spheres, cylinders, and cones and how to add text to a model. A Shape node contains two fields, an appearance field and a geometry field. The appearance field describes properties such as shininess and color and will be described in lesson 3. The geometry field describes the geometric properties of the shape. The geometry field contains a node which gives the information about the geometric properties of the shape. VRML provides nodes called Box, Cone, Cylinder, and Sphere which are used to define simple goemetric shapes and a node called Text which describes the properties of character strings to be displayed. By default a VRML shape is built with its center at the origin of 3-d Cartesian space. We'll see in chapter 2 how to change the location of the center of the shape and how to combine several shapes into one object. The Coordinate System VRML uses a right hand coordinate system, as shown below. ^ | | y-axis |
/ x-axis z-axis / v Unless a transformation is specified, a VRML shape is modeled with its center at the origin. The axis of a cylinder is parallel to the y axis as is the axis of a cone.
Box A Box is a geometry node which represents a rectangular prism centered at (0,0,0). A Simple Example of a Box #VRML V2.0 utf Shape { appearance Appearance { material Material { diffuseColor 0 0 1 # Color is blue } } geometry Box { # primitive shape size 4 3 2 # size of object } } The parameters of the size field describe how large the box is in each direction. In this example the box is 4 units long in the x direction, 3 units long in the y direction, and 2 units long in the z direction. Since a box by default is centered at the origin, the extent of the box is -2 ≤ x ≤ 2, -1.5 ≤ y ≤ 1.5, and -1 ≤ z ≤ 1. Except for in the first line of the file, a '#' begins a comment which ends at the end of the line. Default Parameter Values for a Box A Box by default is white, centered at the origin, and 2 units in size in each of the three dimensions. Something to Try
#VRML V2.0 utf Shape { appearance Appearance { material Material { diffuseColor 0 1 1 } } geometry Cylinder { bottom TRUE # boolean value height 2 # float value radius 1 # float value side TRUE # boolean value top TRUE # boolean value } } Something to Try Build three concentric hollow cylinders, each a different color and with different height and radius.
Cone A cone by default has its tip at the top and is base at the bottom. Its axis is parallel to, and actually coincident with) the y-axis. The point in the center of the circular cross section half way between the tip and the base is by default located at the origin. A Simple Example of a Cone #VRML V2.0 utf Shape { appearance Appearance { material Material { diffuseColor 0 1 0 #Color is green. } } geometry Cone { # primitive shape bottomRadius 1 # float value
height 2 # float value side TRUE # boolean value bottom TRUE # boolean value } } Something to Try Construct a model containing 3 cones of different colors. Choose height and radius for each such that a portion of each cone is visible. Text A Text object is used to display strings of text in a model. The value of the string parameter is one or more strings, each of which is displayed on a separate line. The lengths of the strings are given in a vector The user can change whether the font displayed has serifs or is of fixed-width. By default the first line of text has its baseline on the x-axis and its leftmost character immediately to the right of the y-axis. The text has zero thickness in the z-direction. value of parameter family meaning example sample font name SERIF variable-width, serif abcde Times SANS variable-width, serif abcde Helvetica TYPEWRITER fixed-width abcde^ Courier The length of each line A Simple Example of Text #VRML V2.0 utf Shape { appearance Appearance { material Material { diffuseColor 1 1 0 } } geometry Text { string [ "Hi there!" "How are you?" ] fontStyle FontStyle { family "SERIF" } length [ 6 4 ] # text width of strings } }
Each VRML file has a "world coordinate system." We saw in the previous section that the default position for boxes, spheres, cylinders, and cones is centered at that origin. We use a Transform node to define a "child coordinate system." A child coordinate system may itself contain Transform nodes which define new child coordinate systems. Each child coordinate system may differ from its parent coordinate system in translation, rotation, and scaling. Translation A translation of a coordinate system is a shifting of the axes by specified amounts in each of the 3 coordinate directions while keeping the new axes parallel to the original ones. A Simple Translation Example For example the brown axes show are a transformation by (3 6 9) of the black axes.
This could be described in a VRML model by
Example of a One-Layer Birthday Cake Here is a model of a one-layer birthday cake. It consists of a large white cylinder, representing the cake itsself, a tall thin green cylinder representing a candle, a small yellow sphere representing a flame, and red text saying "Happy Birthday!" We use the translation field of a Transform node to specify the location of the center of each geometric object with respect to the origin of the world coordinate system. #VRML 2.0 utf Shape { appearance Appearance { material Material { diffuseColor 1.0 1.0 1. } } geometry Cylinder { radius 3
height 2 side TRUE top TRUE bottom TRUE } } Transform { translation 0.0 3.0 0. children [ Shape { appearance Appearance { material Material { diffuseColor 0.0 0.8 0. } } geometry Cylinder { radius 0. height 4 side TRUE top TRUE bottom TRUE } ] } Transform { translation 0.0 5.35 0 children [ Shape { appearance Appearance { material Material { emissiveColor 1.0 1.0 0. } } geometry Sphere { radius 0. } } ] } Transform { translation 0 -3 0 children [ Shape { appearance Appearance { material Material { emissiveColor 1 0 0 }
Example of a Snowman We combine translation fields and a rotation field to build a snowman as shown.
This example uses a Group node to combine several objects into one. The Group node can be used in conjunction with the USE (to be discussed in lesson 5) to build more sophisticated complex shapes. #VRML V2.0 utf Group { children [ Shape { appearance Appearance { material Material { diffuseColor 1 1 1 } } geometry Sphere { radius 2 # bottom of snowman } } Transform { translation 0 2 0 children Shape { appearance Appearance { material Material {
diffuseColor 1 1 1 } } geometry Sphere { radius 1 # middle part of snowman } } } Transform { translation 0 3.3 0 children [ Shape { appearance Appearance { material Material { diffuseColor 1 1 1 } } geometry Sphere { radius 0.5 # snowman's head } } Transform { translation 0 0 .8 # snowman's nose rotation 1 0 0 1.57 # rotate cone 90 degrees along x-axis. Cone is now horizontal. children [ Shape { appearance Appearance { material Material { diffuseColor 1 0 0 emissiveColor .5 0 0 # cone gives off it's own color } } geometry Cone { bottomRadius. height. side TRUE bottom TRUE } } ] }
description "Front view" } Viewpoint { fieldOfView 0.785398 # exposedField SFFloat jump TRUE # exposedField SFBool orientation 0 1 0 1.57 # exposedField SFRotation position 10 2 0 # exposedField SFVec3f description "Side view" } The two Viewpoint nodes aren't a necessary part of this model and can be ignored for now. They are here to make it easier to view the snowman in profile to see the orientation of his nose. Most VRML browser plug-ins have a viewpoint control in the lower left corner of the window. Experiment with using this control to view the snowman from two different perpectives. Scaling
#VRML V2.0 utf Transform { translation 2 -2 0 scale 3 1 1 scaleOrientation 0 1 0 -0. rotation 0 0 1 0. center 0 1 0 children [ Shape { appearance Appearance {material Material{}} geometry Cone{} } ] }
Order of Operations Assignment Construct a model of a multi-layered cake, with each layer smaller in radius than the one below it.