• Internet Image to In-Game Texture
    20 replies, posted
Hey Facepunch, I'm new to Lua and I'd like to ask for some (quite a bit perhaps) of help. I want to know how it's possible to allow users to grab a texture from the internet via direct URL, and apply it to their playermodel for all others to see. An addon that did something similar to what I want to do is called "Minecraft Skin Changer". It has a little dialogue box where you can type in any Minecraft username, and suddenly you'll be sporting the associated skin on your (Minecraft) playermodel. What I'd like is to have something similar to this, but instead of a Minecraft Username, it could simply ask the player for the direct URL of an image (example, Imgur) to be pasted in the textbox, which is then applied to their playermodel. Unfortunately I don't really have any idea as to how to achieve this. I've looked around a bit but nothing I've found is considerably relevant or updated. Any help at all is greatly appreciated.
[QUOTE=Rocket;51812128]Here's how PAC does it: [url]https://github.com/CapsAdmin/pac3/blob/master/lua/pac3/core/client/libraries/urltex.lua[/url] Basically, it loads the image in an HTML panel and gets the texture of the loaded page. It's dirty but it's the only option at this point as far as I know.[/QUOTE] Thanks for the quick response! [QUOTE=Moat;51812146]ZeBull made a handy library to fetch images from a URL, write them to the data folder, then draw them. His Post(Useful Code Snippets): [URL]https://facepunch.com/showthread.php?t=1440586&p=51508841&viewfull=1#post51508841[/URL] GitHub: [URL]https://github.com/bull29/b_draw-lib/blob/master/lua/autorun/client/b-draw_lib.lua[/URL][/QUOTE] Thank you, but I've never used a library within Garry's Mod. How would I go about using this / accessing it? Could somebody explain how it works?
Bump.
[QUOTE=Moat;51831580]Just throw it in a lua/autorun/client/ file and make sure it's ran before you use it.[/QUOTE] Perhaps the answer is obvious, but how would I go about running the script? I have placed it in the folders you said and tried using the command "lua_run" but I get an error everytime. (Am I typing something wrong?) Also, once the script is ran, what will it do? Will it draw my Steam avatar on my HUD? Thanks in advance.
So that's what all you wanted? You could say that from begin, you're looking for AvatarImage, it's a vgui element, implementing it into hud wouldn't be that hard, but sincerily, why would do you want to see your avatar in hud, like, you know that's you...
[QUOTE=gonzalolog;51836401]So that's what all you wanted? You could say that from begin, you're looking for AvatarImage, it's a vgui element, implementing it into hud wouldn't be that hard, but sincerily, why would do you want to see your avatar in hud, like, you know that's you...[/QUOTE] Nonono, that's not really what I wanted but to my understanding (not sure if it is true), the script that Moat linked me to does HUD stuff with the player's avatar. What I want to do is open a dialogue box where users can paste a URL, and the image in the URL will be applied to their current playermodel.
Bump once again. :boxhide:
Not sure I understand what the issue is? What Moat linked you should be fine for what you need? [url]https://github.com/bull29/b_draw-lib/blob/master/lua/autorun/client/b-draw_lib.lua#L44[/url] Looks like this function will return you a material from a url as an argument, use this and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetSubMaterial]Entity:SetSubMaterial[/url] to achieve your goal?
[QUOTE=smithy285;51861685]Not sure I understand what the issue is? What Moat linked you should be fine for what you need? [url]https://github.com/bull29/b_draw-lib/blob/master/lua/autorun/client/b-draw_lib.lua#L44[/url] Looks like this function will return you a material from a url as an argument, use this and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetSubMaterial]Entity:SetSubMaterial[/url] to achieve your goal?[/QUOTE] Okay so I've been working with the script a bit and I managed to have it create an image in the garrysmod/data/downloaded_assets folder. The image is in .png format, my next task is to figure out how to load that texture onto the player. I can't seem to get it to locate my texture using ply:SetMaterial, though it does work when using a texture already in the game. How do I locate it through SetMaterial? Does it have to be converted to a proper texture through lua?
[QUOTE=Rockster3400;51866105]Okay so I've been working with the script a bit and I managed to have it create an image in the garrysmod/data/downloaded_assets folder. The image is in .png format, my next task is to figure out how to load that texture onto the player. I can't seem to get it to locate my texture using ply:SetMaterial, though it does work when using a texture already in the game. How do I locate it through SetMaterial? Does it have to be converted to a proper texture through lua?[/QUOTE] Again, use the function 'fetch_asset' in the code you were given. If it detects that the image from the url has already been saved, then it will return that instead of redownloading it. That function returns a mterial, as I've said before, that you will need to use
[QUOTE=smithy285;51868084]Again, use the function 'fetch_asset' in the code you were given. If it detects that the image from the url has already been saved, then it will return that instead of redownloading it. That function returns a mterial, as I've said before, that you will need to use[/QUOTE] I greatly appreciate the clarification, but I cannot for the life of me figure out how to get the material to actually load onto the player. The library has generated "data/downloaded_assets/413260254.png" and I believe it is stored as a variable. (mats[url]) When I run the code [code]LocalPlayer():SetMaterial( mats[url] )[/code] Nothing happens to the player. However, when I change the texture to be a HL2 texture, it works fine. Perhaps I'm missing something?
[QUOTE=Moat;51871867]Unlocalize fetch_asset and use fetch_asset(url) to get the material.[/QUOTE] I unlocalized it, but am having issues getting the material [code]LocalPlayer():SetMaterial( mats[url] )[/code] Doesn't do anything. I think you implied that I change it but I'm not sure how it would look.
[QUOTE=Moat;51871867][B]and use fetch_asset(url) to get the material.[/B][/QUOTE] [QUOTE=Rockster3400;51872016][B]I think you implied that I change it but I'm not sure how it would look.[/B][/QUOTE] I've already tried placing [code]LocalPlayer():SetMaterial( fetch_asset(url) )[/code] within the fetch_asset function. Not working, so I'd ask that you help explain a little more as opposed to restating yourself since I'm new to this. Any and all help is appreciated though. [I]If it's worth mentioning, I can manage to get the image to be rendered on to my screen via[/I] [code]hook.Add( "RenderScreenspaceEffects", "Example", function() render.SetMaterial( mats[url] ) render.DrawScreenQuad() end)[/code]
Bump.
Bump x 2
ent:SetMaterial uses a material name. render.SetMaterial uses an IMaterial. You can get the name of an IMaterial using mat:GetName(). Procedural materials, like the ones you download, require a "!" in front. In short: [code] LocalPlayer():SetMaterial( "!" .. fetch_asset(url):GetName() ) [/code] Of course, this should only be done after the material is finished downloading. Bull hasn't provided a callback to do this as I can tell, so I'm unsure how to proceed using his library.
Sorry, you need to Log In to post a reply to this thread.