• Unity
  • Texture UV wrong after using AtlasUtilities.GetRepackedSkin

Hello,
I'm trying to get our custom mix&match setup working with AtlasUtilities.GetRepackedSkin. Everything appears to be created correctly, and the generated texture looks fine without any artifacts in it, but the rendered Mesh has a strange offset/zoom apparent, something that would be created by bad UV coordinates in the resulting Skin.

I'm creating the skin as follows:

void CopyAttachments(Skin from, Skin to)
{
    if (from == null || to == null)
        return;

foreach (var attachment in from.Attachments)
{
        to.AddAttachment(attachment.Key.slotIndex, attachment.Key.name, attachment.Value);
}
}

public SkeletonAnimation AnimationComp;

public void SetupSkins(List<string> skins)
{
    var skeleton = AnimationComp.Skeleton;
    SkeletonData skeletonData = skeleton.Data;

// Create a new skin, and append those skins to it.
Skin targetSkin = new Skin("TargetSkin");

foreach (var option in skins)
{
    if (option == null || option.Length == 0)
        continue;
    var srcSkin = skeletonData.FindSkin(option);
    if (srcSkin == null)
    {
        Log.warn($"Unable to find skin '{option}' in skeleton '{skeletonData.Name}' for char '{gameObject.name}'");
    }
    else
    {
        CopyAttachments(srcSkin, targetSkin);
    }
}

Material runtimeMaterial;
Texture2D runtimeAtlas;

targetSkin = AtlasUtilities.GetRepackedSkin(targetSkin, $"{gameObject.name}_Skin", Shader.Find("Spine/Skeleton"), out runtimeMaterial, out runtimeAtlas, 4096, 0, TextureFormat.RGBA32, false, useOriginalNonrenderables:false);

// Set and apply the Skin to the skeleton.
skeleton.SetSkin(targetSkin);
skeleton.SetSlotsToSetupPose();
AnimationComp.Update(0);
AnimationComp.LateUpdate();
}

This is how the skin looks without the GetRepackedSkin call (doesn't look great because of Point filtering but ignore that):

And here's how it looks with GetRepackedSkin:

As you can see, the mesh looks the same in both cases, but the texture appears to be scaled up after GetRepackedSkin, leading to noticable cropping of the outline at the top of the hat, for example.

You can find an example project with this issue here:

Thanks for the support.
Isaac


update:
After some experimentation, I've discovered that the bug does not occur after exporting from Spine with 'Strip Whitespace X/Y' both switched off.

2 mjeseci kasnije