Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics Group Script node Jiří Žára. Computer Graphics Group Contents 1.Script node 2.Motion generators 2Script node.

Similar presentations


Presentation on theme: "Computer Graphics Group Script node Jiří Žára. Computer Graphics Group Contents 1.Script node 2.Motion generators 2Script node."— Presentation transcript:

1 Computer Graphics Group Script node Jiří Žára

2 Computer Graphics Group Contents 1.Script node 2.Motion generators 2Script node

3 Computer Graphics Group Sensors, Timers, Interpolators –Defined parameters –Defined behavior Script node –Custom parameters –Custom behavior 3 Dynamic nodes Script node eventOut eventIn field behavior Script node

4 Computer Graphics Group Script node Container for programming language code Supported languages: –Java –ECMAScript (JavaScript) Code can be written –Directly to wrl file (only JavaScript) –To a separate file (parameter url) 4

5 Computer Graphics Group Script node When to use a Script node? Engine part for controlling animation Logic part for processing input conditions Manipulation with the scene hierarchy (add child nodes) Interaction with the VRML browser Communication with a server across the network (only Java) 5

6 Computer Graphics Group interpreted object-based language syntax similar to Java non-strict conversion between data types variable number of args. in functions built-in objects: Array, Boolean, Date, Function, Math, Number, String. 6 ECMAScript

7 Computer Graphics Group 7 Script interface exposedField is not allowed! local variable with default value when received, a function with the same name is called. Params: [value(s), time stamp] sent when variable with the same name is set JavaScript code, path to JavaScript file or path to Java class field eventIn eventOut url

8 Computer Graphics Group Script node Example: Data convertor # Convert SFBool to SFInt32 Script { eventIn SFBool set_bool eventOut SFInt32 value_changed url "javascript: function set_bool (value, time) { if (value) value_changed = 1; else value_changed = 0; } // this is a comment! " } Live example 8

9 Computer Graphics Group Script node Two more params. of Script node SFBool mustEvaluate FALSE If FALSE, the browser may delay sending input events to the script until its outputs are needed by the browser. SFBool directOutput FALSE If FALSE, the script may only affect the rest of the world via events sent through its eventOuts If TRUE, the script may send events directly to any node to which it has access TRUEs causes poor performance 9

10 Computer Graphics Group Script node Example: directOutput TRUE DEF DIRECT Script { field SFNode object IS/USE … # any Shape node eventIn SFBool set_highlight field SFColor bright 0 0 0 directOutput TRUE url "javascript: function set_highlight (value) { if (value) bright[0]=bright[1]=bright[2]= 0.3; else bright.r =bright.g =bright.b = 0; object.appearance.material.emissiveColor = bright; }" } Live example 10

11 Computer Graphics Group Script node ECMAScript functions for Script initialize () called once, after loading the world shutdown () called once, before the world is left eventsProcessed () called when any eventIn is received, accumulation of small changes 11

12 Computer Graphics Group Script node Motion generators PROTO nodes with: script(s) and/or interpolator(s) children influenced by interpolators Examples: 1) shuttle motion generator (interpolator) 2) sin function motion (script) 12

13 Computer Graphics Group Script node Example 1: Shuttle Timer fraction_changed translation Transform PositionInterpolator value_changed set_fraction Script keyPositions keyValue (computes initial key values only) height 13

14 Computer Graphics Group Script node Shuttle PROTO header PROTO Shuttle [ field SFTime time 4 field SFFloat height 2 field MFNode object [ ] ] { DEF TRANSF Transform { children IS object } DEF TIMER TimeSensor { cycleInterval IS time loop TRUE # forever } DEF MOTION PositionInterpolator { key [ 0,.25,.75, 1 ] keyValue [ 0 0 0, 0 1 0, 0 -1 0, 0 0 0 ] } 14

15 Computer Graphics Group Script node Script for Shuttle DEF INIT-VALUES Script { field SFFloat height IS height eventOut MFVec3f keyPositions url "javascript: function initialize ( ) { z = new SFVec3f (); top = new SFVec3f (0, height, 0); down = new SFVec3f (0, -height, 0); keyPositions = new MFVec3f (z, top, down, z); }" } ROUTE … TO... } # end of PROTO Shuttle Live example 15

16 Computer Graphics Group Script node Example 2: Sin function Timer fraction_changed translation Transform Script translation set_fraction A script fully replaces an interpolator height 16

17 Computer Graphics Group Script node Sin PROTO header PROTO Sin [ field SFTime time 4 field SFFloat height 2 field MFNode object [ ] # = the same interface as Shuttle ] { DEF TRANSF Transform { children IS object } DEF TIMER TimeSensor { cycleInterval IS time loop TRUE # forever } 17

18 Computer Graphics Group Script node Example 2: Script for Sin DEF MOTION Script { field SFFloat height IS height eventIn SFFloat set_fraction eventOut SFVec3f translation url "javascript: function set_fraction (x) { translation = new SFVec3f (0, height * Math.sin (2*x*Math.PI), 0); }" } ROUTE … TO … } # end of PROTO Sin Live example 18

19 Computer Graphics Group … end of this part 19


Download ppt "Computer Graphics Group Script node Jiří Žára. Computer Graphics Group Contents 1.Script node 2.Motion generators 2Script node."

Similar presentations


Ads by Google