From 071a1b5472b8ce43e63899afedd13f769d93093b Mon Sep 17 00:00:00 2001 From: John Date: Thu, 16 Mar 2017 16:18:17 +0800 Subject: [PATCH 1/3] CHANGELOG.md rematch new md spec. Removed workaround where gfm was misbehaving ATX headings. Change according to: https://githubengineering.com/a-formal-spec-for-github-markdown/ --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62f68d32b..6e1fb3577 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,8 +53,7 @@ * Fixed renderer to work with 3.6 changes * Added new UPROPERTY to SpineSkeletonRendererComponent called `Color`. This allows to set the tint color of the skeleton in the editor, C++ and Blueprints. Under the hood, the `spSkeleton->color` will be set on every tick of the renderer component. -C# ----- +## C# * **Breaking changes** * `MeshAttachment.parentMesh` is now a private field to enforce using the `.ParentMesh` setter property in external code. The `MeshAttachment.ParentMesh` property is an appropriate replacement wherever `.parentMesh` was used. From 98ab69a61c7313582df59053d3e89cf32c6756c6 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 16 Mar 2017 21:42:19 +0800 Subject: [PATCH 2/3] [unity] Repacking now reuses shared regions. --- .../AttachmentTools/AttachmentTools.cs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs b/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs index 8f947185b..cb79fa83a 100644 --- a/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs +++ b/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs @@ -1,4 +1,4 @@ -/****************************************************************************** +/****************************************************************************** * Spine Runtimes Software License v2.5 * * Copyright (c) 2013-2016, Esoteric Software @@ -302,12 +302,27 @@ namespace Spine.Unity.Modules.AttachmentTools { var skinAttachments = o.Attachments; var newSkin = new Skin(newName); + var existingRegions = new Dictionary(); + var textureIndexes = new List(); + var repackedAttachments = new List(); var texturesToPack = new List(); + int newRegionIndex = 0; foreach (var kvp in skinAttachments) { var newAttachment = kvp.Value.GetClone(true); if (IsRenderable(newAttachment)) { - texturesToPack.Add(newAttachment.GetAtlasRegion().ToTexture()); + + var region = newAttachment.GetAtlasRegion(); + int existingIndex; + if (existingRegions.TryGetValue(region, out existingIndex)) { + textureIndexes.Add(existingIndex); // Store the region index for the eventual new attachment. + } else { + texturesToPack.Add(region.ToTexture()); // Add the texture to the PackTextures argument + existingRegions.Add(region, newRegionIndex); // Add the region to the dictionary of known regions + textureIndexes.Add(newRegionIndex); // Store the region index for the eventual new attachment. + newRegionIndex++; + } + repackedAttachments.Add(newAttachment); } var key = kvp.Key; @@ -326,7 +341,7 @@ namespace Spine.Unity.Modules.AttachmentTools { for (int i = 0, n = repackedAttachments.Count; i < n; i++) { var a = repackedAttachments[i]; - var r = rects[i]; + var r = rects[textureIndexes[i]]; var oldRegion = a.GetAtlasRegion(); var newRegion = UVRectToAtlasRegion(r, oldRegion.name, page, oldRegion.offsetX, oldRegion.offsetY, oldRegion.rotate); a.SetRegion(newRegion); From 3e4722cb561fd397df31df42580706e7b9eab212 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 16 Mar 2017 22:03:08 +0800 Subject: [PATCH 3/3] [unity] Optional repacking texture format params. --- .../AttachmentTools/AttachmentTools.cs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs b/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs index cb79fa83a..a94762dde 100644 --- a/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs +++ b/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs @@ -129,10 +129,10 @@ namespace Spine.Unity.Modules.AttachmentTools { /// /// Creates a Spine.AtlasRegion that uses a premultiplied alpha duplicate texture of the Sprite's texture data. Returns a RegionAttachment that uses it. Use this if you plan to use a premultiply alpha shader such as "Spine/Skeleton" - public static RegionAttachment ToRegionAttachmentPMAClone (this Sprite sprite, Shader shader) { + public static RegionAttachment ToRegionAttachmentPMAClone (this Sprite sprite, Shader shader, TextureFormat textureFormat = SpriteAtlasRegionExtensions.SpineTextureFormat, bool mipmaps = SpriteAtlasRegionExtensions.UseMipMaps) { if (sprite == null) throw new System.ArgumentNullException("sprite"); if (shader == null) throw new System.ArgumentNullException("shader"); - var region = sprite.ToAtlasRegionPMAClone(shader); + var region = sprite.ToAtlasRegionPMAClone(shader, textureFormat, mipmaps); var unitsPerPixel = 1f / sprite.pixelsPerUnit; return region.ToRegionAttachment(sprite.name, unitsPerPixel); } @@ -201,6 +201,9 @@ namespace Spine.Unity.Modules.AttachmentTools { } public static class SpriteAtlasRegionExtensions { + internal const TextureFormat SpineTextureFormat = TextureFormat.RGBA32; + internal const bool UseMipMaps = false; + /// /// Creates a new Spine.AtlasPage from a UnityEngine.Material. If the material has a preassigned texture, the page width and height will be set. public static AtlasPage ToSpineAtlasPage (this Material m) { @@ -237,9 +240,9 @@ namespace Spine.Unity.Modules.AttachmentTools { /// /// Creates a Spine.AtlasRegion that uses a premultiplied alpha duplicate of the Sprite's texture data. - public static AtlasRegion ToAtlasRegionPMAClone (this Sprite s, Shader shader) { + public static AtlasRegion ToAtlasRegionPMAClone (this Sprite s, Shader shader, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps) { var material = new Material(shader); - var tex = s.ToTexture(false); + var tex = s.ToTexture(false, textureFormat, mipmaps); tex.ApplyPMA(true); tex.name = s.name + "-pma-"; @@ -298,7 +301,7 @@ namespace Spine.Unity.Modules.AttachmentTools { /// /// Creates and populates a duplicate skin with cloned attachments that are backed by a new packed texture atlas comprised of all the regions from the original skin. /// No Spine.Atlas object is created so there is no way to find AtlasRegions except through the Attachments using them. - public static Skin GetRepackedSkin (this Skin o, string newName, Shader shader, out Material m, out Texture2D t, int maxAtlasSize = 1024, int padding = 2) { + public static Skin GetRepackedSkin (this Skin o, string newName, Shader shader, out Material m, out Texture2D t, int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps) { var skinAttachments = o.Attachments; var newSkin = new Skin(newName); @@ -329,7 +332,8 @@ namespace Spine.Unity.Modules.AttachmentTools { newSkin.AddAttachment(key.slotIndex, key.name, newAttachment); } - var newTexture = new Texture2D(maxAtlasSize, maxAtlasSize); + var newTexture = new Texture2D(maxAtlasSize, maxAtlasSize, textureFormat, mipmaps); + newTexture.anisoLevel = texturesToPack[0].anisoLevel; newTexture.name = newName; var rects = newTexture.PackTextures(texturesToPack.ToArray(), padding, maxAtlasSize); @@ -358,10 +362,10 @@ namespace Spine.Unity.Modules.AttachmentTools { /// Creates a new Texture2D object based on an AtlasRegion. /// If applyImmediately is true, Texture2D.Apply is called immediately after the Texture2D is filled with data. - public static Texture2D ToTexture (this AtlasRegion ar, bool applyImmediately = true) { + public static Texture2D ToTexture (this AtlasRegion ar, bool applyImmediately = true, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps) { Texture2D sourceTexture = ar.GetMainTexture(); Rect r = ar.GetUnityRect(sourceTexture.height); - Texture2D output = new Texture2D((int)r.width, (int)r.height); + Texture2D output = new Texture2D((int)r.width, (int)r.height, textureFormat, mipmaps); output.name = ar.name; Color[] pixelBuffer = sourceTexture.GetPixels((int)r.x, (int)r.y, (int)r.width, (int)r.height); output.SetPixels(pixelBuffer); @@ -372,11 +376,11 @@ namespace Spine.Unity.Modules.AttachmentTools { return output; } - static Texture2D ToTexture (this Sprite s, bool applyImmediately = true) { + static Texture2D ToTexture (this Sprite s, bool applyImmediately = true, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps) { var spriteTexture = s.texture; var r = s.textureRect; var spritePixels = spriteTexture.GetPixels((int)r.x, (int)r.y, (int)r.width, (int)r.height); - var newTexture = new Texture2D((int)r.width, (int)r.height); + var newTexture = new Texture2D((int)r.width, (int)r.height, textureFormat, mipmaps); newTexture.SetPixels(spritePixels); if (applyImmediately)