Adding Functionality to VRML

Download Report

Transcript Adding Functionality to VRML

Adding Functionality To Web-Based VR





Basic Concepts
Client – server model
Client-side static
Client-side scripting
Server-side scripting
Web / Network Structure





Web consists of a series of interlinked data
repositories
Linked via hubs and routers
Use telephone network, satellite links, private
links
Connected using IP addresses
IP addresses mapped to location by DNS
Client /Server


A`server‘ refers to a
computer that offers a
service that can be
obtained over the
network
workstation becomes a
``client'' when it sends a
request to a server and
waits for a response
The World Wide Web



Many Clients
Many Servers
Many means of
linking
Overall WWW Client - Server model
HTTP Protocol





The protocol is basically stateless, a transaction
consists of:
Connection - The establishment of a connection
by the client to the server
Request - The sending, by the client, of a request
message to the server;
Response - The sending, by the server, of a
response to the client;
Close - The closing of the connection by either
both parties.
Dynamic v Static
Server
Client sends
request
Client
Server sends
data - data
cached locally
Server
Server sends data
– cached locally
- contains variable
data
Client
Client handles
input by user –
browser
invokes actions
Client sends
request
Client side processing

Static Web page



HTML
Cached Locally
Dynamic Web Page





DHTML, XML, vrmlscript, javascript
Java Applets
Flash, Shockwave
Cached locally
Browser deals with locally
Server Side processing




Client sends request back to server with user
request
Server interprets – reconfigures data
Returns new client-interpretable instructions
for browser to refresh local copy
CGI, ASP, Java Servlets
Teleprocessing



Request from client changes underlying data
on server
Web 3D – model changed for other users
Database update e.g.


User 1 looks up book - 3 copies – orders 1
User 2 looks up book – 2 copies
Adding action to 3D worlds



Communicate changes form one state to
another
Execution model
Java uses a class structure to show




state
Behaviour
The state in 3D is the geometry etc.
Behaviour is defined by the events
Requirements



VRML to store geometry
Java to drive the behaviours
How do we link them together?
Scene Graph




VRML file has a a set of nodes organised into
set of hierarchies
Nodes
Nodes exist to define geometry and to control
the scene
Use Routes to link nodes together
Static v Dynamic



VRML enables changes of state where a
route is pre-defined and non-variable I.e.
static
Activation is required to create a dynamic
scene
VRML provides simple methods of activation
via a sensor
Dynamic Behaviours


To create real dynamic worlds a bridge
between VRML and Java is required
Script Node
What is a dynamic behaviour

Behaviours involving





Query state
make decisions based on state
change scene based on decisions
E.g. If door is open go thro else turn left (or
right !!)
Script node allows arbitrary plugging of code
into the VRML scene
Script Node
Script {
exposedField
MFString url
[]
field
SFBool directOutput FALSE
field
SFBool mustEvaluate FALSE
# And any number of:
eventIn
eventTypeName eventName
field
fieldTypeName fieldName initialValue
eventOut
eventTypeName eventName
}
Setting Up a script node


Must have a pointer to the sourc e file
containing the program code
URL to allow web handling
Script {
url ”http:bob.home/ExampleClient.class"
eventIn SFRotation orientation
field SFNode target USE TARGET
}

Also contains




user-defined fields
Event in fields pass control to the referenced
class
Any field referenced can be altered by the code
referred to in the class
Event out generates an event to be sent to
connected nodes
Script Node is a messenger

Events sent to script are




packaged
sent to script (java class)
script updates script node fields
out fields of script node route event to other
nodes in the usual way
Event Class

Gets information about the incoming event



getName (name of event field in script node
getValue (reference to VRML field)
getTimeStamp (time at which event was
generated in VRML field)
Example
#VRML V2.0 utf8
Transform {
children [
DEF TS TouchSensor {} # TouchSensor
Shape {
appearance Appearance {
material DEF SphereColor Material { diffuseColor 1 0 0 } # red
}
geometry Sphere {}
}
]
}
Contd.
DEF ColorScript Script {
url "ChangeColor.class"
eventIn SFBool clicked
eventOut SFColor newColor
field SFBool on FALSE
}
# Routing
ROUTE TS.isActive TO ColorScript.clicked
ROUTE ColorScript.newColor TO SphereColor.set_diffuseColor
Java Class
import vrml.*;
import vrml.field.*;
import vrml.node.*;
public void processEvent(Event e) {
ConstSFBool v = (ConstSFBool)e.getValue();
if(v.getValue()){
if (on.getValue()) {
newColor.setValue(red);
// set red to 'newColor'
} else {
newColor.setValue(blue);
// set blue to 'newColor'
}
on.setValue(!on.getValue());
// = !on.getValue();
}
public class ChangeColor extends Script {
private SFBool on;
// status of on-off
float red[] = { 1, 0, 0 };
// RGB(Red)
float blue[] = { 0, 0, 1 };
// RGB(Blue)
private SFColor newColor ;
public void initialize() {
newColor = (SFColor) getEventOut("newColor");
on = (SFBool) getField("on");
}
}
}
Using JavaScript with VRML
# The Script
DEF toggle Script {
field SFBool active FALSE
eventIn SFBool isClicked
eventOut SFBool click_changed
url "vrmlscript:
function isClicked() {
if (active == 0)
active = 1;
else
active = 0;
click_changed = active;
}
"
}
Uses Script
Node