
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 )
	
	if ( SERVER ) then
		duplicator.StoreEntityModifier( Entity, "material", Data )
	end

	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

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

end
