ArFriction
(ArFriction)
November 9, 2022, 9:55pm
#1
Hi so i was wondering how you would fit a model in a viewport perfectly, basically no matter the size of the model the camera would move for it to show a perfectly aligned model in the viewport frame.

I was wondering if any of you guys would know the math or know other pages which would help.

Thanks

mniao
(mniao)
November 9, 2022, 10:08pm
#2
Here’s a post that you might be interested in:

I agree that we should add this as a built in method. But for now if anyone needs this functionality in Lua here is a script which replicates the Zoom Extents behavior in Studio (pressing the F key with a model/part selected).
local function getCameraOffset(fov, extentsSize)
local halfSize = extentsSize.Magnitude / 2
local fovDivisor = math.tan(math.rad(fov / 2))
return halfSize / fovDivisor
end
local function zoomToExtents(camera, instance)
local isModel = instance:IsA("Model")
local in…
EDIT: Here’s a module specifically made for viewports by @EgoMoose

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 consta…

system
(system)
Closed
November 23, 2022, 10:08pm
#3
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.