local L=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local p=L:WaitForChild("\099\111\109\109\111\110")local A=require(p.util:WaitForChild("\103\101\116\065\115\115\101\116\077\111\100\101\108"))local C={}local function K(L)local p=(A(L)):Clone()assert(p,"\078\111 \109\111\100\101\108 \102\111\114 \104\097\116\058 "..L)local C=Instance.new("\065\099\099\101\115\115\111\114\121")p.Name="\072\097\110\100\108\101"p.Anchored=false p.CanCollide=false p.Massless=true p.Parent=C return C end function C.new(L,p)local A=setmetatable({},{__index=C})A.assetId=L A.rig=p A.viewModel=K(L)local f=p:WaitForChild("\084\111\114\115\111")local h=f:WaitForChild("\072\097\116\065\116\116\097\099\104\109\101\110\116")local z=A.viewModel.Handle.HatAttachment local w=Instance.new("\087\101\108\100")w.Part0=f w.Part1=A.viewModel.Handle w.C0=h.CFrame w.C1=z.CFrame w.Parent=A.viewModel.Handle A.viewModel.Parent=p return A end function C.update(L) end function C.destroy(L)L.viewModel:Destroy()L.rig=nil end return C
-- object based hat renderer, default renderer for hats.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local common = ReplicatedStorage:WaitForChild("common")

local getAssetModel = require(common.util:WaitForChild("getAssetModel"))

local HatRenderer = {}

local function createAccessoryForHat(assetId)
    local model = getAssetModel(assetId):Clone()
    assert(model, "No model for hat: "..assetId)
    local newAccessory = Instance.new("Accessory")
    model.Name = "Handle"
    model.Anchored = false
    model.CanCollide = false
    model.Massless = true
    model.Parent = newAccessory

    return newAccessory
end

function HatRenderer.new(assetId,rig)
    -- create hat for this rig
    local self = setmetatable({},{__index = HatRenderer})

    self.assetId = assetId
    self.rig = rig

    self.viewModel = createAccessoryForHat(assetId)

    local torso = rig:WaitForChild("Torso")
    local torsoHatAttachment = torso:WaitForChild("HatAttachment")
    local hatAttachment = self.viewModel.Handle.HatAttachment
    local weld = Instance.new("Weld")

    weld.Part0 = torso
    weld.Part1 = self.viewModel.Handle

    weld.C0 = torsoHatAttachment.CFrame
    weld.C1 = hatAttachment.CFrame

    weld.Parent = self.viewModel.Handle

    self.viewModel.Parent = rig


    return self
end

function HatRenderer:update()
    -- nothing needed here
end

function HatRenderer:destroy()
    self.viewModel:Destroy()
    self.rig = nil
end

return HatRenderer