mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 15:24:55 +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.
|
||||
/// 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>
|
||||
/// <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,
|
||||
out Material outputMaterial, out Texture2D outputTexture,
|
||||
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
|
||||
string newAssetName = "Repacked Attachments", bool clearCache = false, bool useOriginalNonrenderables = true,
|
||||
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;
|
||||
GetRepackedAttachments(sourceAttachments, outputAttachments, shader, out outputMaterial, out outputTexture,
|
||||
maxAtlasSize, padding, textureFormat, mipmaps, newAssetName,
|
||||
materialPropertySource, clearCache, useOriginalNonrenderables,
|
||||
additionalTexturePropertyIDsToCopy, additionalOutputTextures,
|
||||
additionalTextureFormats);
|
||||
additionalTextureFormats, additionalTextureIsLinear);
|
||||
}
|
||||
|
||||
/// <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.
|
||||
/// 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>
|
||||
/// <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,
|
||||
out Material outputMaterial, out Texture2D outputTexture,
|
||||
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
|
||||
string newAssetName = "Repacked Attachments",
|
||||
Material materialPropertySource = null, bool clearCache = false, bool useOriginalNonrenderables = true,
|
||||
int[] additionalTexturePropertyIDsToCopy = null, Texture2D[] additionalOutputTextures = null,
|
||||
TextureFormat[] additionalTextureFormats = null) {
|
||||
TextureFormat[] additionalTextureFormats = null, bool[] additionalTextureIsLinear = null) {
|
||||
|
||||
if (sourceAttachments == null) throw new System.ArgumentNullException("sourceAttachments");
|
||||
if (outputAttachments == null) throw new System.ArgumentNullException("outputAttachments");
|
||||
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.
|
||||
var existingRegions = new Dictionary<AtlasRegion, int>();
|
||||
@ -317,7 +335,7 @@ namespace Spine.Unity.AttachmentTools {
|
||||
region.ToTexture(textureFormat, mipmaps) :
|
||||
region.ToTexture((additionalTextureFormats != null && i - 1 < additionalTextureFormats.Length) ?
|
||||
additionalTextureFormats[i - 1] : textureFormat,
|
||||
mipmaps, additionalTexturePropertyIDsToCopy[i - 1]));
|
||||
mipmaps, additionalTexturePropertyIDsToCopy[i - 1], additionalTextureIsLinear[i - 1]));
|
||||
texturesToPackAtParam[i].Add(regionTexture);
|
||||
}
|
||||
|
||||
@ -346,9 +364,10 @@ namespace Spine.Unity.AttachmentTools {
|
||||
for (int i = 0; i < numTextureParamsToRepack; ++i) {
|
||||
// Fill a new texture with the collected attachment textures.
|
||||
var newTexture = new Texture2D(maxAtlasSize, maxAtlasSize,
|
||||
(additionalTextureFormats != null && i - 1 < additionalTextureFormats.Length) ?
|
||||
(i > 0 && additionalTextureFormats != null && i - 1 < additionalTextureFormats.Length) ?
|
||||
additionalTextureFormats[i - 1] : textureFormat,
|
||||
mipmaps);
|
||||
mipmaps,
|
||||
(i > 0) ? additionalTextureIsLinear[i - 1] : false);
|
||||
newTexture.mipMapBias = AtlasUtilities.DefaultMipmapBias;
|
||||
|
||||
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.
|
||||
/// 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>
|
||||
/// <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,
|
||||
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
|
||||
bool useOriginalNonrenderables = true, bool clearCache = false,
|
||||
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,
|
||||
maxAtlasSize, padding, textureFormat, mipmaps, materialPropertySource,
|
||||
clearCache, useOriginalNonrenderables, additionalTexturePropertyIDsToCopy, additionalOutputTextures,
|
||||
additionalTextureFormats);
|
||||
additionalTextureFormats, additionalTextureIsLinear);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -428,7 +453,7 @@ namespace Spine.Unity.AttachmentTools {
|
||||
int maxAtlasSize = 1024, int padding = 2, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
|
||||
Material materialPropertySource = null, bool clearCache = false, bool useOriginalNonrenderables = true,
|
||||
int[] additionalTexturePropertyIDsToCopy = null, Texture2D[] additionalOutputTextures = null,
|
||||
TextureFormat[] additionalTextureFormats = null) {
|
||||
TextureFormat[] additionalTextureFormats = null, bool[] additionalTextureIsLinear = null) {
|
||||
|
||||
outputTexture = null;
|
||||
|
||||
@ -447,7 +472,7 @@ namespace Spine.Unity.AttachmentTools {
|
||||
}
|
||||
GetRepackedAttachments(inoutAttachments, inoutAttachments, materialPropertySource, out outputMaterial, out outputTexture,
|
||||
maxAtlasSize, padding, textureFormat, mipmaps, newName, clearCache, useOriginalNonrenderables,
|
||||
additionalTexturePropertyIDsToCopy, additionalOutputTextures, additionalTextureFormats);
|
||||
additionalTexturePropertyIDsToCopy, additionalOutputTextures, additionalTextureFormats, additionalTextureIsLinear);
|
||||
int i = 0;
|
||||
foreach (var originalSkinEntry in o.Attachments) {
|
||||
var newAttachment = inoutAttachments[i++];
|
||||
@ -483,7 +508,7 @@ namespace Spine.Unity.AttachmentTools {
|
||||
/// <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>
|
||||
public static Texture2D ToTexture (this AtlasRegion ar, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps,
|
||||
int texturePropertyId = 0) {
|
||||
int texturePropertyId = 0, bool linear = false) {
|
||||
|
||||
Texture2D output;
|
||||
|
||||
@ -494,7 +519,7 @@ namespace Spine.Unity.AttachmentTools {
|
||||
Rect r = ar.GetUnityRect();
|
||||
int width = (int)r.width;
|
||||
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);
|
||||
AtlasUtilities.CopyTexture(sourceTexture, r, output);
|
||||
CachedRegionTextures.Add(cacheKey, output);
|
||||
@ -504,17 +529,21 @@ namespace Spine.Unity.AttachmentTools {
|
||||
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 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);
|
||||
AtlasUtilities.CopyTexture(spriteTexture, r, newTexture);
|
||||
return newTexture;
|
||||
}
|
||||
|
||||
static Texture2D GetClone (this Texture2D t, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps) {
|
||||
var newTexture = new Texture2D((int)t.width, (int)t.height, textureFormat, mipmaps);
|
||||
static Texture2D GetClone (this Texture2D t, TextureFormat textureFormat = SpineTextureFormat,
|
||||
bool mipmaps = UseMipMaps, bool linear = false) {
|
||||
|
||||
var newTexture = new Texture2D((int)t.width, (int)t.height, textureFormat, mipmaps, linear);
|
||||
newTexture.CopyTextureAttributesFrom(t);
|
||||
AtlasUtilities.CopyTexture(t, new Rect(0, 0, t.width, t.height), newTexture);
|
||||
return newTexture;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user