-- Head v1.1.1

local assetUrl, fileExtension, x, y, baseUrl, mannequinId = ...

local ThumbnailGenerator = game:GetService("ThumbnailGenerator")
ThumbnailGenerator:AddProfilingCheckpoint("ThumbnailScriptStarted")

pcall(function() game:GetService("ContentProvider"):SetBaseUrl(baseUrl) end)
game:GetService("ScriptContext").ScriptsDisabled = true

local mannequin = game:GetObjects(baseUrl.. "asset/?id=" .. tostring(mannequinId))[1]
mannequin.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
mannequin.Parent = workspace

ThumbnailGenerator:AddProfilingCheckpoint("MannequinLoaded")

local objects = game:GetObjects(assetUrl)
local mesh = objects[1]
if objects[1]:IsA("Folder") then
	for _, obj in pairs(objects) do
		if obj:IsA("Folder") and obj.Name == "R15ArtistIntent" then
			local head = obj.Head
			mannequin.Head:Destroy()
			head.Parent = mannequin
			if head:FindFirstChild("face") == nil then
				local face = Instance.new("Decal")
				face.Name = "face"
				face.Texture = "rbxasset://textures/face.png"
				face.Parent = head
			end
		end
	end
else
	mannequin.Head.BrickColor = BrickColor.Gray()
	if mannequin.Head:FindFirstChild("Mesh") then
		mannequin.Head.Mesh:Destroy()
	end
	mesh.Parent = mannequin.Head
end

ThumbnailGenerator:AddProfilingCheckpoint("ObjectsLoaded")

for _, child in pairs(mannequin:GetChildren()) do
	if child:IsA("BasePart") and child.Name ~= "Head" then
		child:Destroy()
	end
end


local result, requestedUrls = ThumbnailGenerator:Click(fileExtension, x, y, --[[hideSky = ]] true)
ThumbnailGenerator:AddProfilingCheckpoint("ThumbnailGenerated")

return result, requestedUrls