vrml tutorial

Upload: nany19901911

Post on 08-Apr-2018

224 views

Category:

Documents


2 download

TRANSCRIPT

  • 8/7/2019 VRML tutorial

    1/59

    VRML File Structure

    A VRML file always starts with the header:

    #VRML V2.0 utf8The identifier "utf8" which appears on the header lets youuse international characters in your VRML models.Comments start with #, all characters until the end of the linebeing ignored.After the header the following can appear:nodesprototypesroutesIn the next sections one shall see what each of the above isused for.Note: For precise syntax and semantic definition pleaseconsult the VRML 2.0 Specification.The color model in VRML is RGB. In order to define a colorthree values are needed: Red Green and Blue, these valuesare between 0.0 and 1.0. For instance 0.0 0.0 0.0 is Black,0.0 0.0 1.0 is Blue, and 1.0 1.0 1.0 is White.The units in VRML are assumed to be meters. Although youdo not have to follow this convention it is advisable that you

    do. If everyone follows this convention then all worlds will bescale compatible.The angles in VRML are measured in radians, not indegrees.

    Shape Node

    All visible objects are defined inside a Shape node. This node has two fields: appearance andgeometry.The appearance field specifies an Appearancenode which is used to define color, texturesand so on to be applied to the geometry, the geometryfield indicates which shape is to bedrawn.

    Syntax:

    Shape {

    appearance NULLgeometry NULL

    }

    The appearance field is optional, if nothing is said the default values will be used.

    the value for the geometry field may be any of the following Nodes:BoxCone

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?routehttp://www.web3d.org/technicalinfo/specifications/vrml97/index.htmhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?appeahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?appeahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?boxhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?boxhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?conehttp://www.web3d.org/technicalinfo/specifications/vrml97/index.htmhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?appeahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?boxhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?conehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?route
  • 8/7/2019 VRML tutorial

    2/59

    CylinderElevationGridExtrusionIndexedFaceSetIndexedLineSetPointSet

    SphereText

    Box Node

    The Box node defines a rectangular parallelepiped box which allows you to specify the width,height, and depth of the box.

    The node contains a single optional field size which has three floating point values, the defaultvalues being applied if the field is not specified.

    Syntax:

    Box {

    size 2.0 2.0 2.0

    }

    The center of the box is at (0,0,0) of the local coordinate system.

    Sphere Node

    The Sphere node has a single field which allows you to specify its radius.The radius field is optional, if a radius is not specified then the radius is 1.0.

    Syntax:

    Sphere {

    radius 1.0

    }

    The center of the sphere is at (0,0,0) of the local coordinate system.

    Cone Node

    The Cone node lets you specify not only the height and radius but also which parts you wantto draw.This node contains four fields: bottomRadius, height, side, and bottom.The bottomRadius andheightfields define the geometrical properties of the cone. The valuesfor these fields must be greater than 0.0.The side and bottom specify which parts of the cone are to be drawn. These two fields takeboolean values. For instance ifside is FALSE then only a circle, the bottom of the cone, is

    drawn. When drawing only a part of the shape note that only one side is lit, the opposite sidebeing black.

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?cylinhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?elevghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?extruhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indfshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indlshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indlshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?pshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?cylinhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?elevghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?extruhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indfshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indlshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?pshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?text
  • 8/7/2019 VRML tutorial

    3/59

  • 8/7/2019 VRML tutorial

    4/59

    }

    IndexedLineSet Node

    The IndexedLineSet node specifies a set of polylines in the local coordinate system andassociated colors.This node contains five fields: coord, coordIndex, color, colorIndexand colorPerVertex.The coordfield specifies a Coordinate node. In this node a set of 3D coordinates are given.The coordIndexfield specifies a list of coordinate indexes defining the polylines to be drawn.To separate the indexes from one polyline a space is used, to separate the sets of indexesfrom two adjacent polylines the marker -1 is used, i.e. an index of -1 indicates that the currentpolyline has ended and the next one begins.The colorfield defines a Colornode. This node defines a list of colors to apply to thepolylines. The coloris optional, the default values being applied if the field is not specified. If a

    Material node is specified the default color is the emissive color from this node. Note that boththe default emissive color and background are black, so if no color is specified and the defaultbackground is used you won't be able to see the lines.The colorIndexserves the same purpose has the coordIndexbut regarding colors.The colorPerVertex is a boolean field which defines how the colors are applied. colorPerVertex is TRUE: colors apply to each vertex. The final result is that each linestarts in one color and ends with another color, producing a gradient effect. On somebrowsers the color for each line will be the average color for the two ends of the line. Theremust be as many indices in colorIndexas in coordIndexwith the end-of-polyline markers,-1, inexactly the same place. If the colorIndexis absent then the coordIndexis used to select thecolors and there must be as many colors as indices in coordIndex. colorPerVertex is FALSE: colors apply to each polyline. There must be at least as manyindices in the colorIndexas there are polylines. If the coordIndexfield is absent then the

    colors are applied in the order presented in the colorfield.Before presenting the syntax let's see some examples. In all the examples presented, thecoord field has the following coordinates: 0 0 0 1 1 0 -1 0 0 -1 -1 0 Playing with coordIndex

    Playing with colors: The colors specified are Red, Green and Blue

    colorPerVertex TRUE colorPerVertex FALSE

    colorIndex [0 1 2 0 ] colorIndex [0 1]coordIndex [3 0 2 1] coordIndex [0 1 -1 2 3]

    Note: On the example which had colorPerVertexset to TRUE the colors presented for eachline are the average color from the two colors defined for the end of each line.

    Syntax:

    IndexedLineSet {

    coord NULLcoordIndex [ ]color NULL

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?coordhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?colorhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?materialhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?coordhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?colorhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?material
  • 8/7/2019 VRML tutorial

    5/59

    colorIndex [ ]colorPerVertex TRUE

    }

    IndexedFaceSet Node

    The IndexedFaceSet node specifies a set of planar faces in the local coordinate system.The coordfield specifies a Coordinate node. In this node a set of 3D coordinates are given.The coordIndexfield specifies a list of coordinate indexes defining the faces to be drawn. Toseparate the indexes from a face the marker -1 is used, i.e. an index of -1 indicates that thecurrent face has ended and the next one begins.Because the faces are always defined by closed polylines, you don't need to define the firstpoint twice. Consider the following values for coord:

    coord Coordinate{point [ 0 0 0, 1 0 0, 1 1 0, 0 1 0]}

    Four points are defined, when you join the points you can make a square face. ThecoordIndexused for a square face could be:

    coordIndex [ 0 1 2 3]What the above coorIndexmeaning is: Join the first point in the coordinate list to the secondpoint, then join the second to the third, the third to the fourth, and finally the fourth to the firstto close the region which defines the shape.The colorfield defines a Colornode. This node defines a list of colors to apply to the faces.The coloris optional, the default values being applied if the field is not specified. If aMaterialnode is specified the default color is the emissive color from this node. Note that both thedefault emissive color and background are black, so if no color is specified and the defaultbackground is used you won't be able to see the faces.The colorIndexserves the same purpose as the coordIndexbut regarding colors. IFcolorIndexis not specified then coordIndexis used instead.The colorPerVertex is a boolean field which defines how the colors are applied. The meaningis similar to theIndexedLineSet case.texCoordspecifies aTextureCoordinate node.texCoordIndex has a similar meaning to coordIndex but applied to Textures.There are 3 normal fields which have the same meaning than the color fields but applied tonormals. The normal field defines a Normal node.The ccwfield specifies if the points which define a face are present counterclockwise, TRUE,or clockwise or unknown order, FALSE. A face has two sides and sometimes it is important toknow which is the front side, and which is the back side. So let's assume you're defining asingle face perpendicular to the Z axis and ccwis TRUE. If the face is definedcounterclockwise then the front side is the side facing you. Otherwise the back side is facing

    you. Ifccwis FALSE then the opposite occurs.The solidfield determines if the browser should draw both sides of a face or just the frontside. VRML assumes by default, solidis TRUE that the faces in an IndexedFaceSet form asolid shape. In this case there is no need to draw the back sides of each face. IfsolidisFALSE then the browser will draw both sides of each face.The convexfield specifies if the faces being defined in coordIndexare convex or not. VRMLcan only draw convex faces. When presented with concave faces, the browser splits the faceinto smaller convex faces. This is a time consuming task. If you are sure that all your facesare convex then setting this field to TRUE tells the browser not to worry splitting the faces,and therefore saving time. The creaseAngle specifies an angle threshold. If two adjacentfaces make an angle bigger than the creaseAngle then you'll see clearly where the two facesmeet, the edge linking the two faces is sharp. Otherwise the edge linking the two faces will besmooth.

    Syntax:IndexedFaceSet {

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?coordhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?colorhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?materialhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?materialhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indlshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indlshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texcohttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texcohttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?normahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?normahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?coordhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?colorhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?materialhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indlshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texcohttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?normahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?norma
  • 8/7/2019 VRML tutorial

    6/59

    coord NULLcoordIndex [ ]color NULLcolorIndex [ ]colorPerVertex TRUEnormal NULL

    normalIndex [ ]normalPerVertex TRUEtexCoord NULLtexCoordIndex [ ]ccw TRUEconvex TRUEsolid TRUEcreaseAngle 0.0

    }

    Extrusion Node

    The IndexedFaceSet node although a very powerful node, requires you to define all the facesin the shape. For certain shapes this requires loads of points and faces. For other shapes thisis almost impossible. For instance consider designing a sphere with an indexed face set.Extrusion is a very powerful node which allows you to define very complex shapes using onlya small amount of points.

    Syntax:

    Extrusion {

    beginCap TRUEendCap TRUE

    ccw TRUEconvex TRUEcreaseAngle 0crossSection [1 1,1 -1, -1-1, -1 0, 1 1]orientation 0 0 1 0scale 1 1solid TRUEspine [0 0 0, 0 1 0]

    }

    The basis of an extruded shape is a 2-D cross section of the final shape. For example,consider a cube. The cross section is a square. Cross sections are defined in the XZ plane.

    The cross section for a cube could be defined using the following points:

    Note the Z axis orientation, the Z axis is positive downwards, not upwards. In 3D, using thedefault View Point this means that points closer to you have a higher Z value than points

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?indfshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?viewhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indfshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?view
  • 8/7/2019 VRML tutorial

    7/59

    further away.Another concept needed in an extrusion is the spine. The spine defines the path that thecross section will travel to create the shape. In the above example, trying to build a cube, onecould start with the cross section at (0,-1,0) and move it upwards to (0,1,0). The followingfigures shows this spine for the cube, and the respective path for the cross section.

    The spine in the above figure is defined by two points, (0,-1,0) and (0,1,0). The list of stepsthat the browser does to draw an extruded shape with two spine points are:

    Translate the cross section to the first spine pointReorient the cross section, defined in the XZ plane so that the Y axis coincides with the

    direction obtained with the two spine points (in the example above this step is not necessary).Move the cross section to the last spine point. When executing the last step the browser

    will create the side walls of the cube. The end result is presented in the following figure.

    Source code for the above figure (without the axes)

    Example:#VRML V2.0 utf8Transform {

    childrenShape{ appearance Appearance { material Material {}}

  • 8/7/2019 VRML tutorial

    8/59

    geometry Extrusion{crossSection [ -1 -1, -1 1, 1 1, 1 -1, -1 -1]spine [0 -1 0 , 0 1 0 ]}}}

    The fields beginCap and endCap specify if the extruded shape is open or closed at the ends.For instance if in the above example both endCap and beginCap were set to false thefollowing figure would be produced

    Notice that you can only see two sides of the cube, the ones that face you. This is becausethe field solidis set to TRUE by default. Setting this field to false yields the following result

    In the above examples the spine had only two points. That is the simplest spine you canhave. However there is nothing preventing you from having more spine points, for example todraw a V shape, or even something more complicated.The principle is always the same however there is something which deserves to bementioned. As mentioned before, when using a two point spine, the cross section is orientedso that the Y axis coincides with the direction defined by the two spine points. When usingmore spine points this is only valid for the first spine point. The remaining spine points behaveslightly differently.

    The second and subsequent spine points orient the cross section so that is perpendicular tothe tangent of the spine. The following figure, presented in 2D for simplicity reasons, showsthe cross section orientation in a 3 point spine.

    The points in the figure are the spine points. The dotted lines show the path defined by thespine. At each spine point the cross section's orientation is presented. Note that the cross

  • 8/7/2019 VRML tutorial

    9/59

    section's orientation for the second point is perpendicular to the spine's tangent.A V shaped spine, defined by the points: (3,5,0), (0,0,0), (-3,5,0), with the square crosssection produces the following result:

    Source code for the above figure (without the axes)

    Example:#VRML V2.0 utf8Transform {childrenShape{ appearance Appearance { material Material {}}geometry Extrusion{crossSection [ -1 -1, -1 1, 1 1, 1 -1, -1 -1]spine [3 5 0 , 0 0 0, -3 5 0]}

    }}

    Extrusion can also be used to create surfaces of revolution using a circularspine. Thefollowing example describes how to build a cone by using extrusion as a surface of revolution.The cross section is defined by the following points: (-1,0), (0,0), (-2,-1), (-1,0). Note that thecross section repeats the first point, if you don't do that then you may end up with a non-solidshape. The spine is defined by selecting eight equally spread points in a unitary circle. Thefollowing figure depicts the cross section (note that the Z axis points downwards), and acircularspine defined in the XY plane.

  • 8/7/2019 VRML tutorial

    10/59

    Please take notice of the cross section points. The point (0,0) is the point that coincides withthe spine's point. The end result is the following figure:

    Source code for the example above (without the axes):

    Example:#VRML V2.0 utf8Transform {children

    Shape{ appearance Appearance { material Material { }}geometry Extrusion{crossSection [ -1 0, 0 0, -1 -2, -1 0]spine [1 0 0 , 0.707 0 0.707 , 0 0 1 ,-0.707 0 0.707 ,-1 0 0 ,-0.707 0 -0.707 , 0 0 -1 ,0.707 0 -0.707 ,1 0 0]}}}

    Wait, there's still more, you can scale and orientthe cross section for each spine pointspecified. In the cube example presented above, you can scale the cross section for thesecond spine point by (0,0), thereby reducing it to a point, to obtain a pyramid as in thefollowing figure.

    When using the field scale you either specify one scale for the whole shape, or a list ofscalefactors for each spine point ( note that scales are provided in 2D because they relate to thecross section).Source code for the above figure (without the axes)

  • 8/7/2019 VRML tutorial

    11/59

    Example:#VRML V2.0 utf8Transform {childrenShape{ appearance Appearance { material Material {}}geometry Extrusion{

    crossSection [ -1 -1, -1 1, 1 1, 1 -1, -1 -1]spine [0 -1 0 , 0 1 0 ]scale [1 1, 0 0]}}}

    Or you could twist the spine's path using rotations to obtain the following picture

    Similarly to the scale field, when using the field orientation you either specify one orientationfor the whole shape, or a list oforientation factors for each spine point. Orientations requirefour values each: three to define the axis of rotation and one to define the angle.Source code for the above figure (without the axes)

    Example:#VRML V2.0 utf8Transform {

    childrenShape{ appearance Appearance { material Material {}}geometry Extrusion{crossSection [ -1 -1, -1 1, 1 1, 1 -1, -1 -1]spine [0 -1 0 , 0 1 0 ]orientation[0 1 0 0, 0 1 0 3.14]}}}

    The ccwfield specifies if the points which define the cross section are presentcounterclockwise, TRUE, or clockwise or unknown order, FALSE.The convexfield specifies if the cross section is convex or not. When presented with concave

    cross sections, the browser splits the cross section into smaller convex cross sections. This isa time consuming task. If you are sure that the cross section is convex then setting this fieldto TRUE tells the browser not to worry splitting the cross section therefore saving time.The creaseAngle specifies an angle threshold. If two adjacent faces make an angle biggerthan the creaseAngle then you'll see clearly where the two faces meet, the edge linking thetwo faces is sharp. Otherwise the edge linking the two faces will be smooth.

    ElevationGrid Node

  • 8/7/2019 VRML tutorial

    12/59

    The ElevationGrid node specifies a grid of points, each with a used defined height. This nodeis useful to create meshes, seeLighting, or to build a terrain.An ElevationGrid is built in the XZ plane, starting from the origin and expanding in the positivedirection of the axes. The shape of an ElevationGrid is defined by the following fields:

    xDimension: the number of points in the grid along the X axis.

    zDimension: the number of grid points in the Z axis.

    xSpacing: the distance between two adjacent points in the X axis direction.zSpacing: the distance between two adjacent points in the Z axis direction.height: a list of floating point values specifying the height for each point in the grid. The

    points are ordered left to right and top to bottom.The other fields for this node are:The colorfield defines a Colornode. This node defines a list of colors to apply to the faces.The coloris optional, the default values being applied if the field is not specified. If aMaterialnode is specified the default color is the emissive color from this node. Note that both thedefault emissive color and background are black, so if no color is specified and the defaultbackground is used you won't be able to see the faces.The colorPerVertex is a boolean field which defines how the colors are applied. The meaningis similar to theIndexedLineSet case.

    texCoordspecifies aTextureCoordinate node.There are 2 normal fields which have the same meaning than the color fields but applied tonormals. The normal field defines a Normal node.The ccwfield specifies if the points which define a face are present counterclockwise, TRUE,or clockwise or unknown order, FALSE. A face has two sides and sometimes it is important toknow which is the front side, and which is the back side. So let's assume you're defining ssingle face perpendicular to the Z axis and ccwis TRUE. If the face is definedcounterclockwise then the front side is the side facing you. Otherwise the back side is facingyou. Ifccwis FALSE then the opposite occurs.The solidfield determines if the browser should draw both sides of a face or just the frontside. VRML assumes by default, solidis TRUE that the faces in an IndexedFaceSet form asolid shape. In this case there is no need to draw the back sides of each face. IfsolidisFALSE then the browser will draw both sides of each face.

    The convexfield specifies if the faces being defined in coordIndexare convex or not. VRMLcan only draw convex faces. When presented with concave faces, the browser splits the faceinto smaller convex faces. This is a time consuming task. If you are sure that all your facesare convex then setting this field to TRUE tells the browser not to worry splitting the faces,and therefore saving time. The creaseAngle specifies an angle threshold. If two adjacentfaces make an angle bigger than the creaseAngle then you'll see clearly where the two facesmeet, the edge linking the two faces is sharp. Otherwise the edge linking the two faces will besmooth.

    Syntax:

    ElevationGrid {

    xDimension 0xSpacing 0.0zDimension 0zSpacing 0.0height [ ]color NULLcolorPerVertex TRUEnormal NULLnormalPerVertex TRUEtexCoord NULLccw TRUEconvex TRUEsolid TRUEcreaseAngle 0.0

    }

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?colorhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?materialhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?materialhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indlshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indlshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texcohttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texcohttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?normahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?normahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?colorhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?materialhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indlshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texcohttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?normahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?norma
  • 8/7/2019 VRML tutorial

    13/59

    The following figure depicts the grid built using this node using a list of heights with allelements equal to 0.0.

    Elevation Grid Example:Chessboard

    A chess board is made of 64 tiles, in a 8x8 grid. The tiles are colored black and white, so thattwo tiles sharing a side have different colors.

    As far as defining the tiles, The ElevationGrid for this purpose is as follows:Example:

    geometry ElevationGrid {xDimension 9zDimension 9xSpacing 1zSpacing 1height [0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0

    0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0] }

    Note that the dimensions specified are the number of tiles plus one. The same goes for thelist of heights, there are xDimension x zDimensionheightvalues specified.Now we need to define the colors. First set the field colorPerVertexto FALSE. This impliesthat the colors defined are applied to each square of the chessboard, and not to the vertices.Next set the colorfield to a Colornode with 64 values, alternating between black and white.The complete code is as follows:

    Example:geometry ElevationGrid {xDimension 9

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?elevghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?colorhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?elevghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?color
  • 8/7/2019 VRML tutorial

    14/59

  • 8/7/2019 VRML tutorial

    15/59

    This node is used inside the Text node to specify the display properties of the strings. Thefollowing fields are present: familyspecifies the font family. Values for this field are: "SERIF", "SANS","TYPEWRITER". style specifies the font style. Values for this field are: "PLAIN", "BOLD", "ITALIC",

    "BOLDITALIC". horizontalis a boolean field which specifies if the text is to be displayed horizontally. leftToRightis a boolean field which specifies if the text is displayed left to right or right toleft (Arabic way) topToBottom is a boolean field which specifies if the text is displayed top to bottom orbottom to top (Chinese way). justifyspecifies justification both along the major and the minor direction. If horizontal isTRUE then the major direction is horizontal and the minor direction is vertical, otherwise themajor direction is vertical and the minor direction is horizontal. If only one value is specifiedthen it refers to the major direction. The default value for the minor direction is "FIRST". Thereare four possible values for each justification: "FIRST", "BEGIN" (left justified), "MIDDLE"(centered), and "END" (right justified). "BEGIN" and "FIRST" are equivalent except for theminor direction when horizontalis TRUE (see note bellow).

    language specifies the character set. "en" for English,"en_US" for US english, "zh" forChinese, etc... size specifies character height in VRML units. spacingspecifies the spacing between lines.

    Syntax:

    FontStyle {

    family "SERIF"horizontal TRUEjustify "BEGIN"language ""leftToRight TRUEsize 1.0spacing 1.0topToBottom TRUE

    }

    Important: VRML is case-sensitive, be careful.Note: When horizontal is TRUE the following difference occurs in the minor directionjustification between using "FIRST" and "BEGIN":"FIRST": The baseline of the first line is placed at the X axis."BEGIN": If topToBottom is TRUE the top edge of the first line is the placed at the X axis, elsethe bottom edge of the first line is placed at the X axis.

    Appearance Node

    The appearance node defines the look of the geometry. This node can only be defined insideaShapenode.The fields included in this node are: material, texture, and textureTransform. All fields areoptional but at least one field should be specified.The materialfield contains a Materialnode. This node specifies the color of the associatedgeometry, see the Shape node, and how the geometry reflects light. Note that if this field isNULL or unspecified then alllights defined in the world are ignored when rendering theassociated geometry.The texture field contains one of the texturenodes available: ImageTexture,MovieTexture, or

    PixelTexture. If this field is absent or unspecified no textures are applied to the associatedgeometry.

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?texthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?shapehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?shapehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?shapehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?materialhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?materialhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?shapehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?imagetexhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?movietexhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?movietexhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?pixeltexhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?shapehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?materialhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?shapehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?imagetexhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?movietexhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?pixeltex
  • 8/7/2019 VRML tutorial

    16/59

    The textureTransform field contains aTextureTransform node. This node specifies how thetexture is applied to the geometry.

    Syntax:

    Appearance {

    material NULL

    texture NULLtextureTransform NULL

    }

    Material Node

    The material node specifies color, light reflection and transparency. This node can only bedefined inside anAppearancenode.This node has six fields: diffuseColor, emissiveColor, ambientIntensity, shininess,specularColor, and transparency.The diffuseColorfield defines the color of the geometry. Note: This field is ignored when usingcolored textures.The emissiveColoris used to define glowing objects.The ambientIntensityfield specifies the amount of light reflected by the geometry.The specularColorfield defines the color of the shiny spots of the geometry.The shininess controls the intensity of the glow for the shiny spots, small values represent softglows, whereas high values define smaller and sharper highlights.The transparencyfield controls the transparency of the associated geometry (I know, it is acircular definition...). If a value of 0.0 is specified then the related geometry is completelyopaque, a value of 1.0 means that the geometry is completely transparent.All the "Color" fields have an RGB value associated, i.e., three floating point values between0.0 and 1.0. The other fields have a single floating point value between 0.0 and 1.0.

    Syntax:

    {

    diffuseColor 0.8 0.8 0.8ambientIntensity 0.2emissiveColor 0.0 0.0 0.0specularColor 0.0 0.0 0.0shininess 0.2transparency 0.0

    }

    Textures

    VRML 2.0 allows you to use Images,Movies and Pixel defined images to texture your shapes.When texturing a shape the texture is applied by default to each of the faces of the shape.The following figure shows an example using an image to texture all the primitive shapes:

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?textrhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?textrhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?appeahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?appeahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?appeahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?imagetexhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?movietexhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?movietexhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?pixeltexhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?textrhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?appeahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?imagetexhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?movietexhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?pixeltex
  • 8/7/2019 VRML tutorial

    17/59

    The texture image used in the above example is

    One can also specify in this node if the texture is to be repeated for each of the faces of the shape.The following figure shows an example for a single square face using the same image as abovefor texturing:

    As you can see from the above example the image can be repeated verticaly, horizontaly, both, ornone.There is still more, you can translate, and rotate the texture as the next figure shows.

    In the above example the number of images is set to 4 in both dimensions, the image is translated(see the lower left corner), and finally the texture is rotated roughly 45 degrees (remember that inVRML the angles are measured in radians, the rotation in radians use was 0.75).In order to fully understand the the understanding of the texture coordinate system is needed. Atexture is represented in a 2-D coordinate system (s,t) that ranges from 0 to 1 in both directions.

    The geometric operations mentioned above, scale, translation, and rotation, are aplied in thiscoordinate system.See theTextureTransform and TextureCoordinate (only applies to IndexedFaceSet andElevationGrid) for more detailed information.

    Combining Textures with Materials

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?textrhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?textrhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texcohttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indfshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?elevghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?textrhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texcohttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indfshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?elevg
  • 8/7/2019 VRML tutorial

    18/59

    Image Typescolor: The shape's diffuse color specified in the Material node is ignored.grayscale: The image's gray values are multiplied by the diffuse color.

    The following image shows a grayscale image applied to 4 cubes with different diffuse colors: red,green, blue and white.

    TransparencySome file formats support transparency levels for pixels. PNG fully implements this concept. Notall GIF formats support pixel transparency level, instead a color can be selected to be transparent.

    JPEG file format does not support transparency information.When using an image with pixel transparency, the transparency level overrides the transparencyof the Material node. JPEG file format does not support transparency information.

    ImageTexture Node

    This node specifies the location of the image to be used for texturing the shape, as well as ifthe image is to be repeated vertically, or horizontally, along each of the faces of the shape.Three fields are present in this node: urlwhich specifies the location of the image. Valid image formats are JPEG, GIF andPNG. You can specify multiple locations if you want to, the browser will look for data in thoselocations in decreasing order of preference. repeatSwhich specifies if the image is to be repeated vertically. repeatTwhich specifies if the image is to be repeated horizontally. All fields are optional,the default values being applied if the field is not specified. Note: if you do not specify thelocation of the image, url, then no texturing takes place.

    Syntax:

    ImageTexture {

    url [ ]repeatS TRUErepeatT TRUE

    }

    Image File Formats in VRML The following formats should be recognized by VRML browsers:JPEG, JPG: Joint Photographic Experts GroupGIF: Graphical Interchange FormatPNG: Portable Network Graphics From the above formats JPEG is the only one which

    does not allow images to have transparent pixels.Note: for the example on the right the image will be repeated twice in each direction if thevalues forrepeatSand repeatTare set ot TRUE. See the node TextureTransformto see howto set the repetition rate.

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?materialhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?materialhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?textrhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?textrhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?materialhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?materialhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?textr
  • 8/7/2019 VRML tutorial

    19/59

    MovieTexture Node

    This node specifies the location of the movie to be used for texturing the shape. The moviemust be in the MPEG format. , as well as if the image is to be repeated vertically, orhorizontally, along each of the faces of the shape.The following fields are present in this node: loop specifies if the movie is to play repeatedly, see notes after field definition. speedspecifies how fast the movie will play, for instance ifspeedis 2 then the film willplay twice as fast. Negative speeds play the film backwards. startTime specifies the starting Time of the movie in seconds. The value of this field is thenumber of seconds since midnight, January the first, 1970. stopTime specifies the stopping time of the movie in seconds. The value of this field is thenumber of seconds since midnight, January the first, 1970. urlwhich specifies the location of the movie. You can specify multiple locations if you wantto, the browser will look for data in those locations in decreasing order of preference. repeatSwhich specifies if the movie is to be repeated vertically.

    repeatTwhich specifies if the movie is to be repeated horizontally. Notes:In VRML the world was created at midnight, January the first, 1970. Some say that the reason for choosing this date as the beginning of time as to do with the birth of the Unixsystem.

    If the loop is set to TRUE and startTime >= stopTime then the movie will run forever.However ifstartTime < stopTime the movie will stop as soon as stopTime is reached.

    If startTime >= stopTime then the movie should start as soon as startTime is reached.Note that some browsers only start the movie when startTime > stopTime. This is because inthe early drafts of the VRML 2.0 specification this later condition was required to start themovie. All fields are optional, the default values being applied if the field is not specified. Note:if you do not specify the location of the movie, url, then no texturing takes place.

    Syntax:

    MovieTexture {

    loop FALSEspeed 1startTime 0stopTime 0url [ ]repeatS TRUErepeatT TRUE

    }

    The MovieTexture node has twoeventOut fields: duration_changed and isActive. Aduration_changedevent is generated when the current url is changed, the value for this eventis the time in seconds of the sound. Note that changing the speeddoes not produce aduration_changedevent. The event isActive will output a value TRUE when the movie startsplaying, when the movie stops the event isActive will output FALSE.Note: for the example on the right the movie will be repeated twice in each direction if thevalues forrepeatSand repeatTare set ot TRUE. See the node TextureTransformto see howto set the repetition rate.

    PixelTexture Node

    This node specifies the location of the image to be used for texturing the shape, as well as ifthe image is to be repeated vertically, or horizontally, along each of the faces of the shape.

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?eventhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?eventhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?textrhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?textrhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?eventhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?textr
  • 8/7/2019 VRML tutorial

    20/59

    Three fields are present in this node: image which defines the image using pixels. repeatSwhich specifies if the image is to be repeated vertically. repeatTwhich specifies if the image is to be repeated horizontally. The first three values ofthe image field define the width of the image (in pixels), the height of the image (in pixels),and the number of bytes used for each pixel. Possible values for the number of bytes are:

    1: Grayscale

    2: Grayscale with alpha channel for transparency3: RGB4: RGB with alpha channel for transparency All fields are optional, the default values being

    applied if the field is not specified. Note: if you do not specify the image field, then no texturingtakes place.Specifying an image pixel by pixel may seem like hard work, however some interesting effectscan be achieved with little effort. For example see the following PixelTexture node:PixelTexture { image 2 1 1 0 255}Note that the color values for the PixelTexture node range from 0 to 255, as opposed to 0 to 1as in the VRML color model used for all the other nodes.This node specifies an image with two pixels wide, 1 pixel tall, the first pixel is black, and thesecond is white. If this image is applied as a texture to a face then, because the image is

    scaled to fit the face, a gradient should be displayed starting from black on the left side andprogressively turning to white as the right side is reached (note: some browsers do not yetimplement this feature and instead will produce a two color image, the left half black and theright half white).This node can also be used to create patterns, although a pattern editor is probably the bestoption for this task.

    Syntax:

    PixelTexture {

    image 0 0 0repeatS TRUErepeatT TRUE

    }

    Note: for the example on the right the image will be repeated twice in each direction if thevalues forrepeatSand repeatTare set ot TRUE. See the node TextureTransformto see howto set the repetition rate.

    TextureCoordinate

    A texture is represented in a 2-D coordinate system (s,t) that ranges from 0 to 1 in bothdirections.

    This node takes a set of points in 2-D to define how a texture is applied to IndexedFaceSetandElevationGrid. If this node is not specified the texture is applied to the shape as a whole.Specifying a TextureCoordinate node causes the texture to be applied to each face of theshape according to the coordinates given.

    Syntax:

    TextureCoordinate {

    point [ ]}

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?textrhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?textrhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indfshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?elevghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?elevghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?elevghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?textrhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indfshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?elevg
  • 8/7/2019 VRML tutorial

    21/59

    the field pointtakes a set of 2-D coordinates which define the selected area. The points areseparated by spaces.The ordering of the points is relevant. The order should be counter clockwise starting from theorigin to keep the orientation of the texture. If the start point is different then the texture isrotated by multiples of 90 degrees. Presenting the point in a clockwise direction will mirror the

    texture. Try it yourself of the right frame.It is now described how TextureCoordinate points define texturing for a single face.Afterwards particular features of textures for IndexedFaceSet and ElevationGrid arepresented.You can select only a part of the texture, for instance if the points given are (0 0) (0.5 0) (0.50.5) (0 0.5). Only a quarter of the texture will be used

    The next figure shows the result obtained.

    You can also use this node to have the texture repeated, for instance consider the followingpoints: (0 0), (2 0),(2 2), (0 2). In this case the texture is repeated twice in each dimension.

    More complex settings can be used which restrict the texture in one dimension but repeat it inthe other dimension. For example consider the points (0 0) (0.5 0) (0.5 2) (0 2). The left imageshows the result of using this texture coordinates in a square face, the right image shows thearea selected in terms os texture coordinates.

  • 8/7/2019 VRML tutorial

    22/59

    In all the examples above the area selected was either square or rectangular. There isnothing preventing you from choosing non-rectangular areas, however the number of pointsmust match the number of coordinates used to build the face, i.e. you can't match a triangularselection into a square face.The next two sections describe particular features of IndexedFaceSet and ElevationGrid,

    IndexedFaceSet

    The number of points should match the number of coordinates used to define the face, ifmultiple faces are defined then the number of points must agree with the number of pointsused to define each face.The number of points in the TextureCoordinate must be at least equal to the number of pointsof the face with highest number of points.If the field texCoordIndex is not NULL then the values of this field specify the indexes of theTextureCoordinate points which are used to define the selection for each face.If the field texCoordIndex is NULL then the field coordIndexis used to specify the indexes.

    ElevationGridsWhen you specify an ElevationGrid you define a grid in which each point of the grid has aheight. By default, i.e. if no TextureCoordinate is defined, texturing is controlled by

    TextureTransform. However sometimes you may want more control in the way textures areapplied.A texture coordinate is defined for each point in the grid. The first point in the gridcorresponds to the first point in the TextureCoordinate node, the last point in the gridcorresponds to the last point in the TextureCoordinate node. There must be as many points inthe ElevationGrid as there are in the TextureCoordinate node.

    TextureTransform Node

    This node allows you to perform simple geometric transformations, scale, rotation, andtranslation, on texture coordinates, see the TextureCoordinatenode. This node is definedinside an Appearance node.

    Syntax:

    TextureTransform {

    scale 1 1rotation 0center 0 0

    translation 0 0}

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?textrhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?textrhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texcohttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texcohttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?appeahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?textrhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texcohttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?appea
  • 8/7/2019 VRML tutorial

    23/59

    The value of the centerfield specifies the center point about which rotation and scale takesplace.When all fields are used in combination then the coordinates specified in theTextureCoordinate node are first scaled and rotated about the center point, and finallytranslated.

    Lighting Nodes

    Up until know the worlds you've seen in this tutorial have been lit by a special light, theheadlight. This light is created by your browser and it is attached to the current viewpoint. Thislight always points to where you're looking at. It is like if you had a light attached to your head.This light can be turned on or off using the browsers options or with the NavigationInfo node.VRML supports three additional types of lights. They are: Directional Light Point Light

    Spot LightWhen using a Directional Light the light rays are all parallel. This light has no defined location,only a direction. It is as if the light is far, far away from your world.APoint Light is a light, placed in your world, which brightens everything around it, the lightrays go in all directions from the light's location. Think of the sun for instance.ASpot Lightis a ... spotlight. This type of light creates a cone of light.Further informationspecific to each type of light is provided in the links above. However ifyou're new to lighting in VRML then the following should be of some use to help youunderstand how it is done in VRML. Note: in all the figures bellow the headlight is turned off.

    Light ReflectionIn theory when light rays hit an object the object may reflect the light rays depending on its

    color and the color of the light. Light reflection depends on the properties of the object beinglit. Surely you have seen 3D realistic static images where this effect is present.However computing light reflection on the fly is hard work. In order to display 3D worldsinteractively some short cuts had to done in order for the action to be as smooth as possible.Therefore there is no reflected light in VRML, only direct light is available. This means that ifan object is not in the path of the light rays from any of the lights placed in your world it willremain dark.As a replacement for light reflectiont, the lights in VRML have a field called ambientIntensity.This field controls how much the light contributes to the overall world lighting. With highvalues forambientIntensitythe world will be a brighter place. Although a crude replacement itcan add some realism to yuor world.

    Light Attenuation and ScopeAnother real world lighting effect is that the light gradually grows weaker with distance. InVRML this feature is implemented. With the field attenuation you can specify how the lightdrops off as distance increases.Note that this field only exists forPoint Light and Spot Light, it doesn't apply to DirectionalLight. This is because, as mentioned above, theDirectional Lightdoes not have a definedlocation in the world.So how does one control lighting attenuation with Directional Light? This type of light onlyiluminates the objects which are placed within the groupwhere the light is defined. On theother hand, the Point LightandSpot Lightare independent of their position within the file, i.e.they're lighting effect is not restricted to thegroup in which they are defined.

    ShadowsLook at the following figure. In it there is a Point Lightplaced at the left, and two Spheresinthe right. The Point Light and the center of the Spheresare colinear.

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?texcohttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?navighttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?grouphttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?grouphttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?grouphttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?grouphttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?texcohttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?navighttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?grouphttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?grouphttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?sphere
  • 8/7/2019 VRML tutorial

    24/59

    According to the text above the left sphere should block the light rays from reaching thesphere on the right. However from the figure it is clear that this is not happening. The reasonis that shadows do not exist in VRML. The computational load to compute shadows is tooheavy to display 3D graphics on the fly.So how does one create shadows? You could create them manually, for instance in the figureabove the right sphere could be defined darker than the left sphere simulating shadowing,however this approach is not realistic for anything but very small models. The only approachto block light is to define the objects which are not supposed to be lit by a particular lightoutside the groupwhere the light is defined, however, as mentioned before, grouping nodesonly have effect on Directional Lights.Basically there is no way out, you're stuck with a shadowless world, unless you're a realperfectionist you're up to some real hard work.

    Lighting Flat SurfacesConsider the following figure. In it a Spot Light is aimed at the center of a cubicBox and thecube's face is inside the cone of light defined by the Spot light.

    So far so good, the cube's face is fully lit as expected. Now consider the next figure. In it aspot light is also aimed at the cube's face but the light cone's intersction with the cube's faceis a circunference which is totally inside the cube's face, i.e. none of the vertices of the cube'sface are inside the cone of light.

    The cube's face is totally dark, why? Let's see another figure which may shed some light intothis obscureness. In this next figure a spot light is aimed at the top right vertex of the cube.The cone of light does not contain any other vertex of the cube's face.

    Again something is wrong, there should be a circular lighter area in the cube, and insteadthere is a linear one.In VRML the light reflection of a flat surface is computed based on the average amount oflight which reaches each vertex of the face. So in the first figure we had all vertices equally lit

    and the face is evenly lit. On the second figure none of the vertices were lit, therefore the facewas dark.

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?grouphttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?grouphttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?boxhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?boxhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?grouphttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?box
  • 8/7/2019 VRML tutorial

    25/59

    The third figure has only one vertex lit, the top right one. Light along the right edge of the faceis computed as the average between the top right vertex, which is lit, and the bottom rightvertex, which is not lit, therefore the face becomes progressivelly darker as we move from thetop right vertex to the bottom right vertex. Similar reasoning can be applied between the topright vertex and the top left vertex, as well as between the top right vertex and the bottom leftvertex.

    Now look at the next figure.

    Now, things are getting better, OK you don't have a circular light inside the shape but at leastthe light doesn't lit the whole shape. The trick is to define either an IndexedFaceSet or a flatElevation Grid. Using any of these shapes one can create a mesh, i.e. instead of defining a

    flat face using just the outer vertices, a mesh is created using small faces to construct theoriginal larger face. As the faces which build up the mesh grow smaller, the light effect will getcloser to a circle. This process, while providing more realism in the light effects, does havethe disadvantage that more faces need to be drawn, therefore slowing down the display of theworld. There is no rule of thumb to say when a performance problem will occur, you just haveto try and use meshes of different granularity, i.e. varying the number of the small faces thatmake up the mesh, and see how performance is affected.

    Colored LightsColor can be applied to lights as well as shapes. You can have blue lights, red lights, brownlights, just pick a color. However there is a detail that you should be aware of.

    In the example above there is a blue sphere and a Spot Light to its right, right? Well, almost.There is also a red Spot light on the left side of the sphere and pointing at it. Yet no tracescan be seen from this red light, why? The answer is simple, a blue sphere can only reflectblue light, and as there is absolutely no blue light in a red light the sphere remains black.In the real world pointing a red light to a blue object wouldn't result in total darkness, but in thereal world there is nothing like true red light, and true blue objects. All lights and objects in theso called real world have a mixture of colors. When we say that an object is blue we are

    saying that its stronger color is blue, and not that it doesn't contain any amount of any othercolor. In computer models true colors do exist though, so be aware.One possible fixture to this 'problem' is to avoid defining true colors. For instance, instead ofdefining blue as 0 0 1 in the RGB model which means true blue, define blue as 0.3 0.3 1, i.e.all colors are present altough there is a predominant color. The following figure has a spheredefined with this later 'blue'.

    The sphere remains blue when lit by a white spot light, but now a tenuous effect from the red

    light is visible. Note however that defining colored lights in this way doesn't work in the sameway. See for example the following figure in which the red light was replaced by a light whose

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?indfshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?elevghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?indfshttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?elevghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?slight
  • 8/7/2019 VRML tutorial

    26/59

    coloring is defined in RGB by 1 0.3 0.3.

    The effect of this new red light is not red at all! This is because only the blue part of the redlight is reflected. The light effect from the light on the left is dimmer than the one from the rightbecause the later has more blue light than the former.

    Shapes UnlitIf the materialfield in the Appearance node is NULL or not specified then the associatedgeometryin the Shape node is not lit. If you don't want to specify a materialyou can alwaysdefine the materialfield as: material Material { }In the following figure aPoint lightis placed above two Spheres. Note however that while theleft sphere is lit correctly, the right one is not affected by the point light.

    The reason why the right sphere doesn't react to light is because the materialfield isundefined in the Appearance node of theshape.

    DirectionalLight Node

    If you're new to lighting in VRML, there is aLightingsection in this tutorial which discussesgeneral features of lighting in VRML. In here only the aspects which are particular toDirectional Lights are discussed.Directional Lights define a light source which is placed very far away from your world (don'tworry you don't have to specify a location for the light). The light rays when they reach theworld are parallel to a given direction). This field specifies a vector in 3D to which the lightrays are parallel. The following figure attempts to define graphically a Directional Light.

    This light should only affect the nodes which are defined within the samegroup, i.e. objectsplaced outside the group where the Directional Light is defined are not lit. I say should and notmust because not all browsers support this feature.The following fields are present in this node: on specifies if the light is active. This is a boolean field. intensityhas values between 0.0 and 1.0. Higher values specify stronger lights. ambientIntensityspecifies how much this light contributes to the overall lighting .Valuesmust be between 0.0 and 1.0

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?appeahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?shapehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?appeahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?shapehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?shapehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?grouphttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?grouphttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?appeahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?shapehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?plighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?appeahttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?shapehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?group
  • 8/7/2019 VRML tutorial

    27/59

    coloris a RGB field to specify the color of the light.. direction which specifies a vector in 3D. The light rays are parallel to this vector.

    Syntax:

    DirectionalLight {

    on TRUEintensity 1

    ambientIntensity 0color 1 1 1direction 0 0 -1

    }

    Note: On the VRML world presented as example thesphere is placed at -2.5 0 0, the cone isplaced at the origin, and the cylinderis placed at 2.5 0 0. If you're not familiar with placingshapes other than at the origin see theTransform node.

    PointLight NodeIf you're new to lighting in VRML, there is aLightingsection in this tutorial which discussesgeneral features of lighting in VRML. In here only the aspects which are particular to PointLights are discussed.Point Lights define a light source in a specified location. The light rays from this type of lightsgo in all directions. This implies that, as opposed to Directional Lights, Point Lights have alocation but not a direction field. The following figure attempts to define a Point Lightgraphically (the point where the light rays start is the light location.

    This light lits all nodes regardless of their position in the file, i.e. this light is not scoped. Thereis however a way of limiting the volume which is lit by this light, one can specify a radiuswhich defines the maximum distance that the light rays can travel. Objects which are furtheraway from the light source than the radius are not lit by the light source.

    There is still another way to control the attenuation within the sphere defined by the radius.Using the attenuation field one can specify how the light grows dimmer with distance, withinthe sphere defined by the radius.The following fields are present in this node: on specifies if the light is active. This is a boolean field. intensityhas values between 0.0 and 1.0. Higher values specify stronger lights. ambientIntensityspecifies how much this light contributes to the overall lighting .Valuesmust be between 0.0 and 1.0 coloris a RGB field to specify the color of the light.. location which specifies a vector in 3D defining the coordinates of the light in your world. attenuation is a 3D vector that specifies how the light looses its intensity as distance fromthe light source increases. All vector values must be greater than or equal to zero radius specifies the maximum distance for the light rays to travel. Must be greater than or

    equal to zero.Syntax:

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?conehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?cylinhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?transhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?transhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?conehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?cylinhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?transhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlight
  • 8/7/2019 VRML tutorial

    28/59

    PointLight {

    on TRUEintensity 1ambientIntensity 0color 1 1 1location 0 0 0

    attenuation 1 0 0radius 100

    }

    Note: On the VRML world presented as example thesphere is placed at -2.5 0 0, the cone isplaced at the origin, and the cylinderis placed at 2.5 0 0. If you're not familiar with placingshapes other than at the origin see theTransform node.

    SpotLight NodeIf you're new to lighting in VRML, there is aLightingsection in this tutorial which discussesgeneral features of lighting in VRML. In here only the aspects which are particular to SpotLights are discussed.Spot Lights define a light source in a specified location pointed at a particulardirection. Thelight rays from this type of light are constrained to the interior of a cone, the cone's apexcoinciding with the light's location. The following figure attempts to define a Point Lightgraphically (the point where the light rays start is the light location.

    The cone of light is defined by two fields: cutOffAngle and beamWidth. The cutOffAngledefines the angle of the cone, in radians. The beamWidth defines the angle of an inner conewithin which the light intensity is constant. The light rays which fall between the inner cone

    and the outer cone have a decreasing intensity from the inner to the outer cone. If thebeamWidth is larger than the cutOffAngle then the light has a constant intensity within thecone.

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?conehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?cylinhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?transhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?transhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?lighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?conehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?cylinhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?transhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?light
  • 8/7/2019 VRML tutorial

    29/59

    A Spot light lits all nodes regardless of their position in the file, i.e. this light is not scoped.There is however a way of limiting the volume which is lit by this light, one can specify aradius which defines the maximum distance that the light rays can travel. Objects which arefurther away from the light source than the radius, or lie outside the outer cone are not lit bythe light source.

    There is still another way to control the attenuation. Using the attenuation field one canspecify how the light grows dimmer with distance, within the sphere defined by the radius.The following fields are present in this node: on specifies if the light is active. This is a boolean field. intensityhas values between 0.0 and 1.0. Higher values specify stronger lights. ambientIntensityspecifies how much this light contributes to the overall lighting .Valuesmust be between 0.0 and 1.0 coloris a RGB field to specify the color of the light. location which specifies a vector in 3D defining the coordinates of the light in your world. direction which specifies a vector in 3D defining the aim of the light. attenuation is a 3D vector that specifies how the light looses its intensity as distance fromthe light source increases. All vector values must be greater than or equal to zero radius specifies the maximum distance for the light rays to travel. Must be greater than or

    equal to zero. cutOffAngle specifies the cone within which the light rays are constrained. Must be greaterthan or equal to zero, and less than or equal to 180 degrees, approximately 1.57 radians. beamWidth specifies an inner cone within which the light rays have a uniform intensity .Must be greater than or equal to zero, and less than or equal to 180 degrees, approximately1.57 radians.

    Syntax:

    SpotLight {

    on TRUEintensity 1ambientIntensity 0color 1 1 1location 0 0 0direction 0 0 0attenuation 1 0 0radius 100cutOffAngle 0.78beamWidth 1.57

    }

    Note: Due to the default location and direction of the Spot Light the initially loaded world isblack. On the VRML world presented as example the sphereis placed at -2.5 0 0, theconeisplaced at the origin, and the cylinderis placed at 2.5 0 0. If you're not familiar with placingshapes other than at the origin see theTransform node.

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?conehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?conehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?conehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?cylinhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?transhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?transhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?spherehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?conehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?cylinhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?trans
  • 8/7/2019 VRML tutorial

    30/59

    Grouping Nodes

    A set of nodes can be defined as a group in VRML. The following grouping nodes areavalable in VRML: Anchor: define a complex shape, built using a set of shapes, as a hyperlink to anotherVRML world, to a HTML page, or to any other data that your browser can read. Billboard: specifying a set of nodes which are always turned to you regardeless of yourposition. Collision: defining a set of nodes which the browser should be warned when collisionoccurs. Group: defining a new node type composed by a set of nodes so that you can reuse itlater without repeating the entire set of nodes. Switch: defining a set of nodes in which at most one of the nodes is drawn. Transform: defining a new coordinate system so that objects can be placed in locationsother than the origin.Grouping also can be used for scoping, i.e. some node types, when placed n a group, only

    affect the other nodes within the same group. For instance,Directional Lights only affectnodes within the same group (at least according to the official VRML 2.0 specification).Sensor nodes are also constrained to the group their defined in.You can place groups inside groups, creating a hierarchical structure of nodes. A group nodecan have any number of child nodes inside the children field.All grouping nodes accept the following events:

    addChildren: which add a new node to the groupremoveChildren: which removes a given node from the group

    To generate one of these events you have to use Scripts.

    Group NodeIf you're not familiar to grouping nodes in VRML see the sectionCreating Hierarchical NodeStructures for general information on grouping.The group node lets you treat a set of nodes as a single entity.The following fields are present: children which contains all the nodes included in the group. bboxCenterspecifies the center of a box that encloses the nodes in the group. The valuefor this field is a 3D point. bboxSize specifies where the size of a box that encloses the nodes in the group. Bydefault this field has a value of -1 -1 -1, which implies that no box is defined. The values forthis field must be greater than or equal to zero. If the children nodes do not fit inside the box

    defined the results are undefined. The latter two fields are optional. They can be used by thebrowser for optimization purposes.

    Syntax:

    Group {

    children []bboxCenter 0 0 0bboxSize -1 -1 -1

    }

    The following hierarchical structure of a VRML file exemplifies scoping with the group node:

    Group g1 {Shape A

    Directional Light 1Group g2 {

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?anchorhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?anchorhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?billbhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?billbhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?collihttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?collihttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?grouphttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?grouphttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?switchhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?transhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://vrml.sgi.com/moving-worlds/http://vrml.sgi.com/moving-worlds/http://www.lighthouse3d.com/vrml/tutorial/index.shtml?groupinghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?groupinghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?groupinghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?anchorhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?billbhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?collihttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?grouphttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?switchhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?transhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://vrml.sgi.com/moving-worlds/http://www.lighthouse3d.com/vrml/tutorial/index.shtml?groupinghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?grouping
  • 8/7/2019 VRML tutorial

    31/59

    DirectionalLight 2Shape B}

    }

    The directional light in group 1 will lit both shapes A and B because a directional light lits allnodes within the same group and in descendent groups. However, the directional light in

    group 2 will only lit shape B. Shape A is placed outside the group where the light is definedand therefore it is not lit by the directional light in group 2.The following code exemplifies the syntax of the Group node:

    Example:#VRML V2.0 utf8Group {children [Shape {geometry Cylinder {height 5.0radius 0.5}}

    Shape {geometry Sphere {}}]}

    Transform Node

    The transform node is agroupingnode. As a group node it can be used to define a set ofnodes as a single object. However this is not the main purpose of this node. This node allowsyou to define a new local coordinate system for the nodes within the group.This node can be used to perform the following geometric transformations:

    ScaleRotationTranslation

    All the nodes inside a Transform group are affected by these transformations, i.e. allcoordinates are computed in the local coordinate system. Transform groups insideTransforms groups accumulate the transformations specified in each Transform. The innerTransform group defines a local coordinate system based on the coordinate system defined inthe outer transform group.The following fields are present: children which contains all the nodes included in the group. scale specifies a 3D scaling transformation. scaleOrientation defines a rotation of the axes for the scaling operation. centerdefines the center of the scaling transform. rotation defines a rotation on an arbitrary axis. translation defines the origin of the local coordinate system. bboxCenterspecifies the center of a box that encloses the nodes in the group. The valuefor this field is a 3D point. bboxSize specifies where the size of a box that encloses the nodes in the group. Bydefault this field has a value of -1 -1 -1, which implies that no box is defined. The values forthis field must be greater than or equal to zero. If the children nodes do not fit inside the boxdefined the results are undefined.

    Syntax:

    Transform {

    scale 1 1 1scaleOrientation 0 0 1 0

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?groupinghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?groupinghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?groupinghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?dlighthttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?grouping
  • 8/7/2019 VRML tutorial

    32/59

    center 0 0 0rotation 0 0 1 0translation 0 0 0bboxCenter 0 0 0bboxSize -1 -1 -1children []

    }}

    ScaleA scaling operation allows you to resize a shape. You can enlarge or decrease the size of ashape in any number of dimensions. The scale factors must be positive. The next figurepresents an example.

    The left box is a cube defined using the Box node without any scaling operation. The secondis scaled in the X axis by 0.2, the third is scaled in the Y axis also by 0.2, and the fourth isscaled both in the Y and Z axes by 0.2.Sometimes, you may wish that the axes to which the scaling operation is applied were not thestandard axes. scaleOrientation field allows you to rotate the axes, the scaling factors will beapplied to the rotated axes and not to the original axes. The scaleOrientation field specifies avector which defines the rotation axis, and the angle measure for rotation.

    The cube from the right had a scale of 1.3 in the Y axis which was previously rotated by 45degrees in the Z axis. The next figure shows the computations involved step by step.

    The left figure shows the axes and a box prior to any geometric transformations. The secondshows the effect of the scaleOrientation , a rotation of 45 degrees in the Z axis. ThescaleOrientation used was 0 0 1 0.75, the first three values specify a vector, the fourth anangle (recall that in VRML angles are defined in radians).Note that after the third step the axes go back to normal, i.e. those in the left figure.Because translation is the last transformation to be applied, it may sometimes be convenientto define a translated set of axes for the scaling operation. Note that as for the

    scaleOrientation, this translation is only effective for the scale transformation. The field centerallows you to perform such a translation.The next figure shows a default box (in the middle) and two scaled boxes, the one on the right

  • 8/7/2019 VRML tutorial

    33/59

    using a centerof (0,-1,0) and the left one without using center.

    The effect of the centerfield in this case is that the final position of the scaled boxes isdifferent. Sometimes this can bring some advantage, if for instance you need to know where aspecific point of the shape will be after scaling. In the above example, the base of the shapein the right after scaling remains at the same position as the original unscaled shape (in themiddle).You can combine all three scaling related fields together, in this case the axes will be

    translated to the center point, rotated according to the scaleOrientation, and finally scaled asdefined in the scale field. Please experiment in the right side frames at your will.

    RotationA rotation is defined by a vector and an angle. The vector specifies the axis of rotation,whereas the angle specifies the amount to rotate in a counter clockwise direction. Thefollowing figure shows a dotted Box in its default position and the Box rotated 45 degrees inthe Z axis.

    Rotations can be done in an arbitrary axis if desired. The following figure shows somerotations applied to boxes.

    The left box has no rotation applied to it, the second box has a rotation of 45 degrees in the Yaxis, the third is rotated in the X axis also by 45 degrees, the fourth is rotated 45 degreesusing a vector (1 1 0).The centerfield explained earlier in the Scale section has the same effect in rotations.

  • 8/7/2019 VRML tutorial

    34/59

    In the above example a center of (2,2,0) was used, middle figure, and afterwards a rotation of45 degrees was performed on the Z axis, right figure.

    TranslationTranslations allow you to place a shape wherever you want to. The following figure attemptsto depict the concept.

    The dotted lines represent the coordinate system outside the Transform node. The full linesrepresent the local coordinate system inside a Transform node which defines a translation asspecified by the arrow vector. The translation in the figure could be (1,1,0), i.e. the localcoordinate system in the Transform node would have has its origin the point (1,1,0) from thecoordinate system defined outside the Transform node.

    You have probably already guessed that the two figures with a set of cubes had severaltranslations involved.

  • 8/7/2019 VRML tutorial

    35/59

    Composing Multiple Geometric TransformationsUp till now you've been playing with single transformations, but you can combine two or allgeometric transformations in a single transform node.The transformations are independent of each other. For instance if you have both a

    translation and an orientation in the same Transform, the translation is not affected by theorientation and vice-versa.In the above example if you did want the translation to occur in the rotated axis system thenyou should define two nested Transform nodes, placing the orientation in the outterTransform, and the translation in the inner Transform node.

    Collision Node

    If you're not familiar to grouping nodes in VRML see the sectionCreating Hierarchical NodeStructures for general information on grouping.By default, all objects in the scene are collidable, i.e. you shouldn't be allowed to walk throughwalls and all that stuff. This is the theory, in practice some browsers still allow you to playghosts.So why do you need a collision node if collision is by default detected? Here are a fewreasons to use this node:turn off collision: This may seem a dumb thing to do but it will provide better performance.provide alternative representations for collision: collision detection is hard work for thebrowser, complex worlds have lots of faces. This node allows you to provide an alternativegraphical representation for collision. If this alternative representation is simpler than the real

    thing, then collision detection is easier to do. The alternative representation is not drawn, it isonly used for collision detection purposes.do something when collision occurs: The Collision node outputs an event collideTime, whichoutputs the time of collision. For example, this event can berouted to an AudioClip node toplay a sound when the user collides with an object. The example at the bottom of this pageshows the code to implement this.The following fields are present: children which contains all the nodes included in the group.

    collide, a boolean field which specifies if the children nodes are eligible for collision detection. proxyspecifies an alternative geometric representation for collision detection. This fieldtakes as value any node, except those which can only appear inside another node asAudioClip, MovieTexture, geometry nodes, etc...

    bboxCenterspecifies the center of a box that encloses the nodes in the group. The valuefor this field is a 3D point. bboxSize specifies where the size of a box that encloses the nodes in the group. Bydefault this field has a value of -1 -1 -1, which implies that no box is defined. The values forthis field must be greater than or equal to zero. If the children nodes do not fit inside the boxdefined the results are undefined. Detecting collision in a complex objectThe latter two fields are optional. They can be used by the browser for optimization purposes.

    Syntax:

    Collision {

    children [ ]collide TRUEproxy NULLbboxCenter 0 0 0

    bboxSize -1 -1 -1}

    http://www.lighthouse3d.com/vrml/tutorial/index.shtml?groupinghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?groupinghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?groupinghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?eventhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?routehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?routehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?audiohttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?groupinghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?groupinghttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?eventhttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?routehttp://www.lighthouse3d.com/vrml/tutorial/index.shtml?audio
  • 8/7/2019 VRML tutorial

    36/59

    In the following example, when the user collides with the sphere a sound will be heard.

    Example:#VRML V2.0 utf8DEF col Collision {children [

    Sound { source DEF ac AudioClip { loop FALSE pitch 1.0 url "ouch.wav" } }Shape {appearance Appearance { material Material {}}geometry Sphere {}}]}ROUTE col.collideTime TO ac.set_startTime

    Anchor Node

    If you're not familiar to grouping nodes in VRML see the