Home

hersto:  Arrow.wrl

Source of Arrow.wrl:

Here is a link for right-clicking and downloading the file: Arrow.wrl (8.74 K Byte),

and below is its content to view online.


#VRML V2.0 utf8




WorldInfo
{
    title "Copyright (C) 2002 by Herbert Stocker (AKA hersto)"

    info 
    [
"       The original versions of the PROTO Arrow was written
        by me, Herbert Stocker. 

        The original versions and some test and demonstration Worlds
        can be found at http://www.hersto.de/ .
"

"       You can use and modify the PROTO in this file if you keep the
        credit information valid and if you don't remove the link to
        the originating site http://www.hersto.de/ .

        In brief, keep this WorldInfo node along with the Proto.
"

"       Please send a message to hersto@hersto.de where you describe
        how you use or improved the nodes. Especially if you included
        the improved versions.
"
    ]
}




#
#EXTERNPROTO Arrow
#[
#    exposedField SFVec3f From        # 0 0 0
#    exposedField SFVec3f To          # 0 1 0
#    
#    exposedField SFFloat CapLength   # .25
#    exposedField SFFloat CapRadius   # .08
#    exposedField SFFloat LineRadius  # .028
#
#    exposedField SFString CapMode    # "keepRadius" or "keepSize" or "keepAspect"
#
#    exposedField SFNode  appearance  # NULL
#]
#  "Arrow.wrl#Arrow"
#



PROTO Arrow
[
    exposedField SFVec3f From        0 0 0
    exposedField SFVec3f To          0 1 0
    
    exposedField SFFloat CapLength  .25
    exposedField SFFloat CapRadius  .08
    exposedField SFFloat LineRadius .028

    exposedField SFString CapMode   "keepRadius" # or "keepSize" or "keepAspect"

    exposedField SFNode  appearance  NULL

    field MFString credits "Initial idea and copyright by Herbert Stocker, http://www.hersto.com/"
]
{

    Group
    {
        children
        [
            DEF TransLine Transform
            {
                children DEF SwLine Switch
                {
                    choice Shape 
                    {
                        appearance IS appearance
                        geometry Cylinder {}
                    }
                }
            }

            DEF TransCap Transform
            {
                children DEF SwCap Switch
                {
                    choice Shape 
                    {
                        appearance IS appearance
                        geometry Cone {}
                    }
                }
            }
        ]
    }





    PROTO EFFS 
    [
        exposedField SFVec3f From  0 0 0
        exposedField SFVec3f To    0 1 0 
    
        exposedField SFFloat CapLength  .25
        exposedField SFFloat CapRadius  .08
        exposedField SFFloat LineRadius .028

        exposedField SFString CapMode   "keepRadius"
    ]
      { Group {} }


    DEF EFFS EFFS 
    {
        From IS From
        To   IS To

        CapLength  IS CapLength
        CapRadius  IS CapRadius
        LineRadius IS LineRadius
        CapMode    IS CapMode
    }




    DEF Worker Script
    {
        field SFNode EFFS USE EFFS 

        field SFVec3f From 0 0 0
        field SFVec3f To   0 1 0

        field SFFloat CapLength     .25
        field SFFloat CapRadius     .08
        field SFFloat LineRadius    .028

        eventIn SFVec3f set_From
        eventIn SFVec3f set_To

        eventIn SFFloat set_CapLength
        eventIn SFFloat set_CapRadius
        eventIn SFFloat set_LineRadius

        eventIn SFString set_CapMode
        


        eventOut SFVec3f LineTranslation
        eventOut SFRotation LineRotation
        eventOut SFVec3f       LineScale 

        eventOut SFVec3f CapTranslation
        eventOut SFRotation CapRotation
        eventOut SFVec3f       CapScale 

        eventOut SFInt32  whichChoiceLine
        eventOut SFInt32  whichChoiceCap

        field    SFBool  IsCortona        FALSE


        field    SFInt32 cKeepRadius 1
        field    SFInt32 cKeepSize   2 
        field    SFInt32 cKeepAspect 3 

        field    SFInt32 CapMode     1


        url "vrmlscript:

        function initialize()
        {
            IsCortona= Browser.getName() == 'Cortona VRML Client';

            From= EFFS.From;
            To=   EFFS.To;
            CapLength=  EFFS.CapLength;
            CapRadius=  EFFS.CapRadius;
            LineRadius= EFFS.LineRadius;
            whichChoiceLine= -1;
            whichChoiceCap=  -1;
            eventsProcessed();

            set_CapMode(EFFS.CapMode);

        }

        function set_From(f)       {From=       f; }
        function set_To(t)         {To=         t; }
        function set_CapLength(l)  {CapLength=  l; }
        function set_CapRadius(r)  {CapRadius=  r; }
        function set_LineRadius(r) {LineRadius= r; }

        function set_CapMode(m)
        {
            if(m == 'keepRadius')  CapMode= cKeepRadius;
            if(m == 'keepSize')    CapMode= cKeepSize;
            if(m == 'keepAspect')  CapMode= cKeepAspect;
        }

        function eventsProcessed()
        {
            var Middle= To.subtract(From).length() > CapLength
                          ? From.add(To.subtract(From).normalize().multiply(To.subtract(From).length() - CapLength))
                          : From
                          ;

            var LineLength= Middle.subtract(From).length();

            if(   LineRadius != 0
               && LineLength != 0
              )
            {
                var a= From;
                var b= Middle;
                LineTranslation= a.add(b).multiply(0.5);
                LineRotation=    new SFRotation(new SFVec3f(0, 1, 0), b.subtract(a));
                LineScale=       new SFVec3f(LineRadius, LineLength / 2, LineRadius);

                if(whichChoiceLine != 0)   whichChoiceLine= 0;
            }else{
                if(whichChoiceLine != -1)  whichChoiceLine= -1;
            }
            
//            var Cap_Length= To.subtract(Middle).length();
            
            if(   CapRadius  != 0 
               && CapLength  != 0
              )
            {
                a= Middle;
                b= To;

                var fraction= To.subtract(Middle).length() / CapLength;

                CapTranslation= a.add(b).multiply(0.5);
                CapRotation=    new SFRotation(new SFVec3f(0, 1, 0), b.subtract(a));

                if(CapMode == cKeepSize)   CapScale= new SFVec3f(CapRadius, CapLength / 2, CapRadius);
                if(CapMode == cKeepRadius) CapScale= new SFVec3f(CapRadius, CapLength * fraction / 2, CapRadius);
                if(CapMode == cKeepAspect) CapScale= new SFVec3f(CapRadius * fraction, CapLength / 2 * fraction, CapRadius * fraction);
                if(whichChoiceCap != 0)   whichChoiceCap= 0;
            }else{
                if(whichChoiceCap != -1)  whichChoiceCap= -1;
            }

//                if(CapMode == cKeepSize)   SetCapScale(new SFVec3f(CapRadius, CapLength / 2, CapRadius));
//                if(CapMode == cKeepRadius) SetCapScale(new SFVec3f(CapRadius, CapLength * fraction / 2, CapRadius));
//                if(CapMode == cKeepAspect) SetCapScale(new SFVec3f(CapRadius * fraction, CapLength / 2 * fraction, CapRadius * fraction));
////                if(whichChoiceCap != 0)   whichChoiceCap= 0;
//            }else{
////                if(whichChoiceCap != -1)  whichChoiceCap= -1;
//            }
            
        }

        function SetCapScale(vec)
        {
            if(vec.x && vec.y && vec.z) // suppress zeroes in scale because Cosmo Player (or is it only Pivoron) cries about even this.
            {
                CapScale= vec;
                if(whichChoiceCap != 0)   whichChoiceCap= 0;
            }else
            {
                if(whichChoiceCap != -1)  whichChoiceCap= -1;
            }
        }

        function MultiplyOri(a, b)
        {
            if(IsCortona)
        return b.multiply(a);
            else
        return a.multiply(b);
        }


        "
    }

    ROUTE EFFS.From TO Worker.set_From
    ROUTE EFFS.To   TO Worker.set_To

    ROUTE EFFS.CapLength  TO Worker.set_CapLength
    ROUTE EFFS.CapRadius  TO Worker.set_CapRadius
    ROUTE EFFS.LineRadius TO Worker.set_LineRadius

    ROUTE EFFS.CapMode    TO Worker.set_CapMode


    ROUTE Worker.LineTranslation TO TransLine.translation
    ROUTE Worker.LineRotation    TO TransLine.rotation
    ROUTE Worker.LineScale       TO TransLine.scale
    ROUTE Worker.whichChoiceLine TO SwLine.whichChoice

    ROUTE Worker.CapTranslation  TO TransCap.translation
    ROUTE Worker.CapRotation     TO TransCap.rotation
    ROUTE Worker.CapScale        TO TransCap.scale
    ROUTE Worker.whichChoiceCap  TO SwCap.whichChoice

}




Arrow
{
    To 1 0 0
}

Arrow
{
    To 0 1 0
}


Arrow
{
    To 0 0 1
}

__.-.__
end of document