Thank you for the response badlogic. Shortly after I made the initial post I dove right into translating the C# code across to Cocos2d-x, and while it's now compiling, no texture is being displayed for the specific attachment I've created using a texture, so I'm hunting down the reason why.
I'm not overly concerned with texture-repacking, at least not for this project, so I didn't port over that section of code.
One question though, in the C# Unity code, if GetRemappedClone() is called with premultiplyAlpha set to false, then for this line:
var atlasRegion = premultiplyAlpha ? sprite.ToAtlasRegionPMAClone(sourceMaterial) : sprite.ToAtlasRegion(false);
The condition result ends up being atlasRegion = sprite.ToAtlasRegion(false);
Now, the extension method ToAtlasRegion that gets called is:
internal static AtlasRegion ToAtlasRegion (this Sprite s, bool isolatedTexture = false) {
var region = new AtlasRegion();
region.name = s.name;
region.index = -1;
region.rotate = s.packed && s.packingRotation != SpritePackingRotation.None;
// World space units
Bounds bounds = s.bounds;
Vector2 boundsMin = bounds.min, boundsMax = bounds.max;
// Texture space/pixel units
Rect spineRect = s.rect.SpineUnityFlipRect(s.texture.height);
region.width = (int)spineRect.width;
region.originalWidth = (int)spineRect.width;
region.height = (int)spineRect.height;
region.originalHeight = (int)spineRect.height;
region.offsetX = spineRect.width * (0.5f - InverseLerp(boundsMin.x, boundsMax.x, 0));
region.offsetY = spineRect.height * (0.5f - InverseLerp(boundsMin.y, boundsMax.y, 0));
if (isolatedTexture) {
region.u = 0;
region.v = 1;
region.u2 = 1;
region.v2 = 0;
region.x = 0;
region.y = 0;
} else {
Texture2D tex = s.texture;
Rect uvRect = TextureRectToUVRect(s.textureRect, tex.width, tex.height);
region.u = uvRect.xMin;
region.v = uvRect.yMax;
region.u2 = uvRect.xMax;
region.v2 = uvRect.yMin;
region.x = (int)spineRect.x;
region.y = (int)spineRect.y;
}
return region;
}
What I don't quite understand is the region being returned has no reference to the texture being used in the sprite, yet all the other ToAtlasRegion() methods do store a reference to the texture/material in the region.atlas field. Does this method actually work as intended? I'm in the process of downloading Unity3D to actually test it, because it seems incorrect.
In GetRemappedClone(), the line
var atlasRegion = premultiplyAlpha ? sprite.ToAtlasRegionPMAClone(sourceMaterial) : sprite.ToAtlasRegion(false);
should perhaps be
var atlasRegion = premultiplyAlpha ? sprite.ToAtlasRegionPMAClone(sourceMaterial) : sprite.ToAtlasRegion(sourceMaterial);
This allows the texture to be displayed properly if premultiplyAlpha is false.