Search code examples
htmlx3d

X3d scene having Multiple touchsensors,need to know which touchsensor is clcikes or selected?


I have an x3d scene that contains multiple touchsensor nodes.When i click a particular touchsensor node i need to get the details about the selected node.Please give me any kind of help.Thanks in advance.


Solution

  • Give a different DEF name to each TouchSensor, then you can ROUTE to different events to distinguish which one the event comes from.


    Full example: multiple_touchsensors.x3dv

    Excerpt:

    [...]
    DEF touchsensor_1 TouchSensor {}
    [...]
    DEF touchsensor_2 TouchSensor {}
    [...]
    
    DEF a_script Script {
        eventIn     SFTime      obj_1_clicked
        eventIn     SFTime      obj_2_clicked
    
        directOutput TRUE
        url "javascript:
    
        function obj_1_clicked(){
            trace('The Box was clicked');
        }
    
        function obj_2_clicked(){
            trace('The Sphere was clicked');
        }
    
        "
    }
    
    ROUTE touchsensor_1.touchTime TO a_script.obj_1_clicked
    ROUTE touchsensor_2.touchTime TO a_script.obj_2_clicked