mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] Fixed GetRepackedSkin partially ignoring textureFormat argument. Closes #1593. Also added optional TextureFormat array parameter for additional texture layers.
This commit is contained in:
parent
3e02f02f63
commit
7b02253831
@ -232,17 +232,23 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
/// <param name="additionalOutputTextures">When <c>additionalTexturePropertyIDsToCopy</c> is non-null,
|
/// <param name="additionalOutputTextures">When <c>additionalTexturePropertyIDsToCopy</c> is non-null,
|
||||||
/// this array will be filled with the resulting repacked texture for every property,
|
/// this array will be filled with the resulting repacked texture for every property,
|
||||||
/// just as the main repacked texture is assigned to <c>outputTexture</c>.</param>
|
/// just as the main repacked texture is assigned to <c>outputTexture</c>.</param>
|
||||||
|
/// <param name="additionalTextureFormats">When <c>additionalTexturePropertyIDsToCopy</c> is non-null,
|
||||||
|
/// 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>
|
||||||
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) {
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -258,12 +264,17 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
/// <param name="additionalOutputTextures">When <c>additionalTexturePropertyIDsToCopy</c> is non-null,
|
/// <param name="additionalOutputTextures">When <c>additionalTexturePropertyIDsToCopy</c> is non-null,
|
||||||
/// this array will be filled with the resulting repacked texture for every property,
|
/// this array will be filled with the resulting repacked texture for every property,
|
||||||
/// just as the main repacked texture is assigned to <c>outputTexture</c>.</param>
|
/// just as the main repacked texture is assigned to <c>outputTexture</c>.</param>
|
||||||
|
/// <param name="additionalTextureFormats">When <c>additionalTexturePropertyIDsToCopy</c> is non-null,
|
||||||
|
/// 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>
|
||||||
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) {
|
||||||
|
|
||||||
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");
|
||||||
@ -303,8 +314,10 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
originalRegions.Add(region);
|
originalRegions.Add(region);
|
||||||
for (int i = 0; i < numTextureParamsToRepack; ++i) {
|
for (int i = 0; i < numTextureParamsToRepack; ++i) {
|
||||||
Texture2D regionTexture = (i == 0 ?
|
Texture2D regionTexture = (i == 0 ?
|
||||||
region.ToTexture(mipmaps : mipmaps) :
|
region.ToTexture(textureFormat, mipmaps) :
|
||||||
region.ToTexture(mipmaps : mipmaps, texturePropertyId: additionalTexturePropertyIDsToCopy[i - 1]));
|
region.ToTexture((additionalTextureFormats != null && i - 1 < additionalTextureFormats.Length) ?
|
||||||
|
additionalTextureFormats[i - 1] : textureFormat,
|
||||||
|
mipmaps, additionalTexturePropertyIDsToCopy[i - 1]));
|
||||||
texturesToPackAtParam[i].Add(regionTexture);
|
texturesToPackAtParam[i].Add(regionTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,7 +345,10 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
Rect[] rects = null;
|
Rect[] rects = null;
|
||||||
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, textureFormat, mipmaps);
|
var newTexture = new Texture2D(maxAtlasSize, maxAtlasSize,
|
||||||
|
(additionalTextureFormats != null && i - 1 < additionalTextureFormats.Length) ?
|
||||||
|
additionalTextureFormats[i - 1] : textureFormat,
|
||||||
|
mipmaps);
|
||||||
newTexture.mipMapBias = AtlasUtilities.DefaultMipmapBias;
|
newTexture.mipMapBias = AtlasUtilities.DefaultMipmapBias;
|
||||||
|
|
||||||
var texturesToPack = texturesToPackAtParam[i];
|
var texturesToPack = texturesToPackAtParam[i];
|
||||||
@ -387,14 +403,20 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
/// <param name="additionalOutputTextures">When <c>additionalTexturePropertyIDsToCopy</c> is non-null,
|
/// <param name="additionalOutputTextures">When <c>additionalTexturePropertyIDsToCopy</c> is non-null,
|
||||||
/// this array will be filled with the resulting repacked texture for every property,
|
/// this array will be filled with the resulting repacked texture for every property,
|
||||||
/// just as the main repacked texture is assigned to <c>outputTexture</c>.</param>
|
/// just as the main repacked texture is assigned to <c>outputTexture</c>.</param>
|
||||||
|
/// <param name="additionalTextureFormats">When <c>additionalTexturePropertyIDsToCopy</c> is non-null,
|
||||||
|
/// 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>
|
||||||
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) {
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -405,7 +427,8 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
public static Skin GetRepackedSkin (this Skin o, string newName, Shader shader, out Material outputMaterial, out Texture2D outputTexture,
|
public static Skin GetRepackedSkin (this Skin o, string newName, Shader shader, 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,
|
||||||
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) {
|
||||||
|
|
||||||
outputTexture = null;
|
outputTexture = null;
|
||||||
|
|
||||||
@ -424,7 +447,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);
|
additionalTexturePropertyIDsToCopy, additionalOutputTextures, additionalTextureFormats);
|
||||||
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++];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user