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:
Model in viewport frame:
And when i try to select something a frame that is in the surfacegui, it does this:
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.)
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.
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.
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
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.