Click here see Simple Animation With One Shared Event
Click here see Simple Animation With Two Shared Events
Click here to Download All My Examples
To try out the examples upload all of the files from the simpleSharedEvents.zip
to the web and set your browser to go to the contact.htm file.
First look at simpleAnimationWithNoSharedEvents.wrl and the code for it.
To make simpleAnimationWithNoSharedEvents.wrl shared so that it becomes simpleAnimationWithOneSharedEvent.wrl we have to do 3 things.
1/ We have to add the blaxxun PROTOs BlaxxunZone and SharedEvent to our file by simply copying and pasting the following text to the top of our file:
# Protos needed for multi-user connections
#
PROTO BlaxxunZone [
eventIn MFNode
addEvents
eventIn MFNode
removeEvents
exposedField MFNode events []
exposedField MFNode avatars []
eventOut MFNode
events_added
eventOut MFNode
events_removed
eventIn SFInt32
set_myAvatarGesture
eventIn SFInt32
myAvatarGestureFromServer
eventOut SFInt32
myAvatarGesture_changed
eventOut SFInt32
myAvatarGestureToServer
exposedField MFString sendToChat ""
exposedField SFFloat beamToDistance 3
exposedField MFString groupChatName ""
exposedField MFString groupChat ""
exposedField SFString myAvatarName ""
exposedField MFNode avatarLOD []
exposedField MFFloat avatarRange []
eventIn MFNode
addAvatars
eventOut MFNode avatars_added
eventIn MFNode removeAvatars
eventOut MFNode avatars_removed
]
{
DEF S Script {
eventOut MFNode avatars_added IS avatars_added
eventOut MFNode avatars_removed IS avatars_removed
eventIn SFInt32 set_myAvatarGesture IS set_myAvatarGesture
eventIn SFInt32 myAvatarGestureFromServer IS myAvatarGestureFromServer
eventOut SFInt32 myAvatarGesture_changed IS myAvatarGesture_changed
eventOut SFInt32 myAvatarGestureToServer IS myAvatarGestureToServer
eventIn MFNode addAvatars IS addAvatars
eventIn MFNode removeAvatars IS removeAvatars
url "vrmlscript:
function addAvatars(value, time) { avatars_added = value; }
function removeAvatars(value, time) { avatars_removed = value;
}
function set_myAvatarGesture(value, time) { myAvatarGestureToServer
= value; }
function myAvatarGestureFromServer(value, time) { myAvatarGesture_changed
= value; }
"
}
}
PROTO SharedEvent [
exposedField SFString name "event"
exposedField SFString type
"SFTime"
exposedField SFString toNickname
""
exposedField SFString toGroup ""
eventIn SFBool boolFromServer
eventIn SFColor colorFromServer
eventIn SFFloat floatFromServer
eventIn SFInt32 int32FromServer
eventIn SFRotation rotationFromServer
eventIn SFString stringFromServer
eventIn SFTime timeFromServer
eventIn SFVec2f vec2fFromServer
eventIn SFVec3f vec3fFromServer
eventOut SFBool boolToServer
eventOut SFColor colorToServer
eventOut SFFloat floatToServer
eventOut SFInt32 int32ToServer
eventOut SFRotation rotationToServer
eventOut SFString stringToServer
eventOut SFTime timeToServer
eventOut SFVec2f vec2fToServer
eventOut SFVec3f vec3fToServer
eventIn SFBool set_bool
eventIn SFColor set_color
eventIn SFFloat set_float
eventIn SFInt32 set_int32
eventIn SFRotation set_rotation
eventIn SFString set_string
eventIn SFTime set_time
eventIn SFVec2f set_vec2f
eventIn SFVec3f set_vec3f
eventOut SFBool bool_changed
eventOut SFColor color_changed
eventOut SFFloat float_changed
eventOut SFInt32 int32_changed
eventOut SFRotation rotation_changed
eventOut SFString string_changed
eventOut SFTime time_changed
eventOut SFVec2f vec2f_changed
eventOut SFVec3f vec3f_changed
eventOut SFBool initialized
]
{
Script {
eventIn SFBool boolFromServer
IS boolFromServer
eventIn SFColor colorFromServer
IS colorFromServer
eventIn SFFloat floatFromServer
IS floatFromServer
eventIn SFInt32 int32FromServer
IS int32FromServer
eventIn SFRotation rotationFromServer
IS rotationFromServer
eventIn SFString stringFromServer
IS stringFromServer
eventIn SFTime timeFromServer
IS timeFromServer
eventIn SFVec2f vec2fFromServer
IS vec2fFromServer
eventIn SFVec3f vec3fFromServer
IS vec3fFromServer
eventOut SFBool boolToServer
IS boolToServer
eventOut SFColor colorToServer IS
colorToServer
eventOut SFFloat floatToServer IS
floatToServer
eventOut SFInt32 int32ToServer IS
int32ToServer
eventOut SFRotation rotationToServer
IS rotationToServer
eventOut SFString stringToServer
IS stringToServer
eventOut SFTime timeToServer
IS timeToServer
eventOut SFVec2f vec2fToServer IS
vec2fToServer
eventOut SFVec3f vec3fToServer IS
vec3fToServer
eventIn SFBool set_bool
IS set_bool
eventIn SFColor set_color
IS set_color
eventIn SFFloat set_float
IS set_float
eventIn SFInt32 set_int32
IS set_int32
eventIn SFRotation set_rotation
IS set_rotation
eventIn SFString set_string
IS set_string
eventIn SFTime set_time
IS set_time
eventIn SFVec2f set_vec2f
IS set_vec2f
eventIn SFVec3f set_vec3f
IS set_vec3f
eventOut SFBool bool_changed
IS bool_changed
eventOut SFColor color_changed IS
color_changed
eventOut SFFloat float_changed IS
float_changed
eventOut SFInt32 int32_changed IS
int32_changed
eventOut SFRotation rotation_changed
IS rotation_changed
eventOut SFString string_changed
IS string_changed
eventOut SFTime time_changed
IS time_changed
eventOut SFVec2f vec2f_changed IS
vec2f_changed
eventOut SFVec3f vec3f_changed IS
vec3f_changed
eventOut SFBool initialized
IS initialized
url "vrmlscript:
function initialize( time ) { initialized = TRUE;}
function boolFromServer (value, time) { bool_changed = value;
}
function colorFromServer (value, time) { color_changed = value;
}
function floatFromServer (value, time) { float_changed = value;
}
function int32FromServer (value, time) { int32_changed = value;
}
function rotationFromServer (value, time) {rotation_changed
= value; }
function stringFromServer (value, time) { string_changed = value;
}
function timeFromServer (value, time) { time_changed = time;
}
function vec2fFromServer (value, time) { vec2f_changed = value;
}
function vec3fFromServer (value, time) { vec3f_changed = value;
}
function set_bool (value, time) { boolToServer = value; }
function set_color (value, time) { colorToServer = value; }
function set_float (value, time) { floatToServer = value; }
function set_int32 (value, time) { int32ToServer = value; }
function set_rotation (value, time) { rotationToServer = value;
}
function set_string (value, time) { stringToServer = value;
}
function set_time (value, time) { timeToServer = value; }
function set_vec2f (value, time) { vec2fToServer = value; }
function set_vec3f (value, time) { vec3fToServer = value; }
"
}
}
2/ We have to make an instance of the PROTO BlaxxunZone and inside that we need an instance of the PROTO SharedEvent.
DEF SharedZone BlaxxunZone {
events [
DEF sharedAnim1 SharedEvent{
}
]
}
3/ We have to make the ROUTE we want shared by replacing it with two
ROUTEs
one of the ROUTEs sends the event to the blaxxun server and the other
ROUTE receives it from the server
#ROUTE touch1.touchTime TO TS1.startTime
#replace this ROUTE with the two following ROUTEs
ROUTE touch1.touchTime TO sharedAnim1.set_time
#Send the touch sensor event to the server
ROUTE sharedAnim1.time_changed TO TS1.startTime #Send
the event received from the server to the timer to start the animationanimation
When one computer sends an event to the blaxxun server all computers including the one that sent the event will receive the event back from the server. This is what makes an event shared.
If we wanted to add another shared event to our world we could use the
same instance of the SharedEvent PROTO for this, so long as it is a different
type. That is we could use a SFTime and a SFInt with out having to make
a new instance of the SharedEvent PROTO because they are two different
types
However if we want to have more than one shared event of the same
type, we have to add another instance for that shared event.
That is, all shared events of the same type must have there own instance.
simpleAnimationWithTwoSharedEvents.wrl
demonstrates how we have more than one of the same type of shared event
The main thing to Note in simpleAnimationWithTwoSharedEvents.wrl is the two instances of the SharedEvent PROTO and how each instance must be identified by having its name field with a unneqe string of characters so that one shared event is not confused with another from the blaxxun server.
DEF sharedAnim1 SharedEvent{
name "SA1" #this field identifies the event so it
is essential this field is given its own unique string when there is more
than one shared event
}
DEF sharedAnim2 SharedEvent{
name "SA2" #this field identifies the event so it
is essential this field is given its own unique string when there is more
than one shared event
}
Blaxxun's information information on shared events:
http://www.blaxxun.com/developer/index.html