Fox Presentation Spring 96 CPS 616 Computational Science Track on Base Technologies for the Information Age: VRML1.0 Language Basics Instructor: Geoffrey Fox Aided by Alvin Leung for online resource Version 8 April 96 -- Some April 97 Updates for VRML2 Context Syracuse University 111 College Place Syracuse New York 13244-4100 Abstract of Basic VRML1.0 for CPS616 VRML 1.0 resource is http://vrml.wired.com/vrml.tech/ This presentation illustrates many but NOT all the VRML 1.0 nodes using some simple examples taken from http://www.npac.syr.edu/users/gcf/vrmldemo/vrml1.0demo.html where there is a car and 8 variants on a pyramid defined We juxtapose formal definitions of nodes with snippets of VRML from these exemplars Note VRML1.0 is a dead language as VRML2.0 has changed nearly all detailed syntax. However design of these two dialects are similar History of VRML from wired VRML Site VRML was conceived in the spring of 1994 at the first annual World Wide Web Conference in Geneva, Switzerland. Tim Berners-Lee and Dave Raggett organized a Birds-of-a-Feather (BOF) session to discuss Virtual Reality interfaces to the World Wide Web. Several BOF attendees described projects already underway to build three dimensional graphical visualization tools which interoperate with the Web. Attendees agreed on the need for these tools to have a common language for specifying 3D scene description and WWW hyperlinks -- an analog of HTML for virtual reality. The term Virtual Reality Markup Language (VRML) was coined, and the group resolved to begin specification work after the conference. The word 'Markup' was later changed to 'Modeling' to reflect the graphical nature of VRML. Overview of VRML Language Details - I VRML defines scene graphs which are defined hierarchically as a set of nodes Nodes fall into one of 36 types arranged into broad classes -- shape, geometry/material, transformation, camera, lighting, group and WWWInline The state of a graph (color, position, rotation etc.) are "advanced" (e.g. transformation matrices are multiplied) when each node is encountered separators are used to limit the effect of a given node to a block defined by { } Thus the order in which nodes appear in file is very significant Overview of VRML Language Details - II Node instances can be given names to allow them to be replicated or otherwise referenced Nodes have attributes (properties or parameters if you prefer) which are called fields Fields have names for specific node types which have mnemonic value However there are a set of global field types ( single or multiple(vector), floating or integer etc.) and each field is assigned a particular type and this implies format that must be used General Structure of VRML Comments begin with # and all characters after this in line are ignored -- just like PERL VRML 1.0 files are currently ascii and stored as name.wrl i.e. .html specifies HTML and .wrl VRML files (.wrl abbreviates world) The MIME type for VRML is defined as x-world/x-vrml where x-world is MIME major type to indicate a 3D descriptor and minor type x-vrml indicates VRML 1.0 becomes model/vrml in VRML2.0 A VRML file contains one and only one scene graph defined by ONE VRML node at top level This top level is likely to be a group node with lots of child nodes We will stick at VRML 1.0 and not discuss 1.1 as this is an intermediate stopping point to be overtaken by VRML 2.0 and so unlikely that set of VRML 1.1 browsers will exist before 2.0 takes over! VRML1.0 to VRML2.0 Transisition After an Interesting "competition", a new standard VRML2.0 was adopted in May 1996. After some uncertainty, it appears that this standard will be accepted by major players Good VRML2.0 browsers are now (Spring 97) available Conceptually it is in most areas similar to VRML1.0 but there are many changes in detail and VRML1.0 is NOT a subset of VRML2.0 (MOST of language is changed) Major goal of VRML2.0 was to support dynamic 3D worlds where components of world move relative to each other and interact together This is achieved by events in VRML nodes which are linked by "routes" and invoked by time stamped animations or Java/JavaScript programs Coordinate System for VRML VRML uses a cartesian, right-handed, 3-dimensional coordinate system. By default, objects are projected onto a 2-dimensional device by projecting them in the direction of the positive Z axis, with the positive X axis to the right and the positive Y axis up. A camera or modeling transformation may be used to alter this default projection. The standard unit for lengths and distances specified is meters. The standard unit for angles is radians. The Types of Fields (attributes,properties) in VRML Types of fields can be: Single Valued -- type name begins with SF Note single valued fields can have more than one number specifying value e.g. SFImage is a stream of white space separated bytes Multiple Valued -- type name begins with MF This is a vector of relevant SF types MF types are written [ v1, v2, v3 ... ] or v1 or [v1] if just one entry The 12 SF and 4 MF Type Classes SFBitMask, SFBool, SFColor, SFEnum, SFFloat, SFImage, SFlong, SFMatrix, SFRotation, SFString, SFVec2f, SFVec3f Note 2 and 3 dimensional vectors are defined as SF so that can join several such vectors together to define MF entity SFEnum corresponds to values from an enumerated list MFColor, MFLong, MFVec2f, MFVec3f SFColor SFLong SFFloat Basic Types SFColor e.g. 0. .5 .5 -- R G B written with blank separators A single-value field containing a color. SFColors are written to file as an RGB triple of floating point numbers in standard scientific notation, in the range 0.0 to 1.0. SFLong -- A field containing a single long (32-bit) integer. SFLongs are written to file as an integer in decimal, hexadecimal (beginning with '0x') or octal (beginning with '0') format. Renamed SFInt32 in VRML2.0 SFFloat -- A field that contains one single-precision floating point number. SFFloats are written to file in standard scientific notation. SFMatrix and SFRotation SFMatrix -- A field containing a classic graphics 4 by 4 transformation matrix specifying 3 by 3 orthogonal transformation and a translation in 3 space. (Not in VRML2.0) SFMatrices are written to file in row-major order as 16 floating point numbers separated by whitespace. For example, a matrix expressing a translation of 7.3 units along the X axis is written as: 1 0 0 0 0 1 0 0 0 0 1 0 7.3 0 0 1 SFRotation -- A field containing an arbitrary rotation. SFRotations are written to file as four floating point values separated by whitespace. The 4 values represent an axis of rotation followed by the amount of right-handed rotation about that axis, in radians. For example, a 180 degree rotation about the Y axis is: 0 1 0 3.14159265 x y z angle SFEnum and SFString SFEnum -- A single-value field that contains an enumerated type value. (Removed in VRML2.0) Nodes that use this field class define mnemonic names for the values. SFEnums are written to file as a mnemonic enumerated type name. The name differs among uses of this field in various node classes. SFString -- A field containing an ASCII string (sequence of characters). Stored as UTF-8 International Character Set in VRML2.0 (Only relevant for general languages) SFStrings are written to file as a sequence of ASCII characters in double quotes (optional if the string doesn't contain any whitespace). Any characters (including newlines) may appear within the quotes. As usual, to include a double quote character within the string, precede it with a backslash. For example valid strings are: Testing "One, Two, Three" "He said, \"Wise Words are uttered in CPS616!\"" SFVec2f and SFVec3f SFVec2f -- Field containing a two-dimensional vector e.g. 3.72 7.6 SFVec2f's are written to file as a pair of floating point values separated by whitespace. Note whitespace used as separator in SF field types and commas in MF field types SFVec3f -- Field containing a three-dimensional vector. SFVec3fs are written to file as three floating point values separated by whitespace. SFImage Specification of Hexadecimal Representation SFImages are written to file as three integers nxpixel nypixel numcomponents=1..4 representing the width, height and number of components in the image, followed by nxpixel*nypixel hexadecimal values representing the pixels in the image, separated by whitespace. A one-component image will have one-byte hexadecimal values representing the intensity of the image. For example, 0xFF is full intensity, 0x00 is no intensity. A two-component image puts the intensity in the first (high) byte and the transparency in the second (low) byte. Pixels in a three-component image have the red component in the first (high) byte, followed by the green and blue components (so 0xFF0000 is red). Four-component images put the transparency byte after red/green/blue (so 0x0000FF80 is semi-transparent blue). A value of 1.0 is completely transparent, 0.0 is completely opaque. SFImage Specification Examples Note: each pixel is actually read as a single unsigned number, so a 3-component pixel with value "0x0000FF" can also be written as "0xFF" or "255" (decimal). Pixels are specified from left to right, bottom to top. The first hexadecimal value is the lower left pixel of the image, and the last value is the upper right pixel. For example, 1 2 1 0xFF 0x00 is a 1 pixel wide by 2 pixel high greyscale image, with the bottom pixel white and the top pixel black. 2 4 3 0xFF0000 0xFF00 0 0 0 0 0xFFFFFF 0xFFFF00 is a 2 pixel wide by 4 pixel high RGB image shown in diagram MFColor and MFLong MFColor -- A multiple-value field that contains any number of RGB colors. MFColors are written to file as one or more RGB triples of floating point numbers in standard scientific notation. When more than one value is present, all of the values must be enclosed in square brackets and separated by commas. For example: [ 1.0 0.0 0.0, 0 1 0, 0 0 1 ] represents the three colors red, green, and blue. MFLong -- A multiple-value field that contains any number of long (32-bit) integers. Becomes MFInt32 in VRML2.0 MFLongs are written to file as one or more integer values, in decimal, hexadecimal or octal format. When more than one value is present, all the values are enclosed in square brackets and separated by commas; For example: [ 17, -0xE20, -518820 ] MFVec2f and MFVec3f MFVec2f e.g. [ x1 y1, x2 y2, x3 y3, .... xn yn] -- A multiple-value field that contains any number of two-dimensional vectors. MFVec2fs are written to file as one or more pairs of floating point values separated by whitespace. When more than one value is present, all of the values are enclosed in square brackets and separated by commas; For example: [ 0 0, 1.2 3.4, 98.6 -4e1 ] MFVec3f -- A multiple-value field that contains any number of three-dimensional vectors. MFVec3fs are written to file as one or more triples of floating point values separated by whitespace. When more than one value is present, all of the values are enclosed in square brackets and separated by commas; For example: [ 0 0 0, 1.2 3.4 5.6, 98.6 -4e1 212 ] The Nodes in VRML1.0 -- Overall Classes and Function VRML1.0 defines several different classes of nodes. Most of the nodes can be classified into one of three categories; shape, property or group. Shape nodes define the geometry in the scene. Conceptually, they are the only nodes that draw anything. Property nodes affect the way shapes are drawn. And Grouping nodes gather other nodes together, allowing collections of nodes to be treated as a single object. Some group nodes also Control nodes whether or not their children are drawn. Coordinate System and How Fields are entered into Nodes in VRML Nodes may contain zero or more fields. Each node type defines the type, name, and default value for each of its fields. The default value for the field is used if a value for the field is not specified in the VRML file. The order in which the fields of a node are read is not important; for example, "Cube { width 2 height 4 depth 6 }" and "Cube { height 4 depth 6 width 2 }" are equivalent. Note that each VRML node uses local coordinates centered at (0,0,0) The data implied by the node is placed in 3D world at position and orientation implied by current accumulated transformation VRML 1.0 Shape Nodes Now we examine the 36 nodes grouped by type. The first group are the shape nodes. These specify geometry: AsciiText, Cone, Cube, Cylinder, IndexedFaceSet, IndexedLineSet, PointSet, Sphere, VRML 1.0 Property Nodes The second group are the properties. These can be further grouped into properties of the geometry and its appearance, matrix or transform properties, and cameras and lights: Geometry and Material Nodes Coordinate3, FontStyle, Info, LOD,Material, MaterialBinding, Normal, NormalBinding, Texture2, Texture2Transform, TextureCoordinate2, ShapeHints The Transformation Nodes MatrixTransform, Rotation, Scale, Transform, Translation The Camera Nodes OrthographicCamera, PerspectiveCamera The Lighting Nodes DirectionalLight, PointLight, SpotLight VRML 2.0 Changes The Shape nodes are now grouped together as children of a global node of type Shape which specifies geometry and apperance of 3D object VRML2.0 node attributes can have field values which are themselves nodes e.g. geometry field of shape node can be Box {} (where Box supercedes cube node in VRML 1.0) More general solids of rotation are allowed (extrusion nodes) Camera nodes are essentially removed and considered part of Browser Transform node in VRML2.0 incorporate Separator Transform and sub-transformations such as VRML1.0 Rotation node WWWAnchor becomes Anchor; WWWInline Inline and a host of syntax changes in all the other node types Most critically are additional capabilities Scripts, Sensors, Sound, Interpolators, Collision, Billboard etc. VRML1.0 Group and "Other" Nodes These are the group nodes: Group, Separator, Switch, TransformSeparator, WWWAnchor Finally, the WWWInline node does not fit neatly into any category. WWWInline General Structure of a VRML1.0 Node DEF nodename nodetype { field1 value1 field2 value2 child1 { fields grandchildren } child2 { morefields moregrandchildren } } or nodetype { fields children } The DEF format allows one to specify a name which is optional but can be used to replicate nodes NPAC Online VRML Examples In the following we discuss a set of VRML examples situated on http://www.npac.syr.edu/users/gcf/vrmldemos/vrmldemo.html Major complex example is a car with VRML at http://www.npac.syr.edu/users/gcf/vrmldemos/car.wrl and a set of 8 "small" examples arranged on one page at http://www.npac.syr.edu/users/gcf/vrmldemos/Pyramid/pyramid.wrl Each of these VRML files has an associated HTML page describing issues: http://www.npac.syr.edu/users/gcf/vrmldemos/car.html http://www.npac.syr.edu/users/gcf/vrmldemos/Pyramid/pyramid.html The Pyramid VRML(wrl) and HTML files is linked to eight further VRML and associated HTML explanation files The Eight Versions of a VRML Pyramid - I http://www.npac.syr.edu/users/gcf/vrmldemos /Pyramid/white.html is a basic white Pyramid with simple color and surface properties Coordinate3 and IndexedFaceSet are used to define Pyramid http://www.npac.syr.edu/users/gcf/vrmldemos/Pyramid/mistake.html This incorrectly uses shapehints to specify order of points in rendering http://www.npac.syr.edu/users/gcf/vrmldemos /Pyramid/per_vertex.html This specifies color using value PER_VERTEX in MaterialBinding http://www.npac.syr.edu/users/gcf/vrmldemos /Pyramid/per_vertex_indexed.html This assigns colors to vertices in IndexedFaceSet field using materialindex The Eight Versions of a VRML Pyramid - II http://www.npac.syr.edu/users/gcf/vrmldemos /Pyramid/per_face.html Specifies colors directly to faces of polygon http://www.npac.syr.edu/users/gcf/vrmldemos /Pyramid/per_face_indexed.html Specifies colors indirectly by indices on faces of polygon http://www.npac.syr.edu/users/gcf/vrmldemos /Pyramid/texture_naive.html lays a 2D texture map on the whole pyramid http://www.npac.syr.edu/users/gcf/vrmldemos /Pyramid/texture.html lays the texture map more precisely on the pyramid The Start of Basic White Pyramid -- Separator and Material Separator { # Start Pyramid Scene Graph Material { diffuseColor 1.0 1.0 1.0 # White ambientColor 0.1 0.1 0.1 # Not much of a glow } # We will discuss rest later ..... This gives the object some color and surface properties. The object is white and it is not reflecting any light. The object is mildly lighted (defined by ambientColor), even when there is no light defined in the world. VRML Material Node This node defines the current surface material properties for all subsequent shapes. Material sets several components of the current material during traversal. Different shapes interpret materials with multiple values differently. To bind materials to shapes, use a MaterialBinding node . FILE FORMAT/DEFAULTS Material { ambientColor 0.2 0.2 0.2 # MFColor diffuseColor 0.8 0.8 0.8 # MFColor specularColor 0 0 0 # MFColor emissiveColor 0 0 0 # MFColor shininess 0.2 # MFFloat transparency 0 # MFFloat } VRML1.0 Separator Node I Replaced by Transform in VRML2.0 This group node performs a push (save) of the traversal state before traversing its children and a pop (restore) after traversing them. This isolates the separator's children from the rest of the scene graph. A separator can include lights, cameras, coordinates, normals, bindings, and all other properties. Separators can also perform render culling. Render culling skips over traversal of the separator's children if they are not going to be rendered, based on the comparison of the separator's bounding box with the current view volume. Culling is controlled by the renderCulling field. These are set to AUTO by default, allowing the implementation to decide whether or not to cull. VRML1.0 Separator Node II -- Formal Specification CULLING ENUMS ON Always try to cull to the view volume OFF Never try to cull to the view volume AUTO Implementation-defined culling behavior FILE FORMAT/DEFAULTS Separator { renderCulling AUTO # SFEnum } Structure of the Pyramid with Coordinate3 and IndexedFaceSet - I Coordinate3 { point [ 0 5 0, # Called Point 0 -2.5 0 -2.5, # Called Point 1 2.5 0 -2.5, # Called Point 2 2.5 0 2.5, # Called Point 3 -2.5 0 2.5 # Called Point 4 ] } The point field defines the vertices of the object. There are five points defined. The points are labeled form 0 to 4. Coordinate3 just defines points to be used later in IndexedFaceSet Replaced by Coordinate in VRML2.0 Structure of the Pyramid with Coordinate3 and IndexedFaceSet - II IndexedFaceSet { coordIndex [ # -1 ends polygon 0, 4, 3, -1, 0, 3, 2, -1, 0, 2, 1, -1, 0, 1, 4, -1, 1, 3, 4, -1, 1, 2, 3, -1 ] } } Builds Pyramid as 6 triangles formed from original points defined in Coordinate3 This part coordIndex unchanged in VRML2 VRML1.0 IndexedFaceSet Node I This node represents a 3D shape formed by constructing faces (polygons) from vertices located at the current coordinates. IndexedFaceSet uses the indices in its coordIndex field to specify the polygonal faces. An index of -1 indicates that the current face has ended and the next one begins. The vertices of the faces are transformed by the current transformation matrix. Treatment of the current material and normal binding is as follows: The PER_PART and PER_FACE bindings specify a material or normal for each face. PER_VERTEX specifies a material or normal for each vertex. The corresponding _INDEXED bindings are the same, but use the materialIndex or normalIndex indices. The DEFAULT material binding is equal to OVERALL. The DEFAULT normal binding is equal to PER_VERTEX_INDEXED; if insufficient normals exist in the state, vertex normals will be generated automatically. MaterialBinding Specification totally changed in VRML2 -- its easier! VRML1.0 IndexedFaceSet Node II Explicit texture coordinates (as defined by TextureCoordinate2) may be bound to vertices of an indexed shape by using the indices in the textureCoordIndex field. TextureCoordinate and tex CoordIndex in VRML2 As with all vertex-based shapes, if there is a current texture but no texture coordinates are specified, a default texture coordinate mapping is calculated using the bounding box of the shape. The longest dimension of the bounding box defines the S coordinates, and the next longest defines the T coordinates. The value of the S coordinate ranges from 0 to 1, from one end of the bounding box to the other. The T coordinate ranges between 0 and the ratio of the second greatest dimension of the bounding box to the greatest dimension. VRML1.0 IndexedFaceSet Node III -- Formal Specification Be sure that the indices contained in the coordIndex, materialIndex, normalIndex, and textureCoordIndex fields are valid with respect to the current state, or errors will occur. FILE FORMAT/DEFAULTS IndexedFaceSet { coordIndex 0 # MFLong materialIndex -1 # MFLong normalIndex -1 # MFLong textureCoordIndex -1 # MFLong } 14 fields in VRML2.0 also specifying material binding and rendering Use of WWWAnchor Transform and WWWInline in Pyramid Demonstration WWWAnchor { # Has Attributes (name) and Children name "http://www.npac.syr.edu/users/gcf/vrmldemos/Pyramid/white_link.html" Transform { # First Child translation 10 0 -5 } # Followed with second child WWWInline { # Load Pyramid into Current VRML page name "http://www.npac.syr.edu/users/gcf/vrmldemos/Pyramid/white.wrl" bboxSize 5 5 5 # Using this as box to put VRML in } } Anchor (and different syntax) in VRML2 Notes on Use of WWWAnchor Transform and WWWInline in Pyramid Demonstration WWWAnchor works as a Separator and associates a link to the object. If the viewer activates this link, the web page specified in name attribute will be displayed on the viewer's browser. The link can also point to any HTML page. WWWInline provides a way to incorporate VRML objects from the web. Inline (name replaced by url) in VRML2 The name field provides the URL of the included object. The bboxSize defines the bounding box of the object. The center of the bounding box can be specified by bboxCenter field. VRML1.0 WWWAnchor Node I The WWWAnchor group node loads a new scene into a VRML browser when one of its children is chosen. Exactly how a user "chooses" a child of the WWWAnchor is up to the VRML browser; typically, clicking on one of its children with the mouse will result in the new scene replacing the current scene. A WWWAnchor with an empty ("") name does nothing when its children are chosen. The name is an arbitrary URL. WWWAnchor behaves like a Separator, pushing the traversal state before traversing its children and popping it afterwards. VRML1.0 WWWAnchor Node II The description field in the WWWAnchor allows for a friendly prompt to be displayed as an alternative to the URL in the name field. Ideally, browsers will allow the user to choose the description, the URL or both to be displayed for a candidate WWWAnchor. The WWWAnchor's map field is an enumerated value that can be either NONE(the default) or POINT. If it is POINT then the object-space coordinates of the point on the object the user chose will be added to the URL in the name field, with the syntax "?x,y,z". VRML1.0 WWWAnchor Node III -- Formal Specification MAP ENUM NONE Do not add information to the URL POINT Add object-space coordinates to URL FILE FORMAT/DEFAULTS WWWAnchor { name "" # SFString description "" # SFString map NONE # SFEnum } Anchor in VRML2 with additional capabilities (e.g. load into another frame) VRML1.0 WWWInline Node - I The WWWInline node reads its children from anywhere in the World Wide Web. Exactly when its children are read is not defined; reading the children may be delayed until the WWWInline is actually displayed. A WWWInline with an empty name does nothing. The name is an arbitrary URL. The effect of referring to a non-VRML URL in a WWWInline node is undefined. VRML1.0 WWWInline Node - II Formal Specification If the WWWInline's bboxSize field specifies a non-empty bounding box (a bounding box is non-empty if at least one of its dimensions is greater than zero), then the WWWInline's object-space bounding box is specified by its bboxSize and bboxCenter fields. This allows an implementation to view-volume cull or LOD switch the WWWInline without reading its contents. FILE FORMAT/DEFAULTS WWWInline { name "" # SFString bboxSize 0 0 0 # SFVec3f bboxCenter 0 0 0 # SFVec3f } name becomes url in VRML2.0 Inline node VRML1.0 Transform Node I This node defines a geometric 3D transformation consisting of (in order) a (possibly) non-uniform scale about an arbitrary point, a rotation about an arbitrary point and axis, and a translation. FILE FORMAT/DEFAULTS Transform { translation 0 0 0 # SFVec3f rotation 0 0 1 0 # SFRotation scaleFactor 1 1 1 # SFVec3f scaleOrientation 0 0 1 0 # SFRotation center 0 0 0 # SFVec3f } In VRML2.0 Transform is basic grouping node and can also specify bounding box The Transform Node is Equivalent to Several Other VRML1.0 Nodes Applied Together Transform { translation T1 rotation R1 scaleFactor S scaleOrientation R2 center T2 } is equivalent to the sequence of elementary VRML transformations Translation { translation T1 } Translation { translation T2 } Rotation { rotation R1 } Rotation { rotation R2 } Scale { scaleFactor S } Rotation { rotation -R2 } Translation { translation -T2 } VRML1.0 Rotation Node This is typical of a particular VRML transform Node with translation and scale also defined This node defines a 3D rotation about an arbitrary axis through the origin. The rotation is accumulated into the current transformation, which is applied to subsequent shapes. FILE FORMAT/DEFAULTS Rotation { rotation 0 0 1 0 # SFRotation } Removed in VRML2.0 -- Use Transform Use of PerspectiveCamera in Pyramid Demonstration The viewer looks at the world from the top as default but this is changed with position (default 0 0 1) and orientation (default is negative z -- 0 0 1 0 ) PerspectiveCamera { position 0 20 0 orientation -0.57735 -0.57735 -0.57735 2.0944 focalDistance 1 heightAngle 1.5708 } Removed in VRML2.0 VRML1.0 PerspectiveCamera Node - I A perspective camera defines a perspective projection from a viewpoint. The viewing volume for a perspective camera is a truncated right pyramid. By default, the camera is located at (0,0,1) and looks along the negative z-axis; The position and orientation fields can be used to change these values. The heightAngle field defines the total vertical angle of the viewing volume. An OrthographicCamera is similar but does not use perspective (decreasing size with distance from viewpoint) VRML1.0 PerspectiveCamera Node - Formal Specification FILE FORMAT/DEFAULTS PerspectiveCamera { position 0 0 1 # SFVec3f orientation 0 0 1 0 # SFRotation focalDistance 5 # SFFloat heightAngle 0.785398 # SFFloat } Use of Separator Transform DirectionalLight in Car Demonstration First the whole world is specified as one object as this is the rule! (Not enforced) DEF World Separator { # Name of Scene Graph This enable the world be used as a component of a larger world. Separator is used as a object wrapper and we will use it to define parts of car later. Transform { # A 30 degree rotation about x axis rotation 1 0 0 0.52359878 } DirectionalLight { # Light the Car ! on TRUE # Switch it on! intensity 1 color 1 1 1 # White direction 1 0 0 # Rays are parallel to rotated x axis } VRML1.0 DirectionalLight Node This node defines a directional light source that illuminates along rays parallel to a given 3-dimensional vector. A light node defines an illumination source that may affect subsequent shapes in the scene graph, depending on the current lighting style. Light sources are affected by the current transformation. A light node under a separator does not affect any objects outside that separator. FILE FORMAT/DEFAULTS DirectionalLight { on TRUE # SFBool intensity 1 # SFFloat color 1 1 1 # SFColor direction 0 0 -1 # SFVec3f } VRML2.0 adds ambientintensity field Use of ShapeHints in Pyramid - I ShapeHints { vertexOrdering CLOCKWISE shapeType SOLID faceType CONVEX creaseAngle 0.5 } ShapeHints node tells the VRML browser about the object, so that optimization can be done during rendering. The creaseAngle field tells the browser to do a smooth transition form one polygon to another. This will have a more pronounced effect on a curved surface. Moved to fields of geometry nodes in VRML2.0 Use of ShapeHints in Pyramid - II Coming back to Triangles defined in IndexedFacSet, we find that ShapeHints has given incorrect advice and so results are unpredictable IndexedFaceSet { coordIndex [ 0, 4, 3, -1, # CounterClockWise 0, 3, 2, -1, # ClockWise 0, 2, 1, -1, # CounterClockWise 0, 1, 4, -1, # ClockWise 1, 3, 4, -1, # CounterClockWise 1, 2, 3, -1 # CounterClockWise ] } VRML1.0 ShapeHints Node I Moved in VRML2.0 to fields of geometry nodes The ShapeHints node indicates that IndexedFaceSets are solid, contain ordered vertices, or contain convex faces. These hints allow VRML implementations to optimize certain rendering features. Optimizations that may be performed include enabling back-face culling and disabling two-sided lighting. For example, if an object is solid and has ordered vertices, an implementation may turn on backface culling and turn off two-sided lighting. If the object is not solid but has ordered vertices, it may turn off backface culling and turn on two-sided lighting. VRML1.0 ShapeHints Node II The ShapeHints node also affects how default normals are generated. When an IndexedFaceSet has to generate default normals, it uses the creaseAngle field to determine which edges should be smoothly shaded and which ones should have a sharp crease. The crease angle is the angle between surface normals on adjacent polygons. For example, a crease angle of .5 radians (the default value) means that an edge between two adjacent polygonal faces will be smooth shaded if the normals to the two faces form an angle that is less than .5 radians (about 30 degrees). Otherwise, it will be faceted. VRML1.0 ShapeHints Node III -- Formal Specification VERTEX ORDERING ENUMS UNKNOWN_ORDERING Ordering of vertices is unknown CLOCKWISE Face vertices are ordered clockwise (from the outside) COUNTERCLOCKWISE Face vertices are ordered counterclockwise (from the outside) SHAPE TYPE ENUMS UNKNOWN_SHAPE_TYPE Nothing is known about the shape SOLID The shape encloses a volume VRML1.0 ShapeHints Node IV -- Formal Specification (contd) FACE TYPE ENUMS UNKNOWN_FACE_TYPE Nothing is known about faces CONVEX All faces are convex FILE FORMAT/DEFAULTS ShapeHints { vertexOrdering UNKNOWN_ORDERING # SFEnum shapeType UNKNOWN_SHAPE_TYPE # SFEnum faceType CONVEX # SFEnum creaseAngle 0.5 # SFFloat } Use of PER_VERTEX MaterialBinding in Pyramid Coloring - I Separator { Material { diffuseColor [ 1.0 1.0 0.0, 0.0 1.0 1.0, ....... Actually 18 lines defining 18 colors ...... 0.0 1.0 0.0, 0.0 0.0 1.0 ] ambientColor 0.1 0.1 0.1 } Use of PER_VERTEX MaterialBinding in Pyramid Coloring - II Changed in VRML2.0 Above we define 18 colors and MaterialBinding value PER_VERTEX associates one with each vertex with no addition needed in IndexFaceSet Node. MaterialBinding { value PER_VERTEX } VRML1.0 MaterialBinding Node - I Changed in VRML2.0 This node specifies how the current materials are bound to shapes that follow in the scene graph. Each shape node may interpret bindings differently. The current material always has a base value, which is defined by the first value of all material fields. Since material fields may have multiple values, the binding determines how these values are distributed over a shape. The bindings for faces and vertices are meaningful only for shapes that are made from faces and vertices. Similarly, the indexed bindings are only used by the shapes that allow indexing. VRML1.0 MaterialBinding Node - II When multiple material values are bound, the values are cycled through, based on the period of the material component with the most values. For example, the following table shows the values used when cycling through (or indexing into) a material with 2 ambient colors, 3 diffuse colors, and 1 of all other components in the current material. (The period of this material cycle is 3): Material Ambient color Diffuse color Other 0 0 0 0 1 1 1 0 2 1 2 0 3 (same as 0) 0 0 0 VRML1.0 MaterialBinding Node - III BINDINGS DEFAULT Use default binding OVERALL Whole object has same material PER_PART One material for each part of object PER_PART_INDEXED One material for each part, indexed PER_FACE One material for each face of object PER_FACE_INDEXED One material for each face, indexed PER_VERTEX One material for each vertex of object PER_VERTEX_INDEXED One material for each vertex, indexed FILE FORMAT/DEFAULTS MaterialBinding { value DEFAULT # SFEnum } Use of PER_VERTEX_INDEXED MaterialBinding in Pyramid Coloring - I Material { diffuseColor [ 1.0 1.0 0.0, 0.0 1.0 1.0, 1.0 0.0 1.0, 1.0 0.0 0.0, 0.0 1.0 0.0, ] ambientColor 0.1 0.1 0.1 } Six colors are defined, but only five are used. The colors defined in diffusecolor are labelled from 0 to 5. Use of PER_VERTEX_INDEXED MaterialBinding in Pyramid Coloring - II MaterialBinding { # Specify that Vertex Colors will be specified Indirectly value PER_VERTEX_INDEXED } One Must now add to IndexedFaceSet a new attribute materialIndex linking vertices to colors (only 0 to 4 used) Use of PER_VERTEX_INDEXED MaterialBinding in Pyramid Coloring - III IndexedFaceSet { materialIndex [ 0, 4, 3, -1, # Colors associated with Vertices 0, 3, 2, -1, # Same Number of Indices 0, 2, 1, -1, # as Points in Polygon 0, 1, 4, -1, 1, 3, 4, -1, 1, 2, 3, -1 ] } Use of PER_FACE MaterialBinding in Pyramid Coloring - I Changed in VRML2.0 Material { # Define 6 Colors diffuseColor [ # One for each triangle 1.0 1.0 1.0, 0.0 0.5 1.0, 1.0 1.0 0.0, 1.0 0.0 0.0, 0.0 1.0 0.0, 0.0 0.0 1.0 ] ambientColor 0.1 0.1 0.1 } Use of PER_FACE MaterialBinding in Pyramid Coloring - II Six colors are defined because there are six triangles making up Pyramid. MaterialBinding { value PER_FACE } The browser will pick a color from the list in natural order of triangles and so no change needed in IndexedFaceSet. Use of PER_FACE_INDEXED MaterialBinding in Pyramid Coloring - I Changed in VRML2.0 This uses same Material Node as PER_FACE with 6 colors defined MaterialBinding { value PER_FACE_INDEXED } Tell the browser to pick a color form the list according to the given indices using MaterialIndex attribute in IndexFaceSet Node. IndexedFaceSet { # Use Usual CoordIndex Attribute materialIndex [ 5, 4, 3, 2, 1, 0, -1, ] } Use of Simple Texture Map in Pyramid Coloring Material { diffuseColor 1.0 1.0 1.0 specularColor 0.8 0.8 0.8 } Texture2 { filename "http://www.npac.syr.edu/users/gcf/vrmldemos/number.gif" } This will wrap Image defined in Texture2 Node onto Pyramid (becomes ImageTexture in VRML2.0) VRML1.0 Texture2 Node - I This property node defines a texture map and parameters for that map. This map is used to apply texture to subsequent shapes as they are rendered. The texture can be read from the URL specified by the filename field. To turn off texturing, set the filename field to an empty string (""). Textures can also be specified inline by setting the image field to contain the texture data. Specifying both a URL and data inline will result in undefined behavior. VRML1.0 Texture2 Node - II Formal Specification WRAP ENUM REPEAT Repeats texture outside 0-1 texture coordinate range CLAMP Clamps texture coordinates to lie within 0-1 range FILE FORMAT/DEFAULTS Texture2 { filename "" # SFString image 0 0 0 # SFImage wrapS REPEAT # SFEnum wrapT REPEAT # SFEnum } Use of TextureCoordinate2 in Pyramid Coloring - I This Optimizes Placement of Texture Map on Pyramid and initially uses Texture2 Node as in naive placement example TextureCoordinate2 { point [ 0 0, 1.0 0, 1.0 1.0, 0 1.0, 0.5 0.5 ] } Some reference points: four corners and a middle point, are defined above on the texture map which is always viewed as a rectangle. By definition, the texture coordinate goes from 0.0 to 1.0 on the x axis and the y axis of the texture image. Becomes TextureCoordinate in VRML2 Use of TextureCoordinate2 in Pyramid Coloring - II Then the browser is told in MaterialBinding to expect a index value for each vertex. MaterialBinding { # Note Indices are "different" value PER_VERTEX_INDEXED # From Previous example } # Using PER_VERTEX_INDEXED IndexedFaceSet { # Add to usual coordIndex textureCoordIndex [ 4, 2, 3, -1, 4, 3, 0, -1, 4, 0, 1, -1, 4, 1, 2, -1, 0, 2, 3, -1, 0, 1, 2, -1 ] } VRML1.0 TextureCoordinate2 Node This node defines a set of 2D coordinates to be used to map textures to the vertices of subsequent PointSet, IndexedLineSet, or IndexedFaceSet objects. It replaces the current texture coordinates in the rendering state for the shapes to use. Texture coordinates range from 0 to 1 across the texture. The horizontal coordinate, called S, is specified first, followed by the vertical coordinate, T. FILE FORMAT/DEFAULTS TextureCoordinate2 { point 0 0 # MFVec2f } VRML1.0 Texture2Transform Node I This node defines a 2D transformation applied to texture coordinates. This affects the way textures are applied to the surfaces of subsequent shapes. The transformation consists of (in order) a non-uniform scale about an arbitrary center point, a rotation about that same point, and a translation. This allows a user to change the size and position of the textures on shapes. Becomes a field in Appearance node in VRML2.0 VRML1.0 Texture2Transform Node II Formal Specification FILE FORMAT/DEFAULTS Texture2Transform { translation 0 0 # SFVec2f rotation 0 # SFFloat scaleFactor 1 1 # SFVec2f center 0 0 # SFVec2f } Definition of Wheel in Car Demonstration - I The left front wheel is defined here. The transform node is enclosed within a separator, so it only affect the children objects of the wheel. The Material node is used to define the color of the wheel. DEF LeftFrontWheel Separator { Transform { translation -2.0 0 2 } Material { diffuseColor 1.0 0 0 } # Continue LeftFrontWheel on next foil ... Definition of Wheel in Car Demonstration - II DEF Wheel Sphere { radius 1 } } # End LeftFrontWheel Use Transform and Material as in RightFrontWheel with changed color and translation. However we can "copy" actual Wheel with USE command DEF RightFrontWheel Separator { USE Wheel } VRML Sphere Node - I Unchanged in VRML2.0 ! This very simple node represents a sphere. By default, the sphere is centered at the origin and has a radius (the only attribute) of 1. The sphere is transformed by the current cumulative transformation and is drawn with the current material and texture. A sphere does not have faces or parts. Therefore, the sphere ignores material and normal bindings, using the first material for the entire sphere and using its own normals. VRML Sphere Node -- Formal Specification When a texture is applied to a sphere, the texture covers the entire surface, wrapping counterclockwise from the back of the sphere. The texture has a seam at the back on the yz-plane. FILE FORMAT/DEFAULTS Sphere { radius 1 # SFFloat } Definition of HeadLight in Car Demonstration - I The head light consists of three objects, a bottomless cone, a sphere and a pointlight source. The PointLight is located inside of the sphere and it gives out a slightly yellow light. The light is filtered by the sphere's surface properties with an emissive yellow color. The result is a yellow light with a hint of high intensity. DEF HeadLight Separator { # We will re-USE! Separator { # The Bottomless Cone Transform { translation -0.2 0 0 rotation 0 0 1 -1.5707963 } # to be continued Definition of HeadLight in Car Demonstration - II Material { diffuseColor 1.0 0 0 } Cone { # Defines sides of Light parts SIDES bottomRadius 0.09 height 0.5 } } # End Bottomless Cone parts replaced by side/bottom in VRML2 Definition of HeadLight in Car Demonstration - III Separator { # Start Sphere and PointLight Transform { translation -0.45 0 0 } Material { emissiveColor 1.0 1.0 0 } PointLight { intensity 1 color 1.0 1.0 0.9 } # To be continued ...... Definition of HeadLight in Car Demonstration - IV # Continue Sphere and PointLight Separator .... Sphere { radius 0.1 } } } # End HeadLight Now we can use the HeadLight again with USE -- good cars have two of them -- this time we save a lot! VRML Cone Node - I This node represents a simple cone whose central axis is aligned with the y-axis. By default, the cone is centered at (0,0,0) and has a size of -1 to +1 in all three directions. The cone has a radius of 1 at the bottom and a height of 2, with its apex at 1 and its bottom at -1. The cone has two parts: the sides and the bottom. The cone is transformed by the current cumulative transformation and is drawn with the current texture and material which will reference the parts. VRML Cone Node - II If the current material binding is PER_PART or PER_PART_INDEXED, the first current material is used for the sides of the cone, and the second is used for the bottom. Otherwise, the first material is used for the entire cone. When a texture is applied to a cone, it is applied differently to the sides and bottom. On the sides, the texture wraps counterclockwise (from above) starting at the back of the cone. The texture has a vertical seam at the back, intersecting the yz-plane. For the bottom, a circle is cut out of the texture square and applied to the cone's base circle. The texture appears right side up when the top of the cone is rotated towards the -Z axis. VRML Cone Node - III PARTS SIDES The conical part BOTTOM The bottom circular face ALL All parts FILE FORMAT/DEFAULTS Cone { parts ALL # SFEnum bottomRadius 1 # SFFloat height 2 # SFFloat } parts replaced by side and bottom which are either true or false in VRML2 VRML1.0 PointLight Node - I This node defines a point light source at a fixed 3D location. A point source illuminates equally in all directions; that is, it is omni-directional. A light node defines an illumination source that may affect subsequent shapes in the scene graph, depending on the current lighting style. Light sources are as you should expect affected by the current transformation. A light node under a separator does not affect any objects outside that separator. VRML1.0 PointLight Node - Formal Specification FILE FORMAT/DEFAULTS PointLight { on TRUE # SFBool intensity 1 # SFFloat color 1 1 1 # SFColor location 0 0 1 # SFVec3f } VRML2 adds fields such as attentuation, radius, ambientIntensity VRML1.0 Cylinder Node - I This node represents a simple capped cylinder centered around the y-axis. By default, the cylinder is centered at (0,0,0) and has a default size of -1 to +1 in all three dimensions. The cylinder has three parts: the sides, the top (y = +1) and the bottom (y = -1). You can use the radius and height fields to create a cylinder with a different size. The cylinder is transformed by the current cumulative transformation and is drawn with the current material and texture. If the current material binding is PER_PART or PER_PART_INDEXED, the first current material is used for the sides of the cylinder, the second is used for the top, and the third is used for the bottom. Otherwise, the first material is used for the entire cylinder. VRML1.0 Cylinder Node - II When a texture is applied to a cylinder, it is applied differently to the sides, top, and bottom. On the sides, the texture wraps counterclockwise (from above) starting at the back of the cylinder. The texture has a vertical seam at the back, intersecting the yz-plane. For the top and bottom, a circle is cut out of the texture square and applied to the top or bottom circle. The top texture appears right side up when the top of the cylinder is tilted toward the +Z axis, and the bottom texture appears right side up when the top of the cylinder is tilted toward the -Z axis. VRML1.0 Cylinder Node Formal Specifications- III PARTS SIDES The cylindrical part TOP The top circular face BOTTOM The bottom circular face ALL All parts FILE FORMAT/DEFAULTS Cylinder { parts ALL # SFBitMask radius 1 # SFFloat height 2 # SFFloat } parts replaced by side bottom and top which are true or false in VRML2.0 VRML1.0 AsciiText in Car Demonstration - I Becomes Text in VRML2.0 Here we display the name of manufacturer and when you click on name, you go to their home page. WWWAnchor { name "http://www.ford.com/" Transform { # Put the name where you want translation 4.5 -1 2 rotation 1 0 0 -1.0471976 scaleFactor 0.125 0.125 0.125 center 0 0 0 } # To be Continued AsciiText in Car Demonstration - II AsciiText { # This string is displayed string "Ford Cars are \"Great\"" spacing 1 justification CENTER width 0 } } # End WWWAnchor VRML2.0 Text node has Fontstyle field (pointing to Fontstyle node) expressing nature of text AsciiText Node Type -- General Structure - I This node represents strings of text characters from the ASCII coded character set. The first string is rendered with its baseline at (0,0,0). All subsequent strings advance y by - (size * spacing). See node type FontStyle for a description of the size field. The justification field determines the placement of the strings in the x dimension as LEFT, CENTER or RIGHT where for instance latter places the right edge of each string at x=0. AsciiText Node Type -- General Structure - II Text is rendered from left to right, top to bottom in the font set by FontStyle. The width field defines a suggested width constraint for each string. The default is to use the natural width of each string. Setting any value to 0 indicates the natural width should be used for that string. The text is transformed by the current cumulative transformation and is drawn with the current material and texture. AsciiText Node Type -- Formal Specification FILE FORMAT/DEFAULTS AsciiText { string "" # MFString -- Note can have several strings spacing 1 # SFFloat -- Line spacing ratio justification LEFT # SFEnum chosen from LEFT CENTER RIGHT width 0 # MFFloat } Specification of JUSTIFICATION enumerated list LEFT Align left edge of text to origin CENTER Align center of text to origin RIGHT Align right edge of text to origin VRML1.0 Level Of Detail LOD Node - I See Discussion of our Terrain Renderer in VRML for use of LOD Node This group node is used to allow applications to switch between various representations of objects automatically. The children of this node typically represent the same object or objects at varying levels of detail, from highest detail to lowest. The specified center point of the LOD is transformed by the current transformation into world space, and the distance from the transformed center to the world-space eye point is calculated. If the distance is less than the first value in the ranges array, then the first child of the LOD group is drawn. If between the first and second values in the ranges array, the second child is drawn, etc. VRML1.0 Level Of Detail LOD Node - II If there are N values in the ranges array, the LOD group should have N+1 children. Specifying too few children will result in the last child being used repeatedly for the lowest levels of detail; if too many children are specified, the extra children will be ignored. Each value in the range array should be less than the previous value, otherwise results are undefined. FILE FORMAT/DEFAULTS LOD { range [ ] # MFFloat center 0 0 0 # SFVec3f } VRML2.0 has additional level field whose value is an array of nodes which are object at lebvels of detail specified