ViewportFrame Model Fitter

Recently I was working on something that required fitting an arbitrary model into an arbitrary viewport frame. I looked around saw this was a pretty common question, so I figured I’d write up a module

The above links to a class that can be used in two ways.

The first is to calculate a fixed minimum distance that’s guaranteed to contain the model regardless of the camera orientation or viewport size.

This is useful as it’s a low-cost one-time calculation assuming you’re not constantly adding/removing/changing the model or viewport frame.

The second is to calculate a camera cframe that best fits the model given an orientation. This will mean that the model will always be touching at least one edge of the viewport frame.

However, it’s important to note that this calculation is based off of the model’s point cloud meaning meshes, csg, and/or any other base part that makes it difficult to get a proper point cloud may cause this calculation to seem inaccurate.

For example compare happy home vs piano in the above video

Hope you find this useful and enjoy!

Here’s the placefile I used to record the above videos:
Fit viewport frame.rbxl (2.9 MB)

217 Likes

This seems really cool, might use it in a later project.

1 Like

Remembering the scripting question. Couldn’t wait to see the end result!!

Saw your scripting question about it, and this seems like a great final result!

Might use it later on too!

This is really nice and super useful for camera calculations, which is one of the trickier parts to nice UI design when working with models with varying sizes (unless you’re manually adjusting CFrame positions, and that can be a lot of manual work + very tedious).

Really nice resource, I will be sure to use this (in the next few days, since I was about to jump into some ViewportFrame usage)!

Awesome module! Looking forward to using this in my upcoming project! :smiley:

1 Like

This looks VERY useful, might use it later, on a new project!

Thank you for making this @EgoMoose what will the community do without you?

Keep up the awesome work!

I think you deserve to accept donations

2 Likes

This is really nice.

This will be useful for the builds preview on my build mode.

It will save me a lot of time.

Thank you!

This is great, and so easy to setup and use. Your code base is very adaptable and sturdy, which is saying a lot. It’s a work of art, well done @EgoMoose.

1 Like

This is awesome and super easy to use! Thanks a lot EgoMoose for yet another incredible donation to the Roblox Developer community.

1 Like