VERGELua API

materials

Create and inspect materials; model queries.

materials

materials.Create(name:string, vmt:string):Material

Create a material from a VMT string; reuses an existing name; returns an error material on a bad VMT.

materials.Find(name:string):Material

Find a material by name.

materials.Loaded(name:string):boolean

Whether a material is loaded.

materials.Remove(name:string):boolean

Remove a script-created material; false when not found.

materials.Enumerate(cb:function)

Call cb(material) for every loaded material; stops if the callback errors.

models

models.GetModel(index:number):Model

Model wrapper for a model index.

models.GetModelIndex(name:string):number

Model index for a name; -1 when unknown.

models.GetStudioModel(model:Model):StudioModelHeader

Studio header of a model.

models.GetModelName(model:Model):string

Name and path of a model.

models.GetModelMaterials(model:Model):table

List of a model's materials.

models.GetModelRenderBounds(model:Model):Vector3,Vector3

Render bounds mins and maxs of a model.

models.GetModelBounds(model:Model):Vector3,Vector3

Collision bounds mins and maxs of a model.

Examples

Gold weapon skins

Override your weapons with a flat gold material using DrawModel.

local gold = materials.Create("weapon_gold", [[
"UnlitGeneric"
{
    "$basetexture" "vgui/white"
    "$model" "1"
}
]])

callbacks.Register("DrawModel", function(ctx)
    local ent = ctx:GetEntity()
    if not ent:IsValid() or not ent:IsWeapon() then return end
    local me = client.GetLocalPlayer()
    if not me:IsValid() or ent:GetIndex() ~= me:GetIndex() then return end

    gold:SetColorModulation(1, 0.8, 0.2)
    ctx:ForcedMaterialOverride(gold)
end)