• Displaying an image from URL using 3d2d
    12 replies, posted
I had no luck asking in the "Problems that don't need their own thread", so maybe someone could see it here and have an answer. I'd like to load an image on a board entity, using 3d2d. Besides using [URL="https://github.com/HandsomeMatt/3d2d-vgui"]this[/URL], are there any alternatives available?
Load it in to a (D)HTML panel, run GetHTMLMaterial. It might be good to throw it on a RT and make your own though.
[QUOTE=zzaacckk;48400475]Load it in to a (D)HTML panel, run GetHTMLMaterial. It might be good to throw it on a RT and make your own though.[/QUOTE] That means i'd have to use [url]https://github.com/HandsomeMatt/3d2d-vgui[/url], no?
No. You just do something like this: [code] -- pHtml is your HTML element cam.Start3D2D(pos, ang, 0.02) surface.SetDrawColor(color_white) surface.SetMaterial(pHtml:GetHTMLMaterial()) surface.DrawTexturedRect(-256, -256, 512, 512) cam.End3D2D() [/code]
[QUOTE=mijyuoon;48401093]No. You just do something like this: [code] -- pHtml is your HTML element cam.Start3D2D(pos, ang, 0.02) surface.SetDrawColor(color_white) surface.SetMaterial(pHtml:GetHTMLMaterial()) surface.DrawTexturedRect(-256, -256, 512, 512) cam.End3D2D() [/code][/QUOTE] I created my panel inside cl_init.lua (not inside any function), and afterwards I did that in ENT:Draw(), but the material is always nil.
[QUOTE=RedNinja;48402868]I created my panel inside cl_init.lua (not inside any function), and afterwards I did that in ENT:Draw(), but the material is always nil.[/QUOTE] In draw check this, if IsValid(pHtml) and pHtml:GetHTMLMaterial() then Thats like just checking it is loaded.
[QUOTE=SteppuFIN;48403043]In draw check this, if IsValid(pHtml) and pHtml:GetHTMLMaterial() then Thats like just checking it is loaded.[/QUOTE] I have done that, and it never loads. As I said it's always nil.
[QUOTE=RedNinja;48403183]I have done that, and it never loads. As I said it's always nil.[/QUOTE] Post your code?
[QUOTE=RedNinja;48402868]I created my panel inside cl_init.lua (not inside any function), and afterwards I did that in ENT:Draw(), but the material is always nil.[/QUOTE] Make sure your panel isn't a local object. Edit: Why are you trying to use a html panel to load an image anyways? If you're trying to have clients load new images without having to use [URL="http://wiki.garrysmod.com/page/resource/AddFile"]resource.AddFile[/URL], you might want to consider using the [URL="http://wiki.garrysmod.com/page/net/WriteData"]WriteData[/URL] and [URL="http://wiki.garrysmod.com/page/Global/Material"]Material[/URL] functions to send and load the image, assuming it's not a really massive file. Awesomium HTML panels can be pretty expensive on the client if you're using several of them.
GetHTMLMaterial creates a material every frame, i'd not call it 24/7
[QUOTE=MeepDarknessM;48404343]GetHTMLMaterial creates a material every frame, i'd not call it 24/7[/QUOTE] Well it doesn't work anyways. [code] include("shared.lua") pnlHTML = vgui.Create("HTML") pnlHTML:SetVisible(true) --pnlHTML:SetPos(50,50) pnlHTML:SetPos(ScrW()-1, ScrH()-1) pnlHTML:SetSize(size, size) pnlHTML:SetHTML( [[ <img src="http://vignette2.wikia.nocookie.net/thestanleyparable/images/0/04/Facepunchoc5.png/revision/latest?cb=20131019161144" alt="Test" style="width:256px;height:256px;"> ]] ) function ENT:Draw() self:DrawModel() local DrawPos = self:LocalToWorld(Vector(1, -111, 58)) local DrawAngles = self:GetAngles() DrawAngles:RotateAroundAxis(self:GetAngles():Forward(), 90) DrawAngles:RotateAroundAxis(self:GetAngles():Up(), 90) cam.Start3D2D(DrawPos, DrawAngles, 0.4) surface.SetDrawColor(color_white) if pnlHTML:GetHTMLMaterial() then surface.SetMaterial(pnlHTML:GetHTMLMaterial()) end surface.DrawTexturedRect(0, 0, 558, 290) cam.End3D2D() end [/code] [editline]8th August 2015[/editline] Tried this aswell: [code] include("shared.lua") net.Receive( "ImageSet", function( len ) local IMAGE_URL = net.ReadString() local pnlHTML = vgui.Create("HTML") pnlHTML:SetVisible(true) --pnlHTML:SetPos(50,50) pnlHTML:SetPos(ScrW()-1, ScrH()-1) pnlHTML:SetSize(size, size) pnlHTML:SetHTML( [[ <img src="]]..IMAGE_URL..[[" alt="Test" style="width:256px;height:256px;"> ]] ) timer.Simple(5, function() if pnlHTML:GetHTMLMaterial() then mat_url_image = pnlHTML:GetHTMLMaterial() end end) end ) function ENT:Draw() self:DrawModel() local DrawPos = self:LocalToWorld(Vector(1, -111, 58)) local DrawAngles = self:GetAngles() DrawAngles:RotateAroundAxis(self:GetAngles():Forward(), 90) DrawAngles:RotateAroundAxis(self:GetAngles():Up(), 90) cam.Start3D2D(DrawPos, DrawAngles, 0.4) if mat_url_image then surface.SetMaterial(mat_url_image) end surface.DrawTexturedRect(0, 0, 558, 290) cam.End3D2D() end [/code] ImageSet is used whenever the pic is changing.
Just take the easy way out and have the image be downloaded as a material.
Here's the interface for a module I created to handle downloading web materials and pooling browser instances: [lua]--- -- Renders a URL as a material. Texture will be updated every time the material -- is requested until the image finishes downloading. -- -- @param url URL. -- @param style HTMLMaterial style (optional). -- @return Material -- function HTMLMaterial( url, style ) -- 'style' parameter accepts registered HTML material style keys. Preregistered -- keys include the following globals: HTMLMAT_STYLE_BLUR HTMLMAT_STYLE_GRAYSCALE HTMLMAT_STYLE_SEPIA HTMLMAT_STYLE_INVERT HTMLMAT_STYLE_CIRCLE -- See 'AddHTMLMaterialStyle' for registering new styles[/lua] Dependencies: [URL="https://github.com/pixeltailgames/gm-mediaplayer/blob/master/lua/mediaplayer/controls/dmediaplayerhtml.lua"]dmediaplayerhtml.lua[/URL], [URL="https://github.com/pixeltailgames/gm-mediaplayer/blob/master/lua/autorun/includes/modules/browserpool.lua"]browserpool.lua[/URL], and [URL="https://github.com/pixeltailgames/gm-mediaplayer/blob/master/lua/autorun/includes/modules/htmlmaterial.lua"]htmlmaterial.lua[/URL].
Sorry, you need to Log In to post a reply to this thread.