ExtProto with javascript...Arg my head hurts! 
Author Message
 ExtProto with javascript...Arg my head hurts!

Hi,
Only been doing vrml for a month and I'm just starting to get my head round
most of it... but I'm getting a little tied up with trying to use javascript
to build fields for node values.

What I'm trying to do is define an ExProto which is passed object co-ords,
object name and destination.

From the name I want to construct a URL entry (ie add ".html" to the name
and pass it to the URL. I use the name as the anchors description.

I believe the way to do this is with a javascript
(ie objectUrl= new MFString (objectName+'.html');)

But getting the objectUrl back from the script into the ExProto is proving
beyond my meger understanding of the ROUTE command.

Is there an easy way? :)

Also I want to be able to plot a line between the object translation and
it's destination and maybe calculate the distance and time to dest given
a 'speed' variable.

Haven't got to that yet, but any pointers would be handy. :)

I've been reading throught the spec, tutorials and websites till my head
hurts. :)

Thanks,
        Jase.

--
#anime##scifi##indst##alt##grnge##indi##gth##rock##atmos##ld##dvd##sr2##srf'n#
         Email To        ##          Word of the month..."okashii"            

                         ##             http://www.*-*-*.com/



Thu, 10 Oct 2002 03:00:00 GMT  
 ExtProto with javascript...Arg my head hurts!

Quote:

> Hi,
> Only been doing VRML for a month and I'm just starting to get my head round
> most of it... but I'm getting a little tied up with trying to use javascript
> to build fields for node values.

> What I'm trying to do is define an ExProto which is passed object co-ords,
> object name and destination.

> From the name I want to construct a URL entry (ie add ".html" to the name
> and pass it to the URL. I use the name as the anchors description.

> I believe the way to do this is with a javascript
> (ie objectUrl= new MFString (objectName+'.html');)

> But getting the objectUrl back from the script into the ExProto is proving
> beyond my meger understanding of the ROUTE command.

> Is there an easy way? :)

If the script is inside the PROTO body and you want to access the eventIn of a
node also in the body, DEF that node, declare a SFNode field in the script that
will USE that node and set directOutput to TRUE. You'll be able to access directly
the eventIn from you function. For example let say the node is an Anchor, so:
DEF A Anchor {}
DEF S Script {
    field SFNode a USE A
    directOutput TRUE
 ... ...... .........etc
and in the script:
a.url = new MFString (objectName+'.html'); # here you assign directly to the
reference of the Anchor node

Sylvain Carette
VRML designer-composer

- Show quoted text -

Quote:

> Also I want to be able to plot a line between the object translation and
> it's destination and maybe calculate the distance and time to dest given
> a 'speed' variable.

> Haven't got to that yet, but any pointers would be handy. :)

> I've been reading throught the spec, tutorials and websites till my head
> hurts. :)

> Thanks,
>         Jase.

> --
> #anime##scifi##indst##alt##grnge##indi##gth##rock##atmos##ld##dvd##sr2##srf'n#
>          Email To        ##          Word of the month..."okashii"

>                          ##             http://www.ailean.com



Thu, 10 Oct 2002 03:00:00 GMT  
 ExtProto with javascript...Arg my head hurts!

Hi,

For your EXTERNPROTO, define a eventOut SFString or MFString and assign your
objectUrl to it in the script node.

i.e.. Proto
[ eventIn SFString name
  eventOut SFString url
]

i.e.. Script
{ eventIn SFString objectName IS name
   eventOut SFString objectUrl IS url

  url "javascript:
  function() ....
    ..... objectUrl= new MFString (objectName+'.html');

This way you pass the information into the proto, it does its computations, and
then it passes
the result back out of the proto.  If you use a MFString, be sure to place the
object in the right
spot: objectUrl[0] = new MFString(objectName + '.html').

This should work for the proto but there may be easier ways to accomplish what
you're trying -
I'm not exactly sure of what you want to do.

Hope this helps,

Ernest Rose

Quote:

> Hi,
> Only been doing VRML for a month and I'm just starting to get my head round
> most of it... but I'm getting a little tied up with trying to use javascript
> to build fields for node values.

> What I'm trying to do is define an ExProto which is passed object co-ords,
> object name and destination.

> From the name I want to construct a URL entry (ie add ".html" to the name
> and pass it to the URL. I use the name as the anchors description.

> I believe the way to do this is with a javascript
> (ie objectUrl= new MFString (objectName+'.html');)

> But getting the objectUrl back from the script into the ExProto is proving
> beyond my meger understanding of the ROUTE command.

> Is there an easy way? :)

> Also I want to be able to plot a line between the object translation and
> it's destination and maybe calculate the distance and time to dest given
> a 'speed' variable.

> Haven't got to that yet, but any pointers would be handy. :)

> I've been reading throught the spec, tutorials and websites till my head
> hurts. :)

> Thanks,
>         Jase.

> --
> #anime##scifi##indst##alt##grnge##indi##gth##rock##atmos##ld##dvd##sr2##srf'n#
>          Email To        ##          Word of the month..."okashii"

>                          ##             http://www.ailean.com



Thu, 10 Oct 2002 03:00:00 GMT  
 ExtProto with javascript...Arg my head hurts!

Quote:

> If the script is inside the PROTO body and you want to access the eventIn of a
> node also in the body, DEF that node, declare a SFNode field in the script that
> will USE that node and set directOutput to TRUE. You'll be able to access directly
> the eventIn from you function. For example let say the node is an Anchor, so:
> DEF A Anchor {}
> DEF S Script {
>     field SFNode a USE A
>     directOutput TRUE
>  ... ...... .........etc
> and in the script:
> a.url = new MFString (objectName+'.html'); # here you assign directly to the
> reference of the Anchor node

> Sylvain Carette
> VRML designer-composer

Many thanks for the swift reply. I've been trying this and I think it's really
close, but not quite there.

Here's what I've done so far, there's an error somewhere as the url field
still doesn't get updated by the script, I think it's the right way to do
it but I've got a syntax error I think in the script...

#VRML V2.0 utf8
PROTO Scouts [
        exposedField SFVec3f scoutTranslation 0 0 0.6
        exposedField SFString scoutName ""
        exposedField SFVec3f scoutDest 0 0 0.6
]{
        Transform {
                translation     IS scoutTranslation
                children [
                        DEF ThisScout Anchor {                                                          
                                parameter ["target=sysdetail"]
                                description IS scoutName
                                url ["argg.html"]
                                children [
                                        Shape {
                                                appearance Appearance {
                                                        material Material {
                                                                diffuseColor 1 1 1
                                                                specularColor 0.8 0.8 0.8
                                                                transparency 0.39
                                                        }
                                                }
                                                geometry Cone {
                                                        bottomRadius 0.1
                                                        height 0.5
                                                }
                                        }
                                ]
                        }
                        DEF ScoutScript Script {
                                field SFNode Scout USE ThisScout
                                directOutput TRUE
                                url     ["javascript:
                                        function Scout.description(value) {
                                                Scout.url = new MFString(value+'.html');
                                        }
                                }"]
                        }
                ]
        }

Quote:
}

--
#anime##scifi##indst##alt##grnge##indi##gth##rock##atmos##ld##dvd##sr2##srf'n#
         Email To        ##          Word of the month..."okashii"            

                         ##             http://www.ailean.com


Fri, 11 Oct 2002 03:00:00 GMT  
 ExtProto with javascript...Arg my head hurts!

Yes, there is error: your function Scout.description(value) isnt linked to any eventIn and
isnt called from elsewere. There is some confusion in the way you use the name for this
function and the statement "Scout.url = new MFString(value+'.html');". Look to me you try to
do two different thing at the same time. Not to mention that using the dot in the middle of
the function name might be illegal.
So lets try this:
add two eventIn in the PROTO declaration:
eventIn SFString setDescription
eventIn MFString setURL
then in the script:
DEF ScoutScript Script {
  eventIn SFString setDescription IS setDescription
  eventIn MFString setURL IS setURL
  field   SFNode scout USE ThisScout
  directOutput TRUE
  url "javascript:
  function setDescription(str, timestamp) {
    scout.description = str;
  }
  function setURL(str, timestamp) {
    scout.url = str;
  }"

Quote:
}

Now you can send events to description and url of Scout if it is what you wanted.
A few notes: Script are designed as event handler and to handle an event is just a matter of
naming the function the same as the eventIn you want to handle. Note that timestamp does
nothing ( as in most case ) but its good practice to take the habit to write it anyway ...
doest hurt.
And to follow standard naming convention, its better to name field starting with lower case
letter, but here, details... :-)
There is also the initialize() function which is called on object creation. For example, you
could had wanted that Scout get a random url from a list on creation only:
field MFString urlList [url1, url2, url3] # could be ISed from the PROTO interface
field SFNode scout USE ThisScout
directOutput TRUE
url "javascript:
  initialise() { // initialise doesnt need arguments and timestamp
    i = Math.round(Math.random() * (urlList.length - 1));
    scout.url[0] = urlList[i];
  }"

You can also build your own functions called from whithin others event handlers.
Hope this helped.

Sylvain Carette
VRML designer-composer

Quote:


> > If the script is inside the PROTO body and you want to access the eventIn of a
> > node also in the body, DEF that node, declare a SFNode field in the script that
> > will USE that node and set directOutput to TRUE. You'll be able to access directly
> > the eventIn from you function. For example let say the node is an Anchor, so:
> > DEF A Anchor {}
> > DEF S Script {
> >     field SFNode a USE A
> >     directOutput TRUE
> >  ... ...... .........etc
> > and in the script:
> > a.url = new MFString (objectName+'.html'); # here you assign directly to the
> > reference of the Anchor node

> > Sylvain Carette
> > VRML designer-composer

> Many thanks for the swift reply. I've been trying this and I think it's really
> close, but not quite there.

> Here's what I've done so far, there's an error somewhere as the url field
> still doesn't get updated by the script, I think it's the right way to do
> it but I've got a syntax error I think in the script...

> #VRML V2.0 utf8
> PROTO Scouts [
>         exposedField SFVec3f scoutTranslation 0 0 0.6
>         exposedField SFString scoutName ""
>         exposedField SFVec3f scoutDest 0 0 0.6
> ]{
>         Transform {
>                 translation     IS scoutTranslation
>                 children [
>                         DEF ThisScout Anchor {
>                                 parameter ["target=sysdetail"]
>                                 description IS scoutName
>                                 url ["argg.html"]
>                                 children [
>                                         Shape {
>                                                 appearance Appearance {
>                                                         material Material {
>                                                                 diffuseColor 1 1 1
>                                                                 specularColor 0.8 0.8 0.8
>                                                                 transparency 0.39
>                                                         }
>                                                 }
>                                                 geometry Cone {
>                                                         bottomRadius 0.1
>                                                         height 0.5
>                                                 }
>                                         }
>                                 ]
>                         }
>                         DEF ScoutScript Script {
>                                 field SFNode Scout USE ThisScout
>                                 directOutput TRUE
>                                 url     ["javascript:
>                                         function Scout.description(value) {
>                                                 Scout.url = new MFString(value+'.html');
>                                         }
>                                 }"]
>                         }
>                 ]
>         }
> }

> --
> #anime##scifi##indst##alt##grnge##indi##gth##rock##atmos##ld##dvd##sr2##srf'n#
>          Email To        ##          Word of the month..."okashii"

>                          ##             http://www.ailean.com



Sat, 12 Oct 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. easy problem, but my head hurts...

2. Prolog makes my head hurt, but in a good way

3. convert HTML head information into javascript code inside the body

4. convert HTML head information into javascript code inside the body

5. Arg, parse arg, command line, and ?

6. Changing actual arg via intent(in) formal arg in F90

7. dynamic method addition, problem with arg=arg in lambdas (was:

8. dynamic method addition, problem with arg=arg in lambdas (was:

9. IE6 +VRML + javascript in VRML trouble (was: problem using javascript window.open in VRML)

10. Important: ListModel with: deprecated; use hurts performance

11. It can't hurt

12. Y2K hurting Clipper?

 

 
Powered by phpBB® Forum Software