local v=require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\078\101\118\101\114\109\111\114\101"))local m=v("\077\097\116\104")local u={}u.ClassName="\077\111\100\101\108\065\112\112\101\097\114\097\110\099\101"u.__index=u function u.new(v)local m=setmetatable({},u)m._parts={}m._interactions={}m._seats={}for v,u in pairs(v:GetDescendants())do if u:IsA("\066\097\115\101\080\097\114\116")then m._parts[u]={Transparency=u.Transparency,Color=u.Color,Material=u.Material;CanCollide=u.CanCollide}if u:IsA("\083\101\097\116")or u:IsA("\086\101\104\105\099\108\101\083\101\097\116")then m._seats[u]=u end elseif u:IsA("\067\108\105\099\107\068\101\116\101\099\116\111\114")or u:IsA("\066\111\100\121\077\111\118\101\114")then table.insert(m._interactions,u)end end return m end function u.DisableInteractions(v)for v,m in pairs(v._interactions)do m:Destroy()end v._interactions={}for v,m in pairs(v._seats)do v.Disabled=true end v:SetCanCollide(false)end function u.SetCanCollide(m,v)assert(type(v)=="\098\111\111\108\101\097\110")if m._canCollide==v then return end m._canCollide=v for m,u in pairs(m._parts)do m.CanCollide=u.CanCollide and v end end function u.ResetCanCollide(m,v)m:SetCanCollide(true)end function u.SetTransparency(u,v)if u._transparency==v then return end u._transparency=v for u,q in pairs(u._parts)do u.Transparency=m.map(v,0,1,q.Transparency,1)end end function u.ResetTransparency(v)if not v._transparency then return end v._transparency=nil for v,m in pairs(v._parts)do v.Transparency=m.Transparency end end function u.SetColor(m,v)assert(typeof(v)=="\067\111\108\111\114\051")if m._color==v then return end m._color=v for m,u in pairs(m._parts)do m.Color=v end end function u.ResetColor(v)if not v._color then return end v._color=nil for v,m in pairs(v._parts)do v.Color=m.Color end end function u.ResetMaterial(v)if not v._material then return end v._material=nil for v,m in pairs(v._parts)do v.Material=m.Material end end function u.SetMaterial(m,v)if m._material==v then return end m._material=v for m,u in pairs(m._parts)do m.Material=v end end return u
--- Control appearance of model being placed
-- @classmod ModelAppearance

local require = require(game:GetService("ReplicatedStorage"):WaitForChild("Nevermore"))

local Math = require("Math")

local ModelAppearance = {}
ModelAppearance.ClassName = "ModelAppearance"
ModelAppearance.__index = ModelAppearance

function ModelAppearance.new(model)
	local self = setmetatable({}, ModelAppearance)

	self._parts = {}
	self._interactions = {}
	self._seats = {}

	for _, part in pairs(model:GetDescendants()) do
		if part:IsA("BasePart") then
			self._parts[part] = {
				Transparency = part.Transparency;
				Color = part.Color;
				Material = part.Material;
				CanCollide = part.CanCollide;
			}

			if part:IsA("Seat") or part:IsA("VehicleSeat") then
				self._seats[part] = part
			end
		elseif part:IsA("ClickDetector") or part:IsA("BodyMover") then
			table.insert(self._interactions, part)
		end
	end

	return self
end

-- Destructive, cannot be reverted
function ModelAppearance:DisableInteractions()
	for _, item in pairs(self._interactions) do
		item:Destroy()
	end
	self._interactions = {}
	for seat, _ in pairs(self._seats) do
		seat.Disabled = true
	end

	self:SetCanCollide(false)
end

function ModelAppearance:SetCanCollide(canCollide)
	assert(type(canCollide) == "boolean")

	if self._canCollide == canCollide then
		return
	end

	self._canCollide = canCollide
	for part, properties in pairs(self._parts) do
		part.CanCollide = properties.CanCollide and canCollide
	end
end

function ModelAppearance:ResetCanCollide(canCollide)
	self:SetCanCollide(true)
end

function ModelAppearance:SetTransparency(transparency)
	if self._transparency == transparency then
		return
	end

	self._transparency = transparency
	for part, properties in pairs(self._parts) do
		part.Transparency = Math.map(transparency, 0, 1, properties.Transparency, 1)
	end
end

function ModelAppearance:ResetTransparency()
	if not self._transparency then
		return
	end

	self._transparency = nil
	for part, properties in pairs(self._parts) do
		part.Transparency = properties.Transparency
	end
end

function ModelAppearance:SetColor(color)
	assert(typeof(color) == "Color3")

	if self._color == color then
		return
	end

	self._color = color
	for part, _ in pairs(self._parts) do
		part.Color = color
	end
end

function ModelAppearance:ResetColor()
	if not self._color then
		return
	end

	self._color = nil
	for part, properties in pairs(self._parts) do
		part.Color = properties.Color
	end
end

function ModelAppearance:ResetMaterial()
	if not self._material then
		return
	end

	self._material = nil
	for part, properties in pairs(self._parts) do
		part.Material = properties.Material
	end
end

function ModelAppearance:SetMaterial(material)
	if self._material == material then
		return
	end

	self._material = material
	for part, _ in pairs(self._parts) do
		part.Material = material
	end
end

return ModelAppearance