This example shows some basic built-in features of VRML2, such as lighting, transparency, etc.
#VRML V2.0 utf8 All VRML files start with a header to identify the version and information encoding scheme. This header should be the first line of the file. In this case, this VRML file is prepared according to 2.0 specifications, and it uses the international UTF-8 character set. header DEF World Transform { rotation 1 0 0 0.523599 children [ DirectionalLight { on TRUE intensity 1 color 1 1 1 direction 1 0 0 }, The Transform node creates a new coordinate system relative to its parent. Transform node fields do translation, rotation and scale. Here we are defining a node called World that is rotated 30 degress on the x axis. The shapes that make up the group are called the groups's children. The first child is a DirectionalLight. DirectionalLight is a light aimed at the world and it points in a specified direction. DEF Car Group { children [ DEF LeftFrontWheel Transform { translation -2 0 2 children [ Shape { appearance Appearance { material Material { diffuseColor 1 0 0 } } geometry DEF Wheel Sphere { radius 1 } } ] }, Group nodes describe a list of member nodes (children) for the group. Here we are defining a group node, Car. The Car object has a child named LeftFrontWheel who also has a child Shape node. Shape nodes describe appearance and geometry. Appearance nodes describe material properties (color, transparency, etc..). Gometry are the primitive shapes (box, cone, cylinder, sphere). Here we have a sphere of radius 1 that is of the color red. Nodes can be named and used repeatedly. Notice we are defining Wheel to be used in the rest of the wheels of the car. DEF RightFrontWheel Transform { translation -2 0 -2 children [ Shape { appearance Appearance { material Material { diffuseColor 0 1 0 } } geometry USE Wheel } ] }, The left front wheel is defined here. USE allows us to use a node multiple times without repeating the definition. Here, we instanciate the node Wheel by using USE. The color of our RightFrontWheel is blue. DEF LeftRearWheel Transform { translation 2 0 2 children [ Shape { appearance Appearance { material Material { diffuseColor 0 0 1 } } geometry USE Wheel } ] }, DEF RightRearWheel Transform { translation 2 0 -2 children [ Shape { appearance Appearance { material Material { diffuseColor 1 1 0 } } geometry USE Wheel } ] }, Similarly, the LeftRearWheel and RightRearWheel are defined. DEF WindShield Transform { translation -2 1 0 rotation 0 0 1 -1.0472 children [ Shape { appearance Appearance { material Material { diffuseColor 0.2 0.2 0.2 specularColor 0.8 0.8 0.8 shininess 0.7 transparency 0.8 } } geometry Box { size 0.01 2 1.5 } } ] }, The WindShield is defined here. It is constructed by a box using the transparency field of the material node to give it a transparent look. DEF LeftSign Transform { translation 0 0 1.01 rotation 0 1 0 -1.5708 children [ DEF Sign Group { children [ Shape { appearance Appearance { material DEF SignMaterial Material { diffuseColor 1 1 1 specularColor 0.8 0.8 0.8 shininess 0.7 } texture DEF SignTexture ImageTexture { url "number.gif" } } geometry DEF SignBox Box { size 0.01 1 1 } } ] } ] }, Here, we introduce ImageTexture for mapping textures to shapes. ImageTexture node can be used as a texture field of Appearance node. It is used by specifying the URL address of the texture image file. The formats supported for texture image are JPEG, GIF or PNG. The RightSign of the race car is constructed by texture mapping number.gif image file onto the surface of a box. DEF RightSign Transform { translation 0 0 -1.01 rotation 0 1 0 -1.5708 children [ Group { children [ Shape { appearance Appearance { material USE SignMaterial texture USE SignTexture } geometry Box { size 0.01 1 1 } } ] } ] }, Similarly, the RightSign is defined here. DEF DrivingWheel Transform { translation -1.2 0.5 0.2 rotation 0 0 1 -1.5708 children [ Shape { appearance Appearance { material Material { diffuseColor 0.2 0.2 0.2 } } geometry Cylinder { radius 0.5 height 0.01 } } ] }, DrivingWheel is defined here and it is made out of a cylinder. DEF Body Group { children [ Shape { appearance Appearance { material Material { diffuseColor 1 1 1 } } geometry Box { size 6 1 2 } } ] }, The Body is defined here and it is made out of a white box. DEF RightHeadLight Transform { translation -3 0.3 -0.5 children [ DEF HeadLight Group { children [ Transform { translation -0.2 0 0 rotation 0 0 1 -1.5708 children [ Shape { appearance Appearance { material DEF HeadLightMaterial Material { diffuseColor 1 0 0 } } geometry DEF HeadLightCone Cone { bottomRadius 0.09 height 0.5 } } ] }, Transform { translation -0.45 0 0 children [ DEF HeadLightPointLight PointLight { intensity 1 color 1 1 0.9 }, Shape { appearance Appearance { material DEF PointLightMaterial Material { emissiveColor 1 1 0 } } geometry DEF PointLightSphere Sphere { radius 0.1 } } ] } ] } ] }, RightHeadLight is defined here. The headlight consists of three objects, a bottomless cone, a sphere and a point light source. The PointLight is located inside of the sphere and it gives out slightly yellow light. The light is filtered by the sphere's surface properties, emissive yellow color. The result is a yellow light with a hint of high intensity. DEF LeftHeadLight Transform { translation -3 0.3 0.5 children [ Group { children [ Transform { translation -0.2 0 0 rotation 0 0 1 -1.5708 children [ Shape { appearance Appearance { material USE HeadLightMaterial } geometry Cone { bottomRadius 0.09 height 0.5 } } ] }, Transform { translation -0.45 0 0 children [ PointLight { intensity 1 color 1 1 0.9 }, Shape { appearance Appearance { material USE PointLightMaterial } geometry USE PointLightSphere } ] } ] } ] } ] }, Similarly, the LeftHeadLight is defined here. Transform { translation 0 -2 5 First, we move the rest of the objects away from the car. children [ Anchor { url "http://www.lamborghini.com/" children [ Transform { translation 4.5 0 0 rotation 1 0 0 -1.0472 scale 0.125 0.125 0.125 center 0 0 0 children [ Shape { appearance Appearance { material DEF _DefMat Material { } } geometry Text { fontStyle FontStyle { size 10 justify "MIDDLE" } string "Lamborghini" length 0 } } ] } ] }, We have a child node that contains four Anchor Grouping Nodes. Anchor Grouping Node allows one to link different VRML Worlds. The node's url field specifies the URL address of the corresponding VRML/Web page to which the viewer travels/loads when the viewer clicks on the anchor shape. The anchor shape in this case is a Text node. Text Node builds 2D flat text characters in X-Y plane with a Z axis depth of 0.0. The fontStyle field specifies the characteristics defining the look and alighnment of text created by the Text node. Size field specifies the height of the characters measured in VRML units while the justify field determines the alignment of the text layout relative to the origin of the object coordinate system. Possible values for the justify field are FIRST, BEGIN, MIDDLE and END. Text strings list the text to build in string field. Each entry in string vector generates a single line or column (depending on fontstyle field horizontal field value). The length field specifies the desired length for each line of text, length of zero implies no length constraint. Anchor { url "http://www.bmwusa.com/" children [ Transform { translation -4.5 0 0 rotation 1 0 0 -1.0472 scale 0.125 0.125 0.125 center 0 0 0 children [ Shape { appearance Appearance { material USE _DefMat } geometry Text { fontStyle FontStyle { size 10 justify "MIDDLE" } string "BMW" length 0 } } ] } ] }, Similarly, we have another Anchor Node that loads BMW homepage at http://www.bmwusa.com upon a click on the string BMW. Anchor { url "http://www.ford.com/" children [ Transform { translation 4.5 -1 2 rotation 1 0 0 -1.0472 scale 0.125 0.125 0.125 center 0 0 0 children [ Shape { appearance Appearance { material USE _DefMat } geometry Text { fontStyle FontStyle { size 10 justify "MIDDLE" } string "Ford" length 0 } } ] } ] }, Similarly, we have another Anchor Node that loads Ford homepage at http://www.ford.com upon a click on the string Ford. Anchor { url "http://www.gm.com/" children [ Transform { translation -4.5 -1 2 rotation 1 0 0 -1.0472 scale 0.125 0.125 0.125 center 0 0 0 children [ Shape { appearance Appearance { material USE _DefMat } geometry Text { fontStyle FontStyle { size 10 justify "MIDDLE" } string "General Motors" length 0 } } ] } ] } Similarly, we have another Anchor Node that loads GM homepage at http://www.gm.com upon a click on the string General Motors. ] } ] }