#VRML V2.0 utf8


#--------------------------------------------------------------------------

#

# demo moving objects by removeChildren and addChildren

#

#

# the red box, red sphere, and blue sphere are "moved" to another poition:

#

# - they are removed from the original MFNode 

# - they are added to the destination MFNode

#

# note: same code for all three objects

#

#--------------------------------------------------------------------------



# a red box with a tough sensor

#------------------------------


DEF TR_RedBox Transform 

{

  translation -5 10 0


  children 

  [

    DEF RedBox Shape 

    {

           appearance Appearance 

      {

             material Material 

        { 

          diffuseColor 1 0 0 

        }

            }

           

      geometry Box {}

    }

    

    DEF TS_RedBox TouchSensor {}

  ]

}



# a red spere with a tough sensor

#--------------------------------


DEF TR_RedSphere Transform 

{

  translation  0 10 0

  

  children 

  [

    DEF RedSphere Shape 

    {

           appearance Appearance 

      {

             material Material

        { 

          diffuseColor 1 0 0 

        }

           }

           

      geometry Sphere {}

    }

   

     DEF  TS_RedSphere TouchSensor {}

  ]

}



# a blue sphere with a tough sensor

#----------------------------------


DEF TR_BlueSphere Transform 

{

  translation 5 10 0

  

  children 

  [

    DEF BlueSphere Shape 

    {

           appearance Appearance 

      {

             material Material 

        { 

          diffuseColor 0 0 1 

        }

           }

           

      geometry Sphere {}

    }

    

    DEF TS_BlueSphere TouchSensor {}

  ]

}



# ----------- The Scene into which we insert


Group 

{

  children 

  [

    # the floor

    

    Transform 

    {

           translation 0 -0.1 0


             children 

      [

              Shape 

        {

               appearance Appearance 

          {

                       material Material 

            {

                         emissiveColor 0.5 0.5 0.5

            }

               }

        

          geometry Box

          {

            size 20 0.1 20

               }

              } 

      ] 

    }



    # top to bottom


    DEF TR_BlueSphereHolder Transform 

    {

           translation 0 5 0

    }

      

    DEF TR_RedSphereHolder Transform 

    {

           translation 0 3 0

    }


    DEF TR_BoxHolder Transform 

    {

      translation 0 1 0

    }

  ]

}



# =========================== SCRIPTS AND ROUTINGS ===========================


DEF TS_RedSphere_SCR Script

{

  eventIn   SFBool  isActive                                        # the TS on the red spere is active

  eventOut  MFNode  child                                           # a "helper" MFNode to hold the red sphere

  field     MFNode  node        USE   RedSphere                     # a node that is filles with the red spere for "transfer"


  url [ "javascript:


      function isActive( value ) 

      {

                         if ( value )                                                // if TS Pressed the red sphere is output via the child node

        {

          child = node;

        }                                                           // child is the red sphere

           }

         "

  ]

}



ROUTE TS_RedSphere.isActive     TO  TS_RedSphere_SCR.isActive       # start the script

ROUTE TS_RedSphere_SCR.child    TO  TR_RedSphere.removeChildren     # remove the red sphere from original position

ROUTE TS_RedSphere_SCR.child    TO  TR_RedSphereHolder.addChildren  # add it to the new position



# ----------------------------------------------------------------------------


DEF TS_BlueSphere_SCR Script 

{

  eventIn   SFBool  isActive

  eventOut  MFNode  child

  field     MFNode  node      USE BlueSphere


  url [ "javascript:

      

      function isActive( value )

      {

                         if ( value )

        {

          child = node;

        }

                 }

         "

  ]

}



ROUTE TS_BlueSphere.isActive    TO  TS_BlueSphere_SCR.isActive

ROUTE TS_BlueSphere_SCR.child   TO  TR_BlueSphere.removeChildren

ROUTE TS_BlueSphere_SCR.child   TO  TR_BlueSphereHolder.addChildren



# ----------------------------------------------------------------------------


DEF TS_RedBox_SCR Script 

{

  eventIn   SFBool  isActive

  eventOut  MFNode  child

  field     MFNode  node      USE RedBox


  url [ "javascript:

       

            function isActive( value )

      {

                         if ( value )

        {

          child = node;

        }

                 }

         "

  ]

}



ROUTE   TS_RedBox.isActive      TO  TS_RedBox_SCR.isActive

ROUTE   TS_RedBox_SCR.child     TO  TR_RedBox.removeChildren

ROUTE   TS_RedBox_SCR.child     TO  TR_BoxHolder.addChildren







Viewpoint 

{

  position     17.262 7.980 35.154

  orientation  -0.065 0.998 0.020 0.464

  fieldOfView  0.785

}

Created with the Personal Edition of HelpNDoc: Easy to use tool to create HTML Help files and Help web sites