Local textureId = ViewportFrame:GenerateImage(size)

ViewportFrames are an epic addition to roblox!
If you’re trying to create icons for different furniture/weapons etc. you dont have to create and upload a new decal for every single item in your game, you can just use a viewportframe.

The issue
Altho handy, it has some flaws.

  1. Every client needs to render the icons.
    Having inventory, toolbar etc. This gets unnesscarily expensive and complex overtime.
    Assume you destroy the menu while the player is playing, this would demand a new render for all objects.
  2. Slows down player access time
    ViewportFrames require all models of which you want rendered to be accessable to the client so all tools, furniture etc. needs to be in ReplicatedStorage and thus slows down the time it takes for a player to join a game.
  3. Difficult to work with ViewportFrames
    Having to copy a model, setup a camera, fix correct lighting properties just for a simple image can easily get messy. To have the icon at two places (inventory and toolbar for example) require you to have knowledge of it’s camera and lighting settings. Much more complex than a simple textureid.

The solution
I want to suggest a function for the viewport frame that lets you preload an image and use it as a normal texture ingame anywhere.

Example:

local textureId = ViewportFrame:GenerateImage(400)
tool.TextureId = textureId --Or imageLabel.Image = textureId

This way you could preload all your weapons, furniture icons once the game starts and then never having to render them again.

I’m sure alot of these issues can be solved by some complex code structure, but my point is that having a textureid is so much simpler and easy to use for beginners aswell as “senior roblox citizens”.

11 Likes

This doesn’t seem to improve issue #3. You’re still having to copy a model / setup a camera / set lighting properties – you’re just doing it in a different place now.

For the other 2, have you actually done benchmarks to verify ViewportFrames are causing performance issues? ViewportFrame images don’t get rerendered unless there is a change in its contents/camera. There would be an initial cost of generating those images, but that’s it – nothing sustained. There are some memory consumption gains you could take advantage of using an image instead of ViewportFrames, but that doesn’t seem like what you’re requesting.

2 Likes

I only do it once, on the server side. Instead of doing it one time (per client) when i open the inventory and another time when its added to the toolbar and a third time when i return to the inventory.

Rendering an image vs Rendering a scene should have quite a big difference in performance. It depends on the complexity of the object, multiplied by the amount of times you need to re-render the same object (as in the inventory-toolbox example).

Even so my suggestion is to make generated icons much simpler to use than the current Viewframe solution.

3 Likes