local X=(require(script.Parent.loader)).load(script)local I=game:GetService("\087\111\114\107\115\112\097\099\101")local d=game:GetService("\067\111\108\108\101\099\116\105\111\110\083\101\114\118\105\099\101")local T=X("\067\111\108\108\101\099\116\105\111\110\083\101\114\118\105\099\101\085\116\105\108\115")local Q=X("\068\114\097\119")local v=X("\065\100\111\114\110\101\101\085\116\105\108\115")local D={}local M=5 function D.getGripAttachmentName(X)assert(X=="\076\101\102\116"or X=="\082\105\103\104\116","\066\097\100 \115\105\100\101\078\097\109\101")return("\086\082\069\110\097\098\108\101\100\072\117\109\097\110\111\105\100\095\073\075\037\115\071\114\105\112\065\116\116\097\099\104\109\101\110\116"):format(X)end function D.getHoldingValueName(X)assert(X=="\076\101\102\116"or X=="\082\105\103\104\116","\066\097\100 \115\105\100\101\078\097\109\101")return("\086\082\069\110\097\098\108\101\100\072\117\109\097\110\111\105\100\095\037\115\072\111\108\100\105\110\103"):format(X)end function D.findHoldable(X,D)local J=I:GetPartBoundsInRadius(X,M)if D then D._render=Q.sphere(X,M)end local y={}for I,Q in pairs(J)do local D=T.findFirstAncestor("\086\082\072\111\108\100\097\098\108\101",Q)if not D then if d:HasTag(Q,"\086\082\072\111\108\100\097\098\108\101")then D=Q end end if D then local I=v.getCenter(Q)if I then y[Q]=(X-I).magnitude end end end local H=nil local A=math.huge for X,I in pairs(y)do if I<A then A=I H=X end end return H end return D
--[=[
	@class VREnabledHumanoidUtils
]=]

local require = require(script.Parent.loader).load(script)

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

local CollectionServiceUtils = require("CollectionServiceUtils")
local Draw = require("Draw")
local AdorneeUtils = require("AdorneeUtils")

local VREnabledHumanoidUtils = {}

local GRIP_RADIUS_STUDS = 5

function VREnabledHumanoidUtils.getGripAttachmentName(sideName)
	assert(sideName == "Left" or sideName == "Right", "Bad sideName")

	return ("VREnabledHumanoid_IK%sGripAttachment"):format(sideName)
end

function VREnabledHumanoidUtils.getHoldingValueName(sideName)
	assert(sideName == "Left" or sideName == "Right", "Bad sideName")

	return ("VREnabledHumanoid_%sHolding"):format(sideName)
end

function VREnabledHumanoidUtils.findHoldable(position, debugMaid)
	local partsAvailable = Workspace:GetPartBoundsInRadius(position, GRIP_RADIUS_STUDS)

	if debugMaid then
		debugMaid._render = Draw.sphere(position, GRIP_RADIUS_STUDS)
	end

	local options = {}
	for _, item in pairs(partsAvailable) do
		local holdable = CollectionServiceUtils.findFirstAncestor("VRHoldable", item)
		if not holdable then
			if CollectionService:HasTag(item, "VRHoldable") then
				holdable = item
			end
		end

		if holdable then
			local center = AdorneeUtils.getCenter(item)
			if center then
				options[item] = (position - center).magnitude
			end
		end
	end

	local closest = nil
	local bestDist = math.huge
	for adornee, dist in pairs(options) do
		if dist < bestDist then
			bestDist = dist
			closest = adornee
		end
	end

	return closest
end

return VREnabledHumanoidUtils