ViewportFrame Release

Viewport frames are pretty cool! I’ve been using them instead to replace images of models. But I’ve just found a bug when a model in a viewport frame has surface guis on it. When i put the model in a viewport frame, the surfaceguis on the model make a strange rendering artifact in game.
Model in workspace:
image

Model in viewport frame:
image

And when i try to select something a frame that is in the surfacegui, it does this:
image
You can even see it in game!
Now it is easy to fix, (just remove the surface gui for the model in the viewport frame) but i think it still should be mentioned… (Also, I would post this in engine bugs, but i’m a new user so i can’t post there and imo this is the best thread to post this on since it’s on viewport frames.)

3 Likes

In the future, you can ask make a thread in #bulletin-board and Lead Top Contributor to move it for you to the right place.

2 Likes

Ah thank you! I had that category muted for me so i didn’t see it. ;p

1 Like

Have you heard of the glass material bug with transparency? You can replicate that effect with that as well, but it’s a matter of preference. I think the glass alternative looks better but it’s also going to be patched according to Roblox, so.

I don’t believe that’s a bug, but just something due to the way SurfaceGuis and BillboardGuis function when in PlayerGui

I have recently noticed an issue with Viewport Frames, It will not set the ViewportSize property of a Camera.

This is especially annoying since you are unable to use WorldToScreenPoint or WorldToViewportPoint as it will always return 0

That’s because multiple ViewportFrames can use the same camera. Since ViewportFrames can have different sizes, there’s no way to decide which size to use.

Is there a way to work around this?

I am using this as a Minimap and I am wanting to be able to mark where people are on the map.

You’re going to have to calculate the positions yourself. Sorry if I can’t tell you how exactly, since I don’t how to, either.

I will probably just end up making a 3D Marker for players in the minimap to save time

Have you tried the AbsoluteSize of a ViewportFrame?

1 Like

Even with me knowing the AbsoluteSize, that would not allow the function WorldtoScreenPoint to work.

1 Like

Here’s some code from a module I wrote, which was borrowed from another module by someone else:

local function pointToScreenSpace(cframe, fieldOfView, point, viewportSize)
	-- borrowed from https://devforum.roblox.com/t/3d-gui-module/5183 ( http://www.roblox.com/Roblox-3D-GUI-Module-item?id=159576724 )
	-- used for transforming points from GetCameraParams into a size
	-- no need to rewrite what's already written!
	local screenSize = viewportSize
	local relative = cframe:pointToObjectSpace(point)
	local ratio = screenSize.x/screenSize.y
	local yFactor = math.tan(math.rad(fieldOfView/2))
	local xFactor = ratio*yFactor
	local y = (relative.y/relative.z) / yFactor
	local x = (relative.x/relative.z) / -xFactor
	return Vector2.new(screenSize.x*(0.5 + 0.5*x), screenSize.y*(0.5 + 0.5*y))
end
5 Likes

I have created a function that will allow you to mimic the function WorldToScreenPoint in a ViewportFrame

    ScreenSpace.ViewportAspectRatio = function(viewport)
	return viewport.AbsoluteSize.X / viewport.AbsoluteSize.Y
end

ScreenSpace.ViewportWorldToScreen = function(viewport,at)
	local point = viewport.CurrentCamera.CoordinateFrame:pointToObjectSpace(at)
	local aspectRatio = ScreenSpace.ViewportAspectRatio(viewport)
	local hfactor = math.tan(math.rad(viewport.CurrentCamera.FieldOfView) / 2)
	local wfactor = aspectRatio * hfactor
	local x = point.x / point.z / -wfactor
	local y = point.y / point.z / hfactor
	return Vector2.new(viewport.AbsoluteSize.X * (0.5 + 0.5 * x), viewport.AbsoluteSize.Y * (0.5 + 0.5 *y)), point.z
end
6 Likes

Thanks for this, I haven’t tested my code so I’m glad I can have something to fall back on!

You could do it with camera CFrame trickery.

It’d be neat to see but impractical.

ViewportFrames are brilliant!

A way for multiple ViewportFrames to render the same model/parts (at the same time) without having to clone them would be appreciated though; managing all of the separate models can become quite a pain.

1 Like


its already possible but it does not use the ViewportFrame :smile:

5 Likes

I’m guessing the sky we see is fake and the real sky box is the galaxy?

1 Like

Yea the HD Skybox is fake and the Space skybox is real