mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
Merge branch '3.8' into 3.9-beta
This commit is contained in:
commit
6fa46fbbae
@ -101,8 +101,7 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
material.CopyPropertiesFromMaterial(materialPropertySource);
|
material.CopyPropertiesFromMaterial(materialPropertySource);
|
||||||
material.shaderKeywords = materialPropertySource.shaderKeywords;
|
material.shaderKeywords = materialPropertySource.shaderKeywords;
|
||||||
}
|
}
|
||||||
var newTexture = t.GetClone(textureFormat, mipmaps);
|
var newTexture = t.GetClone(textureFormat, mipmaps, applyPMA : true);
|
||||||
newTexture.ApplyPMA(true);
|
|
||||||
|
|
||||||
newTexture.name = t.name + "-pma-";
|
newTexture.name = t.name + "-pma-";
|
||||||
material.name = t.name + shader.name;
|
material.name = t.name + shader.name;
|
||||||
@ -163,9 +162,7 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
material.shaderKeywords = materialPropertySource.shaderKeywords;
|
material.shaderKeywords = materialPropertySource.shaderKeywords;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tex = s.ToTexture(textureFormat, mipmaps);
|
var tex = s.ToTexture(textureFormat, mipmaps, applyPMA : true);
|
||||||
tex.ApplyPMA(true);
|
|
||||||
|
|
||||||
tex.name = s.name + "-pma-";
|
tex.name = s.name + "-pma-";
|
||||||
material.name = tex.name + shader.name;
|
material.name = tex.name + shader.name;
|
||||||
|
|
||||||
@ -512,7 +509,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, bool linear = false) {
|
int texturePropertyId = 0, bool linear = false, bool applyPMA = false) {
|
||||||
|
|
||||||
Texture2D output;
|
Texture2D output;
|
||||||
|
|
||||||
@ -525,6 +522,9 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
int height = (int)r.height;
|
int height = (int)r.height;
|
||||||
output = new Texture2D(width, height, textureFormat, mipmaps, linear) { name = ar.name };
|
output = new Texture2D(width, height, textureFormat, mipmaps, linear) { name = ar.name };
|
||||||
output.CopyTextureAttributesFrom(sourceTexture);
|
output.CopyTextureAttributesFrom(sourceTexture);
|
||||||
|
if (applyPMA)
|
||||||
|
AtlasUtilities.CopyTextureApplyPMA(sourceTexture, r, output);
|
||||||
|
else
|
||||||
AtlasUtilities.CopyTexture(sourceTexture, r, output);
|
AtlasUtilities.CopyTexture(sourceTexture, r, output);
|
||||||
CachedRegionTextures.Add(cacheKey, output);
|
CachedRegionTextures.Add(cacheKey, output);
|
||||||
CachedRegionTexturesList.Add(output);
|
CachedRegionTexturesList.Add(output);
|
||||||
@ -534,21 +534,27 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Texture2D ToTexture (this Sprite s, TextureFormat textureFormat = SpineTextureFormat,
|
static Texture2D ToTexture (this Sprite s, TextureFormat textureFormat = SpineTextureFormat,
|
||||||
bool mipmaps = UseMipMaps, bool linear = false) {
|
bool mipmaps = UseMipMaps, bool linear = false, bool applyPMA = 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, linear);
|
var newTexture = new Texture2D((int)r.width, (int)r.height, textureFormat, mipmaps, linear);
|
||||||
newTexture.CopyTextureAttributesFrom(spriteTexture);
|
newTexture.CopyTextureAttributesFrom(spriteTexture);
|
||||||
|
if (applyPMA)
|
||||||
|
AtlasUtilities.CopyTextureApplyPMA(spriteTexture, r, newTexture);
|
||||||
|
else
|
||||||
AtlasUtilities.CopyTexture(spriteTexture, r, newTexture);
|
AtlasUtilities.CopyTexture(spriteTexture, r, newTexture);
|
||||||
return newTexture;
|
return newTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Texture2D GetClone (this Texture2D t, TextureFormat textureFormat = SpineTextureFormat,
|
static Texture2D GetClone (this Texture2D t, TextureFormat textureFormat = SpineTextureFormat,
|
||||||
bool mipmaps = UseMipMaps, bool linear = false) {
|
bool mipmaps = UseMipMaps, bool linear = false, bool applyPMA = false) {
|
||||||
|
|
||||||
var newTexture = new Texture2D((int)t.width, (int)t.height, textureFormat, mipmaps, linear);
|
var newTexture = new Texture2D((int)t.width, (int)t.height, textureFormat, mipmaps, linear);
|
||||||
newTexture.CopyTextureAttributesFrom(t);
|
newTexture.CopyTextureAttributesFrom(t);
|
||||||
|
if (applyPMA)
|
||||||
|
AtlasUtilities.CopyTextureApplyPMA(t, new Rect(0, 0, t.width, t.height), newTexture);
|
||||||
|
else
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -564,6 +570,24 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void CopyTextureApplyPMA (Texture2D source, Rect sourceRect, Texture2D destination) {
|
||||||
|
Color[] pixelBuffer = source.GetPixels((int)sourceRect.x, (int)sourceRect.y, (int)sourceRect.width, (int)sourceRect.height);
|
||||||
|
for (int i = 0, n = pixelBuffer.Length; i < n; i++) {
|
||||||
|
Color p = pixelBuffer[i];
|
||||||
|
float a = p.a;
|
||||||
|
p.r = p.r * a;
|
||||||
|
p.g = p.g * a;
|
||||||
|
p.b = p.b * a;
|
||||||
|
pixelBuffer[i] = p;
|
||||||
|
}
|
||||||
|
destination.SetPixels(pixelBuffer);
|
||||||
|
destination.Apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool IsRenderable (Attachment a) {
|
||||||
|
return a is IHasRendererObject;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a rect with flipped Y so that a Spine atlas rect gets converted to a Unity Sprite rect and vice versa.</summary>
|
/// Get a rect with flipped Y so that a Spine atlas rect gets converted to a Unity Sprite rect and vice versa.</summary>
|
||||||
static Rect SpineUnityFlipRect (this Rect rect, int textureHeight) {
|
static Rect SpineUnityFlipRect (this Rect rect, int textureHeight) {
|
||||||
@ -689,21 +713,6 @@ namespace Spine.Unity.AttachmentTools {
|
|||||||
destination.wrapModeV = source.wrapModeV;
|
destination.wrapModeV = source.wrapModeV;
|
||||||
destination.wrapModeW = source.wrapModeW;
|
destination.wrapModeW = source.wrapModeW;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ApplyPMA (this Texture2D texture, bool applyImmediately = true) {
|
|
||||||
var pixels = texture.GetPixels();
|
|
||||||
for (int i = 0, n = pixels.Length; i < n; i++) {
|
|
||||||
Color p = pixels[i];
|
|
||||||
float a = p.a;
|
|
||||||
p.r = p.r * a;
|
|
||||||
p.g = p.g * a;
|
|
||||||
p.b = p.b * a;
|
|
||||||
pixels[i] = p;
|
|
||||||
}
|
|
||||||
texture.SetPixels(pixels);
|
|
||||||
if (applyImmediately)
|
|
||||||
texture.Apply();
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
static float InverseLerp (float a, float b, float value) {
|
static float InverseLerp (float a, float b, float value) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user