🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Fitting model in camera viewport?

Started by
-1 comments, last by xexuxjy 8 years, 9 months ago
I'm trying to setup a form of character select screen, where the user can select from a drop down a list of characters and that character is loaded and displayed in a separate window. That's all working, I create the character model, parent it to a separate camera , render it to a texture and put it in on my GUI.

What I'm struggling with is getting the model to fit 'nicely' in the viewport so it fills the whole texture. In theory this should be simple, I get the bounds of the model and use the those along with a chosen distance from the camera and frustum height at that distance to apply a local scale to the model so it just fits at the given distance.

What usually happens though is that I get very odd scale values (bounds.extents has something like 0.001,0.003,0.001) and when I try and scale to my desired height based on this the model ends up far too big and I can just see the characters foot in the display window.

The model has a SkinnedMeshRenderer and I've tried renderer.bounds , renderer.localBounds , baking the model to a Mesh and using it's bounds but not of these seems to give correct results.

I'm sure I'm doing something incredibly dumb in terms of mis-matching local and world coordinates for this calculation but has anyone created anything similar and could offer some pointers?

Thanks,
--- Just a note on this, it was mainly down to my own errors, the model I was trying to fit had multiple skinned mesh renderers and the first one happened to be an eye-ball , so I was doing all my calculations based on a small part of the overall model. Once i'd found the total bounds for all the SMR's it was a lot better.

This topic is closed to new replies.

Advertisement