• Player colors in DModelPanel / clientside entities?
    18 replies, posted
As the title simply says, how would I change the player color of a player model in a clientside model? (shall be applied in a DModelPanel, more specifically)
[lua] DModelPanel:SetColor(Color(250,0,0)) [/lua] I think that work
[QUOTE=Myrage2000;40353712][lua] DModelPanel:SetColor(Color(250,0,0)) [/lua] I think that work[/QUOTE] That's something else. I need to change the color of a material proxy, not of the rendering thingie.
Here's what I use: [lua] local PlayerColor = LocalPlayer():GetPlayerColor() function GUI_ModelDisplay.Entity:GetPlayerColor() return Vector( PlayerColor.r, PlayerColor.g, PlayerColor.b ) end [/lua]
[QUOTE=Crap-Head;40356255]Here's what I use: [lua] local PlayerColor = LocalPlayer():GetPlayerColor() function GUI_ModelDisplay.Entity:GetPlayerColor() return Vector( PlayerColor.r, PlayerColor.g, PlayerColor.b ) end [/lua][/QUOTE] So THAT will change the PlayerColor?
I cant really explain matproxies, since I dont understand them better than you. But taking a look to the source might help you: [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/matproxy/player_color.lua[/url]
[i]mPri.Entity:SetVector("$color2", Vector(1, 0, 0))[/i] SetVector is nil.
Seems I wasn't clear at all. If you are not familiar with matproxies, there is a nice documentation, from the SourceSDK wiki: [url]https://developer.valvesoftware.com/wiki/Material_proxies[/url] In short, materials could specify proxies to change their specific values, on a per entity basis. Example taken from a playermodel vmt: [code] "VertexLitGeneric" { -- SNIP -- Proxies { PlayerColor { resultVar $color2 default 0.75 0.75 0.75 } } } [/code] As you see, the material tells the engine, it has a proxy, PlayerColor. It is added to the system in the lua file I linked in my previous post. Basically, every time you render an entity, that uses a material with a proxy, it will look it up, and call the proxys bind function, so it could make the neccesary changes to the vmt to render the entity. In the case of the PlayerColor proxy, change color2. The proxy achieves this by checking for a method "GetPlayerColor" on the entity being rendered. If it is found, it uses its return value to change the color2 value of the vmt, effectively changing the color of the players suit in this case. Sorry if I wasnt understandable this time either, I tried my best
By looking around the source, it appears that you need the matproxy connected to the material of the model, which means you need your own custom material and put [code]Proxies { PlayerColor { resultVar $color2 default 0.1 0.1 0.1 } }[/code] into it. Make sure you're using the correct models that uses this proxy if you're using the playermodels already in gmod. After you've put that in your material, it should be just to do "SetPlayerColor" onto the entity and the magic should happen. Actually, it could be that "GetPlayerColor" and "SetPlayerColor" isn't defined on normal entities, maybe you need to create those functions yourself (simply save the color in a variable in set, and then return it in get) and the matproxy should work. The matproxy requires GetPlayerColor to be set on the entity in order to render it with the color.
[QUOTE=vercas;40358087][i]mPri.Entity:SetVector("$color2", Vector(1, 0, 0))[/i] SetVector is nil.[/QUOTE] You could've just told me to do [i]mPri.Entity:GetMaterial():SetVector("$color2", Vector(1, 0, 0))[/i] instead... Let me try that. [editline]asd[/editline] Nope... Damn. How do I get the specific IMaterial of the entity? >_<
You're not ment to edit the material, the player already has the correct material and matproxy attached to it. Did you try what I said about creating the methods on the entity?
[QUOTE=Donkie;40360499]You're not ment to edit the material, the player already has the correct material and matproxy attached to it. Did you try what I said about creating the methods on the entity?[/QUOTE] I did do as Crap-Head and you suggested, it did not work. [editline]asd[/editline] I think [URL="https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/matproxy/player_color.lua#L30-L33"]here[/URL] is where it stops on clientside entities. It asks for an owner of the ragdoll - a player. [editline]asdasda[/editline] I doubt I can override that with Garry's new brilliant [i]Entity.__index[/i], but I'll try. Tomorrow.
Getting a bit confused as you what you mean now. Are you not just trying to change the color of the player model you are drawing on your DModelPanel? Just like Garry does it in the player model selector in Sandbox?
[QUOTE=Crap-Head;40360784]Getting a bit confused as you what you mean now. Are you not just trying to change the color of the player model you are drawing on your DModelPanel? Just like Garry does it in the player model selector in Sandbox?[/QUOTE] That's exactly what I am trying to do.
[QUOTE=vercas;40360682]I did do as Crap-Head and you suggested, it did not work. [editline]asd[/editline] I think [URL="https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/matproxy/player_color.lua#L30-L33"]here[/URL] is where it stops on clientside entities. It asks for an owner of the ragdoll - a player. [editline]asdasda[/editline] I doubt I can override that with Garry's new brilliant [i]Entity.__index[/i], but I'll try. Tomorrow.[/QUOTE] Have you tried DModelPanel.Entity:SetPlayerColor?
[QUOTE=skullorz;40360852]Have you tried DModelPanel.Entity:SetPlayerColor?[/QUOTE] Function doesn't exist.
[QUOTE=vercas;40360846]That's exactly what I am trying to do.[/QUOTE] [url]http://wiki.garrysmod.com/page/VGUI/Elements/DModelPanel[/url] Here you go then.
[QUOTE=Crap-Head;40361259][url]http://wiki.garrysmod.com/page/VGUI/Elements/DModelPanel[/url] Here you go then.[/QUOTE] Judging by the code, you override DModelPanel:GetPlayerColor(), returning LocalPlayer:GetPlayerColor or whatever.
[QUOTE=Crap-Head;40361259][url]http://wiki.garrysmod.com/page/VGUI/Elements/DModelPanel[/url] Here you go then.[/QUOTE] God damn it, it didn't work yesterday. It worked now, so thanks a lot! [editline]lol[/editline] Not gonna mark this as solved until I see it working tomorrow as well.
Sorry, you need to Log In to post a reply to this thread.