Temechon Posted November 17, 2013 Share Posted November 17, 2013 Hello guys, I'm currently workng on several small thing with our favorite 3D engine, and one of these things is the mesh drag 'n drop.I know this feature is in the babylon roundmap, but I will need it very soon for a bigger project. Today, I have a drag and drop that is currently working in 2 dimensions (on X and Y axis). I use the scene.pick method to get the picked mesh.Here is the code : var pickedMesh; // Add event listener window.addEventListener("click", function(evt){ var pick = scene.pick(evt.clientX, evt.clientY); if (pick.pickedMesh) { pickedMesh = pick.pickedMesh; } }); window.addEventListener("mousemove", function(evt) { if (pickedMesh){ var pick = scene.pick(evt.clientX, evt.clientY); pickedMesh.position.x = pick.pickedPoint.x; pickedMesh.position.y = pick.pickedPoint.y; } });However, it is not working as intended : if the mouse is out of the selected mesh, then pick.pickedPoint is null, and the box position is not updated. What I would like is a way to convert the mouse coordinates to scene coordinates. I tried to look at the class BABYLON.Ray, but I need a world matrix. In the method scene.pick, the mesh world matrix is used, but obviously i cannot use it (as my scene can be empty).Is there a way to create a "scene.getWorldMatrix" in BABYLON ? What is the best way to do it ? Thank you for your help ! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 18, 2013 Share Posted November 18, 2013 Just use BABYLON.Matrix.Identity() Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 18, 2013 Author Share Posted November 18, 2013 Hi Delta, Thanks for your answer.I tried to use the method scene.createPickingRay(x, y), with x and y my mouse coordinates. In this method, the identity matrix is used when world is not defined, so I guess I was using it without declaring it explicitly. However, it does not work : the origin of the ray is always something like (0,9,0). (My camera is in (0,10,0) and look at (0,0,0) ). Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 18, 2013 Share Posted November 18, 2013 It should be ok with (0, 9,0) because the camera has a minZ offset value Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 19, 2013 Author Share Posted November 19, 2013 Thank you Delta, I used another solution : I created a pseudo infinite ground. This way, scene.pick.pickedPoint is never null. I know this does not answer the question correctly, but it do the trick. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 19, 2013 Share Posted November 19, 2013 If this works this is good:) 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.