© Richard Jones, 2009 CO641 Computer Graphics 1 CO641 Computer Graphics and Animation X3d / VRML Richard Jones SW107

Slides:



Advertisements
Similar presentations
1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 10 VRML - An Introduction.
Advertisements

1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 11 VRML Animation and Interaction.
11.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 11 VRML - An Introduction.
3D sprog X3D: Et 3D sprog til at definere realtime 3D grafik der kan formidles via WWW. – XML integreret – Baseret på VRML – Relativt nyt så der findes.
KompoZer. This is what KompoZer will look like with a blank document open. As you can see, there are a lot of icons for beginning users. But don't be.
VRML 97 Formato per la definizione di oggetti 3D. La versione VRML 1 viene da una semplificazione degli scene graphs di OpenInventor. La versione 2.0 (97)
© TMC Computer School HC20203 VRML HIGHER DIPLOMA IN COMPUTING Chapter 1 – Introduction to VRML.
Event Routing §Some VRML nodes generate events in response to environmental changes or user interaction. Event routing gives authors a mechanism, separate.
Viewpoint { eventIn SFBool set_bind exposedField SFFloat fieldOfView # (0,  ) exposedField SFBool jump TRUE exposedField SFRotation orientation.
Introduction to VRML By Salman Yussof Diego Iglesias.
Adding Functionality To Web-Based VR Basic Concepts Client – server model Client-side static Client-side scripting Server-side scripting.
What Is VRML? VRML is: Stands for Virtual Reality Modeling Language A simple text language for describing 3-D shapes and interactive environments VRML.
Virtual reality interfaces in connection with building process simulations. Prof. Nash Dawood Centre for Construction Innovation Research University of.
Multimedia and the WWW Howell Istance and Chris Hand, Napier University.
An Overview of VRML §Scene Graph Structure VRML files describe 3D objects and worlds using a hierarchical scene graph. Entities in the scene graph are.
© De Montfort University, D Graphics and VRML Howell Istance and Chris Hand* De Montfort University * now at
A Standard Humanoid Representation on The Web: VRML/X3D Humanoid Animation Working Group (H-anim) Che-Jen Chen May/30/2003.
Cse591 Spring 981 VRML Basics The basic elements of VRML files are nodes. Every type of node has a set of fields associated with it. –Common single-valued.
Event Routing §Some VRML nodes generate events in response to environmental changes or user interaction. Event routing gives authors a mechanism, separate.
University College Dublin1 Scope ROOT Light SourceTransform Light SourceSphere.
Multimedia Web Components VRML. Introduction to VRML Case sensitive Most easy technique to provide interactive 3D environment in Web Required special.
3D on-line representations Jan Valcik → introduction, main idea → VRML 97 → building of virtual worlds → VRML 97 at work → X3D → MUDVR → animations, navigation.
VRML Virtual Reality Modeling Language. What Are We Going to See? What is VRML? Syntax of the language Features Examples.
1 The World Wide Web. 2  Web Fundamentals  Pages are defined by the Hypertext Markup Language (HTML) and contain text, graphics, audio, video and software.
Getting started © juhanita2015.
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
© TMC Computer School HC20203 VRML HIGHER DIPLOMA IN COMPUTING Chapter 3 – Object Definition in VRML.
Virtual reality. Tasks 3D digital model from planes 3D digital model of existing objects Office work Field observations Solid modeling Photogrammetry.
VRML Dr. Alun Moon What is VRML The Virtual Reality Modeling Language (VRML) is a file format for describing interactive 3D objects.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
HTML HyperText Markup Language Constantly evolving - extra facilities being added regularly Java applets and JavaScript used to increase functionality.
VRML - 1 Virtual Reality Modeling Language (VRML) Peter O’Grady.
London April 2005 London April 2005 Creating Eyeblaster Ads The Rich Media Platform The Rich Media Platform Eyeblaster.
CP2022 Multimedia Internet Communication1 HTML and Hypertext The workings of the web Lecture 7.
VRML Shapes and Geometry
VRML Scene Graphs. Learning Objectives Understand the concept of a scene graph Understand how VRML defines transformations (translations, rotations, and.
History of VRML and Its Development Process. Learning Objectives Understand the history of VRML Understand the purpose and functions of VRML Learn how.
Chapter 8 Introduction to HTML and Applets Fundamentals of Java.
Mashups with X3D Earth Mike McCann (MBARI) Alan Hudson (Yumetech)
1 Virtual Reality Modeling Language (VRML97) ©Anthony Steed
Tutorial 1 Introducing Adobe Flash CS3 Professional
Object Orientated Data Topic 5: Multimedia Technology.
UFCFS D Technologies for the Web Unity 3D: Review of Topics and Related Concepts.
Introduction HTML (Hypertext Markup Language) is used to create document on the World Wide Web. HTML is not a programming language, it is a markup language.
CVVR National Dong Hwa Univ. 國立東華大學 VRML Virtual Reality Modeling Language
Computer Graphics Group Script node Jiří Žára. Computer Graphics Group Contents 1.Script node 2.Motion generators 2Script node.
H3D API Training Part 2.1: X3D. Outline  Scene graphs  X3D – XML syntax  X3D components overview.
VRML virtual reality modeling language. what is it? standardised (sort of) notation for virtual reality over the web text file (use normal text editor)
111/16/ :14 UML Instance Transformation x y z x y z x y z x y z SRT Model Coordinates.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
Virtual Reality Modeling Language 97. What’s VRML? Virtual Reality Modeling Language 2D/3D graphics Audio:.wav,.mid Video: MPEG-1 Interactivity: time-
111/22/ :40 UML VRML 2.0 Scene Graph Structure Group Transformation Shape Nodes.
VRML Anthony Steed Department of Computer Science University College London ©Anthony Steed
Interface Opportunities for 3D Data and Media User Interface Software TechNote Panel Virginia Tech CS Fall 2002 Nicholas F. Polys Umur Yilmaz Will Lee.
© TMC Computer School HC20203 VRML HIGHER DIPLOMA IN COMPUTING Chapter 2 – Basic VRML.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Intro to VRML Let’s build something! The source code examples in this tutorial WORK!
DESIGNING 3D WEB USING VRML Bob Hobbs Introduction to Virtual Reality and Simulation CE
Introduction to HTML. _______________________________________________________________________________________________________________ 2 Outline Key issues.
© TMC Computer School HC20203 VRML HIGHER DIPLOMA IN COMPUTING Chapter 6 – Texture Maps.
© TMC Computer School HC20203 VRML HIGHER DIPLOMA IN COMPUTING Chapter 5 – Animation in VRML.
HTML5 and CSS3 Illustrated Unit F: Inserting and Working with Images.
© TMC Computer School HC20203 VRML HIGHER DIPLOMA IN COMPUTING Chapter 4 – Object Manipulation in VRML.
DLP for Virtual Environments (I)
MPEG-4 Binary Information for Scenes (BIFS)
Inserting and Working with Images
Department of Computer Science University College London
VIRTUAL REALITY IN ROBOTICS
VRML Shapes.
Lecture 3. Virtual Worlds : Representation,Creation and Simulation
Presentation transcript:

© Richard Jones, 2009 CO641 Computer Graphics 1 CO641 Computer Graphics and Animation X3d / VRML Richard Jones SW107

© Richard Jones, 2009 CO641 Computer Graphics 2 3D worlds Objects (International Space Station) Tours: building

© Richard Jones, 2009 CO641 Computer Graphics 3 Constructing 3d worlds OpenGL DirectX Java 3d java.sun.com/products/java-media/3D/ X3D Virtual Reality Modelling Language (VRML)

© Richard Jones, 2009 CO641 Computer Graphics 4 VRML Markup language for 3D scenes Widely supported, non-proprietary, scene description language animation (scripts, sensors, interpolators, event routes) VRML 2.0 (VRML97) specifications. VRML files MIME type is "model/vrml ” Filename extensions is ".wrl ” Plugins for browsers Cortona (good for developing) Cosmoplayer (nicer user interface but crashes nastily)

© Richard Jones, 2009 CO641 Computer Graphics 5 X3D Open software standard. Successor to VRML. New features, APIs, encoding formats, stricter conformance, componentised architecture (profiles). XML encoding and Scene Authoring Interface. Event model, VRML left many decisions to the browser implementer. Compatible with Scalable Vector Graphics (SVG). New nodes.

© Richard Jones, 2009 CO641 Computer Graphics 6 Why? Simple syntax Learning curve is not steep Focus on graphics rather than complexities of library Easy to get quite nice images Simple animation models Helps Understanding of scene graph Understanding hierarchies Understanding of transformations

© Richard Jones, 2009 CO641 Computer Graphics 7 Syntax Transform { children Shape { appearance Appearance { material Material { diffuseColor } } geometry { Cylinder { height 0.1 radius 0.5 } } } }.wrl,.x3dv.x3d

© Richard Jones, 2009 CO641 Computer Graphics 8 X3D/VRML basics X3D/VRML comes with a fixed set of objects (called nodes). X3D/VRML is a programming language. We ’ ll want to structure the code and create new (specific) nodes The prototyping feature allows complex objects to be created, reused, and changing certain characteristics when desired. It ’ s important to use good programming practice…just like you would in Java.

© Richard Jones, 2009 CO641 Computer Graphics 9 Creating objects X3d/VRML has a notion of a node A fundamental building block Objects –Cylinder, Cone, Box, SpotLight Containers –Shape (contains geometry node and appearance node) Hierarchies Nodes can contain nodes Each node contains fields (the parameters) Special nodes include: Hyperlinking, collision detection The node hierarchy is the scene graph.

© Richard Jones, 2009 CO641 Computer Graphics 10 Shape node Shape nodes are basic containers for geometry (Cylinder, Box, etc..) They allow two child nodes: appearance and geometry. #VRML V2.0 utf8 Shape { appearance Appearance { material Material { } } geometry Cylinder { } } #X3D V3.0 utf-8 mandatory file headers

© Richard Jones, 2009 CO641 Computer Graphics 11 VRML and HTML Embed VRML in a web page Embeded VRML test <embed src= "world.wrl" border=0 height="250" width="600">

© Richard Jones, 2009 CO641 Computer Graphics 12 Appearance node Add properties: colour, smoothness, shininess etc. Commonly used fields: material (diffuseColor, shininess, ambientIntensity, transparency) texture (ImageTexture, MovieTexture, PixelTexture) Material { diffuseColor # red green blue = Gray shininess0.5 ambientIntensity 0.35 }

© Richard Jones, 2009 CO641 Computer Graphics 13 Geometry node #VRML V2.0 utf8 Shape { appearance Appearance { material Material { diffuseColor shininess.5 } geometry Cylinder { radius 3 height6 sideTRUE topFALSE bottomTRUE } Important: centre of the object (0,0)

© Richard Jones, 2009 CO641 Computer Graphics 14 Scene graphs A VRML world is a hierarchy of nodes, including Shapes and transformations. Useful to think of this as a graph. Use transformations to scale, rotate and move objects.

© Richard Jones, 2009 CO641 Computer Graphics 15 Transformations Transform { rotation translation scale children [ Inline { url “ frog.wrl ” } ] } Default values used for omitted fields. Order is always: scale—rotate—translate. axis (defined by origin to this point) angle in radians:  radians = 180° right-hand coords scaled relative to the origin x y z

© Richard Jones, 2009 CO641 Computer Graphics 16 Simple Example #X3D V3.0 utf-8 # first child - a red sphere # red NB: use a good layout style for readability.

© Richard Jones, 2009 CO641 Computer Graphics 17 #VRML V2.0 utf8 Transform { children [ NavigationInfo { headlight FALSE } # We'll add our own light DirectionalLight { direction } # Light illuminating scene Transform { # Third child - a red sphere translation children [ Shape { geometry Sphere { radius 2.3 } appearance Appearance { material Material { diffuseColor } # Red } ] } Transform { # Fourth child - a blue box translation rotation children [ Shape { geometry Box { } appearance Appearance { material Material { diffuseColor } # Blue } ] } ] # end of children for world } DRAW THE SCENE GRAPH

© Richard Jones, 2009 CO641 Computer Graphics 18 Title and information As with HTML, you can also add a title and information about the file: #VRML V2.0 utf8 WorldInfo { title “ A virtual picture of a house ” info “ VRML model of a house ” }...

© Richard Jones, 2009 CO641 Computer Graphics 19 Programming style 1.Start with the header #VRML 2.0 utf8 2.Global nodes WorldInfo metadata & scene setup. 3.Prototypes a ‘ constructor ’ — must be defined before you can create an instance of the prototyped type. 4.Scene hierarchy most scene hierarchies have one root node. 5.Scripts & Interpolators, placed anywhere often placed in complex nodes or after scene hierarchy. 6.Routes must appear after the nodes and fields they refer to often they are placed in complex nodes or after the scene hierarchy 7.Time sensors can appear after/before scene hierarchy.

© Richard Jones, 2009 CO641 Computer Graphics 20 Reuse It ’ s good software engineering practice to reuse code — in any language. There are 3 ways to do this: 1.Inline 2.DEF/USE 3.PROTO (and EXTERNPROTO)

© Richard Jones, 2009 CO641 Computer Graphics 21 Inline #VRML V2.0 utf8 Inline { url ” LowerPlatform.wrl ” } #X3D V3.0 utf-8 Reads its children from any URL (can be delayed until the Inline is displayed). Optional fields bboxSize and bboxCenter

© Richard Jones, 2009 CO641 Computer Graphics 22 DEF/USE A simple naming mechanism. Use for multiple instances, repetition... Appearance { texture DEF GRAINY ImageTexture {url ” grainy.jpg ” } # names a texture map... }... Appearance { texture USE GRAINY } # names a texture map......

© Richard Jones, 2009 CO641 Computer Graphics 23 Prototypes These are IMPORTANT They are the key to good practice, and the reason why most tools (which don ’ t use them) generate hard to maintain models. A PROTO defines a new node type in terms of pre-defined nodes (either built in nodes, or other prototypes). The type of the prototype is given by its root node. Its good practice to utilize prototypes rather than DEF/USE — make all your nodes into a prototype.

© Richard Jones, 2009 CO641 Computer Graphics 24 PROTO PROTO Seat [ ] { Shape { appearance Appearance { material Material { diffuseColor } geometry Box {} } Once you ’ ve built your prototype, you can use it as below… Seat{} This gives a blue seat — it ’ s always blue.

© Richard Jones, 2009 CO641 Computer Graphics 25 PROTO parameters PROTO Seat [ field SFColor seatColor ] { Shape { appearance Appearance { material Material { diffuseColor IS seatColor } geometry Box {} } By default Seat{} the seat is grey. But we can instantiate a seat of any colour, e.g. red Seat{seatColor 1 0 0} Note that only seatColor is public.

© Richard Jones, 2009 CO641 Computer Graphics 26 Node specifications The ISO standard gives the interface details to each node, etc. (refer to the spec), e.g. Sphere { field SFFloat radius 1 } Text { exposedField MFString string [] exposedField SFNode fontStyle NULL exposedField MFFloat length[] exposedField SFFloat maxExtent0.0 } SFNode (MFNode) The field is a single node (any number of nodes) field The field can only be set in the ‘constructor’ exposedField The field automatically has a set_ method ( set_string ) so that it can be changed by other nodes (e.g. scripts)

© Richard Jones, 2009 CO641 Computer Graphics 27 Advanced PROTO #VRML V2.0 utf8 PROTO SizedPositionedObject [ field SFColor baseColor field SFVec3f position field SFNode model NULL ] { Transform { children [ Shape { appearance Appearance { material Material { diffuseColor IS baseColor } geometry IS model } ] translation IS position } Group { children [ SizedPositionedObject { model Cone{} baseColor position } SizedPositionedObject { model Cylinder{} baseColor position 0 0 0} ] }

© Richard Jones, 2009 CO641 Computer Graphics 28 Other VRML nodes 1.Box 2.Cylinder 3.Cone 4.Sphere 5.Coodinate 6.Pointsets 7.Indexed LineSets 8.Indexed Face Sets 9.Text 10. DirectionalLight 11. PointLight 12. SpotLight 13. AudioClip (sound) ElevationGrid (for terrain modelling) Extrusion

© Richard Jones, 2009 CO641 Computer Graphics 29 BoxCone Cone { field SFFloat bottomRadius 1 # (0,  ) field SFFloat height 2 # (0,  ) field SFBool side TRUE field SFBool bottom TRUE } Box { field SFVec3f size # (0,  ) }

© Richard Jones, 2009 CO641 Computer Graphics 30 Shape nodes & fields... Fields specify attributes of the node Predefined name and can contain a certain type of value (integer “ 2 ” or float “ ” ) Node using { } uses default values e.g. Cylinder has default radius of 1 and default height of 2 (0,0) at the middle #VRML V2.0 utf8 Shape { appearance Appearance { material Material { } } geometry Cylinder { radius 3 height 6 side TRUE top FALSE bottom TRUE }

© Richard Jones, 2009 CO641 Computer Graphics 31 Coordinate node Every piece of vertex-based geometry must include a list of the vertices to be used. The Coordinate nodes allow the vertices to be described in 3D space Coordinate { point [ , # point 0, , # point 1, 1 1 0, # point 2, , # point 3, ] # end point }

© Richard Jones, 2009 CO641 Computer Graphics 32 geometry IndexedFaceSet { coord Coordinate { point [ # base of 3dtriangle 0 0 1, # point 0, center front , # point 1, back right , # point 2, back left , # point 3, top of 3dtriangle ] # end point } # end coord coordIndex [ # Need to go counter-clockwise # from the OUTSIDE. 0, 1, 2, 0, -1, 3,2,1,-1, # front 3,0,2,-1, # left 3,1,0,-1, # right ] # end coordIndex } # end geometry Indexed Face Sets

© Richard Jones, 2009 CO641 Computer Graphics 33 geometry IndexedFaceSet { coordCoordinate { point[ , , 5 5 0, , ] } colorColor { color[ 1 0 0, 0 1 0, 0 0 1, 1 1 0, ] } coordIndex[ 0, 1, 4, -1, 1, 2, 4, -1, 2, 3, 4, -1, 3, 0, 4, -1, 3, 2, 1, 0, -1 ] normalNULL texCoordNULL colorPerVertexTRUE } Indexed Face Sets Color per vertex..

© Richard Jones, 2009 CO641 Computer Graphics 34 #VRML V2.0 utf8 Shape { geometry Text { string “hello world” } Text Can also specify size, family (of fonts) and style geometry Text { string “hello world” fontStyle FontStyle { size 2.5 family “SERIF” style “ITALIC” }

© Richard Jones, 2009 CO641 Computer Graphics 35 #VRML V2.0 utf8 Shape { geometry IndexedLineSet { coord Coordinate { point [ #base of pyramid , # point 0, left and close , # point 1, left and back , # point 2, right and back 2 0 2, # point 3, right and close #top of pyramid 0 2 0, #point 4, top of pyramid ] # end point } # end coord coordIndex [ #base 0, 1, 2, 3, 0, -1, #vertical edges 0, 4, -1, 1, 4, -1, 2, 4, -1, 3, 4, -1, ] # end coordIndex } Indexed Line Set

© Richard Jones, 2009 CO641 Computer Graphics 36 ElevationGrid “ The ElevationGrid node specifies a uniform rectangular grid of varying height in the Y=0 plane of the local coordinate system. ”

© Richard Jones, 2009 CO641 Computer Graphics 37 VRML Links - anchor #VRML V2.0 utf8 Group { children [ Anchor { url " children [ Shape { geometry Sphere { radius 2.3} appearance Appearance { material Material { diffuseColor # Green } ] }# end Anchor ] }

© Richard Jones, 2009 CO641 Computer Graphics 38 Level Of Detail #VRML V2.0 utf8 LOD { range [ 10, 30, 60] level [ Shape { geometry Sphere { } } Shape { geometry Box { } } Shape { geometry Cone {} } ] }

© Richard Jones, 2009 CO641 Computer Graphics 39 Billboard Group { children [ Billboard { axisOfRotation children [ Shape { appearance Appearance { texture ImageTexture { url "sphere.gif“ } } geometry Sphere { } } ] } ] } A special grouping node All children nodes will automatically face the observer The children nodes will rotate in a user defined axis Billboard { children [ ] axisOfRotation bboxCenter bboxSize } Y-axis

© Richard Jones, 2009 CO641 Computer Graphics 40 Collision Transform { translation children [ Collision { collide TRUE proxy Shape { geometry Box { size } } #children [ # Inline { url “complex.wrl”} #] } ] } Collision of the Avatar with objects. e.g. prevent you walking through a wall. Quite processor intensive. Best to put collision only over nodes that require it. Also simplify the geometry & use collision proxies. By default, collision detection is on.

© Richard Jones, 2009 CO641 Computer Graphics 41 I CAD X3D Profiles Target a common market or functionality. Interactive Core Interchange Immersive Full

© Richard Jones, 2009 CO641 Computer Graphics 42 Core: basic defs (e.g. ROUTE), no geometry, appearance,… Interchange: exchange models between 3D applications, geometries, appearances, keyframe animation Immersive: closest to VrML97, Interactive + new nodes Full: Interactive + Humanoid Animations and other advanced components

© Richard Jones, 2009 CO641 Computer Graphics 43 Interaction Anchor load up an HTML file or another VRML file Inline Load up an external VRML file into this one. Collision detection whilst moving round a scene Events: Sensor –effect the world from a mouse event –detect that the mouse is over me - and then change the world... Scripts (user defined programs..) Interpolators (pre-defined) Timers tick, tick... then after 6 seconds do something

© Richard Jones, 2009 CO641 Computer Graphics 44 Events As well as fields, some nodes have events. input events output events ROUTE events between nodes Group { children [ DEF LIGHT_CONTROL TouchSensor {} Inline{ url [ “lightswitch.wrl” ] } ] } DEF LIGHT PointLight { location on FALSE } Inline {url [ “table.wrl” ] } ROUTE LIGHT_CONTROL.isActive TO LIGHT.on isActive on TouchSensor PointLight

© Richard Jones, 2009 CO641 Computer Graphics 45 Plane sensor Make object move ONLY along a plane Group { children [ DEF DRAG_ME PlaneSensor { minPosition 0 0 # start at 0,0 maxPosition 10 0 # move to 10,0 } DEF OBJ Transform { translation children [ Inline { url [“geometry_to_move.wrl” ] } ] } ] } ROUTE DRAG_ME.translation_changed TO OBF.translation

© Richard Jones, 2009 CO641 Computer Graphics 46 Forms of animation Flip book predefined set of images consecutively replayed works on 2D bitmap images interaction: stop,play,rewind Key frame define some key frames interpolate between (in-betweening) interaction: stop,play,rewind,trajectory,re-action Procedural start with an object in space use physical laws (and other equations) to effect the object interaction: stop, play, rewind, mass, gravity, shape... gravity =10 reflection =90 o

© Richard Jones, 2009 CO641 Computer Graphics 47 Flip Book animation in VRML Have a series of predefined VRML geometry files. Place them in a switch statement, a choice Switch between them using a timer node Group { children [ DEF TOUCH TouchSensor { }, DEF TOGGLE Script {..holds current choice, and if called moves to next.... at end moves to first choice }, DEF SWITCH Switch { whichChoice 0 choice [ Inline { url "frame1.wrl" }, Inline { url "frame2.wrl" }, Inline { url "frame3.wrl" }, ] } ] ROUTE TOUCH.touchTime TO TOGGLE.toggle ROUTE TOGGLE.which TO SWITCH.whichChoice }

© Richard Jones, 2009 CO641 Computer Graphics 48 Interpolator Nodes Interpolator nodes are designed for linear key-framed animation. An interpolator node defines a piecewise-linear function, f(t), over the interval (-infinity, +infinity). The piecewise-linear function is defined by n values of t, called keys, and the n corresponding values of f(t), called keyValues. The keys must be monotonically non-decreasing, otherwise the results are undefined. The keys are not restricted to any interval.

© Richard Jones, 2009 CO641 Computer Graphics 49 Interpolators The following node types are interpolator nodes, each based on the type of value that is interpolated: ColorInterpolator CoordinateInterpolator NormalInterpolator OrientationInterpolator PositionInterpolator ScalarInterpolator Interpolator semantics: eventIn SFFloat set_fraction eventOut [S|M]F value_changed exposedField MFFloat key [...] exposedField MF keyValue [...]

© Richard Jones, 2009 CO641 Computer Graphics 50 Key frame in VRML Use an Engine (such as an Interpolator) Moving a cube (left to right) x + 3 enterTime startTime fraction set_fraction TriggerTimerEngine e.g Position- Interpolator Touch SensorTimerMover intensity Target Object value_changed

© Richard Jones, 2009 CO641 Computer Graphics 51 Key frame in VRML Group { children [ DEF TARGET_Xform Transform { children [ Shape { geometry Box { } } ] }, DEF TIMER TimeSensor { cycleInterval 2 loop TRUE }, DEF MOVER_POS PositionInterpolator { key [ 0.0, 0.5, 1 ] keyValue [ 0 0 0, 3 0 0, ] } ] ROUTE TIMER.fraction TO MOVER_POS.set_fraction ROUTE MOVER_POS.value_changed TO TARGET_Xform.translation } Key frames... 2 seconds

© Richard Jones, 2009 CO641 Computer Graphics 52 Key frame animation example Using PositionInterpolator Timer

© Richard Jones, 2009 CO641 Computer Graphics 53 Script nodes The script node allows code to be incorporated. The script can be in various Scripting languages, JavaScript (or ECMASCRIPT) is the most commonly used. A script node activates when it receives an event. Script nodes receive events in timestamp order. Scripts that have access to other nodes (via SFNode/MFNode fields or eventIns) and that have their directOutput field set to TRUE may directly post eventIns to those nodes. They may also read the last value sent from any of the node's eventOuts.

© Richard Jones, 2009 CO641 Computer Graphics 54 Accessing eventIns and eventOuts of other nodes The script can access any eventIn or eventOut of any node to which it has access. access and modify an exposed field of another node (i.e., sends a set_translation eventIn to the Transform node) using ECMAScript: DEF SomeNode Transform { } DEF SomeScript Script { field SFNode tnode USE SomeNode eventIn SFVec3f pos directOutput TRUE url "javascript: function pos (value, timestamp) { tnode.set_translation = value; }" }

© Richard Jones, 2009 CO641 Computer Graphics 55 #VRML V2.0 utf8 Group { children [ DEF TOUCH TouchSensor {}, DEF TOGGLE Script { eventIn SFTime toggle eventOut SFInt32 which field SFInt32 thisVal 0 url "javascript: function toggle() { thisVal = thisVal >= 2 ? 0 : thisVal+1; which = thisVal; }" }, DEF SWITCH Switch { whichChoice 0 choice [ Inline { url "arrowDOWN.wrl" }, Inline { url "arrowUP.wrl" }, Inline { url "object.wrl" }, ] } ] ROUTE TOUCH.touchTime TO TOGGLE.toggle ROUTE TOGGLE.which TO SWITCH.whichChoice }

© Richard Jones, 2009 CO641 Computer Graphics 56 Initialize() shutdown() Initialize() method: invoked before the browser presents the world to the user before any events are processed by nodes in the same VRML file as the Script node. Events generated by the initialize() method have timestamps less than any other events generated by the Script node. Allowing script initialization tasks to be performed prior to the user interacting with the world. Shutdown() method invoked when the corresponding Script node is deleted or the world containing the Script node is unloaded or replaced by another world. used as a clean-up operation, e.g. remove temporary files. Events routed to those being removed will not get through! nothing of the script may be invoked after the shutdown() method has completed, though the shutdown() method may invoke methods or send events while shutting down.

© Richard Jones, 2009 CO641 Computer Graphics 57 Trick - Head Up Display (HUD) Head Up Displays usually called HUDs are a simple collection of nodes which ensure that objects will remain in the same position relative to the user regardless of the movement or rotation. They sense when the viewer has moved, then move the world to match appropriately.

© Richard Jones, 2009 CO641 Computer Graphics 58 # ProximitySensor to ensure HUD geometry moves with user # used in all HUD systems DEF GlobalProx ProximitySensor { size } DEF HUD Transform { children [ # needed to prevent collisions with nearby HUD geometry # not needed if far away (a backdrop) or just lighting Collision { collide FALSE children [..HUD geometry and/or lighting ] } ] } # Route user position and orientation to HUD ROUTE GlobalProx.position_changed TO HUD.translation ROUTE GlobalProx.orientation_changed TO HUD.rotation