fix: replace AssetId if-chain with lookup table, improve warnings

This commit is contained in:
2026-04-07 15:48:38 -04:00
parent cec933c906
commit 89f54ed4b9
+22 -23
View File
@@ -3,31 +3,30 @@ local convert = {}
local faceByMesh = require("./faceByMesh") local faceByMesh = require("./faceByMesh")
local meshByName = require("./meshByName") local meshByName = require("./meshByName")
-- these heads do not expose HeadShape correctly due to Roblox not migrating them fully
-- they are mapped by AssetId instead
local meshByAssetId: {[number]: string} = {
[77954380016578] = "Hex",
[123297947692270] = "Diamond",
[83797968787123] = "CylinderMadness",
[124045894066016] = "Octoblox",
[87670789201977] = "iBot",
}
local function headMeshFromHumanoidDescription(humDesc: HumanoidDescription): number local function headMeshFromHumanoidDescription(humDesc: HumanoidDescription): number
for _, bodyPartDescription in humDesc:GetChildren() do for _, bodyPartDescription in humDesc:GetChildren() do
if not bodyPartDescription:IsA("BodyPartDescription") then continue end if not bodyPartDescription:IsA("BodyPartDescription") then continue end
local meshName = meshByAssetId[bodyPartDescription.AssetId]
if meshName then
return meshByName[meshName]
end
local HeadShape = bodyPartDescription.HeadShape local HeadShape = bodyPartDescription.HeadShape
-- HACK: these heads are not fully supported yet
if bodyPartDescription.AssetId == 77954380016578 then
return meshByName["Hex"]
end
if bodyPartDescription.AssetId == 123297947692270 then
return meshByName["Diamond"]
end
if bodyPartDescription.AssetId == 83797968787123 then
return meshByName["CylinderMadness"]
end
if bodyPartDescription.AssetId == 124045894066016 then
return meshByName["Octoblox"]
end
if bodyPartDescription.AssetId == 87670789201977 then
return meshByName["iBot"]
end
if HeadShape ~= "" then if HeadShape ~= "" then
return meshByName[HeadShape] return meshByName[HeadShape]
end end
warn(`rbx-reface: head with ID {bodyPartDescription.AssetId} has no mesh equivalent - defaulting to classic head`) warn(`rbx-reface: head with ID {bodyPartDescription.AssetId} has no mesh equivalent - defaulting to classic head`)
end end
return meshByName["RobloxClassic"] return meshByName["RobloxClassic"]
@@ -36,8 +35,10 @@ end
function convert.convertCharacter(humanoid: Humanoid): () function convert.convertCharacter(humanoid: Humanoid): ()
local humDesc = humanoid:GetAppliedDescription() local humDesc = humanoid:GetAppliedDescription()
if humDesc == nil then if humDesc == nil then
warn(`rbx-reface: could not get applied description for {humanoid.Parent.Name}`)
return return
end end
local currentMesh = humDesc.Head local currentMesh = humDesc.Head
local targetMesh = headMeshFromHumanoidDescription(humDesc) local targetMesh = headMeshFromHumanoidDescription(humDesc)
local face = faceByMesh[currentMesh] local face = faceByMesh[currentMesh]
@@ -47,7 +48,6 @@ function convert.convertCharacter(humanoid: Humanoid): ()
return return
end end
humDesc.Head = targetMesh humDesc.Head = targetMesh
humDesc.Face = face humDesc.Face = face
@@ -60,16 +60,15 @@ function convert.convertCharacter(humanoid: Humanoid): ()
return return
end end
-- VERY UGLY HACK: iBot head texture workaround -- iBot's texture is not correctly restored
if targetMesh == meshByName["iBot"] then if targetMesh == meshByName["iBot"] then
local head = humanoid.Parent:FindFirstChild("Head") local head = humanoid.Parent:FindFirstChild("Head")
if head then if head then
(head :: MeshPart).TextureID = "rbxassetid://97292285" (head :: MeshPart).TextureID = "rbxassetid://97292285"
else
warn(`rbx-reface: could not find Head part to apply iBot texture workaround`)
end end
end end
end end
return convert return convert