| View previous topic :: View next topic |
| Author |
Message |
Rick Site Admin

Joined: 08 May 2003 Posts: 106 Location: NC, US
|
Posted: Sat Feb 21, 2004 5:14 pm Post subject: SharedEvent - exercise all options |
|
|
Description: Trigger a shared sound when a box is clicked
Keywords: shared, events, sound, click
VRML: http://vrmlworld.net/sharedevents/example01.wrl
ABNet: http://vrmlworld.net/frameset.php?url=http://vrmlworld.net/sharedevents/example01.wrl
VRML Source:
| Code: | #VRML V2.0 utf8
#
# simple ShareEvent test world
#
# This world tests all the various types
# of shared events available in the current
# release of ABNet. It is probably not the
# best use of the shared events however it
# provides a test bed for each type.
#
EXTERNPROTO ABNetZone [
exposedField MFNode events
exposedField MFString sendToChat
exposedField MFString groupChat
] "http://vrmlworld.net/no_cache/protos.wrl#ABNetZone"
EXTERNPROTO SharedEvent
[
exposedField SFString name
exposedField SFString type
eventIn SFBool boolFromServer
eventIn SFBool set_bool
eventOut SFBool bool_changed
eventIn SFFloat floatFromServer
eventIn SFFloat set_float
eventOut SFFloat float_changed
eventIn SFInt32 int32FromServer
eventIn SFInt32 set_int32
eventOut SFInt32 int32_changed
eventIn SFRotation rotationFromServer
eventIn SFRotation set_rotation
eventOut SFRotation rotation_changed
eventIn SFString stringFromServer
eventIn SFString set_string
eventOut SFString string_changed
eventIn SFTime timeFromServer
eventIn SFTime set_time
eventOut SFTime time_changed
eventIn SFVec3f vec3fFromServer
eventIn SFVec3f set_vec3f
eventOut SFVec3f vec3f_changed
] "http://vrmlworld.net/no_cache/protos.wrl#SharedEvent"
DEF ABNetZone ABNetZone {
events [
DEF SHARED_EV0 SharedEvent { name "se0" type "SFString" },
DEF SHARED_EV1 SharedEvent { name "se1" type "SFTime" },
DEF SHARED_EV2 SharedEvent { name "se2" type "SFInt32" },
DEF SHARED_EV3 SharedEvent { name "se3" type "SFBool" },
DEF SHARED_EV4 SharedEvent { name "se4" type "SFFloat" },
DEF SHARED_EV5 SharedEvent { name "se5" type "SFRotation" },
DEF SHARED_EV6 SharedEvent { name "se6" type "SFVec3f" }
]
}
NavigationInfo { avatarSize [ .25 1.75 .5 ] headlight TRUE }
Viewpoint {
position 0 0 10
description "Entry"
}
DirectionalLight { direction 0 -1 .5 }
DEF RED Appearance { material Material { diffuseColor 1.0 0.0 0.0 } }
DEF GREEN Appearance { material Material { diffuseColor 0.0 0.9 0.0 } }
DEF BLUE Appearance { material Material { diffuseColor 0.0 0.0 1.0 } }
DEF PURPLE Appearance { material Material { diffuseColor 1.0 0.0 1.0 } }
DEF GRAY Appearance { material Material { diffuseColor .8 .8 .8 } }
DEF CHECK Appearance { texture PixelTexture { image 2 2 3 0xCC00CC 0x00FF00 0xCC00CC 0x00FF00 } }
Transform {
translation 0 -3 0
children Shape {
appearance USE GRAY geometry Box { size 25 .25 25 }
}
}
Transform {
translation -1 -1.5 2
children [
DEF TS1 TouchSensor {}
Shape {
appearance USE RED
geometry Box { size .25 .25 .25 }
}
]
}
Transform {
translation 0 -1.5 2
children [
DEF TS2 TouchSensor {}
Shape {
appearance USE GREEN
geometry Box { size .25 .25 .25 }
}
]
}
Transform {
translation 1 -1.5 2
children [
DEF TS3 TouchSensor {}
Shape {
appearance USE BLUE
geometry Box { size .25 .25 .25 }
}
]
}
Transform {
translation 2 -1.5 2
children [
DEF TS4 TouchSensor {}
DEF SW1 Switch {
whichChoice 0
choice [
Shape { appearance USE PURPLE geometry Box { size .25 .25 .25 } } #0
Shape { appearance USE PURPLE geometry Cone { height .25 bottomRadius .125 } } #1
Shape { appearance USE PURPLE geometry Sphere { radius .125 } } #2
]
}
]
}
DEF T5 Transform {
translation 3 -1.5 2
children [
DEF TS5 CylinderSensor {}
Shape { appearance USE CHECK geometry Cylinder { height .25 radius .125 } }
]
}
Sound {
location 2 -1.5 2
maxFront 50
maxBack 50
source DEF SND1 AudioClip {
url "example01_rc/zip01.wav"
}
}
Shape {
appearance Appearance {
material DEF CUBE_MATERIAL Material {
diffuseColor .5 .5 .5
}
}
geometry Box {}
}
DEF S Script {
directOutput TRUE
mustEvaluate TRUE
field SFNode red USE RED
field SFNode green USE GREEN
field SFNode blue USE BLUE
field SFNode m USE CUBE_MATERIAL
field SFNode sw1 USE SW1
eventIn SFTime setRed
eventIn SFTime setGreen
eventIn SFTime setBlue
eventIn SFString set_color
eventIn SFFloat set_fcolor
eventIn SFBool set_bool
eventIn SFBool set_mouseOver
eventOut SFString color_changed
eventOut SFTime time_changed
eventOut SFInt32 int32_changed
eventOut SFBool bool_changed
eventOut SFFloat float_changed
eventOut MFString sendToChat_changed
eventIn MFString chatFromServer
url "javascript:
function setRed(v,ts) { color_changed='r'; }
function setGreen(v,ts) {
float_changed=green.material.diffuseColor[1];
sendToChat_changed=new MFString('changed to green');
}
function setBlue(v,ts) {
color_changed='b';
n = sw1.whichChoice;
if ( n+1 < sw1.choice.length ) {
n++;
}
else {
n=0;
}
int32_changed = n;
}
function set_color(v,ts) {
print('change the color to ['+v+'] because of a network touch');
if ( v == 'r' ) {
_changeBox(red.material.diffuseColor);
}
else if ( v == 'b' ) {
_changeBox(blue.material.diffuseColor);
}
}
function set_fcolor(v,ts) {
print('change the fcolor to ['+v+'] because of a network touch');
_changeBox(new SFColor(0,v,0));
}
function set_bool(v,ts) { bool_changed=v; }
function set_mouseOver(v,ts) {
print('set_mouseOver v='+v);
if ( v ) {
m.transparency=.5;
}
else {
m.transparency=0.0;
}
}
function _changeBox(v) {
m.diffuseColor = v;
}
function chatFromServer(v,ts) {
print('chatFromServer: ' + v );
if ( v == '/red') {
setRed();
}
if ( v == 'red') {
set_color('r');
}
if ( v == 'green') {
setGreen();
}
if ( v == 'blue') {
set_color('b');
}
if ( v == 'FPS?' ) {
sendToChat_changed=new MFString('FPS '+Browser.getCurrentFrameRate());
}
if ( v == 'version?' ) {
sendToChat_changed=new MFString(Browser.getVersion());
}
}
"
}
# change the color of the big box when you click on the smaller boxes
ROUTE TS1.touchTime TO S.setRed
ROUTE TS2.touchTime TO S.setGreen
ROUTE TS3.touchTime TO S.setBlue
# change the color of the cube based on click
# send notification as a string
ROUTE S.color_changed TO SHARED_EV0.set_string
ROUTE SHARED_EV0.string_changed TO S.set_color
# start the sound playing with the purple shape is clicked
ROUTE TS4.touchTime TO SHARED_EV1.set_time
ROUTE SHARED_EV1.time_changed TO SND1.startTime
# each time the blue cube is clicked change
# the shape of the purple object
ROUTE S.int32_changed TO SHARED_EV2.set_int32
ROUTE SHARED_EV2.int32_changed TO SW1.whichChoice
# make the cube semi transparent when pointer
# is over purple object
ROUTE TS4.isOver TO SHARED_EV3.set_bool
ROUTE SHARED_EV3.bool_changed TO S.set_mouseOver
# spin the cylinder for everyone
ROUTE TS5.rotation_changed TO SHARED_EV5.set_rotation
ROUTE SHARED_EV5.rotation_changed TO T5.set_rotation
# change just the green component of the material
ROUTE S.float_changed TO SHARED_EV4.set_float
ROUTE SHARED_EV4.float_changed TO S.set_fcolor
# xmit text to chat
ROUTE S.sendToChat_changed TO ABNetZone.set_sendToChat
# recv text from chat
ROUTE ABNetZone.groupChat_changed TO S.chatFromServer
#-- end sharedtest.wrl
|
|
|
| Back to top |
|
 |
alain Forum Junkie
Joined: 31 Aug 2008 Posts: 10
|
|
| Back to top |
|
 |
Rick Site Admin

Joined: 08 May 2003 Posts: 106 Location: NC, US
|
Posted: Sat Mar 28, 2009 9:07 am Post subject: |
|
|
Alain,
Your code looks ok. You might want to try copying the
file protos.wrl to your machine and changing your
extern definition. Sometimes the delay in loading extern protos
causes issues.
We can try it online and see what happens.
-rick |
|
| Back to top |
|
 |
alain Forum Junkie
Joined: 31 Aug 2008 Posts: 10
|
Posted: Sun Mar 29, 2009 5:45 am Post subject: |
|
|
ah sorry , I didnt got your answer
I checked yesterday that I have the "notify me the answers" yes,
but it can"t be saved , the submit does nothing ..
it stays blank , so by default I guess that means "no" ...
humm
well ,
thanx ,
I hosted the protos for
http://mixed3d.free.fr/paintingweb/amir/galeriesamir/piano/abnettestson2.wrl
and I tested with my whife ,
http://www.odisseia.univ-ab.pt/ABNet2/3dchat.aspx?x3durl=http://mixed3d.free.fr/paintingweb/amir/galeriesamir/piano/abnettestson2.wrl
but same result ...
what is strange to me , as I was used to have that on blaxx ,
is that with the SharedZone of blaxx ,
normaly when you clik with that ROUTE ,
you get no event
( so no sound )
you get it only on the chat .
and here , cliking on the wrl I get the sound ..
normal ?? |
|
| Back to top |
|
 |
vcard Forum Junkie

Joined: 01 Aug 2008 Posts: 58
|
|
| Back to top |
|
 |
alain Forum Junkie
Joined: 31 Aug 2008 Posts: 10
|
Posted: Fri Apr 03, 2009 1:22 am Post subject: |
|
|
| Quote: | You only forgot to define ABNetZone
DEF ABNetZone ABNetZone { ... |
aaaaaaaaaaahh !! OKKKKKK !!!
I never thought it was necessary , btw it is not referenced ,
just
DEF SHARED_EV1 SharedEvent { name "se1" type "SFTime"
is ...
But OK , je te crois
and I will test it with my wife
on the other hand I still free strange that the wrl ( yours ) still plays the sound ( when not in chat )
But merci beaucoup ... |
|
| Back to top |
|
 |
vcard Forum Junkie

Joined: 01 Aug 2008 Posts: 58
|
Posted: Fri Apr 03, 2009 11:40 am Post subject: |
|
|
| alain wrote: |
on the other hand I still free strange that the wrl ( yours ) still plays the sound ( when not in chat )
|
Yes the shared ABNet proto plays the animations in single mode too.
In blaxxun it was annoying to see the shared animations "broken" when the server was down, and it was often
I think having the shared animations work even in single mode is better and more standard. Your world's behaviour is less dependent on this or that server. Don't you agree?
vcard |
|
| Back to top |
|
 |
Laz Forum Junkie

Joined: 15 May 2003 Posts: 91 Location: upper midwest
|
Posted: Sat May 02, 2009 8:53 pm Post subject: SFNode Event |
|
|
Rick,
I was wondering if it were possible to add an SFNode event to SharedEvent or if is way to much work? lol
Just curious about this and i realize you are very busy these days so if that is too far out there then disregard my silliness.  |
|
| Back to top |
|
 |
fabricator Forum Junkie
Joined: 10 Jul 2006 Posts: 49
|
Posted: Tue May 05, 2009 11:29 pm Post subject: Re: SFNode Event |
|
|
| Laz wrote: | Rick,
I was wondering if it were possible to add an SFNode event to SharedEvent or if is way to much work? lol
Just curious about this and i realize you are very busy these days so if that is too far out there then disregard my silliness.  |
SFNode is possible, but really tricky to do.
Simply converting a node to a string doesn't work, I tried that. You have to read the contents of the different fields and make some ling string up bit by bit.
Best way for now is to send the node as a string, then use CreateVrmlFromString on the returned result. |
|
| Back to top |
|
 |
Laz Forum Junkie

Joined: 15 May 2003 Posts: 91 Location: upper midwest
|
Posted: Wed May 06, 2009 1:55 am Post subject: |
|
|
| I was talking with VC and we were discussing how cool it might be to be able to make a world using the drophandler proto from BM. That is the context in which i was inquiring about the sfnode sharedevent. The proto sends an SFNode event is why i was asking. I thought about the possibility of sending it as a string and then feeding the string back into the sfnode eventIn but man that could get lengthy lol. Maybe it's just one of those things that is pretty hard to do. lol |
|
| Back to top |
|
 |
|