Viewport Frame part fitting with BillboardGUI's

Hey forums, I’m trying to make Billboard GUI’S that contain a Viewport Frame. The Viewport Frame is supposed to render a model within the Billboard and have it fill the Billboard GUI. The GUI has to be unique for many different models so it has to be automatic using some sort of math that i don’t understand.

I attempted to use ViewportFrame Model Fitter by @EgoMoose Link This doesn’t work for Billboard GUI’s and I’m lost. I know that its not a coding error because I copy and pasted the code in a ScreenGUI and in a BillboardGUI and the Billboard screwed up, any ideas?

Code for ScreenGUI

local ViewportFit = require(game.ReplicatedStorage.ViewportFit)
local player = game.Players.LocalPlayer

player.CharacterAdded:Wait()
 

local viewport = player.PlayerGui.ScreenGui.ViewportFrame
local camera = Instance.new("Camera", viewport)
local model = game.Workspace.Model:Clone()

viewport.CurrentCamera = camera
model.Parent = viewport



local vpfModel = ViewportFit.new(viewport, camera)
vpfModel:SetModel(model)

camera.CFrame = vpfModel:GetMinimumFitCFrame(CFrame.fromEulerAnglesYXZ(0,0,0))

Code for BillboardGUI (There is some code above but this is the base code for camera positioning.)

local viewport_fit = require(game.ReplicatedStorage.Performance.ViewportFit)
local viewport = Instance.new("ViewportFrame", billboard)
local view_cam : Camera = Instance.new("Camera", viewport)
local viewport_model = model:Clone()

local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera

player.CharacterAdded:Wait()

local orientation = CFrame.fromEulerAnglesXYZ(0,0,0)
	
local vpfModel = viewport_fit.new(viewport, view_cam)
vpfModel:SetModel(viewport_model)

view_cam.CFrame = vpfModel:GetMinimumFitCFrame(orientation)

There are no error printed to the console just two drastically different results.

Billboard Screenshot


As you can see the part is not filling the whole billboard and is also angled very incorrectly. The Viewport frame is scaled correctly at {1, 0}, {1, 0} making it fit to the billboard.

ScreenGUI Screenshot


And in the ScreenGUI you can see that the test part fits perfectly in the ScreenGUI with the same code.

Any help on this would be greatly appreciated.

3 Likes

Works fine for me using both scale and offset. I notice a couple things from your billboard script though, but it could be omitted for brevity:
1- You don’t set viewport.CurrentCamera
2- You don’t parent the viewport_model to the viewport frame
3- Is it possible the character is loaded before waiting for player.CharacterAdded to fire?

Hey thanks for the response, all three of your potential issues were written later up the code. I didn’t want people reading the post to be confused by my bad code, sorry about that. Could you send your code for the billboard? Thanks again for the help.

1 Like

Yeah, this worked for me:

local billboard = script.Parent

local viewport_fit = require(game.ReplicatedStorage.ViewportModel)
local viewport = Instance.new("ViewportFrame", billboard)
viewport.Size = UDim2.fromScale(1, 1)
viewport.BackgroundTransparency = 1

local view_cam : Camera = Instance.new("Camera", viewport)
local viewport_model = workspace:WaitForChild('Model'):Clone()

viewport.CurrentCamera = view_cam

local orientation = CFrame.lookAt(Vector3.new(0, 10, -10), Vector3.zero)

local vpfModel = viewport_fit.new(viewport, view_cam)
vpfModel:SetModel(viewport_model)
viewport_model.Parent = viewport

view_cam.CFrame = vpfModel:GetMinimumFitCFrame(orientation)

This still didn’t work for me, I got a really tiny part not one that fills the area. Here’s my explorer:
image