Sign in to follow this  

Fitting model in camera viewport?

This topic is 816 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.
 
Edited by xexuxjy

Share this post


Link to post
Share on other sites

This topic is 816 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this