How to make Viewport models actually look good?

I’m not quite sure on the math/formula to do it, you would just have to mess around with it or wait for someone else to reply

ill keep messing around and maybe ill figure it out but I’m not sure tbh

If you wanted to, you could script the viewport frame so that it gets bigger whenever the user’s mouse is hovering over it, but then smaller after.

For my plugin, I get the distance of the center of the object from the camera by using this function:

-- fov is the camera's fov (in degrees).
-- targetSize is the size of the object's bounding box. GetExtentsSize will help here.
local function GetCameraOffset(fov, targetSize)
	local x, y, z = targetSize.x, targetSize.y, targetSize.Z
	local maxSize = math.sqrt(x^2 + y^2 + z^2)
	local fac = math.tan(math.rad(fov)/2)
	
	local depth = 0.5*maxSize/fac
	
	return depth+maxSize/2
end

So that this:

image

Gets rendered as this when the fov is set to 1:

image

Or this when the fov is set to 30:

image

This should look good regardless of how you rotate the object or how oddly-proportioned the object is since this uses all three dimensions of the object to determine its distance from the camera.

EDIT: As for how I got the sorta-isometric angle, I point the camera at (-0.5, -0.4, -0.5). If your camera is at the center pointing at that direction (such that its CFrame is set to CFrame.new(Vector3.new(), Vector3.new(-0.5, -0.4, -0.5)), then this is how you would position the model:

model:SetPrimaryPartCFrame(CFrame.new(Vector3.new(-0.5, -0.4, -0.5).unit * GetCameraOffset(camera.FieldOfView, model:GetExtentsSize()))
18 Likes

What’s GetCameraOffset???

It’s a function I wrote. Like I said, it gets the distance that the camera should be from the object so that it fits a box nicely.

local function GetCameraOffset(fov, targetSize)
	local x, y, z = targetSize.x, targetSize.y, targetSize.Z
	local maxSize = math.sqrt(x^2 + y^2 + z^2)
	local fac = math.tan(math.rad(fov)/2)
	
	local depth = 0.5*maxSize/fac
	
	return depth+maxSize/2
end

clone:SetPrimaryPartCFrame(CFrame.new(Vector3.new(-0.5, -0.4, -0.5).unit * GetCameraOffset(camera.FieldOfView, clone:GetExtentsSize())))

camera.CFrame = clone.PrimaryPart.CFrame

This the result with the code I have above

I said this:

So set the CFrame of the camera to that:

camera.CFrame = CFrame.new(Vector3.new(), Vector3.new(-0.5, -0.4, -0.5))

Please read the entire reply next time. You’ve asked like two questions which were answered pretty clearly in my reply.

Oh sorry, it’s incredibly early for me.

How would I then edit the cameras position to be closer/further away/different angles?
I tried even a small jump to this

camera.CFrame = CFrame.new(Vector3.new(), Vector3.new(-0.5, -0.4, 0))

Which for some reason caused the models not even appear on the frame, cause with the -0.5 in the Z axis is making them a lil small


So if there’s a way to move the Z axis closer so they appear larger

To increase/decrease the size of the picture, then it’s just a matter of scaling the result of GetCameraOffset. Multiply the result of it by 0.5 if you want the camera to be half as far from the object, for example. Tweak that number to your liking.

I would suggest keeping the direction at Vector3.new(-0.5, -0.4, -0.5) until you find a good size. Changing the direction of the camera does not change the size of the object on the image.

EDIT: You should also probably decrease the FieldOfView of the camera. Try setting it to 1.

1 Like

In addition to the consistency, the wiki states another reason moving the camera itself is a better idea.

Moving a viewport’s physical children is less performant than keeping them static. If you need to update the view, it’s better to move the camera than move the parts/models.

Thanks for the code!

2 Likes