local j=(require(script.Parent.loader)).load(script)local E=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local T=game:GetService("\087\111\114\107\115\112\097\099\101")local e=j("\066\097\115\105\099\080\097\110\101")local q=j("\082\097\121\099\097\115\116\101\114")local p=j("\083\105\103\110\097\108")local o=setmetatable({},e)o.ClassName="\077\097\116\101\114\105\097\108\073\110\112\117\116"o.__index=o function o.new(j)local B=setmetatable(e.new(),o)B._mouse=j or error("\078\111 \109\111\117\115\101")B.MaterialSelected=p.new()B.ConvertRequest=p.new()B._raycaster=q.new()B._raycaster.Filter=function(j)if j.Part~=T.Terrain then return true end end B._maid:GiveTask(E.InputBegan:Connect(function(j,T)if T then return end if j.UserInputType==Enum.UserInputType.MouseButton1 then if E:IsKeyDown(Enum.KeyCode.LeftAlt)or E:IsKeyDown(Enum.KeyCode.RightAlt)then local j=B:_findMaterial()if j then B.MaterialSelected:Fire(j)end end elseif j.KeyCode==Enum.KeyCode.B then B.ConvertRequest:Fire()end end))return B end function o._startUpdate(j) end function o._findMaterial(j)local E=Ray.new(j._mouse.Origin.p,j._mouse.UnitRay.Direction*10000)local T=j._raycaster:FindPartOnRay(E)if T then return T.Material end end return o
--[=[
	@class MaterialInput
]=]
local require = require(script.Parent.loader).load(script)

local UserInputService = game:GetService("UserInputService")
local Workspace = game:GetService("Workspace")

local BasicPane = require("BasicPane")
local Raycaster = require("Raycaster")
local Signal = require("Signal")

local MaterialInput = setmetatable({}, BasicPane)
MaterialInput.ClassName = "MaterialInput"
MaterialInput.__index = MaterialInput

function MaterialInput.new(mouse)
	local self = setmetatable(BasicPane.new(), MaterialInput)

	self._mouse = mouse or error("No mouse")

	self.MaterialSelected = Signal.new() -- :Fire(material)
	self.ConvertRequest = Signal.new() -- :Fire()

	self._raycaster = Raycaster.new()
	self._raycaster.Filter = function(hitData)
		if hitData.Part ~= Workspace.Terrain then
			return true
		end
	end

	self._maid:GiveTask(UserInputService.InputBegan:Connect(function(inputObject, gameProcessed)
		if gameProcessed then
			return
		end

		if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
			if UserInputService:IsKeyDown(Enum.KeyCode.LeftAlt) or UserInputService:IsKeyDown(Enum.KeyCode.RightAlt) then
				local material = self:_findMaterial()
				if material then
					self.MaterialSelected:Fire(material)
				end
			end
		elseif inputObject.KeyCode == Enum.KeyCode.B then
			self.ConvertRequest:Fire()
		end
	end))

	return self
end

function MaterialInput:_startUpdate()

end

function MaterialInput:_findMaterial()
	local mouseRay = Ray.new(self._mouse.Origin.p, self._mouse.UnitRay.Direction*10000)
	local hitData = self._raycaster:FindPartOnRay(mouseRay)
	if hitData then
		return hitData.Material
	end
end

return MaterialInput