Jump to content
havenphillip

Is there a way to access an entity's current material from code?

Recommended Posts

If I drag a material onto a model or brush, how can I then reference that material from a code placed on that object or brush without having to create a material then add a bunch of textures? I just want to reference the material I put on it. Something like a Material:GetCurrent() for the entity?

Share this post


Link to post

Actually I see GetSurface() but I'm getting this funky looking rock which ought to look more like the second picture.

Here's my code here so far:

function Script:Start()

    --mat = Material:Load("Gloss/wet_rock.mat")
    mat = Material:Create()
    surface = self.entity:GetSurface(0)
    surface:SetMaterial(material)
    shader = Shader:Load("Gloss/wet_rock.shader");
    mat:SetShader(shader)
    self.entity:SetMaterial(mat)
    shader:SetFloat("puddlesize", self.puddleSize)
    shader:SetFloat("puddlefade", self.puddleFade)
    shader:SetFloat("intensity" , self.intensity)
    mat:Release()

end


 

funky rock.png

funky rock2.png

Share this post


Link to post

Ah ok I see. But now it's blue, even though the color is set to 1,1,1. How do I fix that?:

    surface = self.entity:GetSurface(0)
    mat = surface:GetMaterial()
    mat:SetColor(1,1,1)
    shader = Shader:Load("Gloss/wet_rock.shader");
    mat:SetShader(shader)
    self.entity:SetMaterial(mat)
    shader:SetFloat("puddlesize", self.puddleSize)
    shader:SetFloat("puddlefade", self.puddleFade)
    shader:SetFloat("intensity" , self.intensity)
    mat:Release()

 

funky rock.png

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...