| Andrew Neiderer 2004-02-27, 9:29 am |
| Sorry for the length of this, but I can't the sound to work when I touch
a door in this case. Could someone tell me where the Audio node (TS_SOUND_DOOR)
should be added or how to modify the ROUTE (at the end of Door.wrl).
Thank you.
-------------------------- doors.wrl ----------------------------------
#VRML V2.0 utf8
EXTERNPROTO Door [
# copyright Vincent Gardet - 2002.
# modified by Andrew M. Neiderer, 23 Feb 2004.
field SFVec3f size
field SFString direction
field SFString side
field SFString sensorType
field SFVec3f proxiSize
field SFTime openingDuration
field SFTime closingDuration
field SFBool audio
exposedField SFVec3f translation
exposedField SFRotation rotation
exposedField SFColor diffuseColor
exposedField SFColor specularColor
exposedField SFColor emissiveColor
exposedField SFFloat transparency
exposedField MFString textureUrl
exposedField SFVec2f textureScale
] "Door.wrl#Door"
# outer door
Door {
size 0.8 2.05 0.03
translation 0.0 0.0 5.0
side "Left"
direction "Pull"
sensorType "Touch"
textureUrl "out_door.jpg"
diffuseColor 0.2 0.5 0.5
openingDuration 3.0
closingDuration 5.0
audio TRUE
}
# inner door
Door {
size 0.8 2.05 .03
translation 0.0 0.0 3.0
side "Right"
direction "Pull"
sensorType "Touch"
textureUrl "in_door.jpg"
diffuseColor .5 0.3 0.2
openingDuration 3.0
closingDuration 5.0
audio TRUE
}
-------------------------------- Door.wrl ---------------------------------
#VRML V2.0 utf8
PROTO Door [
# copyright Vincent Gardet - 2002.
# modified by Andrew M. Neiderer, 23 February 2004.
field SFVec3f size .85 2.05 .05 # size of the door
field SFString direction "Push" # direction of the opening : "Push" or "Pull"
field SFString side "Right" # side of the opening : "Left" or "Right"
field SFString sensorType "Proximity" # type of the sensor controlling the opening
# of the door : "Proximity" = ProximitySensor,
# "Touch" = TouchSensor
field SFVec3f proxiSize 4 4 8 # size of the bounding box of the ProximitySensor,
field SFTime openingDuration .5
field SFTime closingDuration 1
field SFBool audio TRUE
exposedField SFVec3f translation 0 0 0
exposedField SFRotation rotation 0 0 0 0
exposedField SFColor diffuseColor .8 .8 .8
exposedField SFColor specularColor 0 0 0
exposedField SFColor emissiveColor 0 0 0
exposedField SFFloat transparency 0
exposedField MFString textureUrl "" # if not symetrical, the texture of the
# door must present the handle at left side
exposedField SFVec2f textureScale 1 1
]
{
Transform {
translation IS translation
rotation IS rotation
children [
DEF TS_DOOR TouchSensor {}
DEF PS_DOOR ProximitySensor {
size IS proxiSize
}
DEF TR_DOOR Transform {
center .45 0 0
children [
Shape {
appearance Appearance {
material Material {
diffuseColor IS diffuseColor
specularColor IS specularColor
emissiveColor IS emissiveColor
transparency IS transparency
}
texture ImageTexture {
url IS textureUrl
}
textureTransform TextureTransform {
scale IS textureScale
}
} # end Appearance
geometry IndexedFaceSet {
coord DEF COORD Coordinate {}
coordIndex [
0,1,2,3,-1
7,6,5,4,-1
]
texCoord DEF TEXTCOORD TextureCoordinate {
point [0 0,1 0,1 1,0 1]
}
texCoordIndex [
0,1,2,3,-1
3,2,1,0,-1
]
} # end IndexedFaceSet
} # end Shape
Shape {
appearance Appearance {
material Material {
diffuseColor IS diffuseColor
specularColor IS specularColor
emissiveColor IS emissiveColor
transparency IS transparency
}
} # end Appearance
geometry IndexedFaceSet {
coord USE COORD coordIndex [
1,5,6,2,-1
4,0,3,7,-1
2,6,7,3,-1
0,4,5,1,-1
]
} # end IndexedFaceSet
} # end Shape
]
} # end TR_DOOR
]
}
DEF TIS_OPEN_DOOR TimeSensor {
cycleInterval IS openingDuration
loop FALSE
}
DEF OI_OPEN_DOOR OrientationInterpolator {
key [ 0.0, 1.0 ]
keyValue [ 0.0 1.0 0.0 0.0, 0.0 1.0 0.0 -1.5708 ]
}
DEF TIS_CLOSE_DOOR TimeSensor {
cycleInterval IS closingDuration
loop FALSE
}
DEF OI_CLOSE_DOOR OrientationInterpolator {
key [ 0.0, 1.0 ]
keyValue [ 0.0 1.0 0.0 -1.5708, 0.0 1.0 0.0 0.0 ]
}
DEF TS_SOUND_DOOR TouchSensor {}
Sound {
source DEF SOUND_DOOR AudioClip {
url "DOOR3.WAV"
loop FALSE
}
}
DEF SCR_B_DOOR Script {
directOutput TRUE
field SFVec3f size IS size
field SFString sensorType IS sensorType
field SFString side IS side
field SFString direction IS direction
field SFBool state FALSE
field SFNode OI_OPEN_DOOR USE OI_OPEN_DOOR
field SFNode OI_CLOSE_DOOR USE OI_CLOSE_DOOR
field SFNode COORD USE COORD
field SFNode TEXTCOORD USE TEXTCOORD
eventIn SFTime touchDoor
eventIn SFTime enterDoor
eventIn SFTime exitDoor
eventOut SFBool Pstate
eventOut SFBool Tstate
eventOut SFTime openDoor
eventOut SFTime closeDoor
eventOut SFVec3f turningPoint
url "java script:
function initialize() {
COORD.point[0][0] = -size.x / 2;
COORD.point[0][1] = -size.y / 2;
COORD.point[0][2] = size.z / 2;
COORD.point[1][0] = size.x / 2;
COORD.point[1][1] = -size.y / 2;
COORD.point[1][2] = size.z / 2;
COORD.point[2][0] = size.x / 2;
COORD.point[2][1] = size.y / 2;
COORD.point[2][2] = size.z / 2;
COORD.point[3][0] = -size.x / 2;
COORD.point[3][1] = size.y / 2;
COORD.point[3][2] = size.z / 2;
COORD.point[4][0] = -size.x / 2;
COORD.point[4][1] = -size.y / 2;
COORD.point[4][2] = -size.z / 2;
COORD.point[5][0] = size.x / 2;
COORD.point[5][1] = -size.y / 2;
COORD.point[5][2] = -size.z / 2;
COORD.point[6][0] = size.x / 2;
COORD.point[6][1] = size.y / 2;
COORD.point[6][2] = -size.z / 2;
COORD.point[7][0] = -size.x / 2;
COORD.point[7][1] = size.y / 2;
COORD.point[7][2] = -size.z / 2;
turningPoint[0] = ((size.x / 2) - (size.z / 2));
turningPoint[1] = 0;
turningPoint[2] = 0;
if ( sensorType == 'Touch' ) {
Pstate = false;
}
else {
Tstate = false;
}
if ( side == 'Left' ) {
turningPoint[0] = -((size.x / 2) - (size.z / 2));
turningPoint[1] = 0;
turningPoint[2] = 0;
TEXTCOORD.point[0][0] = 1;
TEXTCOORD.point[0][1] = 0;
TEXTCOORD.point[1][0] = 0;
TEXTCOORD.point[1][1] = 0;
TEXTCOORD.point[2][0] = 0;
TEXTCOORD.point[2][1] = 1;
TEXTCOORD.point[3][0] = 1;
TEXTCOORD.point[3][1] = 1;
}
if ( ((side == 'Left') && (direction == 'Push')) ||
((side == 'Right') && (direction == 'Pull')) ) {
OI_OPEN_DOOR.keyValue[0][0] = 0;
OI_OPEN_DOOR.keyValue[0][1] = 1;
OI_OPEN_DOOR.keyValue[0][2] = 0;
OI_OPEN_DOOR.keyValue[0][3] = 0;
OI_OPEN_DOOR.keyValue[1][0] = 0;
OI_OPEN_DOOR.keyValue[1][1] = 1;
OI_OPEN_DOOR.keyValue[1][2] = 0;
OI_OPEN_DOOR.keyValue[1][3] = 1.5708;
OI_CLOSE_DOOR.keyValue[0][0] = 0;
OI_CLOSE_DOOR.keyValue[0][1] = 1;
OI_CLOSE_DOOR.keyValue[0][2] = 0;
OI_CLOSE_DOOR.keyValue[0][3] = 1.5708;
OI_CLOSE_DOOR.keyValue[1][0] = 0;
OI_CLOSE_DOOR.keyValue[1][1] = 1;
OI_CLOSE_DOOR.keyValue[1][2] = 0;
OI_CLOSE_DOOR.keyValue[1][3] = 0;
}
}
function touchDoor (value) {
if ( state == FALSE ) {
state = TRUE;
openDoor = value;
}
else {
state = FALSE;
closeDoor = value;
}
}
function enterDoor (value) {
if ( state == FALSE ) {
state = TRUE;
openDoor = value;
}
}
function exitDoor (value) {
if ( state == TRUE ) {
state = FALSE;
closeDoor = value;
}
}
"
}
ROUTE SCR_B_DOOR.Tstate TO TS_DOOR.set_enabled
ROUTE SCR_B_DOOR.Pstate TO PS_DOOR.set_enabled
ROUTE SCR_B_DOOR.turningPoint TO TR_DOOR.set_center
ROUTE TS_DOOR.touchTime TO SCR_B_DOOR.touchDoor
ROUTE PS_DOOR.enterTime TO SCR_B_DOOR.enterDoor
ROUTE PS_DOOR.exitTime TO SCR_B_DOOR.exitDoor
ROUTE SCR_B_DOOR.openDoor TO TIS_OPEN_DOOR.startTime
ROUTE TIS_OPEN_DOOR.fraction_changed TO OI_OPEN_DOOR.set_fraction
ROUTE OI_OPEN_DOOR.value_changed TO TR_DOOR.set_rotation
ROUTE SCR_B_DOOR.closeDoor TO TIS_CLOSE_DOOR.startTime
ROUTE TIS_CLOSE_DOOR.fraction_changed TO OI_CLOSE_DOOR.set_fraction
ROUTE OI_CLOSE_DOOR.value_changed TO TR_DOOR.set_rotation
ROUTE TS_SOUND_DOOR.touchTime TO SOUND_DOOR.set_startTime
}
|