Sony Corporation.
The following describes the API accessible to scripts to access, define and manipulate VS Objects present in a VS 3D world and defined in Sony's extension of the VRML laungage E-VRML. These commands can be called from scripts running in the browser and in application objects.
vsGetObjByName vsAddObjFromFile vsAddObjFromStr vsNewVariable vsDelVariable VsGetVariable VsSetVariable VsGetObjAttribute VsSetObjAttribute vsSetSwitchObjByNo vsGetSwitchObjInfo vsGetSwitchObjByNo *Index.
vsGetObjPart vsSetPartMaterial vsSetObjMaterial vsSetObjAllMaterial vsGetPartMaterial vsGetObjMaterial vsGetObjAllMaterial *Index.
vsRotate vsRotateAngle vsTranslate vsRotateTranslate vsRotateTranslateAngle vsGetObjWRT vsGetObjLRT *Index.
vsKinNew vsKinDelete vsKinSetFrame vsKinNextPosture vsKinPrevPosture vsKinGetFrame *Index.
vsGetEventType vsGetEventModifier vsGetEventKey vsGetEventPart vsGetEventPoint vsGetEvent2DPoint vsGetEventTime *Index.
vsGetActiveCamera vsSetCameraAttribute vsGetCameraAttribute *Index.
vsSetLightAttribute vsGetLightAttribute *Index.
vsAddEventHandler vsRemoveEventHandler vsAddTimeOutHandler vsRemoveTimeOutHandler *Index.
vsPlay3DMovie vsPause3DMovie vsGet3DMovieSpeed vsSet3DMovieSpeed vsGet3DMovieInfo vsSet3DMovieFrame vsSet3DMovieNextFrame vsSet3DMoviePrevFrame vsPlay2DVideo *Index.
vsPlayAmbientSoundByName vsPlayAmbientSound vsStopSoundByName vsStopSound vsPlaySpotSoundByName vsPlaySpotSound vsSetSoundVolumeByName vsSetSoundVolume vsSuspendSuspendByName vsSuspendSound vsSuspendAllSound vsResumeSoundByName vsResumeSound vsResumeAllSound *Index.
vsWwwOpenUrl vsWwwGetFile vsWwwOpenFile *Index.
vsBackwardPage vsForwardPage vsMenuExec *Index.
vsMessage vsWarning vsError vs2DPosTo3DPos vsRand vsGetLocalTime vsGetCTime vstkInit *Index.
[wrl]
DEF robot Separator { # robot
DEF hand Separator { # hand
Cone {}
DEF finger Separator { # finger
Cube {}
}
}
}
DEF robot Separator { # dog
DEF robot Separator { # robot
DEF hand Separator { # hand
Cone {}
DEF finger Separator { # finger
Cube {}
}
}
}
}
[Object tree]
----------+-------------+--------- topobj
| |
robot dog <- [dog]
| |
hand robot
| |
[robot_finger]->finger hand
|
finger <- [dog_robot_finger]
[tcl]
set dog [vsGetObjByName "dog"] ;
if {$dog != 0} {
set dog_robot_finger [vsGetObjByName dog "robot.hand.finger"]
}
set robot_finger [vsGetObjByName "robot.hand.finger"]
if {$robot_finger} {
global vsAmbient
vsSetObjAllMaterial $robot_finger $vsAmbient 1.0 0.0 0.0
}
[tcl]
global $vsSuccess
if {0 == vsAddObjFromFile $obj vsWwwGetFile["models/bird.wrl"]} {
vsWarning "vsAddObjFromFile failed."
}
[tcl]
if {0 == [vsAddObjFromStr $obj " \
#VRLM V1.0 ascii\n\
Cone \{ \n\
parts ALL\n\
bottomRadius 2\n\
height 7\n\
\}"] } {
vsWarning "vsAddObjFromStr failed."
}
If valuemane dose exist get, novalue initialises the valuename to the empty string and returns it.
vsSetVariable : If valuename is read only, warning message dialog has appeared on the screen.
[tcl] vsNewVariable $obj count 100 ; # set [count] to 100. vsSetVariable $obj count 200 ; # set [count] to 100. vsNewVariable $obj rocount 100 ro ; # set [count] to 100, ro. vsSetVariable $obj rocount 200 ; # display the warning dialog in this line. set localcount [vsGetVariable $obj count] ; # get value of [count]. incr localcount vsSetVariable $obj count $localcount ; # set [count] to $localcount.
+----------------------------------------------+ | attribute | value type | access | +---------------------+---------------+--------+ |vsObjAttrNode |string | RO | |vsObjAttrName |string | RW | |vsObjAttrComment |string | RW | |vsObjAttrVisible |vsTrue/vsFalse | RW | |vsObjAttrGrasp |vsTrue/vsFalse | RO | |vsObjAttrSolid |vsTrue/vsFalse | RO | |vsObjAttrCollision |vsTrue/vsFalse | RO | +---------------------+---------------+--------+
[tcl]
global vsObjAttrNode vsObjAttrVisible vsTrue
set ret [ vsGetObjAttribute $coneobj $vsObjAttrNode node]
if {$ret == $vsSuccess} {
vsWarning "$node" ; # <- "Cone"
}
set ret [vsGetObjAttribute $coneobj $vsObjAttrVisible $vsTrue]
if {$ret != $vsSuccess} {
vsWarning "vsGetObjAttribute failed."
}
[wrl]
#VRML V1.0 ascii
DEF Root Separator {
DirectionalLight {
intensity 1
color 0.8 0.2 0.9
direction -1 0 1
}
Separator {
PeriodicTask {
filename "switch.tcl"
millisecond 300
userData "data"
function "switchFunc"
scriptType TCL
}
Switch {
whichChild 0
Cone {
parts ALL
bottomRadius 2
height 7
}
Transform { translation 0 1 0 }
Cone {
parts ALL
bottomRadius 2
height 9
}
Transform { translation 0 3 0 }
Cone {
parts ALL
bottomRadius 2
height 15
}
}
}
}
[tcl]
set objNo 0
proc switchFunc {obj eve userdata} {
global objNo vsContinue
if {$switch == 0} {
vsSetSwitchObjByNo $obj 0 ;
set objNo 1
} elseif {$switch == 1} {
vsSetSwitchObjByNo $obj 1 ;
set objNo 2
} elseif {$switch == 2} {
vsSetSwitchObjByNo $obj 2 ;
set objNo 0
}
return $vsContinue
}
[tcl]
global vsCSLocal vsRelative
vsGetSwitchObjInfo $swobj current max
incr current
if {$current >= $max} {
set current 0
}
vsSetSwitchObjByNo $swobj $current
set obj [vsGetSwitchObjByNo $swobj $current]
if {0 == $obj} {
vsWarning "vsGetSwitchObjByNo"
} else {
vsTranslate $obj 1.0 0.0 0.0 $vsCSLocal $vsRelative
}
[tcl]
global vsConeBottom
set bottom [vsGetObjPart $coneobj $vsConeBottom]
if {$bottom == 0} {
vsWarning "vsGetObjPart failed"
}
and see also vsSetObjMaterial
[tcl]
global vsAmbient vsShininess
global vsConeBottom
set f 0.0
set r 0.0
set g 0.0
set b 0.0
vsGetObjMaterial $obj $vsAmbient r g b
vsGetObjMaterial $obj $vsShininess $f
vsSetObjMaterial $obj $vsAmbient [expr $r/2] $g $b
vsSetObjMaterial $obj $vsShininess [expr $f/2]
vsSetPartMaterial [vsGetObjPart $coneobj $vsConeBottom] \
$vsAmbient 1.0 0.0 1.0
vsGetPartMaterial [vsGetObjPart $cubeobj 1] $vsAmbient $r $g $b
[tcl]
global vsCSLocal vsRelative vsSuccess
set ret [vsRotateAngle $obj 10.0 0.0 0.0 $vsCSLocal $vsRelative]
if {$ret != $vsSuccess} {
vsWarning "vsRotateAngle failed"
}
[tcl]
global vsCSLocal vsRelative vsSuccess
set ret [vsTranslate $obj 10.0 0.0 0.0 $vsCSLocal $vsRelative]
if {$ret != $vsSuccess} {
vsWarning "vsTranslate failed"
}
vsRotateTranslate obj rx1 ry1 rz1 rx2 ry2 rz2 rx3 ry3 rz3 tx ty tz VsCoordSystem VsTransferMode
vsRotateAngleTranslate obj xangle yangle zangle tx ty tz VsCoordSystem VsTransferMode
[tcl]
global vsCSLocal vsRelative vsSuccess
set ret [vsRotateAngleTranslate $obj 10.0 0.0 0.0 \
20.0 10.0 10.0 $vsCSLocal $vsRelative]
if {$ret != $vsSuccess} {
vsWarning "vsRotateAngleTranslate failed"
}
[tcl] global vsCSWorld vsAbsolute set x 0 set y 0 set z 0 vsGetObjWRT $obj x y z vsTranslate $obj [expr $x+10.0] \ $y $z $vsCSWorld $vsAbsolute
[tcl] global vsCSLocal vsAbsolute set x 0 set y 0 set z 0 vsGetObjLRT $obj x y z vsTranslate $obj [expr $x+10.0] \ $y $z $vsCSWorld $vsAbsolute
[tcl]
global vsSuccess
set kinobj 0
set ret [vsKinNew "../kinema/boy.wrl" kinobj]
if {$ret != $vsSuccess} {
vsWarning "vsKinNew failed"
}
[tcl] vsKinDelete $obj
[wrl]
SporadicTask {
fields [ SFLong millisecond, SFString userData, SFString function, SFString filename, SFEnum scriptType ]
millisecond 50
userData "data"
function "KinGirlInit"
filename "../scripts/kinema.tcl"
scriptType TCL
}
any object definition.
[tcl]
set kinGirlCounter 0
###############################################################
# animate kinemation object.
###############################################################
proc KinGirlMove { obj ev userdata } {
global kinGirlCounter
global vsCSWorld vsAbsolute vsRelative
set x 0.0
set y 0.0
set z 0.0
if { $kinGirlCounter < 400 } {
incr kinGirlCounter
vsKinNextPosture $obj
} else {
set kinGirlCounter 0
vsGetObjWRT $obj x y z
vsTranslate $obj 0.0 0.0 0.0 $vsCSWorld $vsAbsolute
vsRotateAngle $obj 0.0 180.0 0.0 $vsCSWorld $vsRelative
vsTranslate $obj $x $y $z $vsCSWorld $vsAbsolute
}
}
###############################################################
# create kinemation object, and set KinGirlMove as periodictask.
###############################################################
proc KinGirlInit { obj ev userdata } {
global vsTclScript vsPeriodicTask vsCSWorld vsRelative
set girl 0
vsKinNew ../models/girl.wrl girl
vsTranslate $girl -21.0 0.0 -35.5 $vsCSWorld $vsRelative
vsAddTimeOutHandler $girl 300 $vsTclScript "" KinGirlMove 0 $vsPeriodicTask
}
[tcl]
global vsSuccess
if{$vsSuccess != [vsKinGetFrame $kinobj cur max]} {
vsWarning "vsKinGetFrane Failure."
} else {
if {$cur > [expr $max/2]} {
vsKinSetFrame $kinobj 0
} else {
vsKinNextPosture $kinobj
}
}
A mask denoting any combination of:
+----------------------+------------------+ | eventType on wrl | on tcl | +----------------------+------------------+ |WORLD_IN | $vsWorldIn | |WORLD_OUT | $vsWorldOut | |COLLISION | $vsCollision | |CREATE_WORLD | $vsCreateWorld | |DELETE_WORLD | $vsDeleteWorld | |CREATE_NOTIFY | $vsCreateNotify | |DELETE_NOTIFY | $vsDeleteNotify | |TIME_OUT | $vsTimeOut | |GRAB | $vsGrab | |RELEASE | $vsRelease | |DRAG | $vsDrag | |PICK | $vsPick | |FRAME | $vsFrame | +----------------------+------------------+
[tcl]
proc eventproc {obj event user_data} {
global vsPick
set type [vsGetEventType $event]
if {1 == [expr $type & $vsPick]} {
vsWarning "picked."
}
}
[tcl]
proc eventHandler {obj event user} {
global vsAmbient
set part [vsGetEventPart $event]
vsSetPartMaterial $part $vsAmbient 0.5 1.0 1.0
}
[tcl]
proc eventHandler {obj event user} {
vsGetEvent2DPoint $event x y
}
[tcl]
proc eventHandler {obj event user} {
vsGetEventTime $event sec milli_sec
}
[tcl] set orgcamera [vsGetActiveCamera]
+--------------------------+----------------+---------------+ | attribute | value type | camera type | +--------------------------+----------------+---------------+ | vsCameraAttrLookAt | x(float) | all | | | y(float) | | | | z(float) | | +--------------------------+----------------+---------------+ | vsCameraAttrFocalDistance| dist(float) | all | +--------------------------+----------------+---------------+ | vsCameraAttrBackground | r(0.0-1.0) | all | | | g(0.0-1.0) | | | | b(0.0-1.0) | | +--------------------------+----------------+---------------+ | vsCameraAttrHeight | height(float) | orthographic | +--------------------------+----------------+---------------+ | vsCameraAttrHeightAngle | angle(float) | perspective | +--------------------------+----------------+---------------+
[tcl]
global vsCameraAttrBackground vsSuccess
set camera [vsGetActiveCamera]
if {0 == $camera} {
vsWarning "vsGetActiveCamera failed"
}
set ret [vsSetCameraAttribute $camera \
$vsCameraAttrBackground 1.0 0.0 0.0]
if {$ret != $vsSuccess} {
vsWarning "vsSetCameraAttribute failed."
}
+--------------------------+----------------+---------------+ | attribute | value type | light type | +--------------------------+----------------+---------------+ | vsLightAttrOn | vsTrue/vsFalse| all | +--------------------------+----------------+---------------+ | vsLightAttrIntensity | val(float) | all | +--------------------------+----------------+---------------+ | vsLightAttrColor | r(0.0-1.0) | all | | | g(0.0-1.0) | | | | b(0.0-1.0) | | +--------------------------+----------------+---------------+ | vsLightAttrLocation | x(float) | spot & point | | | y(float) | | | | z(float) | | +--------------------------+----------------+---------------+ | vsLightAttrDirection | x(float) | spot & | | | y(float) | directional | | | z(float) | | +--------------------------+----------------+---------------+ | vsLightAttrDropOffRate | val(float) | spot | +--------------------------+----------------+---------------+ | vsLightAttrCutOffAngle | val(float) | spot | +--------------------------+----------------+---------------+
[tcl]
global vsLightAttrOn vsTrue vsSuccess
set ret [vsSetLightAttribute $light \
$vsLightAttrOn $vsTrue]
if {$ret != $vsSuccess} {
vsWarning "vsSetLightAttribute failed."
}
[tcl]
global vsSuccess vsPick vsTclScript
set ret [vsAddEventHandler $obj $vsPick \
$vsTclScript "../script/task.tcl" "bdfunc" "data"]
if {$ret != $vsSuccess} {
vsWarning "vsAddEventHandler failed"
}
[wrl]
EventHandler {
fields [ SFSBitMask eventType, SFString userData, SFString function, SFString filename, SFEnum scriptType ]
eventType PICK
userData "data"
function "vs_H_Event_RBProc"
filename "proc.tcl"
scriptType TCL
}
Cone {
parts ALL
bottomRadius 2
height 7
}
[tcl]
set red 0
proc coneTmFunc {obj event data} {
global red count vsContinue vsDiffuse
if {$red == 0} {
vsSetObjMaterial $obj $vsDiffuse 1.0 0.0 0.0
} else {
vsSetObjMaterial $obj $vsDiffuse 0.0 0.0 1.0
}
return $vsContinue
}
set TmId 0
proc RbProc {obj event userdata} {
global TmId vsPeriodicTask vsTclScript
if {$TmId == 0} { # timeouthandler is not living
set TmId [vsAddTimeOutHandler $obj 120 \
$vsTclScript "" coneTmFunc \
$userdata $vsPeriodicTask]
if {$TmId == 0} {
vsWarning "vsAddTimeOutHandler failed"
}
} else {
vsRemoveTimeOutHandler $obj $TmId
}
}
[wrl]
Separator {
Texture2 { # set movie file to object .
filename "../video/bballs/bballs.bmp"
}
Coordinate3 {
point [
-2 2 0, 0 2 0, 2 2 0, -2 0 0, 0 0 0, 2 0 0]
}
TextureCoordinate2 {
point [0 0, 0 1, 1 1, 1 0]
}
PeriodicTask {
fields [ SFLong millisecond, SFString userData, SFString function, SFString filename, SFEnum scriptType ]
millisecond 167
userData "data"
function "vs_H_Periodic3DPray"
filename "video.tcl"
scriptType TCL
}
IndexedFaceSet {
coordIndex [ 0, 3, 4, 1, -1]
textureCoordIndex [1, 0, 3, 2, -1]
}
}
[tcl]
proc Periodic3DPray {obj event user} {
vsPlay3DVideo $obj
}
[wrl]
Separator {
Movie2 { # set movie file to object .
filename "../video/bballs/bballs.bmp"
}
Coordinate3 {
point [
-2 2 0, 0 2 0, 2 2 0, -2 0 0, 0 0 0, 2 0 0]
}
TextureCoordinate2 {
point [0 0, 0 1, 1 1, 1 0]
}
EventHandler {
userData "data"
function "vs_H_Create3DPlay"
filename "video.tcl"
scriptType TCL
}
IndexedFaceSet {
coordIndex [ 0, 3, 4, 1, -1]
textureCoordIndex [1, 0, 3, 2, -1]
}
}
[tcl]
proc vs_H_Create3DPlay {obj event user} {
vsPlay3DVideo $obj
}
[tcl]
vsSet3DMovieSpeed $movieobj 2.0 ;# double speed play.
vsSet3DMovieSpeed $movieobj -2.0 ;# double speed, revers play.
[tcl]
set cur [vsGet3DMovieSpeed $movieobj]
vsSet3DMovieSpeed $movieobj [expr -1 * $cur]
[tcl]
global vsTrue vsFalse
vsPause3DMovie $movieobj
vsSet3DMovieInfo $movieobj cur max
vsSet3DMovieFrame $movieobj [expr $cur/2]
vsPlay3DMovie $movieobj
See also vsSet3DMovieFrame.
[tcl]
proc RandFrame {movieobj} {
vsPause3DMovie $movieobj
vsSet3DMovieInfo $movieobj cur
vsSet3DMovieSetFrame $movieobj [expr $cur/2]
}
[tcl] vsPlay2DVideo "foo.avi"
[tcl]
global vsSuccess
set ret [vsWwwOpenUrl "http://www.sony.co.jp"]
if {$ret != $vsSuccess} {
vsWarning "vsWwwOpenUrl failed"
}
[tcl]
set localfile [vsWwwGetFile "../movie/run.avi"]
if {$localfile != ""} {
vsPlay2DVideo $localfile
}
[tcl] vsWwwOpenVRML "foo.wrl"
[tcl] global vsFileOpenUrl vsMenuExec $vsFileOpenUrl ; # popup OPEN-URL dialog of browser.
[tcl] vsMessageDlg "message from vsMessage"
[tcl] vsGetObjWRT $obj x y z vs3DPosTo2DPos $x $y $z xx yyBack to Index.
[tcl] set v [vsRand]Back to Index.
[tcl] vsGetLocalTime sec min hour vsWarning "$hour hour $min min $sec sec." [result] 12 hour 10 min 10 sec.Back to Index.
[tcl] set v [vsGetCTime]Back to Index.
[tcl]
vstkInit
proc event {obj ev data} {
wm deiconify . ; # Map the default toplevel window.
}
Back to Index.