230 likes | 480 Views
Chapter 2 – Basic VRML. Structure of VRML File. A VRML file consists of the following major functional components the VRML header the scene graph which includes Shapes Interpolators sensors and scripts the prototypes event routing. #VRML V2.0 utf8 # A brown hut Group {
E N D
Structure of VRML File • A VRML file consists of the following major functional components • the VRML header • the scene graph which includes • Shapes • Interpolators • sensors and scripts • the prototypes • event routing
#VRML V2.0 utf8 # A brown hut Group { children [ # Draw the hut walls Shape { appearance DEF Brown Appearance { material Material { diffuseColor 0.6 0.4 0.0 } } geometry Cylinder { height 2.0 radius 2.0 } },
# Draw the hut roof Transform { translation 0.0 2.0 0.0 children Shape { appearance USE Brown geometry Cone { height 2.0 bottomRadius 2.5 } } } ] }
VRML Header • For easy identification of VRML files, every VRML file shall begin with • #VRML V2.0 <encoding type> • The <encoding type> is either "utf8" or any other authorized values defined in other parts of ISO/IEC 14772 • In this course, we are using "utf8" which indicates a clear text encoding that allows for international characters to be displayed in VRML
UTF-8 File Format • # character begins a comment • Only the first comment (the file header) has semantic meaning • The only exception is within double-quoted SFString and MFString fields where the # character is defined to be part of the string • Commas, spaces, tabs, linefeeds, and carriage-returns are separator characters wherever they appear outside of string fields • One or more separator characters separate the syntactical entities in VRML • The separator characters collectively are termed whitespace
VRML Statements • VRML file may contain any combination of the following : • Any number of PROTO or EXTERNPROTO statements • Any number of root children node statements • Any number of USE statements • Any number of ROUTE statements
Scene Graph • The scene graph contains nodes, which describe objects and their properties • It contains hierarchically grouped geometry to provide an audio-visual representation of objects • It also provides a means for nodes to participate in the event generation and routing mechanism
Nodes • Nodes are used to describe shapes and properties of the world such as: • shapes • colors • lights • viewpoints, how to position and orient shapes • animation times, sensors and interpolators
Nodes • A node contains the following information: • type of nodes • a set of curly brackets • fields • For example, a cylinder node could be described: cylinder { height 2.0 radius 2.0 }
Fields and Field Values • Fields define the attributes of a node • In the above example, the height field defines the height of the cylinder • Fields are optional within the nodes • If the values are not given, then a default value would be assigned • For example, the default values of cylinder have radius = 1.0 units and height = 2.0 units • Field values defines the attributes like color, size or position
Defining and Using Node Name • Any node can be defined in the world • The name of the node must begin with a letter, followed by any combination of characters and/or digits • DEF node_name name_type • Once a node has a name, we could reuse the node. • The node with defined name is called original node while the reuse nodes are called instances • USE node_name • Note that the node names are case-sensitive
Describing Shapes • A VRML shape has appearance (based on material), color and surface texture • These attributes are specified by the field values within a shape node • VRML supports several primitives shape geometries that include boxes, cylinders, cones, and shapes • VRML also supports advanced shape geometries like extruded shapes and elevation grids • Using these primitive shapes, we could group them and build more complex shapes • Shapes can be grouped by the Group node
Event Routing • Some VRML nodes generate events in response to environmental changes or user interaction • Event routing provides a mechanism, which allow events to be propagated to effect changes in other nodes • Once generated, events are sent to their routed destinations in time order and processed by the receiving node • This processing can change the state of the node, generate additional events, or change the structure of the scene graph
Event Routing • In order to build a dynamic world and propagate events based on environmental changes, we need “wiring instructions” • This process involves • a pair of nodes to wire together • a wiring route or path between these two nodes • Once the nodes are wired, messages could be sent along that route • Such message is called events which contains communicating values
Event Routing • For a successful routing, nodes must have eventIn and the corresponding eventOut • An eventIn receives events when it is connected to a route and a message is being sent to it • An eventOut sends the events out along the connected route • VRML “wiring” architecture is built by describing a route from one node’s eventOut to another node’s eventIn
Event Routing • The receiving node reacts based on the event depends on the following: • type of node receiving the event • node input jack to which the route is wired • values contained in the event • current activities of the node
Presentation and Interaction • The interpretation, execution, and presentation of VRML files will typically be undertaken a browser, which displays the shapes and sounds in the scene graph • This presentation is known as a virtual world and is navigated in the browser by a human or mechanical entity, known as a user • The world is displayed as if experienced from a particular location; that position and orientation in the world is known as the viewer
Presentation and Interaction • The browser may define navigation paradigms (such as walking or flying) that enables the user to move the viewer through the virtual world • The browser may provide a mechanism allowing the user to interact with the world through sensor nodes in the scene graph hierarchy • Sensors respond to user interaction with geometric objects in the world, the movement of the user through the world, or the passage of time
Presentation and Interaction • The visual presentation of geometric objects in a VRML world follows a conceptual model designed to resemble the physical characteristics of light • The VRML lighting model describes how appearance properties and lights in the world are combined to produce displayed colours • Refer to the diagram for the conceptual model of the VRML browser
Presentation and Interaction Conceptual Model of VRML Browser
USE Statement • The USE statement enables us to reuse all the objects that we have defined earlier in the scene graph • A USE statement consists of the USE keyword followed by a node name as follows: • USE <name>
ROUTE Statement • A ROUTE statement provides the message passing mechanism from one node to another • A ROUTE statement consists of the ROUTE keyword followed in order by a node name, a period character, a field name, the TO keyword, a node name, a period character, and a field name. • Whitespace is allowed but not required before or after the period characters: • ROUTE <name>.<field/eventName> TO <name>.<field/eventName> • All these commands will be covered in more details as the course proceeds