AB4D Forum
Autofit visible models to screen - Printable Version

+- AB4D Forum (https://forum.ab4d.com)
+-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4)
+--- Forum: Ab3d.PowerToys (https://forum.ab4d.com/forumdisplay.php?fid=9)
+--- Thread: Autofit visible models to screen (/showthread.php?tid=3957)



Autofit visible models to screen - jwa - 12-11-2015

Hello Ab4d Team,

I have a Model and dimmensions displayed in a viewport. I can calculate the distance of the camera based on the width of the model, but this does not respect the camera settings (attitude/heading/bank). So eventually it has too large margins or the model is chopped off.

[Image: http://abload.de/img/3drgzvw.png]

Is there a possibility to fit the "visible" model to screen?

Thanks and regards
Johannes


RE: Autofit visible models to screen - abenedik - 12-11-2015

You can check the "Scene editor" sample that comes with Ab3d.PowerToys library - it contains a sample code that can be used to achieve "Fit to view" functionality.

But because this works on scene's bounding box, you should not expect that your models with be shown from edge to edge - there will almost always be an empty margin around your scene.


RE: Autofit visible models to screen - jwa - 12-11-2015

(12-11-2015, 10:52 AM)abenedik Wrote: You can check the "Scene editor" sample that comes with Ab3d.PowerToys library - it contains a sample code that can be used to achieve "Fit to view" functionality.

But because this works on scene's bounding box, you should not expect that your models with be shown from edge to edge - there will almost always be an empty margin around your scene.

I already have that code implemented in my solution :) And it works good but it is exactly the problem you mentioned. Some times the models are quite large or the minimum resolution is set, so it is important that the model fits to the bounds and nothing is hidden, even with different camera settings.

Is it possible that the camera makes a 2D projection from its look direction to calculate the bounding box of the visible area?


RE: Autofit visible models to screen - jwa - 12-14-2015

Is it possible to calculate the visible rectanlge with the usage of the camera's "Rect3DTo2D" method? As shown in the Example "Camera 3D to 2D"?