Jump to content

Passing webGL canvas widget click event to jQuery


dbawel
 Share

Recommended Posts

Hello,

I get caught up in the most rediculous problems - which should be simple. I have a GUI element (widget) on a webGL canvas using bGUI, and need to click on the widget (object) and pass that event to the jQuery 'click' event. I've tried and studied every method, but I'm obviously mising something. @Nabroski provided the following code which works fine in my scripts now, but I need to avoid appending (creating) a new button to pass the click event to the jQuery event handler. How might I use any object in the following playground scene to pass the 'click' event or a 'pick' event to pass this to the jQuery event handler if an object in the scene below is clicked, and no button is created to "choose file"?

http://www.babylonjs-playground.com/#VNVOU#12

I feel really stupid on this one.:blink: So I've tried countless solutions, but nothing but errors on var files = evt.target.files; as I can't manage to pass a 'click' event from my GUI. Not even using: 

alert(event.currentTarget === this);

Thanks,

DB

Link to comment
Share on other sites

Hiya DB.  These two event objects are not the same type.  If it were a KEYPRESS event on the canvas, then the keypress handler code would get a "genuine" event to actionManager executeCodeAction(here).  But mouse picks on mesh... use a "special" event object... not the same type as jQuery/DOM needs.  (as least I THINK this is true).  BJS pick events have a pickInfo object attached, which carries a duffle bag of MESH-pick info.  They are Deltakosh-created event objects.

So, you might think this way.  What would it take to CREATE a jQuery event object... inside code... in an actionManager executeCodeAction function?  Can you "build" an event for jQuery?  Can you "fire it"? 

If so... do that.  Make a bridge.  :)  (not sure if ANY of this is correct, but maybe) 

http://playground.babylonjs.com/?11 Here, a non-actionManager pick is seen... having a standard event object AND a BJS pickResult.  You can check the evt object for things like .ctrlKey, plus check the pickResult for hits on mesh, as shown.  Handy.

Link to comment
Share on other sites

Thank you for all of the help. @Pryme8 -  I've tried to impliment $(e.target).click() into my codebut am missing something. If you might expand a bit, I've read EVERY post for the past 5 years on every forum, and am still baffled.

@Nabroski - I wish I could simply call a FileReader, but am using jQuery to pass the files to the server. Is there a way to impliment the following into the jQuery click event when the widget is pressed?:

window.addEventListener("click", function (evt) {  

This should be simple, but for some reason this one is really killing me. Perhaps this is what @Wingnut is suggesting?

Thanks,

DB

Link to comment
Share on other sites

You guys are awesome. I was missing the logic in the order of operations, and got very close with @Nabroski's post and @RaananW's playground example showed me exactly where my code wasn't passing the event to the file reader/loader. This is the dumbest I've felt in a while, as my pride kept me from creating this thread and wasting time. I'm so glad to be a part of this community, and this topic re-wired how I can interact with jQuery.

Thanks to you all,

DB

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...