[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Aother hard one on PROTO & vrml/java-script



Hi,

Here's the second problem I have found:

-----------------------------------------------
2. Now I have various objects created from a PROTO and I would like to
eliminate them from the wrl by clicking on them. How can I know which is which?
The following example is another frustrated effort:


PROTO fooProto [
   field SFVec3f position 0 0 0
   field SFNode father NULL ]
{

   # Define Shape of object and the TouchSensor which has to activate deletion
   DEF GenTrans Transform {
      translation IS position
      children [
         Shape {
            geometry Box { size 1 1 1 }
            appearance Appearance { material Material { diffuseColor 1 1 1 } }
         }
         DEF TSProtoD TouchSensor {}
      ]
   }

   # Script which deletes object
   DEF DelProto Script {
      directOutput TRUE
      eventIn SFBool delete
      field SFNode whoami NULL
      field SFNode environment IS father

      url "vrmlscript:
         // Hold identity in field "whoami"
         function initialize(){
            whoami = environment.children_changed[
                           environment.children_changed.length - 1];
         }

         // Delete object whose pointer is held in "whoami"
         function delete(v) {
            if(v){
               environment.removeChildren = new MFNode(whoami);
            }
         }
      "
   }
   ROUTE TSProtoD.isActive TO DelProto.delete

}


DEF Environment Group {
   children [
      fooProto{ position 5 0 0, father USE Environment }
      fooProto{ position 0 0 0, father USE Environment }
      fooProto{ position -5 0 0, father USE Environment }
   ]
}


When I click on any of the cubes, nothing happens!

If I change the line in the "initialize"  function for:

            whoami = environment.children_changed[0];

then, when I click on any of the objects, the first cube is deleted but the
rest (of course) are not.

* Anybody has a clue why this happens?
* Anybody has alternatives to doing this?
---------------------------------------------

Thank you very much in advance!

Best regards,

Narcis.

-- 
01001011101101101100101101010010000100100010
1                                          1
1  Narcis Pares i Burgues                  0
0  Coordinator of the VR Lab               0
1  Institut Universitari de l'Audiovisual  1 
0  Universitat Pompeu Fabra                1 
1  Rambla, 31                              0
1  08002 Barcelona                         1 
0  http://www.iua.upf.es/~npares/          1
1                                          0
00100110010101111110111011110100101000101011
-------------------------------------------------------------------
*** Please send administrative requests to <majordomo@sdsc.edu> ***
-------------------------------------------------------------------