Преглед изворни кода

[love] Refactored renderer, should be quite a bit faster now. Added clipping support.

badlogic пре 8 година
родитељ
комит
bc7b061fe2

+ 4 - 0
examples/export/runtimes.sh

@@ -110,6 +110,10 @@ cp -f ../stretchyman/export/stretchyman.png ../../spine-corona/data
 
 echo "spine-love"
 rm -f ../../spine-love/data/*
+cp -f ../coin/export/coin.json ../../spine-love/data
+cp -f ../coin/export/coin.atlas ../../spine-love/data
+cp -f ../coin/export/coin.png ../../spine-love/data
+
 cp -f ../goblins/export/goblins-mesh.json ../../spine-love/data
 cp -f ../goblins/export/goblins.atlas ../../spine-love/data
 cp -f ../goblins/export/goblins.png ../../spine-love/data

+ 27 - 0
spine-love/data/coin.atlas

@@ -0,0 +1,27 @@
+
+coin.png
+size: 512,128
+format: RGBA8888
+filter: Linear,Linear
+repeat: none
+coin
+  rotate: false
+  xy: 2, 2
+  size: 130, 123
+  orig: 130, 123
+  offset: 0, 0
+  index: -1
+coin-invert
+  rotate: false
+  xy: 134, 2
+  size: 130, 123
+  orig: 130, 123
+  offset: 0, 0
+  index: -1
+shine
+  rotate: false
+  xy: 266, 2
+  size: 36, 123
+  orig: 36, 123
+  offset: 0, 0
+  index: -1

+ 171 - 0
spine-love/data/coin.json

@@ -0,0 +1,171 @@
+{
+"skeleton": { "hash": "4cI0KYdFTZbO7vkQYPFQN+yauDw", "spine": "3.6.14-beta", "width": 260, "height": 359.92, "images": "./images/" },
+"bones": [
+	{ "name": "root" },
+	{ "name": "coin-root", "parent": "root", "y": 300, "color": "ff0000ff" },
+	{ "name": "coin", "parent": "coin-root", "color": "ffe037ff" },
+	{ "name": "clipping", "parent": "coin", "x": 7.25, "scaleX": 0.96, "scaleY": 0.967, "color": "ffe037ff" },
+	{ "name": "shine", "parent": "coin-root", "rotation": -24.17, "scaleY": 1.478, "color": "ffffffff" }
+],
+"slots": [
+	{ "name": "images/coin", "bone": "coin", "attachment": "coin" },
+	{ "name": "clipping", "bone": "clipping", "attachment": "clipping" },
+	{ "name": "images/shine", "bone": "shine", "color": "ffffff93", "attachment": "shine", "blend": "additive" }
+],
+"skins": {
+	"default": {
+		"clipping": {
+			"clipping": {
+				"type": "clipping",
+				"end": "images/coin",
+				"vertexCount": 36,
+				"vertices": [ 0.82, 120.87, 25.27, 118.4, 49.23, 110.99, 71.46, 98.15, 88.25, 83.08, 102.58, 64.8, 112.21, 46.03, 117.89, 28, 121.35, 9.23, 120.61, -11.52, 117.65, -30.29, 111.72, -48.08, 102.33, -65.61, 89.47, -82.23, 76.24, -94.71, 61.33, -105.13, 46.26, -112.54, 28.73, -118.22, 8.73, -120.89, -12.27, -120.89, -32.03, -116.94, -51.04, -110.27, -67.59, -101.63, -82.91, -88.78, -96.25, -74.21, -108.35, -55.68, -116.5, -35.43, -120.7, -14.19, -121.69, 5.57, -118.97, 27.56, -111.56, 49.04, -100.43, 69.69, -84.38, 87.47, -66.1, 102.29, -45.6, 112.67, -23.62, 118.59 ],
+				"color": "ce3a3aff"
+			}
+		},
+		"images/coin": {
+			"coin": {
+				"type": "mesh",
+				"uvs": [ 1, 1, 0.51662, 0.99661, 0.38311, 0.99567, 0.29957, 0.96664, 0.22817, 0.93237, 0.16736, 0.88777, 0.11597, 0.83202, 0.06732, 0.76058, 0.03288, 0.69072, 0.00816, 0.61391, 0, 0.52843, 0, 0.43778, 0.02307, 0.33992, 0.06544, 0.24204, 0.11924, 0.16659, 0.17691, 0.10919, 0.24399, 0.06252, 0.31853, 0.02742, 0.41818, 0.0076, 0.52609, 1.0E-5, 1, 0, 0.45994, 0.99066, 0.37873, 0.97119, 0.30719, 0.94057, 0.24626, 0.89841, 0.19491, 0.85157, 0.14893, 0.79961, 0.11299, 0.73943, 0.08595, 0.67565, 0.06609, 0.60105, 0.05753, 0.52647, 0.05856, 0.44906, 0.07176, 0.36094, 0.10407, 0.28078, 0.15657, 0.19211, 0.22811, 0.1162, 0.29907, 0.0658, 0.38388, 0.02814, 0.46119, 0.00993 ],
+				"triangles": [ 38, 18, 19, 37, 17, 18, 37, 18, 38, 36, 16, 17, 36, 17, 37, 35, 15, 16, 35, 16, 36, 34, 14, 15, 34, 15, 35, 34, 33, 13, 34, 13, 14, 12, 13, 33, 32, 12, 33, 11, 12, 32, 31, 11, 32, 31, 10, 11, 30, 10, 31, 31, 33, 30, 29, 30, 33, 29, 9, 10, 29, 10, 30, 32, 33, 31, 34, 28, 29, 8, 9, 29, 8, 29, 28, 33, 34, 29, 25, 26, 27, 7, 8, 28, 7, 28, 27, 27, 28, 25, 26, 7, 27, 6, 7, 26, 34, 36, 28, 28, 36, 25, 6, 26, 25, 5, 6, 25, 34, 35, 36, 37, 24, 25, 5, 25, 24, 4, 5, 24, 36, 37, 25, 22, 23, 24, 4, 24, 23, 3, 4, 23, 24, 21, 22, 3, 23, 22, 38, 24, 37, 24, 1, 21, 2, 22, 21, 3, 22, 2, 1, 38, 19, 1, 24, 38, 2, 21, 1, 19, 20, 0, 1, 19, 0 ],
+				"vertices": [ 130, -123.5, 4.32, -122.66, -30.39, -122.43, -52.11, -115.26, -70.68, -106.8, -86.49, -95.78, -99.85, -82.01, -112.5, -64.36, -121.45, -47.11, -127.88, -28.14, -130, -7.02, -130, 15.37, -124, 39.54, -112.99, 63.72, -99, 82.35, -84, 96.53, -66.56, 108.06, -47.18, 116.73, -21.27, 121.62, 6.78, 123.5, 130, 123.5, -10.42, -121.19, -31.53, -116.39, -50.13, -108.82, -65.97, -98.41, -79.32, -86.84, -91.28, -74, -100.62, -59.14, -107.65, -43.39, -112.82, -24.96, -115.04, -6.54, -114.77, 12.58, -111.34, 34.35, -102.94, 54.15, -89.29, 76.05, -70.69, 94.8, -52.24, 107.25, -30.19, 116.55, -10.09, 121.05 ],
+				"hull": 21,
+				"edges": [ 0, 40, 42, 44, 44, 46, 46, 48, 48, 50, 50, 52, 52, 54, 54, 56, 56, 58, 58, 60, 60, 62, 62, 64, 64, 66, 66, 68, 68, 70, 70, 72, 72, 74, 74, 76, 36, 34, 34, 32, 32, 30, 30, 28, 28, 26, 26, 24, 24, 22, 20, 22, 20, 18, 18, 16, 16, 14, 14, 12, 12, 10, 10, 8, 8, 6, 6, 4, 0, 2, 2, 4, 42, 2, 38, 40, 36, 38, 76, 38, 2, 38 ],
+				"width": 259,
+				"height": 245
+			},
+			"coin-invert": {
+				"type": "mesh",
+				"uvs": [ 0.61921, 0.00932, 0.70137, 0.03058, 0.76675, 0.06301, 0.82357, 0.10192, 0.86533, 0.14084, 0.90128, 0.1866, 0.92763, 0.22768, 0.95707, 0.28353, 0.97795, 0.33937, 0.99074, 0.38663, 1, 0.45194, 1, 0.50671, 1, 0.56148, 0.98993, 0.62238, 0.97282, 0.6757, 0.95125, 0.73083, 0.91771, 0.78704, 0.88283, 0.83498, 0.84141, 0.87966, 0.79349, 0.91785, 0.73701, 0.95172, 0.65999, 0.98127, 0.60659, 0.991, 0.51662, 0.99661, 0, 1, 0, 0, 0.52609, 1.0E-5, 0.57849, 0.98348, 0.64806, 0.96162, 0.70899, 0.92882, 0.75987, 0.89639, 0.80219, 0.85685, 0.83745, 0.81722, 0.86381, 0.77794, 0.89445, 0.72582, 0.9167, 0.67213, 0.93142, 0.61628, 0.94164, 0.56011, 0.94506, 0.50823, 0.9437, 0.45454, 0.93514, 0.39905, 0.91905, 0.34031, 0.89748, 0.28194, 0.8691, 0.2284, 0.83932, 0.18768, 0.79995, 0.143, 0.76298, 0.10841, 0.71814, 0.07598, 0.66748, 0.04824, 0.61408, 0.0277, 0.5665, 0.01437 ],
+				"triangles": [ 50, 26, 0, 49, 50, 0, 48, 0, 1, 49, 0, 48, 47, 1, 2, 48, 1, 47, 46, 47, 2, 46, 2, 3, 45, 46, 3, 45, 3, 4, 44, 45, 4, 44, 4, 5, 43, 44, 5, 43, 5, 6, 42, 43, 6, 42, 6, 7, 41, 42, 7, 41, 7, 8, 40, 41, 8, 40, 8, 9, 39, 40, 9, 10, 39, 9, 39, 10, 11, 38, 39, 11, 41, 40, 38, 38, 40, 39, 38, 11, 12, 37, 38, 12, 38, 36, 41, 37, 36, 38, 13, 37, 12, 36, 37, 13, 36, 43, 41, 41, 43, 42, 14, 36, 13, 35, 36, 14, 44, 43, 36, 35, 34, 36, 15, 35, 14, 34, 35, 15, 44, 36, 45, 34, 33, 36, 16, 34, 15, 33, 34, 16, 48, 47, 49, 36, 33, 45, 17, 33, 16, 32, 33, 17, 32, 31, 33, 18, 32, 17, 31, 32, 18, 33, 29, 45, 45, 47, 46, 31, 30, 33, 19, 30, 31, 19, 31, 18, 49, 47, 45, 30, 29, 33, 20, 29, 30, 20, 30, 19, 50, 49, 29, 45, 29, 49, 21, 28, 29, 21, 29, 20, 29, 27, 50, 28, 27, 29, 22, 27, 28, 22, 28, 21, 23, 25, 26, 23, 26, 50, 23, 50, 27, 23, 27, 22, 24, 25, 23 ],
+				"vertices": [ 42.18, 121.2, 63.54, 115.95, 80.54, 107.94, 95.31, 98.32, 106.17, 88.71, 115.51, 77.41, 122.37, 67.26, 130.02, 53.47, 135.45, 39.68, 138.77, 28, 141.18, 11.87, 141.18, -1.66, 141.18, -15.19, 138.56, -30.23, 134.11, -43.4, 128.51, -57.02, 119.79, -70.9, 110.72, -82.74, 99.95, -93.78, 87.49, -103.21, 72.8, -111.58, 52.78, -118.87, 38.9, -121.28, 15.5, -122.66, -118.82, -123.5, -118.82, 123.5, 17.97, 123.5, 31.59, -119.42, 49.68, -114.02, 65.52, -105.92, 78.75, -97.91, 89.75, -88.14, 98.92, -78.35, 105.77, -68.65, 113.74, -55.78, 119.52, -42.52, 123.35, -28.72, 126.01, -14.85, 126.9, -2.03, 126.54, 11.23, 124.32, 24.94, 120.13, 39.44, 114.53, 53.86, 107.15, 67.09, 99.4, 77.14, 89.17, 88.18, 79.56, 96.72, 67.9, 104.73, 54.73, 111.59, 40.84, 116.66, 28.47, 119.95 ],
+				"hull": 27,
+				"edges": [ 46, 52, 46, 54, 54, 56, 56, 58, 58, 60, 60, 62, 62, 64, 64, 66, 66, 68, 68, 70, 70, 72, 72, 74, 74, 76, 76, 78, 78, 80, 80, 82, 82, 84, 84, 86, 86, 88, 88, 90, 90, 92, 92, 94, 94, 96, 96, 98, 98, 100, 100, 52, 52, 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 20, 22, 22, 24, 24, 26, 26, 28, 28, 30, 30, 32, 32, 34, 34, 36, 36, 38, 38, 40, 40, 42, 42, 44, 44, 46, 48, 50, 50, 52, 46, 48, 16, 18, 18, 20 ],
+				"width": 259,
+				"height": 245
+			}
+		},
+		"images/shine": {
+			"shine": { "width": 72, "height": 245 }
+		}
+	}
+},
+"animations": {
+	"rotate": {
+		"slots": {
+			"images/coin": {
+				"attachment": [
+					{ "time": 0.5, "name": "coin-invert" }
+				]
+			},
+			"images/shine": {
+				"color": [
+					{ "time": 0, "color": "ffffff00" },
+					{ "time": 0.2667, "color": "ffffffbc" },
+					{ "time": 0.5, "color": "ffffff00" },
+					{ "time": 0.7333, "color": "ffffffbc" },
+					{ "time": 1, "color": "ffffff00" }
+				]
+			}
+		},
+		"bones": {
+			"shine": {
+				"translate": [
+					{
+						"time": 0,
+						"x": 175.08,
+						"y": 0,
+						"curve": [ 0.213, 0.65, 0.931, 0.67 ]
+					},
+					{
+						"time": 0.5,
+						"x": -127.2,
+						"y": 0,
+						"curve": [ 0.55, 0.09, 0.931, 0.67 ]
+					},
+					{ "time": 1, "x": 175.08, "y": 0 }
+				],
+				"scale": [
+					{
+						"time": 0,
+						"x": 1,
+						"y": 1,
+						"curve": [ 0.213, 0.65, 0.931, 0.67 ]
+					},
+					{
+						"time": 0.5,
+						"x": 2,
+						"y": 1,
+						"curve": [ 0.55, 0.09, 0.931, 0.67 ]
+					},
+					{ "time": 1, "x": 1, "y": 1 }
+				]
+			},
+			"coin": {
+				"translate": [
+					{ "time": 0, "x": 0, "y": 0 },
+					{ "time": 0.5, "x": 0.93, "y": 0 },
+					{ "time": 0.5011, "x": -9.18, "y": 0 },
+					{ "time": 1, "x": 2, "y": 0 }
+				]
+			},
+			"clipping": {
+				"translate": [
+					{ "time": 0, "x": -0.41, "y": 0 },
+					{ "time": 0.2667, "x": 1.2, "y": 1.21 },
+					{ "time": 0.5, "x": 0, "y": 0 },
+					{ "time": 0.7333, "x": -4.15, "y": 0 },
+					{ "time": 1, "x": -3.16, "y": 0 }
+				],
+				"scale": [
+					{ "time": 0, "x": 1, "y": 1 },
+					{ "time": 0.2667, "x": 0.464, "y": 1.014 },
+					{ "time": 0.4667, "x": 0.067, "y": 1.002 },
+					{ "time": 0.5, "x": 0.033, "y": 1 },
+					{ "time": 0.7333, "x": 0.492, "y": 1.014 },
+					{ "time": 1, "x": 1, "y": 1 }
+				]
+			}
+		},
+		"deform": {
+			"default": {
+				"images/coin": {
+					"coin": [
+						{
+							"time": 0,
+							"offset": 4,
+							"vertices": [ 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598 ]
+						},
+						{
+							"time": 0.2333,
+							"vertices": [ -57.61087, 0, 1.15225, 0, 15.20888, 0, 24.26007, 0, 31.99586, 0, 38.58396, 0, 44.15197, 0, 49.42246, 0, 53.15465, 0, 55.83239, 0, 56.71656, 0, 56.71656, 0, 54.21722, 0, 49.62682, 0, 43.79747, 0, 37.5494, 0, 30.28123, 0, 22.2055, 0, 11.40953, 0, 0, 0, -57.61087, 0, 8.04186, 0, 17.91416, 0, 26.61125, 0, 34.01835, 0, 40.26029, 0, 45.85036, 0, 50.21972, 0, 53.50714, 0, 55.9207, 0, 56.96101, 0, 56.83617, 0, 55.23131, 0, 51.30379, 0, 44.9216, 0, 36.22496, 0, 27.59846, 0, 17.28874, 0, 7.89076 ]
+						},
+						{
+							"time": 0.4667,
+							"vertices": [ -115.22174, 0, 2.3045, 0, 20.08046, 0, 40.51821, 0, 57.98577, 0, 72.86182, 0, 85.43448, 0, 97.33535, 0, 105.76271, 0, 111.80908, 0, 113.80557, 0, 113.80557, 0, 108.16202, 0, 97.7968, 0, 84.63402, 0, 70.52576, 0, 54.11411, 0, 35.87894, 0, 11.50145, 1.74997, 0, 0, -115.22174, 0, 16.08371, 0, 35.82832, 0, 53.2225, 0, 68.0367, 0, 80.52058, 0, 91.70073, 0, 100.43944, 0, 107.01427, 0, 111.84139, 0, 113.92201, 0, 113.67234, 0, 110.46262, 0, 102.60757, 0, 89.84319, 0, 72.44992, 0, 55.19692, 0, 34.57748, 0, 15.78153 ]
+						},
+						{
+							"time": 0.5,
+							"vertices": [ -123.45187, 0, 2.46911, 0, 21.49595, 0, 43.40345, 0, 62.12716, 0, 78.07299, 0, 91.54979, 0, 104.3065, 0, 113.33989, 0, 119.82108, 0, 121.96114, 0, 121.96114, 0, 115.91174, 0, 104.80113, 0, 90.69177, 0, 75.56894, 0, 57.97707, 0, 38.43056, 0, 12.3, 0, 0, 0, -123.45187, 0, 17.23255, 0, 38.38749, 0, 57.02411, 0, 72.89646, 0, 86.27205, 0, 98.25078, 0, 107.61369, 0, 114.65815, 0, 119.83006, 0, 122.0593, 0, 121.79179, 0, 118.35281, 0, 109.93669, 0, 96.26056, 0, 77.62492, 0, 59.13956, 0, 37.0473, 0, 16.90878 ]
+						}
+					],
+					"coin-invert": [
+						{
+							"time": 0.5,
+							"vertices": [ -23.47706, 1.27002, -43.40744, 0, -59.7846, 0, -74.77602, 0, -85.79382, 0, -95.27632, 0, -102.23021, 0, -109.99683, 0, -115.50598, 0, -118.87909, 0, -121.32259, 0, -121.32259, 0, -121.32258, 0, -118.66653, 0, -114.15101, 0, -108.4615, 0, -99.61115, 0, -90.41013, 0, -79.48267, 0, -66.83928, 0, -51.93813, 0, -31.61855, 0, -19.56224, -1.52396, -12.52719, 0, 120.72772, 0, 120.72777, 0, -14.97203, 0, -28.48602, 0, -46.43241, 0, -62.14667, 0, -75.27165, 0, -86.18799, 0, -95.28229, 0, -102.08092, 0, -109.98608, 0, -115.7252, 0, -119.52184, 0, -122.15746, 0, -123.04041, 0, -122.68725, 0, -120.4799, 0, -116.33008, 0, -110.76754, 0, -103.44593, 0, -95.76433, 0, -85.61052, 0, -76.07477, 0, -64.50826, 0, -51.44074, 0, -37.66688, 0, -25.39402 ]
+						},
+						{
+							"time": 0.7667,
+							"vertices": [ -12.2558, 0, -21.82668, 0, -29.4435, 0, -36.06335, 0, -40.92855, 0, -45.1158, 0, -48.18647, 0, -51.61602, 0, -54.04874, 0, -55.53822, 0, -56.61722, 0, -56.61722, 0, -56.61721, 0, -55.44436, 0, -53.45041, 0, -50.93806, 0, -47.02994, 0, -42.967, 0, -38.1417, 0, -32.55868, 0, -25.97868, 0, -17.00604, 0, -10.78498, 0, -5.84602, 0, 56.33961, 0, 56.33963, 0, -6.98695, 0, -13.29348, 0, -21.66846, 0, -29.00178, 0, -35.12677, 0, -40.22107, 0, -44.46507, 0, -47.63776, 0, -51.32684, 0, -54.0051, 0, -55.77686, 0, -57.00682, 0, -57.41886, 0, -57.25405, 0, -56.22396, 0, -54.28737, 0, -51.69152, 0, -48.27477, 0, -44.69002, 0, -39.95158, 0, -35.50156, 0, -30.10386, 0, -24.00568, 0, -17.57788, 0, -11.85054 ]
+						},
+						{
+							"time": 1,
+							"vertices": [ -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001 ]
+						}
+					]
+				}
+			}
+		}
+	}
+}
+}

BIN
spine-love/data/coin.png


+ 1 - 0
spine-love/main.lua

@@ -88,6 +88,7 @@ end
 
 function love.load(arg)
 	if arg[#arg] == "-debug" then require("mobdebug").start() end
+	table.insert(skeletons, loadSkeleton("coin", "coin", "rotate", nil, 0.5, 400, 500))
 	table.insert(skeletons, loadSkeleton("spineboy", "spineboy", "walk", nil, 0.5, 400, 500))
 	table.insert(skeletons, loadSkeleton("raptor", "raptor", "walk", nil, 0.3, 400, 500))
 	table.insert(skeletons, loadSkeleton("goblins-mesh", "goblins", "walk", "goblin", 1, 400, 500))

+ 69 - 206
spine-love/spine-love/spine.lua

@@ -46,6 +46,7 @@ spine.MeshAttachment = require "spine-lua.attachments.MeshAttachment"
 spine.VertexAttachment = require "spine-lua.attachments.VertexAttachment"
 spine.PathAttachment = require "spine-lua.attachments.PathAttachment"
 spine.PointAttachment = require "spine-lua.attachments.PointAttachment"
+spine.PointAttachment = require "spine-lua.attachments.ClippingAttachment"
 spine.Skeleton = require "spine-lua.Skeleton"
 spine.Bone = require "spine-lua.Bone"
 spine.Slot = require "spine-lua.Slot"
@@ -64,6 +65,8 @@ spine.TextureRegion = require "spine-lua.TextureRegion"
 spine.TextureAtlasRegion = require "spine-lua.TextureAtlasRegion"
 spine.AtlasAttachmentLoader = require "spine-lua.AtlasAttachmentLoader"
 spine.Color = require "spine-lua.Color"
+spine.Triangulator = require "spine-lua.Triangulator"
+spine.SkeletonClipping = require "spine-lua.SkeletonClipping"
 
 spine.utils.readFile = function (fileName, base)
 	local path = fileName
@@ -160,7 +163,7 @@ function PolygonBatcher:begin ()
 	self.drawCalls = 0
 end
 
-function PolygonBatcher:draw (texture, vertices, numVertices, indices)
+function PolygonBatcher:draw (texture, vertices, uvs, numVertices, indices, color, darkColor)
 	local numIndices = #indices
 	local mesh = self.mesh
 
@@ -182,44 +185,36 @@ function PolygonBatcher:draw (texture, vertices, numVertices, indices)
 		indexStart = indexStart + 1
 		i = i + 1
 	end
-	self.indicesLength = self.indicesLength + numIndices
+	self.indicesLength = self.indicesLength + numIndices	
 
-	i = 1
 	local vertexStart = self.verticesLength + 1
 	local vertexEnd = vertexStart + numVertices
 	local vertex = self.vertex
 	if not self.useTwoColorTint then
-		while vertexStart < vertexEnd do
-			vertex[1] = vertices[i]
-			vertex[2] = vertices[i+1]
-			vertex[3] = vertices[i+2]
-			vertex[4] = vertices[i+3]
-			vertex[5] = vertices[i+4] * 255
-			vertex[6] = vertices[i+5] * 255
-			vertex[7] = vertices[i+6] * 255
-			vertex[8] = vertices[i+7] * 255
-			mesh:setVertex(vertexStart, vertex)
-			vertexStart = vertexStart + 1
-			i = i + 8
-		end
+		vertex[5] = color.r * 255
+		vertex[6] = color.g * 255
+		vertex[7] = color.b * 255
+		vertex[8] = color.a * 255
 	else
-		while vertexStart < vertexEnd do
-			vertex[1] = vertices[i]
-			vertex[2] = vertices[i+1]
-			vertex[3] = vertices[i+2]
-			vertex[4] = vertices[i+3]
-			vertex[5] = vertices[i+4] * 255
-			vertex[6] = vertices[i+5] * 255
-			vertex[7] = vertices[i+6] * 255
-			vertex[8] = vertices[i+7] * 255
-			vertex[9] = vertices[i+8] * 255
-			vertex[10] = vertices[i+9] * 255
-			vertex[11] = vertices[i+10] * 255
-			vertex[12] = vertices[i+11] * 255
-			mesh:setVertex(vertexStart, vertex)
-			vertexStart = vertexStart + 1
-			i = i + 12
-		end
+		vertex[5] = color.r * 255
+		vertex[6] = color.g * 255
+		vertex[7] = color.b * 255
+		vertex[8] = color.a * 255
+		vertex[9] = darkColor.r * 255
+		vertex[10] = darkColor.g * 255
+		vertex[11] = darkColor.b * 255
+		vertex[12] = darkColor.a * 255
+	end
+	
+	local v = 1
+	while vertexStart < vertexEnd do
+		vertex[1] = vertices[v]
+		vertex[2] = vertices[v + 1]
+		vertex[3] = uvs[v]
+		vertex[4] = uvs[v + 1]
+		mesh:setVertex(vertexStart, vertex)
+		vertexStart = vertexStart + 1
+		v = v + 2
 	end
 	self.verticesLength = self.verticesLength + numVertices
 end
@@ -259,7 +254,8 @@ function SkeletonRenderer.new (useTwoColorTint)
 	local self = {
 		batcher = PolygonBatcher.new(3 * 500, useTwoColorTint),
 		premultipliedAlpha = false,
-		useTwoColorTint = useTwoColorTint
+		useTwoColorTint = useTwoColorTint,
+		clipper = spine.SkeletonClipping.new()
 	}
 
 	setmetatable(self, SkeletonRenderer)
@@ -282,24 +278,29 @@ function SkeletonRenderer:draw (skeleton)
 	local drawOrder = skeleton.drawOrder
 	for i, slot in ipairs(drawOrder) do
 		local attachment = slot.attachment
-		local vertices = nil
-		local indics = nil
+		local vertices = worldVertices
+		local uvs = nil
+		local indices = nil
 		local texture = nil
 		local color = tmpColor
 		if attachment then
 			if attachment.type == spine.AttachmentType.region then
 				numVertices = 4
-				vertices = self:computeRegionVertices(slot, attachment, premultipliedAlpha, color)
+				attachment:computeWorldVertices(slot.bone, vertices, 0, 2)
+				uvs = attachment.uvs
 				indices = SkeletonRenderer.QUAD_TRIANGLES
 				texture = attachment.region.renderObject.texture
 			elseif attachment.type == spine.AttachmentType.mesh then
 				numVertices = attachment.worldVerticesLength / 2
-				vertices = self:computeMeshVertices(slot, attachment, premultipliedAlpha, color)
+				attachment:computeWorldVertices(slot, 0, attachment.worldVerticesLength, vertices, 0, 2)
+				uvs = attachment.uvs
 				indices = attachment.triangles
 				texture = attachment.region.renderObject.texture
+			elseif attachment.type == spine.AttachmentType.clipping then
+				self.clipper:clipStart(slot, attachment)
 			end
 
-			if texture then
+			if texture then								
 				local slotBlendMode = slot.data.blendMode
 				if lastBlendMode ~= slotBlendMode then
           batcher:stop()
@@ -316,179 +317,41 @@ function SkeletonRenderer:draw (skeleton)
 					end
 					lastBlendMode = slotBlendMode					
 				end
-				batcher:draw(texture, vertices, numVertices, indices)
+				
+				local skeleton = slot.bone.skeleton
+				local skeletonColor = skeleton.color
+				local slotColor = slot.color
+				local attachmentColor = attachment.color
+				local alpha = skeletonColor.a * slotColor.a * attachmentColor.a
+				local multiplier = alpha
+				if premultipliedAlpha then multiplier = 1 end
+				color:set(skeletonColor.r * slotColor.r * attachmentColor.r * multiplier,
+							skeletonColor.g * slotColor.g * attachmentColor.g * multiplier,
+							skeletonColor.b * slotColor.b * attachmentColor.b * multiplier,
+							alpha)
+						
+				local dark = tmpColor2
+				if slot.darkColor then dark = slot.darkColor
+				else dark:set(0, 0, 0, 0) end
+				
+				if self.clipper:isClipping() then
+					self.clipper:clipTriangles(vertices, attachment.uvs, indices, #indices)
+					vertices = self.clipper.clippedVertices
+					numVertices = #vertices / 2
+					uvs = self.clipper.clippedUVs
+					indices = self.clipper.clippedTriangles
+				end
+				
+				batcher:draw(texture, vertices, uvs, numVertices, indices, color, dark)
 			end
+			
+			self.clipper:clipEnd(slot)
 		end
 	end
 
 	batcher:stop()
 	love.graphics.setBlendMode(lastLoveBlendMode)
-end
-
-function SkeletonRenderer:computeRegionVertices(slot, region, pma, color)
-	local skeleton = slot.bone.skeleton
-	local skeletonColor = skeleton.color
-	local slotColor = slot.color
-	local regionColor = region.color
-	local alpha = skeletonColor.a * slotColor.a * regionColor.a
-	local multiplier = alpha
-	if pma then multiplier = 1 end
-	color:set(skeletonColor.r * slotColor.r * regionColor.r * multiplier,
-				skeletonColor.g * slotColor.g * regionColor.g * multiplier,
-				skeletonColor.b * slotColor.b * regionColor.b * multiplier,
-				alpha)
-			
-	local dark = tmpColor2
-	if slot.darkColor then dark = slot.darkColor
-	else dark:set(0, 0, 0, 0) end
-
-	local vertices = worldVertices
-	if not self.useTwoColorTint then
-		region:computeWorldVertices(slot.bone, vertices, 0, 8)
-	else
-		region:computeWorldVertices(slot.bone, vertices, 0, 12)
-	end
-
-	local uvs = region.uvs
-
-	if not self.useTwoColorTint then
-		vertices[3] = uvs[1]
-		vertices[4] = uvs[2]
-		vertices[5] = color.r
-		vertices[6] = color.g
-		vertices[7] = color.b
-		vertices[8] = color.a
-
-		vertices[11] = uvs[3]
-		vertices[12] = uvs[4]
-		vertices[13] = color.r
-		vertices[14] = color.g
-		vertices[15] = color.b
-		vertices[16] = color.a
-
-		vertices[19] = uvs[5]
-		vertices[20] = uvs[6]
-		vertices[21] = color.r
-		vertices[22] = color.g
-		vertices[23] = color.b
-		vertices[24] = color.a
-
-		vertices[27] = uvs[7]
-		vertices[28] = uvs[8]
-		vertices[29] = color.r
-		vertices[30] = color.g
-		vertices[31] = color.b
-		vertices[32] = color.a
-	else
-		vertices[3] = uvs[1]
-		vertices[4] = uvs[2]
-		vertices[5] = color.r
-		vertices[6] = color.g
-		vertices[7] = color.b
-		vertices[8] = color.a
-		vertices[9] = dark.r
-		vertices[10] = dark.g
-		vertices[11] = dark.b
-		vertices[12] = 0
-
-		vertices[15] = uvs[3]
-		vertices[16] = uvs[4]
-		vertices[17] = color.r
-		vertices[18] = color.g
-		vertices[19] = color.b
-		vertices[20] = color.a
-		vertices[21] = dark.r
-		vertices[22] = dark.g
-		vertices[23] = dark.b
-		vertices[24] = 0
-
-		vertices[27] = uvs[5]
-		vertices[28] = uvs[6]
-		vertices[29] = color.r
-		vertices[30] = color.g
-		vertices[31] = color.b
-		vertices[32] = color.a
-		vertices[33] = dark.r
-		vertices[34] = dark.g
-		vertices[35] = dark.b
-		vertices[36] = 0
-
-		vertices[39] = uvs[7]
-		vertices[40] = uvs[8]
-		vertices[41] = color.r
-		vertices[42] = color.g
-		vertices[43] = color.b
-		vertices[44] = color.a
-		vertices[45] = dark.r
-		vertices[46] = dark.g
-		vertices[47] = dark.b
-		vertices[48] = 0
-	end
-
-	return vertices
-end
-
-function SkeletonRenderer:computeMeshVertices(slot, mesh, pma, color)
-	local skeleton = slot.bone.skeleton
-	local skeletonColor = skeleton.color
-	local slotColor = slot.color
-	local meshColor = mesh.color
-	local alpha = skeletonColor.a * slotColor.a * meshColor.a
-	local multiplier = alpha
-	if pma then multiplier = 1 end
-	color:set(skeletonColor.r * slotColor.r * meshColor.r * multiplier,
-				skeletonColor.g * slotColor.g * meshColor.g * multiplier,
-				skeletonColor.b * slotColor.b * meshColor.b * multiplier,
-				alpha)
-			
-	local numVertices = mesh.worldVerticesLength / 2
-	local vertices = worldVertices
-	
-	local dark = tmpColor2
-	if slot.darkColor then dark = slot.darkColor
-	else dark:set(0, 0, 0, 0) end
-	
-	if not self.useTwoColorTint then
-		mesh:computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, 8)
-	else
-		mesh:computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, 12)
-	end
-	
-	local uvs = mesh.uvs
-	local i = 1
-	local n = numVertices + 1
-	local u = 1
-	local v = 3
-	if not self.useTwoColorTint then
-		while i < n do
-			vertices[v] = uvs[u]
-			vertices[v + 1] = uvs[u + 1]
-			vertices[v + 2] = color.r
-			vertices[v + 3] = color.g
-			vertices[v + 4] = color.b
-			vertices[v + 5] = color.a
-			i = i + 1
-			u = u + 2
-			v = v + 8
-		end
-	else
-		while i < n do
-			vertices[v] = uvs[u]
-			vertices[v + 1] = uvs[u + 1]
-			vertices[v + 2] = color.r
-			vertices[v + 3] = color.g
-			vertices[v + 4] = color.b
-			vertices[v + 5] = color.a
-			vertices[v + 6] = dark.r
-			vertices[v + 7] = dark.g
-			vertices[v + 8] = dark.b
-			vertices[v + 9] = 0
-			i = i + 1
-			u = u + 2
-			v = v + 12
-		end
-	end
-	return vertices
+	self.clipper:clipEnd2()
 end
 
 spine.PolygonBatcher = PolygonBatcher