shaharyar.ahmed Posted January 4, 2014 Share Posted January 4, 2014 I set up a small scene in 3Ds max to test object picking in babylon.js. I exported the scene to .obj and then convert it to .babylon using http://www.babylonjs.com/converter.html. But I got some unexpected results, here is the link http://developerslink.net16.net/scene2.html . Its not picking the objects perfectly. You can check it yourself. Here is the one more test but got the same results http://developerslink.net16.net/loadScene.html Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 4, 2014 Share Posted January 4, 2014 I think that this a report with the white band at the top.That is what i done:var pickResult = newScene.pick(evt.clientX, evt.clientY - 33);This should be more precise Quote Link to comment Share on other sites More sharing options...
shaharyar.ahmed Posted January 4, 2014 Author Share Posted January 4, 2014 I've updated the code as you said.. but still the same results.... Quote Link to comment Share on other sites More sharing options...
shaharyar.ahmed Posted January 4, 2014 Author Share Posted January 4, 2014 I used the 50 instead of 33 var pickResult = newScene.pick(evt.clientX, evt.clientY - 50);and it worked.. Wow !! I couldn't imagine that was so simple.. Thanks Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 4, 2014 Share Posted January 4, 2014 Yes, 33 is a value approximate. I think that is your white band at the top which must make 50. which corresponds to the offset of pick Quote Link to comment Share on other sites More sharing options...
ProfessorF Posted January 6, 2014 Share Posted January 6, 2014 This is more precise (assuming your canvas is named renderCanvas) var pickResult=newScene.pick(event.clientX+renderCanvas.offsetLeft, event.clientY - renderCanvas.offsetTop). shaharyar.ahmed and gwenael 2 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 6, 2014 Share Posted January 6, 2014 Oh, yes, that is much better. No need to look for the fair value manually.However in my case it does not work, I think that returns the value 1 at the places of 30.offsetTop, retrieves the value of 'top' and not 'margin-top' Quote Link to comment Share on other sites More sharing options...
ProfessorF Posted January 6, 2014 Share Posted January 6, 2014 Hm... I think if your canvas is inside of another element, or if your body has margins you may have to add that as well. Do you have a link? I can take a look. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 6, 2014 Share Posted January 6, 2014 I work in local. But actually, my canvas is in an html table, I have a tool bar at the top of my table of 30px. Quick Example:<div style="width:100%;height:30px"> tool bar top </div><table style="width:100%;height:100%"> <tr> <td><canvas id="canvas" style="width:100%;height:100%"></canvas></td> <td style="width:500px;">Menu right</td> </tr></table>Behold in image on what i work: Quote Link to comment Share on other sites More sharing options...
ProfessorF Posted January 6, 2014 Share Posted January 6, 2014 oh I see. Since you canvas is inside of the table, you should give your table and id (like <table id=tbl), then also subtract tbl.offsetTop Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 6, 2014 Share Posted January 6, 2014 Ok, it works like this. Thank You ProfessorF Quote Link to comment Share on other sites More sharing options...
Nico Posted January 8, 2014 Share Posted January 8, 2014 Why did you handle click on your window, do you really need to catch all click inside the window ? If not you can use this :canvas.addEventListener("click", function(){ var pickResult = newScene.pick(evt.offsetX, evt.offsetY);});offsetX/Y will give you relative position from delegate. gwenael and shaharyar.ahmed 2 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 8, 2014 Share Posted January 8, 2014 Ah yes, it is also a good idea. Thank You Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.