From 89f54ed4b9900c6ac9b7e242de0e7891fa5b8642 Mon Sep 17 00:00:00 2001 From: secret-rare Date: Tue, 7 Apr 2026 15:48:38 -0400 Subject: [PATCH] fix: replace AssetId if-chain with lookup table, improve warnings --- src/convert.luau | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/convert.luau b/src/convert.luau index 08994ad..06a49aa 100644 --- a/src/convert.luau +++ b/src/convert.luau @@ -3,31 +3,30 @@ local convert = {} local faceByMesh = require("./faceByMesh") 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 for _, bodyPartDescription in humDesc:GetChildren() do if not bodyPartDescription:IsA("BodyPartDescription") then continue end + + local meshName = meshByAssetId[bodyPartDescription.AssetId] + if meshName then + return meshByName[meshName] + end + 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 return meshByName[HeadShape] end + warn(`rbx-reface: head with ID {bodyPartDescription.AssetId} has no mesh equivalent - defaulting to classic head`) end return meshByName["RobloxClassic"] @@ -36,8 +35,10 @@ end function convert.convertCharacter(humanoid: Humanoid): () local humDesc = humanoid:GetAppliedDescription() if humDesc == nil then + warn(`rbx-reface: could not get applied description for {humanoid.Parent.Name}`) return end + local currentMesh = humDesc.Head local targetMesh = headMeshFromHumanoidDescription(humDesc) local face = faceByMesh[currentMesh] @@ -47,7 +48,6 @@ function convert.convertCharacter(humanoid: Humanoid): () return end - humDesc.Head = targetMesh humDesc.Face = face @@ -60,16 +60,15 @@ function convert.convertCharacter(humanoid: Humanoid): () return end - -- VERY UGLY HACK: iBot head texture workaround + -- iBot's texture is not correctly restored if targetMesh == meshByName["iBot"] then local head = humanoid.Parent:FindFirstChild("Head") if head then (head :: MeshPart).TextureID = "rbxassetid://97292285" + else + warn(`rbx-reface: could not find Head part to apply iBot texture workaround`) end end - end - - return convert