dsman Posted March 1, 2015 Share Posted March 1, 2015 I have checked drag-drop example by @deltakosh on playground ( http://www.babylonjs.com/playground/?18 ). But that example is about dragging meshes inside the babylon scene. What I want to achieve is to be able to drag HTML object (an <img> ) and drop on any mesh. Inside the event I should be able to find out and modify mesh on which I dropped. Any pointer ? Quote Link to comment Share on other sites More sharing options...
davrous Posted March 1, 2015 Share Posted March 1, 2015 Idea:- add your own monitoring drag/drop code on our rendering canvas- read your image file via the FileReader- get the clientX and the clientY coordinates after the drag operation- find the corresponding mesh by sending a ray into the scene using for instance our picking algorithm (check our doc: http://doc.babylonjs.com)- do whatever you'd like with this mesh and your image (a texture I suppose?)David ferat 1 Quote Link to comment Share on other sites More sharing options...
iiceman Posted March 1, 2015 Share Posted March 1, 2015 Hi and welcome to the forum dsman, it's a bit messy but you might get the idea: http://www.babylonjs-playground.com/#25LQ6Q Let me know if that is what you want or if you have questions about it... I'll try to answer even if most of the time I actually don't know what I am doing myself DellaFree, ozRocker and adam 3 Quote Link to comment Share on other sites More sharing options...
dsman Posted March 10, 2015 Author Share Posted March 10, 2015 Thanks @iiceman and @davrous I was able to do that as suggested. But I have one another problem now. I tried Flat2009 model from babylon website's home page. Everything worked fine. I was able to change mesh's texture. Then I used model named "RETAIL" . Nothing works. I debugged the javascript. Everything is fine. In the drop event pointer's x,y co-ordinates are also detected correctly. But following function call returns null instead of mesh. I tried running in full screen and clicking everywhere. But it just doesn't hit the mesh. scene.pick(ev.clientX, ev.clientY); This is mysterious thing. There's nothing even to suspect here. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 10, 2015 Share Posted March 10, 2015 Did you check the mesh are pickable? (mesh.isPickable) Quote Link to comment Share on other sites More sharing options...
dsman Posted March 10, 2015 Author Share Posted March 10, 2015 I am sorry. I am just beginner . How do I loop through all meshes to check if they are pickable ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 10, 2015 Share Posted March 10, 2015 no problem:for (var index = 0; index < scene.meshes.length; index++) {var mesh = meshes[index];} Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted March 10, 2015 Share Posted March 10, 2015 Awesome iiceman !!! What a nice PG !BTW, doesn't work on FF... Quote Link to comment Share on other sites More sharing options...
iiceman Posted March 12, 2015 Share Posted March 12, 2015 Glad you like it. Might be the same problem as with my editor, have to check the event handling in firefox, but should't be too hard to fix I guess Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted March 12, 2015 Share Posted March 12, 2015 Yep, check that :http://stackoverflow.com/questions/21507189/dragenter-dragover-and-drop-events-not-working-in-firefox iiceman 1 Quote Link to comment Share on other sites More sharing options...
hit2501 Posted July 25, 2015 Share Posted July 25, 2015 Sorry to write right know but I´m trying to use the iiceman example but I get in the console: "Uncaught TypeError: Cannot read property 'addEventListener' of null" in the line:"canvas.addEventListener('dragover', dragover, false);" What am I doing wrong? Thanks Quote Link to comment Share on other sites More sharing options...
iiceman Posted July 25, 2015 Share Posted July 25, 2015 Hi hit, you get that error when using that example on your own project, right? The playground is okay, it works there for you? (I just checked, for me the playground still works in firefox and chrome) I am just guessing, but maybe the name of your canvas element might be different then the one used in the playground. That would mean that you have to change this line (line number 12):var canvas = document.getElementById('canvasZone');Replace 'canvasZone' with the Id your canvas element actually has. If that doesn't work or you are already using the right id, show us your whole html file and maybe tell us what browser you are using. Quote Link to comment Share on other sites More sharing options...
hit2501 Posted July 25, 2015 Share Posted July 25, 2015 Thanks iiceman, its working now but the size of the scene shrink: How can I fix it? Thanks again and sorry for being a pain in the a** Quote Link to comment Share on other sites More sharing options...
iiceman Posted July 25, 2015 Share Posted July 25, 2015 Hard to tell just from the screenshot. Can you upload it to a webserver and give us a link? I assume it's just CSS defining the size of the canvas element. But again, just guessing Quote Link to comment Share on other sites More sharing options...
hit2501 Posted July 25, 2015 Share Posted July 25, 2015 Of course, here is it: http://www.wilawara.com/dragndrop/ Quote Link to comment Share on other sites More sharing options...
iiceman Posted July 26, 2015 Share Posted July 26, 2015 Yeah, it's as I said. Your canvas element has now the id 'canvasZone' but your CSS still referes to renderCanvas. So just change the #renderCanvas in your CSS rule to #canvasZone and it should be the full screen again. Quote Link to comment Share on other sites More sharing options...
hit2501 Posted July 30, 2015 Share Posted July 30, 2015 Thank you iiceman, I need to learn more Quote Link to comment Share on other sites More sharing options...
Gerente Posted July 30, 2015 Share Posted July 30, 2015 I hate the fast that when a texture is being loaded the previous texture disappear. I had to create an additional mesh to "preload" the next texture and then switch the visibility. Anyone has solve this? Just drag Lisa into the sphere and you will see the sphere disappear for some seconds: http://www.babylonjs-playground.com/#25LQ6Q Quote Link to comment Share on other sites More sharing options...
Lugtigheid Posted January 20, 2017 Share Posted January 20, 2017 On 30-7-2015 at 11:54 PM, Gerente said: I hate the fast that when a texture is being loaded the previous texture disappear. I had to create an additional mesh to "preload" the next texture and then switch the visibility. Anyone has solve this? Just drag Lisa into the sphere and you will see the sphere disappear for some seconds: http://www.babylonjs-playground.com/#25LQ6Q Great! Has anyone got this example working with touch possibilities, for tablets? 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.