This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > VRML > December 2003 > Prototyping scripts and using proto script events





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Prototyping scripts and using proto script events
PrisNo6

2003-12-23, 3:28 am

I am a beginner working with Ames _VRML 2.0 Sourcebook_, specifically
example 31.8, a prototyped boolean filter. I have been trying
unsuccessfully to use any script events from a prototyped objects and
am looking for an example or guidance. As a consequence, I have been
unable to reuse behaviors encapsulated in a script. Fields from an
instance of a prototype I can handle fine.

The specific context I am working with was a switch statement and a
series of menu item controls. When the user clicks on the menu item
button (a sphere), the number of the menu item is captured and sent to
a switch statement. The objects and behaviors in each switch node
differ on the selection. In psuedo-VRML-code, it looks like this:

DEF Option_Group Switch
whichChoice 0
choice [ < some option groups > ]
End Switch

DEF Menu_Options
Control_1 <-- Proto or ExternProto Menu_Item
TouchSensor { Sphere }
DEF Sphere_Click Script { <code> }
Route
< back to Option_Group.set_whichChoice
by proto >

Control_2 <-- Proto or ExternProto Menu_Item
TouchSensor { Sphere }
DEF Sphere_Click Script {<code> }
Route < back to
Option_Group.set_whichChoice >

Try though I may, whenever I try to instance a Menu_Item prototype, as
object Control_1, I cannot get an OnClick event on the Sphere to
trigger whichChoice. I keep on getting a "bad node within node"
syntax error, or thing just sits there and ignores the onclick event.

Conversely, this works fine, but suffers from a excessive code-reuse
by being able to abstract the Menu_Item behavior:

DEF Option_Group Switch
whichChoice 0
choice [ < some option groups > ]
End Switch

DEF Menu_Options
Control_1
TouchSensor { Sphere }
Sphere_Click Script { <code> }
Route < back to Option_Group.set_whichChoice >

Control_2
TouchSensor { Sphere }
Sphere_Click Script { <code> }
Route < back to Option_Group.set_whichChoice >

For example, on an 8 menu control panel, the repaste and repeated code
works fine, but eats up a couple of hundred lines of code.

I couldn't get other simplier variations to work, like:

DEF Option_Group Switch
whichChoice 0
choice [ < some option groups > ]
End Switch

DEF Menu_Options
Control_1
TouchSensor { Sphere }
Sphere_Click Script { <-- PROTO Boolean_Filter Script { <code>
}
}
Route < back to Option_Group.set_whichChoice >

Control_2
TouchSensor { Sphere }
DEF Sphere_Click Script { PROTO Boolean_Filter Script { <code>
}
}
Route < back to Option_Group.set_whichChoice >

At this point, I concluded there was something very basic that I'm
just not "getting" about prototyping when proto'ing script events and
reusing the script object. About the only thing I haven't tried is
nesting prototypes.

Some guidance or an example using the VRML 2.0 Handbook's Figure 31.8
code as an external prototype - showing how to access the eventOut
once the prototyped is instanced and routing it to a set_whichChoice
or other event, would be greatly appreciated.

- Kurt

P.S. - Thank you for the help and code samples the group has provided
over the last week. I have been able to get an initial working VRML
application up with the desired features, but would still like to
shrink some of those repeated code lines paired down (and get a handle
on this basic script prototyping skill).
Bill Angel

2003-12-26, 9:28 am

Hi:

The following code shows one way to define MenuItems as instances of
a PROTO, and then route events generated by a Script withing the PROTO
instances to another Script for the purpose of setting the whichChoice
value of a Switch node.


#VRML V2.0 utf8

PROTO MenuItem [
field SFInt32 itemSelection -1
eventOut SFInt32 itemSelected
]
{
DEF TOUCHSENSOR TouchSensor {}
Sphere {radius .5}

DEF MENUITEM-SCRIPT Script {
field SFInt32 itemSelection IS itemSelection
eventIn SFBool sensorIsActive
eventOut SFInt32 itemSelected IS itemSelected
directOutput TRUE
url "java script:
function sensorIsActive (value) {
if(value == true)
itemSelected = itemSelection;
}
"
}

ROUTE TOUCHSENSOR.isActive TO MENUITEM-SCRIPT.sensorIsActive
}


DEF SWITCH Switch {
choice [
Text {
string "No Item Selected"
}
Text {
string "Item 1 Selected"
}
Text {
string "Item 2 Selected"
}
]
whichChoice 0
}


Transform {
translation 0 -2 0
children [
DEF MENUITEM1 MenuItem {itemSelection 1}
]
}

Transform {
translation 1.5 -2 0
children [
DEF MENUITEM2 MenuItem {itemSelection 2}
]
}


DEF SELECTION-SCRIPT Script {
field SFNode menuSwitch USE SWITCH
eventIn SFInt32 setSwitch
directOutput TRUE
url "java script:
function setSwitch (value) {
menuSwitch.set_whichChoice = value;
}
"
}

ROUTE MENUITEM1.itemSelected TO SELECTION-SCRIPT.setSwitch
ROUTE MENUITEM2.itemSelected TO SELECTION-SCRIPT.setSwitch

#<end of code>

-- Hope this helps,
Bill Angel


fisherka@csolutions.net (PrisNo6) wrote in message news:<9865fa0b.0312222251.581e4658@posting.google.com>...
quote:

> I am a beginner working with Ames _VRML 2.0 Sourcebook_, specifically
> example 31.8, a prototyped boolean filter. I have been trying
> unsuccessfully to use any script events from a prototyped objects and
> am looking for an example or guidance. As a consequence, I have been
> unable to reuse behaviors encapsulated in a script. Fields from an
> instance of a prototype I can handle fine.
>
> The specific context I am working with was a switch statement and a
> series of menu item controls. When the user clicks on the menu item
> button (a sphere), the number of the menu item is captured and sent to
> a switch statement. The objects and behaviors in each switch node
> differ on the selection. In psuedo-VRML-code, it looks like this:
>
> DEF Option_Group Switch
> whichChoice 0
> choice [ < some option groups > ]
> End Switch
>
> DEF Menu_Options
> Control_1 <-- Proto or ExternProto Menu_Item
> TouchSensor { Sphere }
> DEF Sphere_Click Script { <code> }
> Route
> < back to Option_Group.set_whichChoice
> by proto >
>
> Control_2 <-- Proto or ExternProto Menu_Item
> TouchSensor { Sphere }
> DEF Sphere_Click Script {<code> }
> Route < back to
> Option_Group.set_whichChoice >
>
> Try though I may, whenever I try to instance a Menu_Item prototype, as
> object Control_1, I cannot get an OnClick event on the Sphere to
> trigger whichChoice. I keep on getting a "bad node within node"
> syntax error, or thing just sits there and ignores the onclick event.
>
> Conversely, this works fine, but suffers from a excessive code-reuse
> by being able to abstract the Menu_Item behavior:
>
> DEF Option_Group Switch
> whichChoice 0
> choice [ < some option groups > ]
> End Switch
>
> DEF Menu_Options
> Control_1
> TouchSensor { Sphere }
> Sphere_Click Script { <code> }
> Route < back to Option_Group.set_whichChoice >
>
> Control_2
> TouchSensor { Sphere }
> Sphere_Click Script { <code> }
> Route < back to Option_Group.set_whichChoice >
>
> For example, on an 8 menu control panel, the repaste and repeated code
> works fine, but eats up a couple of hundred lines of code.
>
> I couldn't get other simplier variations to work, like:
>
> DEF Option_Group Switch
> whichChoice 0
> choice [ < some option groups > ]
> End Switch
>
> DEF Menu_Options
> Control_1
> TouchSensor { Sphere }
> Sphere_Click Script { <-- PROTO Boolean_Filter Script { <code>
> }
> }
> Route < back to Option_Group.set_whichChoice >
>
> Control_2
> TouchSensor { Sphere }
> DEF Sphere_Click Script { PROTO Boolean_Filter Script { <code>
> }
> }
> Route < back to Option_Group.set_whichChoice >
>
> At this point, I concluded there was something very basic that I'm
> just not "getting" about prototyping when proto'ing script events and
> reusing the script object. About the only thing I haven't tried is
> nesting prototypes.
>
> Some guidance or an example using the VRML 2.0 Handbook's Figure 31.8
> code as an external prototype - showing how to access the eventOut
> once the prototyped is instanced and routing it to a set_whichChoice
> or other event, would be greatly appreciated.
>
> - Kurt
>
> P.S. - Thank you for the help and code samples the group has provided
> over the last week. I have been able to get an initial working VRML
> application up with the desired features, but would still like to
> shrink some of those repeated code lines paired down (and get a handle
> on this basic script prototyping skill).


PrisNo6

2003-12-28, 10:28 pm

wtangel@shell.cais.net (Bill Angel) wrote in message news:<c4ba4731.0312260439.44b7f5b0@posting.google.com>...

Bill, thanks for the sample. I'll study it closely.
quote:

> The following code shows one way to define MenuItems as instances of
> a PROTO, and then route events generated by a Script withing the PROTO
> instances to another Script for the purpose of setting the whichChoice
> value of a Switch node.


<snip>
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews