mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Merge branch '3.8' into 3.9-beta
This commit is contained in:
commit
5a29e12fc4
@ -236,19 +236,25 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
/// this array will be used as <c>TextureFormat</c> at the Texture at the respective property.
|
/// this array will be used as <c>TextureFormat</c> at the Texture at the respective property.
|
||||||
/// When <c>additionalTextureFormats</c> is <c>null</c> or when its array size is smaller,
|
/// When <c>additionalTextureFormats</c> is <c>null</c> or when its array size is smaller,
|
||||||
/// <c>textureFormat</c> is used where there exists no corresponding array item.</param>
|
/// <c>textureFormat</c> is used where there exists no corresponding array item.</param>
|
||||||
|
/// <param name="additionalTextureIsLinear">When <c>additionalTexturePropertyIDsToCopy</c> is non-null,
|
||||||
|
/// this array will be used to determine whether <c>linear</c> or <c>sRGB</c> color space is used at the
|
||||||
|
/// Texture at the respective property. When <c>additionalTextureIsLinear</c> is <c>null</c>, <c>linear</c> color space
|
||||||
|
/// is assumed at every additional Texture element.
|
||||||
|
/// When e.g. packing the main texture and normal maps, pass 'new bool[] { true }' at this parameter, because normal maps use
|
||||||
|
/// linear color space.</param>
|
||||||
public static void GetRepackedAttachments (List<Attachment> sourceAttachments, List<Attachment> outputAttachments, Material materialPropertySource,
|
public static void GetRepackedAttachments (List<Attachment> sourceAttachments, List<Attachment> outputAttachments, Material materialPropertySource,
|
||||||
out Material outputMaterial, out Texture2D outputTexture,
|
out Material outputMaterial, out Texture2D outputTexture,
|
||||||
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
|
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
|
||||||
string newAssetName = "Repacked Attachments", bool clearCache = false, bool useOriginalNonrenderables = true,
|
string newAssetName = "Repacked Attachments", bool clearCache = false, bool useOriginalNonrenderables = true,
|
||||||
int[] additionalTexturePropertyIDsToCopy = null, Texture2D[] additionalOutputTextures = null,
|
int[] additionalTexturePropertyIDsToCopy = null, Texture2D[] additionalOutputTextures = null,
|
||||||
TextureFormat[] additionalTextureFormats = null) {
|
TextureFormat[] additionalTextureFormats = null, bool[] additionalTextureIsLinear = null) {
|
||||||
|
|
||||||
Shader shader = materialPropertySource == null ? Shader.Find("Spine/Skeleton") : materialPropertySource.shader;
|
Shader shader = materialPropertySource == null ? Shader.Find("Spine/Skeleton") : materialPropertySource.shader;
|
||||||
GetRepackedAttachments(sourceAttachments, outputAttachments, shader, out outputMaterial, out outputTexture,
|
GetRepackedAttachments(sourceAttachments, outputAttachments, shader, out outputMaterial, out outputTexture,
|
||||||
maxAtlasSize, padding, textureFormat, mipmaps, newAssetName,
|
maxAtlasSize, padding, textureFormat, mipmaps, newAssetName,
|
||||||
materialPropertySource, clearCache, useOriginalNonrenderables,
|
materialPropertySource, clearCache, useOriginalNonrenderables,
|
||||||
additionalTexturePropertyIDsToCopy, additionalOutputTextures,
|
additionalTexturePropertyIDsToCopy, additionalOutputTextures,
|
||||||
additionalTextureFormats);
|
additionalTextureFormats, additionalTextureIsLinear);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -268,17 +274,29 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
/// this array will be used as <c>TextureFormat</c> at the Texture at the respective property.
|
/// this array will be used as <c>TextureFormat</c> at the Texture at the respective property.
|
||||||
/// When <c>additionalTextureFormats</c> is <c>null</c> or when its array size is smaller,
|
/// When <c>additionalTextureFormats</c> is <c>null</c> or when its array size is smaller,
|
||||||
/// <c>textureFormat</c> is used where there exists no corresponding array item.</param>
|
/// <c>textureFormat</c> is used where there exists no corresponding array item.</param>
|
||||||
|
/// <param name="additionalTextureIsLinear">When <c>additionalTexturePropertyIDsToCopy</c> is non-null,
|
||||||
|
/// this array will be used to determine whether <c>linear</c> or <c>sRGB</c> color space is used at the
|
||||||
|
/// Texture at the respective property. When <c>additionalTextureIsLinear</c> is <c>null</c>, <c>linear</c> color space
|
||||||
|
/// is assumed at every additional Texture element.
|
||||||
|
/// When e.g. packing the main texture and normal maps, pass 'new bool[] { true }' at this parameter, because normal maps use
|
||||||
|
/// linear color space.</param>
|
||||||
public static void GetRepackedAttachments (List<Attachment> sourceAttachments, List<Attachment> outputAttachments, Shader shader,
|
public static void GetRepackedAttachments (List<Attachment> sourceAttachments, List<Attachment> outputAttachments, Shader shader,
|
||||||
out Material outputMaterial, out Texture2D outputTexture,
|
out Material outputMaterial, out Texture2D outputTexture,
|
||||||
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
|
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
|
||||||
string newAssetName = "Repacked Attachments",
|
string newAssetName = "Repacked Attachments",
|
||||||
Material materialPropertySource = null, bool clearCache = false, bool useOriginalNonrenderables = true,
|
Material materialPropertySource = null, bool clearCache = false, bool useOriginalNonrenderables = true,
|
||||||
int[] additionalTexturePropertyIDsToCopy = null, Texture2D[] additionalOutputTextures = null,
|
int[] additionalTexturePropertyIDsToCopy = null, Texture2D[] additionalOutputTextures = null,
|
||||||
TextureFormat[] additionalTextureFormats = null) {
|
TextureFormat[] additionalTextureFormats = null, bool[] additionalTextureIsLinear = null) {
|
||||||
|
|
||||||
if (sourceAttachments == null) throw new System.ArgumentNullException("sourceAttachments");
|
if (sourceAttachments == null) throw new System.ArgumentNullException("sourceAttachments");
|
||||||
if (outputAttachments == null) throw new System.ArgumentNullException("outputAttachments");
|
if (outputAttachments == null) throw new System.ArgumentNullException("outputAttachments");
|
||||||
outputTexture = null;
|
outputTexture = null;
|
||||||
|
if (additionalTexturePropertyIDsToCopy != null && additionalTextureIsLinear == null) {
|
||||||
|
additionalTextureIsLinear = new bool[additionalTexturePropertyIDsToCopy.Length];
|
||||||
|
for (int i = 0; i < additionalTextureIsLinear.Length; ++i) {
|
||||||
|
additionalTextureIsLinear[i] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Use these to detect and use shared regions.
|
// Use these to detect and use shared regions.
|
||||||
var existingRegions = new Dictionary<AtlasRegion, int>();
|
var existingRegions = new Dictionary<AtlasRegion, int>();
|
||||||
@ -317,7 +335,7 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
region.ToTexture(textureFormat, mipmaps) :
|
region.ToTexture(textureFormat, mipmaps) :
|
||||||
region.ToTexture((additionalTextureFormats != null && i - 1 < additionalTextureFormats.Length) ?
|
region.ToTexture((additionalTextureFormats != null && i - 1 < additionalTextureFormats.Length) ?
|
||||||
additionalTextureFormats[i - 1] : textureFormat,
|
additionalTextureFormats[i - 1] : textureFormat,
|
||||||
mipmaps, additionalTexturePropertyIDsToCopy[i - 1]));
|
mipmaps, additionalTexturePropertyIDsToCopy[i - 1], additionalTextureIsLinear[i - 1]));
|
||||||
texturesToPackAtParam[i].Add(regionTexture);
|
texturesToPackAtParam[i].Add(regionTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,9 +364,10 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
for (int i = 0; i < numTextureParamsToRepack; ++i) {
|
for (int i = 0; i < numTextureParamsToRepack; ++i) {
|
||||||
// Fill a new texture with the collected attachment textures.
|
// Fill a new texture with the collected attachment textures.
|
||||||
var newTexture = new Texture2D(maxAtlasSize, maxAtlasSize,
|
var newTexture = new Texture2D(maxAtlasSize, maxAtlasSize,
|
||||||
(additionalTextureFormats != null && i - 1 < additionalTextureFormats.Length) ?
|
(i > 0 && additionalTextureFormats != null && i - 1 < additionalTextureFormats.Length) ?
|
||||||
additionalTextureFormats[i - 1] : textureFormat,
|
additionalTextureFormats[i - 1] : textureFormat,
|
||||||
mipmaps);
|
mipmaps,
|
||||||
|
(i > 0) ? additionalTextureIsLinear[i - 1] : false);
|
||||||
newTexture.mipMapBias = AtlasUtilities.DefaultMipmapBias;
|
newTexture.mipMapBias = AtlasUtilities.DefaultMipmapBias;
|
||||||
|
|
||||||
var texturesToPack = texturesToPackAtParam[i];
|
var texturesToPack = texturesToPackAtParam[i];
|
||||||
@ -407,16 +426,22 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
/// this array will be used as <c>TextureFormat</c> at the Texture at the respective property.
|
/// this array will be used as <c>TextureFormat</c> at the Texture at the respective property.
|
||||||
/// When <c>additionalTextureFormats</c> is <c>null</c> or when its array size is smaller,
|
/// When <c>additionalTextureFormats</c> is <c>null</c> or when its array size is smaller,
|
||||||
/// <c>textureFormat</c> is used where there exists no corresponding array item.</param>
|
/// <c>textureFormat</c> is used where there exists no corresponding array item.</param>
|
||||||
|
/// <param name="additionalTextureIsLinear">When <c>additionalTexturePropertyIDsToCopy</c> is non-null,
|
||||||
|
/// this array will be used to determine whether <c>linear</c> or <c>sRGB</c> color space is used at the
|
||||||
|
/// Texture at the respective property. When <c>additionalTextureIsLinear</c> is <c>null</c>, <c>linear</c> color space
|
||||||
|
/// is assumed at every additional Texture element.
|
||||||
|
/// When e.g. packing the main texture and normal maps, pass 'new bool[] { true }' at this parameter, because normal maps use
|
||||||
|
/// linear color space.</param>
|
||||||
public static Skin GetRepackedSkin (this Skin o, string newName, Material materialPropertySource, out Material outputMaterial, out Texture2D outputTexture,
|
public static Skin GetRepackedSkin (this Skin o, string newName, Material materialPropertySource, out Material outputMaterial, out Texture2D outputTexture,
|
||||||
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
|
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
|
||||||
bool useOriginalNonrenderables = true, bool clearCache = false,
|
bool useOriginalNonrenderables = true, bool clearCache = false,
|
||||||
int[] additionalTexturePropertyIDsToCopy = null, Texture2D[] additionalOutputTextures = null,
|
int[] additionalTexturePropertyIDsToCopy = null, Texture2D[] additionalOutputTextures = null,
|
||||||
TextureFormat[] additionalTextureFormats = null) {
|
TextureFormat[] additionalTextureFormats = null, bool[] additionalTextureIsLinear = null) {
|
||||||
|
|
||||||
return GetRepackedSkin(o, newName, materialPropertySource.shader, out outputMaterial, out outputTexture,
|
return GetRepackedSkin(o, newName, materialPropertySource.shader, out outputMaterial, out outputTexture,
|
||||||
maxAtlasSize, padding, textureFormat, mipmaps, materialPropertySource,
|
maxAtlasSize, padding, textureFormat, mipmaps, materialPropertySource,
|
||||||
clearCache, useOriginalNonrenderables, additionalTexturePropertyIDsToCopy, additionalOutputTextures,
|
clearCache, useOriginalNonrenderables, additionalTexturePropertyIDsToCopy, additionalOutputTextures,
|
||||||
additionalTextureFormats);
|
additionalTextureFormats, additionalTextureIsLinear);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -428,7 +453,7 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
|
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
|
||||||
Material materialPropertySource = null, bool clearCache = false, bool useOriginalNonrenderables = true,
|
Material materialPropertySource = null, bool clearCache = false, bool useOriginalNonrenderables = true,
|
||||||
int[] additionalTexturePropertyIDsToCopy = null, Texture2D[] additionalOutputTextures = null,
|
int[] additionalTexturePropertyIDsToCopy = null, Texture2D[] additionalOutputTextures = null,
|
||||||
TextureFormat[] additionalTextureFormats = null) {
|
TextureFormat[] additionalTextureFormats = null, bool[] additionalTextureIsLinear = null) {
|
||||||
|
|
||||||
outputTexture = null;
|
outputTexture = null;
|
||||||
|
|
||||||
@ -447,7 +472,7 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
}
|
}
|
||||||
GetRepackedAttachments(inoutAttachments, inoutAttachments, materialPropertySource, out outputMaterial, out outputTexture,
|
GetRepackedAttachments(inoutAttachments, inoutAttachments, materialPropertySource, out outputMaterial, out outputTexture,
|
||||||
maxAtlasSize, padding, textureFormat, mipmaps, newName, clearCache, useOriginalNonrenderables,
|
maxAtlasSize, padding, textureFormat, mipmaps, newName, clearCache, useOriginalNonrenderables,
|
||||||
additionalTexturePropertyIDsToCopy, additionalOutputTextures, additionalTextureFormats);
|
additionalTexturePropertyIDsToCopy, additionalOutputTextures, additionalTextureFormats, additionalTextureIsLinear);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (var originalSkinEntry in o.Attachments) {
|
foreach (var originalSkinEntry in o.Attachments) {
|
||||||
var newAttachment = inoutAttachments[i++];
|
var newAttachment = inoutAttachments[i++];
|
||||||
@ -483,7 +508,7 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
/// <summary>Creates a new Texture2D object based on an AtlasRegion.
|
/// <summary>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.</summary>
|
/// If applyImmediately is true, Texture2D.Apply is called immediately after the Texture2D is filled with data.</summary>
|
||||||
public static Texture2D ToTexture (this AtlasRegion ar, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
|
public static Texture2D ToTexture (this AtlasRegion ar, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
|
||||||
int texturePropertyId = 0) {
|
int texturePropertyId = 0, bool linear = false) {
|
||||||
|
|
||||||
Texture2D output;
|
Texture2D output;
|
||||||
|
|
||||||
@ -494,7 +519,7 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
Rect r = ar.GetUnityRect();
|
Rect r = ar.GetUnityRect();
|
||||||
int width = (int)r.width;
|
int width = (int)r.width;
|
||||||
int height = (int)r.height;
|
int height = (int)r.height;
|
||||||
output = new Texture2D(width, height, textureFormat, mipmaps) { name = ar.name };
|
output = new Texture2D(width, height, textureFormat, mipmaps, linear) { name = ar.name };
|
||||||
output.CopyTextureAttributesFrom(sourceTexture);
|
output.CopyTextureAttributesFrom(sourceTexture);
|
||||||
AtlasUtilities.CopyTexture(sourceTexture, r, output);
|
AtlasUtilities.CopyTexture(sourceTexture, r, output);
|
||||||
CachedRegionTextures.Add(cacheKey, output);
|
CachedRegionTextures.Add(cacheKey, output);
|
||||||
@ -504,17 +529,21 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Texture2D ToTexture (this Sprite s, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps) {
|
static Texture2D ToTexture (this Sprite s, TextureFormat textureFormat = SpineTextureFormat,
|
||||||
|
bool mipmaps = UseMipMaps, bool linear = false) {
|
||||||
|
|
||||||
var spriteTexture = s.texture;
|
var spriteTexture = s.texture;
|
||||||
var r = s.textureRect;
|
var r = s.textureRect;
|
||||||
var newTexture = new Texture2D((int)r.width, (int)r.height, textureFormat, mipmaps);
|
var newTexture = new Texture2D((int)r.width, (int)r.height, textureFormat, mipmaps, linear);
|
||||||
newTexture.CopyTextureAttributesFrom(spriteTexture);
|
newTexture.CopyTextureAttributesFrom(spriteTexture);
|
||||||
AtlasUtilities.CopyTexture(spriteTexture, r, newTexture);
|
AtlasUtilities.CopyTexture(spriteTexture, r, newTexture);
|
||||||
return newTexture;
|
return newTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Texture2D GetClone (this Texture2D t, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps) {
|
static Texture2D GetClone (this Texture2D t, TextureFormat textureFormat = SpineTextureFormat,
|
||||||
var newTexture = new Texture2D((int)t.width, (int)t.height, textureFormat, mipmaps);
|
bool mipmaps = UseMipMaps, bool linear = false) {
|
||||||
|
|
||||||
|
var newTexture = new Texture2D((int)t.width, (int)t.height, textureFormat, mipmaps, linear);
|
||||||
newTexture.CopyTextureAttributesFrom(t);
|
newTexture.CopyTextureAttributesFrom(t);
|
||||||
AtlasUtilities.CopyTexture(t, new Rect(0, 0, t.width, t.height), newTexture);
|
AtlasUtilities.CopyTexture(t, new Rect(0, 0, t.width, t.height), newTexture);
|
||||||
return newTexture;
|
return newTexture;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user