Last active
December 1, 2022 18:04
-
-
Save mattkrins/5455b96631cc2ebdf0e577a71d1a3d54 to your computer and use it in GitHub Desktop.
This is a simple Garry's Mod helper function to hot-load images from a web URL for use in your rendering operations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local WebMaterials = {} | |
function surface.GetURL(url, w, h, time) | |
if !url or !w or !h then return Material("error") end | |
if WebMaterials[url] then return WebMaterials[url] end | |
local WebPanel = vgui.Create( "HTML" ) | |
WebPanel:SetAlpha( 0 ) | |
WebPanel:SetSize( tonumber(w), tonumber(h) ) | |
WebPanel:OpenURL( url ) | |
WebPanel.Paint = function(self) | |
if !WebMaterials[url] and self:GetHTMLMaterial() then | |
WebMaterials[url] = self:GetHTMLMaterial() | |
self:Remove() | |
end | |
end | |
timer.Simple( 1 or tonumber(time), function() if IsValid(WebPanel) then WebPanel:Remove() end end ) // In case we do not render | |
return Material("error") | |
end |
cache the error material
and dont use HTML for this, use an http fetch request and put the body in a file, then use Material("../data/image.png")
or whatever
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example Image:
https://cloud.githubusercontent.com/assets/2367602/24143894/673bda7a-0e7f-11e7-9d4c-53a7174672af.png
Example Code:
Result: