2 Replies Latest reply on May 29, 2006 8:24 AM by Bukue

    Interaction with a 3D Cube

    Bukue
      I´m developing a webpage where it has to be a 3D cube, and each of its faces has to point to a different URL. I have already constructed and shaded the cube. I have also coded the part of the rotation of the cube. But I still not find the part where the click on a certain face lead me to a specified URL.

      I wrote this code in order to find the way to know wich face has been clicked:



      ****************************************************************************************** *****************************************

      on mouseUp me
      returnData = member("3D").camera[1].modelsUnderLoc(the mouseLoc,#detailed)
      member("TXTcara").text = "You clicked on face " && returnData[1].faceID
      end

      ****************************************************************************************** ***************************************
      where TXTcara is a textfield on the stage where I print which face has been clicked



      But it always says me that I clicked on face 1 or face 2. I mean a cube has 6 faces... and this code says that it has only two!!

      How can I cerainly know wich face has been clicked??

      The cube was constructed as a box.
        • 1. Re: Interaction with a 3D Cube
          a¿ex Level 1
          the face is the polygon and not the face of the cube.
          if you use the built-in modelresource than each face of the cube has a seperate shader (look at the models shaderlist). I am pretty sure, you will assign different shaders to the different clickable cube faces. so you will need to get the shader which was clicked on.
          this information is the #meshID of the picking data which is returned by the picking functions (modelunderloc and modelunderray), if set to #detailed.

          so in your case:

          on mouseUp me
          returnData = member("3D").camera[1].modelsUnderLoc(the mouseLoc,#detailed)
          member("TXTcara").text = "You clicked on face " && returnData[1].meshID
          end



          I guess your snippet is a fast sample to point out the problem, but just in case...you should check, if a model was hit in the first place and often the above behavior is on the 3-D sprite and if you have only one camera you could get away with all the hardcode (member name, camera index etc.) with:

          on mouseUp me
          sp = sprite(me.spritenum)
          ml = the mouseLoc - point(sp.left, sp.top)
          cam = sp.camera
          returnData = cam.modelsUnderLoc(ml, #detailed)
          if count(returnData) > 0 then member("TXTcara").text = "You clicked on face " && returnData[1].meshID
          end
          • 2. Re: Interaction with a 3D Cube
            Bukue Level 1
            Thank you very much!! It works perfect!! =D