diff --git a/CHANGELOG.md b/CHANGELOG.md index 392258e3f..a74a93257 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ * Added support for rotated regions in texture atlas loaded via StarlingAtlasAttachmentLoader. * Added support for vertex effects. See `RaptorExample.as` * Added 'getTexture()' method to 'StarlingTextureAtlasAttachmentLoader' + * Breaking change: if a skeleton requires two color tinting, you have to enable it via `SkeletonSprite.twoColorTint = true`. In this case the skeleton will use the `TwoColorMeshStyle`, which internally uses a different vertex layout and shader. This means that skeletons with two color tinting enabled will break batching and hence increase the number of draw calls in your app. ## C * **Breaking changes** diff --git a/spine-starling/spine-starling-example/lib/spine-starling.swc b/spine-starling/spine-starling-example/lib/spine-starling.swc index eaa134509..f360d6595 100644 Binary files a/spine-starling/spine-starling-example/lib/spine-starling.swc and b/spine-starling/spine-starling-example/lib/spine-starling.swc differ diff --git a/spine-starling/spine-starling-example/src/spine/examples/CoinExample.as b/spine-starling/spine-starling-example/src/spine/examples/CoinExample.as index eb0ee2248..2c1978d55 100644 --- a/spine-starling/spine-starling-example/src/spine/examples/CoinExample.as +++ b/spine-starling/spine-starling-example/src/spine/examples/CoinExample.as @@ -72,6 +72,11 @@ package spine.examples { skeleton.state.timeScale = 0.5; skeleton.state.update(0.25); skeleton.state.apply(skeleton.skeleton); + + // enable two color tinting, which breaks batching between this skeleton + // and other Starling objects. + skeleton.twoColorTint = true; + skeleton.skeleton.updateWorldTransform(); addChild(skeleton); diff --git a/spine-starling/spine-starling/src/spine/starling/SkeletonSprite.as b/spine-starling/spine-starling/src/spine/starling/SkeletonSprite.as index 7c4c885c7..f1c4d1463 100644 --- a/spine-starling/spine-starling/src/spine/starling/SkeletonSprite.as +++ b/spine-starling/spine-starling/src/spine/starling/SkeletonSprite.as @@ -59,9 +59,9 @@ package spine.starling { static private var _tempMatrix : Matrix = new Matrix(); static private var _tempVertices : Vector. = new Vector.(8); static internal var blendModes : Vector. = new [BlendMode.NORMAL, BlendMode.ADD, BlendMode.MULTIPLY, BlendMode.SCREEN]; - private var _skeleton : Skeleton; - public var batchable : Boolean = true; + private var _skeleton : Skeleton; private var _smoothing : String = "bilinear"; + private var _twoColorTint : Boolean = false; private static var clipper: SkeletonClipping = new SkeletonClipping(); private static var QUAD_INDICES : Vector. = new [0, 1, 2, 2, 3, 0]; @@ -112,7 +112,7 @@ package spine.starling { region.rendererObject = mesh = new SkeletonMesh(Image(region.rendererObject).texture); if (region.rendererObject is AtlasRegion) region.rendererObject = mesh = new SkeletonMesh(Image(AtlasRegion(region.rendererObject).rendererObject).texture); - mesh.setStyle(new TwoColorMeshStyle()); + if (_twoColorTint) mesh.setStyle(new TwoColorMeshStyle()); indexData = mesh.getIndexData(); for (ii = 0; ii < indices.length; ii++) indexData.setIndex(ii, indices[ii]); @@ -136,7 +136,7 @@ package spine.starling { meshAttachment.rendererObject = mesh = new SkeletonMesh(Image(meshAttachment.rendererObject).texture); if (meshAttachment.rendererObject is AtlasRegion) meshAttachment.rendererObject = mesh = new SkeletonMesh(Image(AtlasRegion(meshAttachment.rendererObject).rendererObject).texture); - mesh.setStyle(new TwoColorMeshStyle()); + if (_twoColorTint) mesh.setStyle(new TwoColorMeshStyle()); indexData = mesh.getIndexData(); indicesLength = meshAttachment.triangles.length; @@ -198,13 +198,13 @@ package spine.starling { tempVertex.dark.setFromColor(tempDark); vertexEffect.transform(tempVertex); vertexData.colorize("color", Color.rgb(tempVertex.light.r * 255, tempVertex.light.g * 255, tempVertex.light.b * 255), tempVertex.light.a, ii, 1); - vertexData.colorize("color2", Color.rgb(tempVertex.dark.r * 255, tempVertex.dark.g * 255, tempVertex.dark.b * 255), a, ii, 1); + if (_twoColorTint) vertexData.colorize("color2", Color.rgb(tempVertex.dark.r * 255, tempVertex.dark.g * 255, tempVertex.dark.b * 255), a, ii, 1); mesh.setVertexPosition(ii, tempVertex.x, tempVertex.y); mesh.setTexCoords(ii, tempVertex.u, tempVertex.v); } } else { vertexData.colorize("color", rgb, a); - vertexData.colorize("color2", dark); + if (_twoColorTint) vertexData.colorize("color2", dark); for (ii = 0, iii = 0; ii < verticesCount; ii++, iii += 2) { mesh.setVertexPosition(ii, worldVertices[iii], worldVertices[iii + 1]); mesh.setTexCoords(ii, uvs[iii], uvs[iii + 1]); @@ -303,5 +303,13 @@ package spine.starling { public function set smoothing(smoothing : String) : void { _smoothing = smoothing; } + + public function get twoColorTint() : Boolean { + return _twoColorTint; + } + + public function set twoColorTint(tint : Boolean) : void { + _twoColorTint = tint; + } } } \ No newline at end of file diff --git a/spine-starling/spine-starling/src/spine/starling/TwoColorEffect.as b/spine-starling/spine-starling/src/spine/starling/TwoColorEffect.as index 462f178f1..9f39a75f2 100644 --- a/spine-starling/spine-starling/src/spine/starling/TwoColorEffect.as +++ b/spine-starling/spine-starling/src/spine/starling/TwoColorEffect.as @@ -39,6 +39,7 @@ package spine.starling { public class TwoColorEffect extends MeshEffect { public static const VERTEX_FORMAT : VertexDataFormat = TwoColorMeshStyle.VERTEX_FORMAT; + private static const VECTOR_ONES:Vector. = Vector.([1, 1, 1, 1]); override protected function createProgram() : Program { // v0 -> tex coords @@ -75,7 +76,7 @@ package spine.starling { vertexFormat.setVertexBufferAt(3, vertexBuffer, "color2"); // fc0 -> (1, 1, 1, 1) - context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, Vector.([1, 1, 1, 1])); + context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, VECTOR_ONES); } override protected function afterDraw(context : Context3D) : void { diff --git a/spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs b/spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs index ca11f4269..846113088 100644 --- a/spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs +++ b/spine-unity/Assets/spine-unity/Editor/SpineAttributeDrawers.cs @@ -159,6 +159,10 @@ namespace Spine.Unity.Editor { protected override Texture2D Icon { get { return SpineEditorUtilities.Icons.slot; } } protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineSlot targetAttribute, SkeletonData data) { + + if (TargetAttribute.includeNone) + menu.AddItem(new GUIContent(NoneString), string.IsNullOrEmpty(property.stringValue), HandleSelect, new SpineDrawerValuePair(string.Empty, property)); + for (int i = 0; i < data.Slots.Count; i++) { string name = data.Slots.Items[i].Name; if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal)) {