Jump to content

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


havenphillip
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

 Share

×
×
  • Create New...