Temechon Posted November 28, 2013 Share Posted November 28, 2013 Hello there, Is there a way to display a model bounding box ? Thank you for your time ! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 28, 2013 Share Posted November 28, 2013 Right now no, you have to create a box and scale it accordingly then display it with wireframe Quote Link to comment Share on other sites More sharing options...
Nico Posted November 29, 2013 Share Posted November 29, 2013 Hi, If you don't need to draw bounding box in 3D view, you can do it by using a 2D canvas and place it over the 3D view.You can find an example here : http://jsfiddle.net/nicolas_obre/R9j2z/. Temechon, GameMonetize and isigui 3 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 29, 2013 Share Posted November 29, 2013 Excellent Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 29, 2013 Author Share Posted November 29, 2013 Thanks Nico, it's perfect ! Cheers ! Quote Link to comment Share on other sites More sharing options...
gwenael Posted December 13, 2013 Share Posted December 13, 2013 It is what I was looking for, thanks @Nico, unfortunately I found a bug. I modified the jsfiddle to show the bug: http://jsfiddle.net/R9j2z/2/ I noticied that the following line gives weird results whereas if you unzoom, the bug doesn't appear anymore and the results are correct:screenCoordinates = BABYLON.Vector3.TransformCoordinates(screenCoordinates, camera.getProjectionMatrix());Here are my results: no bug: for i=1 screenCoordinates = (-16.69; -1.59)no bug: for i=7 screenCoordinates = (-12.74; -4.94) bug: for i=1 screenCoordinates = (15.33; 1.46)bug: for i=7 screenCoordinates = (21.43; 8.31) For the other i values, results for "bug" and "no bug" do not really change whereas for i=1 and i=7, negative values become positive values. I found in the code the funciton BABYLON.Vector3.Project, I guess we could use it to replace:var screenCoordinates = BABYLON.Vector3.TransformCoordinates(mesh.getBoundingInfo().boundingBox.vectorsWorld[i], camera.getViewMatrix());screenCoordinates = BABYLON.Vector3.TransformCoordinates(screenCoordinates, camera.getProjectionMatrix()); var objectScreenPosition = new BABYLON.Vector2(screenCoordinates.x * (canvas2D.width / 2) + canvas2D.width / 2, canvas2D.height - (screenCoordinates.y * (canvas2D.height / 2) + canvas2D.height / 2));but I didn't manage to use it correctly. Quote Link to comment Share on other sites More sharing options...
gwenael Posted December 13, 2013 Share Posted December 13, 2013 I have updated the jsfiddle to define the getVectorOnScreen function. That's the one to fix... http://jsfiddle.net/R9j2z/3/ I tried to fix it by using BABYLON.Vector3.Project without success. http://jsfiddle.net/R9j2z/6/ Quote Link to comment Share on other sites More sharing options...
gwenael Posted December 16, 2013 Share Posted December 16, 2013 (edited) Now the maths are correct http://jsfiddle.net/gwenaelhagenmuller/R9j2z/33/ These two articles were really helpful http://stackoverflow.com/questions/3329308/perspective-projection-how-do-i-project-points-which-are-behind-camerahttp://stackoverflow.com/questions/5666222/3d-line-plane-intersection The issue was due to the fact that some summits of the bounding box can be behind the camera. Edited January 10, 2014 by gwenael Quote Link to comment Share on other sites More sharing options...
Temechon Posted January 10, 2014 Author Share Posted January 10, 2014 Thank you Gwenael for this, it's perfect now gwenael 1 Quote Link to comment Share on other sites More sharing options...
gwenael Posted January 10, 2014 Share Posted January 10, 2014 My pleasure. Nico did the biggest part. I fixed what was needed to be fixed. Nico 1 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.