
TOOL.Category		= "Render"
TOOL.Name			= "#Material"
TOOL.Command		= nil
TOOL.ConfigName		= nil


TOOL.ClientConVar[ "override" ] = "debug/env_cubemap_model"

local function SetMaterial( Player, Entity, Data )

	Entity:SetMaterial( Data.MaterialOverride )
	Entity.MaterialOverride = Data.MaterialOverride

	return true

end
duplicator.RegisterEntityModifier( "material", SetMaterial )

function TOOL:LeftClick( trace )

	if !( trace.Entity &&			// Hit an entity
	      trace.Entity:IsValid() && 	// And the entity is valid
	      trace.Entity:EntIndex() != 0	// And isn't worldspawn
	    ) then return end

	local mat = self:GetClientInfo( "override" )
	SetMaterial( self:GetOwner(), trace.Entity, { MaterialOverride = mat } )
	return true

end



function TOOL:RightClick( trace )

	if !( trace.Entity &&			// Hit an entity
	      trace.Entity:IsValid() && 	// And the entity is valid
	      trace.Entity:EntIndex() != 0	// And isn't worldspawn
	    ) then return end

	trace.Entity:SetMaterial( "" )
	trace.Entity.MaterialOverride = nil
	return true

end
