Skip to content

Commit cd22906

Browse files
committed
[unity] Added support for blend modes at Spine Visual Element (UI Toolkit). Closes #3019. See #1943.
1 parent e5f7ffb commit cd22906

File tree

54 files changed

+4259
-69
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+4259
-69
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@
366366
- Added define `SPINE_DISABLE_THREADING` to disable threaded animation and mesh generation entirely, removing the respective code. This define can be set as `Scripting Define Symbols` globally or for selective build profiles where desired.
367367
- Added automatic load balancing (work stealing) for improved performance when using threaded animation and mesh generation, enabled by default. Load balancing can be disabled via a new Spine preferences parameter `Threading Defaults - Load Balancing` setting a build define accordingly.
368368
Additional configuration parameters `SkeletonUpdateSystem.UpdateChunksPerThread` and `LateUpdateChunksPerThread` are available to fine-tune the chunk count for load balancing. A minimum of 8 chunks is recommended with load balancing enabled. Higher values add higher overhead with potentially detrimental effect on performance.
369+
- Spine UI Toolkit UPM package now supports rendering back-face triangles. Enable `Flip Back Faces` to automatically fix back-face geometry in an additional pass (defaults to enabled). Disable the setting to save additional processing overhead.
370+
- Spine UI Toolkit UPM package now supports PMA atlas textures. At the `SpineVisualElement` expand `Blend Mode Materials` and hit `Detect Materials` to automatically assign the proper PMA or straight alpha material at `Normal Material`. Unity minimum version increased to 6000.3 which added support for UI Toolkit materials.
371+
- Spine UI Toolkit UPM package now supports all Spine blend modes via blend mode materials and multiple materials per skeleton. Enable `Multiple Materials` (enabled by default), expand `Blend Mode Materials` and hit `Detect Materials` to automatically assign the correct PMA or straight alpha blend mode materials.
369372

370373
- **Deprecated**
371374

spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SkeletonGraphicUtility.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,15 @@ public static void DetectPMAVertexColors (SkeletonGraphic skeletonGraphic) {
100100

101101
public static bool IsSkeletonTexturePMA (SkeletonGraphic skeletonGraphic, out bool detectionSucceeded) {
102102
Texture texture = skeletonGraphic.mainTexture;
103+
return IsSkeletonTexturePMA(texture, skeletonGraphic.name, out detectionSucceeded);
104+
}
105+
106+
public static bool IsSkeletonTexturePMA (Texture texture, string skeletonName, out bool detectionSucceeded) {
103107
string texturePath = AssetDatabase.GetAssetPath(texture.GetInstanceID());
104108
TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(texturePath);
105109
if (importer.alphaIsTransparency != importer.sRGBTexture) {
106110
Debug.LogWarning(string.Format("Texture '{0}' at skeleton '{1}' is neither configured correctly for " +
107-
"PMA nor Straight Alpha.", texture, skeletonGraphic), texture);
111+
"PMA nor Straight Alpha.", texture, skeletonName), texture);
108112
detectionSucceeded = false;
109113
return false;
110114
}

spine-unity/Assets/Spine/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "com.esotericsoftware.spine.spine-unity",
33
"displayName": "spine-unity Runtime",
44
"description": "This plugin provides the spine-unity runtime core and examples. Spine Examples can be installed via the Samples tab.",
5-
"version": "4.3.41",
5+
"version": "4.3.42",
66
"unity": "2018.3",
77
"author": {
88
"name": "Esoteric Software",

spine-unity/Modules/com.esotericsoftware.spine.ui-toolkit/Editor/SpineVisualElementAttributeDrawers.cs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,117 @@
2929

3030
//#define CHANGE_BOUNDS_ON_ANIMATION_CHANGE
3131

32+
using System.Linq;
3233
using UnityEditor;
3334
using UnityEditor.UIElements;
3435
using UnityEngine;
3536
using UnityEngine.UIElements;
3637

3738
namespace Spine.Unity.Editor {
3839

40+
[CustomPropertyDrawer(typeof(UITKBlendModeMaterialsAttribute))]
41+
public class UITKBlendModeMaterialsAttributeDrawer : PropertyDrawer {
42+
43+
protected UITKBlendModeMaterialsAttribute TargetAttribute { get { return (UITKBlendModeMaterialsAttribute)attribute; } }
44+
45+
public override VisualElement CreatePropertyGUI (SerializedProperty materialsProperty) {
46+
var container = new VisualElement();
47+
PropertyField blendModeMaterials = new PropertyField();
48+
blendModeMaterials.BindProperty(materialsProperty);
49+
50+
SerializedProperty normalMaterialProperty = materialsProperty.FindPropertyRelative("normalMaterial");
51+
SerializedProperty additiveMaterialProperty = materialsProperty.FindPropertyRelative("additiveMaterial");
52+
SerializedProperty multiplyMaterialProperty = materialsProperty.FindPropertyRelative("multiplyMaterial");
53+
SerializedProperty screenMaterialProperty = materialsProperty.FindPropertyRelative("screenMaterial");
54+
PropertyField normalField = new PropertyField();
55+
PropertyField additiveField = new PropertyField();
56+
PropertyField multiplyField = new PropertyField();
57+
PropertyField screenField = new PropertyField();
58+
59+
normalField.BindProperty(normalMaterialProperty);
60+
additiveField.BindProperty(additiveMaterialProperty);
61+
multiplyField.BindProperty(multiplyMaterialProperty);
62+
screenField.BindProperty(screenMaterialProperty);
63+
64+
var parentPropertyPath = materialsProperty.propertyPath.Substring(0, materialsProperty.propertyPath.LastIndexOf('.'));
65+
var parent = materialsProperty.serializedObject.FindProperty(parentPropertyPath);
66+
SerializedProperty skeletonDataProperty = parent.FindPropertyRelative(TargetAttribute.dataField);
67+
68+
Button detectMaterialsButton = new Button(() => {
69+
DetectMaterials(materialsProperty, (SkeletonDataAsset)skeletonDataProperty.objectReferenceValue);
70+
});
71+
detectMaterialsButton.text = "Detect Materials";
72+
container.Add(detectMaterialsButton);
73+
74+
//container.Add(blendModeMaterials);
75+
container.Add(normalField);
76+
container.Add(additiveField);
77+
container.Add(multiplyField);
78+
container.Add(screenField);
79+
80+
container.Bind(materialsProperty.serializedObject);
81+
return container;
82+
}
83+
84+
protected void DetectMaterials (SerializedProperty materialsProperty, SkeletonDataAsset skeletonDataAsset) {
85+
if (!skeletonDataAsset)
86+
return;
87+
88+
SerializedProperty normalMaterialProperty = materialsProperty.FindPropertyRelative("normalMaterial");
89+
SerializedProperty additiveMaterialProperty = materialsProperty.FindPropertyRelative("additiveMaterial");
90+
SerializedProperty multiplyMaterialProperty = materialsProperty.FindPropertyRelative("multiplyMaterial");
91+
SerializedProperty screenMaterialProperty = materialsProperty.FindPropertyRelative("screenMaterial");
92+
bool hasPMATextures = HasPMATextures(skeletonDataAsset);
93+
94+
if (hasPMATextures) {
95+
AssignMaterial(normalMaterialProperty, "Spine-UITK-Normal-PMA");
96+
} else {
97+
AssignMaterial(normalMaterialProperty, "Spine-UITK-Normal-Straight");
98+
}
99+
100+
if (!skeletonDataAsset.blendModeMaterials.RequiresBlendModeMaterials) {
101+
additiveMaterialProperty.objectReferenceValue = null;
102+
multiplyMaterialProperty.objectReferenceValue = null;
103+
screenMaterialProperty.objectReferenceValue = null;
104+
} else {
105+
if (hasPMATextures) {
106+
AssignMaterial(additiveMaterialProperty, "Spine-UITK-Additive-PMA");
107+
AssignMaterial(multiplyMaterialProperty, "Spine-UITK-Multiply-PMA");
108+
AssignMaterial(screenMaterialProperty, "Spine-UITK-Screen-PMA");
109+
} else {
110+
AssignMaterial(additiveMaterialProperty, "Spine-UITK-Additive-Straight");
111+
AssignMaterial(multiplyMaterialProperty, "Spine-UITK-Multiply-Straight");
112+
AssignMaterial(screenMaterialProperty, "Spine-UITK-Screen-Straight");
113+
}
114+
}
115+
materialsProperty.serializedObject.ApplyModifiedProperties();
116+
}
117+
118+
bool HasPMATextures (SkeletonDataAsset skeletonDataAsset) {
119+
if (skeletonDataAsset.atlasAssets.Length == 0) return false;
120+
AtlasAssetBase firstAtlasAsset = skeletonDataAsset.atlasAssets[0];
121+
if (firstAtlasAsset.MaterialCount == 0) return false;
122+
123+
Texture texture = firstAtlasAsset.Materials.First().mainTexture;
124+
bool detectionSucceeded;
125+
return IsSkeletonTexturePMA(texture, skeletonDataAsset.name, out detectionSucceeded);
126+
}
127+
128+
void AssignMaterial (SerializedProperty property, string name) {
129+
Material material = MaterialWithName(name);
130+
if (material != null)
131+
property.objectReferenceValue = material;
132+
}
133+
134+
public static Material MaterialWithName (string name) {
135+
return SkeletonGraphicUtility.MaterialWithName(name);
136+
}
137+
138+
public static bool IsSkeletonTexturePMA (Texture texture, string skeletonName, out bool detectionSucceeded) {
139+
return SkeletonGraphicUtility.IsSkeletonTexturePMA(texture, skeletonName, out detectionSucceeded);
140+
}
141+
}
142+
39143
[CustomPropertyDrawer(typeof(BoundsFromAnimationAttribute))]
40144
public class BoundsFromAnimationAttributeDrawer : PropertyDrawer {
41145

spine-unity/Modules/com.esotericsoftware.spine.ui-toolkit/Materials.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!21 &2100000
4+
Material:
5+
serializedVersion: 8
6+
m_ObjectHideFlags: 0
7+
m_CorrespondingSourceObject: {fileID: 0}
8+
m_PrefabInstance: {fileID: 0}
9+
m_PrefabAsset: {fileID: 0}
10+
m_Name: Spine-UITK-Additive-PMA
11+
m_Shader: {fileID: 4800000, guid: 9818276b7a7ab2148a8a3ed86c9ac555, type: 3}
12+
m_Parent: {fileID: 0}
13+
m_ModifiedSerializedProperties: 0
14+
m_ValidKeywords: []
15+
m_InvalidKeywords: []
16+
m_LightmapFlags: 4
17+
m_EnableInstancingVariants: 0
18+
m_DoubleSidedGI: 0
19+
m_CustomRenderQueue: -1
20+
stringTagMap: {}
21+
disabledShaderPasses: []
22+
m_LockedProperties:
23+
m_SavedProperties:
24+
serializedVersion: 3
25+
m_TexEnvs:
26+
- unity_Lightmaps:
27+
m_Texture: {fileID: 0}
28+
m_Scale: {x: 1, y: 1}
29+
m_Offset: {x: 0, y: 0}
30+
- unity_LightmapsInd:
31+
m_Texture: {fileID: 0}
32+
m_Scale: {x: 1, y: 1}
33+
m_Offset: {x: 0, y: 0}
34+
- unity_ShadowMasks:
35+
m_Texture: {fileID: 0}
36+
m_Scale: {x: 1, y: 1}
37+
m_Offset: {x: 0, y: 0}
38+
m_Ints: []
39+
m_Floats:
40+
- _StraightAlphaTexture: 0
41+
m_Colors: []
42+
m_BuildTextureStacks: []
43+
m_AllowLocking: 1

spine-unity/Modules/com.esotericsoftware.spine.ui-toolkit/Materials/Spine-UITK-Additive-PMA.mat.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!21 &2100000
4+
Material:
5+
serializedVersion: 8
6+
m_ObjectHideFlags: 0
7+
m_CorrespondingSourceObject: {fileID: 0}
8+
m_PrefabInstance: {fileID: 0}
9+
m_PrefabAsset: {fileID: 0}
10+
m_Name: Spine-UITK-Additive-Straight
11+
m_Shader: {fileID: 4800000, guid: 9818276b7a7ab2148a8a3ed86c9ac555, type: 3}
12+
m_Parent: {fileID: 0}
13+
m_ModifiedSerializedProperties: 0
14+
m_ValidKeywords: []
15+
m_InvalidKeywords: []
16+
m_LightmapFlags: 4
17+
m_EnableInstancingVariants: 0
18+
m_DoubleSidedGI: 0
19+
m_CustomRenderQueue: -1
20+
stringTagMap: {}
21+
disabledShaderPasses: []
22+
m_LockedProperties:
23+
m_SavedProperties:
24+
serializedVersion: 3
25+
m_TexEnvs:
26+
- unity_Lightmaps:
27+
m_Texture: {fileID: 0}
28+
m_Scale: {x: 1, y: 1}
29+
m_Offset: {x: 0, y: 0}
30+
- unity_LightmapsInd:
31+
m_Texture: {fileID: 0}
32+
m_Scale: {x: 1, y: 1}
33+
m_Offset: {x: 0, y: 0}
34+
- unity_ShadowMasks:
35+
m_Texture: {fileID: 0}
36+
m_Scale: {x: 1, y: 1}
37+
m_Offset: {x: 0, y: 0}
38+
m_Ints: []
39+
m_Floats:
40+
- _StraightAlphaTexture: 1
41+
m_Colors: []
42+
m_BuildTextureStacks: []
43+
m_AllowLocking: 1

spine-unity/Modules/com.esotericsoftware.spine.ui-toolkit/Materials/Spine-UITK-Additive-Straight.mat.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!21 &2100000
4+
Material:
5+
serializedVersion: 8
6+
m_ObjectHideFlags: 0
7+
m_CorrespondingSourceObject: {fileID: 0}
8+
m_PrefabInstance: {fileID: 0}
9+
m_PrefabAsset: {fileID: 0}
10+
m_Name: Spine-UITK-Multiply-PMA
11+
m_Shader: {fileID: 4800000, guid: ed93aea253bcdc94a84ee09cd390c587, type: 3}
12+
m_Parent: {fileID: 0}
13+
m_ModifiedSerializedProperties: 0
14+
m_ValidKeywords: []
15+
m_InvalidKeywords: []
16+
m_LightmapFlags: 4
17+
m_EnableInstancingVariants: 0
18+
m_DoubleSidedGI: 0
19+
m_CustomRenderQueue: -1
20+
stringTagMap: {}
21+
disabledShaderPasses: []
22+
m_LockedProperties:
23+
m_SavedProperties:
24+
serializedVersion: 3
25+
m_TexEnvs:
26+
- unity_Lightmaps:
27+
m_Texture: {fileID: 0}
28+
m_Scale: {x: 1, y: 1}
29+
m_Offset: {x: 0, y: 0}
30+
- unity_LightmapsInd:
31+
m_Texture: {fileID: 0}
32+
m_Scale: {x: 1, y: 1}
33+
m_Offset: {x: 0, y: 0}
34+
- unity_ShadowMasks:
35+
m_Texture: {fileID: 0}
36+
m_Scale: {x: 1, y: 1}
37+
m_Offset: {x: 0, y: 0}
38+
m_Ints: []
39+
m_Floats:
40+
- _StraightAlphaTexture: 0
41+
m_Colors: []
42+
m_BuildTextureStacks: []
43+
m_AllowLocking: 1

0 commit comments

Comments
 (0)