diff --git a/examples/export/runtimes.sh b/examples/export/runtimes.sh index f39dec09e..0d658945c 100755 --- a/examples/export/runtimes.sh +++ b/examples/export/runtimes.sh @@ -80,6 +80,10 @@ cp -f ../tank/export/tank.png ../../spine-cocos2dx/example/Resources/common/ echo "spine-corona" rm -f ../../spine-corona/data/* +cp -f ../coin/export/coin.json ../../spine-corona/data +cp -f ../coin/export/coin.atlas ../../spine-corona/data +cp -f ../coin/export/coin.png ../../spine-corona/data + cp -f ../goblins/export/goblins-mesh.json ../../spine-corona/data cp -f ../goblins/export/goblins.atlas ../../spine-corona/data cp -f ../goblins/export/goblins.png ../../spine-corona/data diff --git a/spine-corona/data/coin.atlas b/spine-corona/data/coin.atlas new file mode 100644 index 000000000..bcdb26b10 --- /dev/null +++ b/spine-corona/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 diff --git a/spine-corona/data/coin.json b/spine-corona/data/coin.json new file mode 100644 index 000000000..f678be598 --- /dev/null +++ b/spine-corona/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 ] + } + ] + } + } + } + } +} +} \ No newline at end of file diff --git a/spine-corona/data/coin.png b/spine-corona/data/coin.png new file mode 100644 index 000000000..f5ea3ad0d Binary files /dev/null and b/spine-corona/data/coin.png differ diff --git a/spine-corona/main.lua b/spine-corona/main.lua index df72a9ecd..a31136587 100644 --- a/spine-corona/main.lua +++ b/spine-corona/main.lua @@ -76,12 +76,13 @@ function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin) end -- table.insert(skeletons, loadSkeleton("test.atlas", "test.json", 240, 300, 0.4, "animation")) -table.insert(skeletons, loadSkeleton("spineboy.atlas", "spineboy.json", 240, 300, 0.4, "walk")) +table.insert(skeletons, loadSkeleton("coin.atlas", "coin.json", 240, 300, 0.4, "rotate")) +--[[table.insert(skeletons, loadSkeleton("spineboy.atlas", "spineboy.json", 240, 300, 0.4, "walk")) table.insert(skeletons, loadSkeleton("raptor.atlas", "raptor.json", 200, 300, 0.25, "walk")) table.insert(skeletons, loadSkeleton("goblins.atlas", "goblins-mesh.json", 240, 300, 0.8, "walk", "goblin")) table.insert(skeletons, loadSkeleton("stretchyman.atlas", "stretchyman.json", 40, 300, 0.5, "sneak")) table.insert(skeletons, loadSkeleton("tank.atlas", "tank.json", 400, 300, 0.2, "drive")) -table.insert(skeletons, loadSkeleton("vine.atlas", "vine.json", 240, 300, 0.3, "animation")) +table.insert(skeletons, loadSkeleton("vine.atlas", "vine.json", 240, 300, 0.3, "animation"))]]-- local triangulator = spine.Triangulator.new() local polygon = { 411, 219, 199, 230, 161, 362, 534, 407, 346, 305, 596, 265 } @@ -109,7 +110,7 @@ Runtime:addEventListener("enterFrame", function (event) state = skeletons[activeSkeleton].state state:update(delta) - state:apply(skeleton) + -- state:apply(skeleton) skeleton:updateWorldTransform() -- uncomment if you want to know how many batches a skeleton renders to diff --git a/spine-corona/spine-corona/spine.lua b/spine-corona/spine-corona/spine.lua index bae4e54a5..8b614f291 100644 --- a/spine-corona/spine-corona/spine.lua +++ b/spine-corona/spine-corona/spine.lua @@ -44,6 +44,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.ClippingAttachment = require "spine-lua.attachments.ClippingAttachment" spine.Skeleton = require "spine-lua.Skeleton" spine.Bone = require "spine-lua.Bone" spine.Slot = require "spine-lua.Slot" @@ -63,6 +64,7 @@ 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) if not base then base = system.ResourceDirectory end @@ -89,6 +91,7 @@ spine.Skeleton.new = function(skeletonData, group) self.premultipliedAlpha = false self.batches = 0 self.tempColor = spine.Color.newWith(1, 1, 1, 1) + self.tempColor2 = spine.Color.newWith(-1, 1, 1, 1) return self end @@ -131,7 +134,8 @@ function spine.Skeleton:updateWorldTransform() local groupIndices = {} local groupUvs = {} local color = self.tempColor - local lastColor = nil + local lastColor = self.tempColor2 + lastColor.r = -1 local texture = nil local lastTexture = nil local blendMode = nil @@ -158,7 +162,7 @@ function spine.Skeleton:updateWorldTransform() if texture and vertices and indices then if not lastTexture then lastTexture = texture end - if not lastColor then lastColor = color end + if lastColor.r == -1 then lastColor:setFrom(color) end if not lastBlendMode then lastBlendMode = blendMode end if (texture ~= lastTexture or not colorEquals(color, lastColor) or blendMode ~= lastBlendMode) then diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/Triangulator.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/Triangulator.java index fa92773e4..2d37136a8 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/Triangulator.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/Triangulator.java @@ -285,6 +285,7 @@ class Triangulator { ShortArray triangles = triangulator.triangulate(polygon); System.out.println(triangles); for (short i: triangles.items) System.out.print((i + 1) + ", "); + System.out.println(); Array polys = triangulator.decompose(polygon, triangles); System.out.println(polys); diff --git a/spine-lua/AtlasAttachmentLoader.lua b/spine-lua/AtlasAttachmentLoader.lua index 7a4234869..a6a7d166f 100644 --- a/spine-lua/AtlasAttachmentLoader.lua +++ b/spine-lua/AtlasAttachmentLoader.lua @@ -36,6 +36,7 @@ local BoundingBoxAttachment = require "spine-lua.attachments.BoundingBoxAttachme local MeshAttachment = require "spine-lua.attachments.MeshAttachment" local PathAttachment = require "spine-lua.attachments.PathAttachment" local PointAttachment = require "spine-lua.attachments.PointAttachment" +local ClippingAttachment = require "spine-lua.attachments.ClippingAttachment" local TextureAtlas = require "spine-lua.TextureAtlas" local AtlasAttachmentLoader = {} @@ -84,4 +85,8 @@ function AtlasAttachmentLoader:newPointAttachment(skin, name) return PointAttachment.new(name) end +function AtlasAttachmentLoader:newClippingAttachment(skin, name) + return ClippingAttachment.new(name) +end + return AtlasAttachmentLoader diff --git a/spine-lua/AttachmentLoader.lua b/spine-lua/AttachmentLoader.lua index 62b771257..405e22e27 100644 --- a/spine-lua/AttachmentLoader.lua +++ b/spine-lua/AttachmentLoader.lua @@ -34,6 +34,7 @@ local BoundingBoxAttachment = require "spine-lua.attachments.BoundingBoxAttachme local MeshAttachment = require "spine-lua.attachments.MeshAttachment" local PathAttachment = require "spine-lua.attachments.PathAttachment" local PointAttachment = require "spine-lua.attachments.PointAttachment" +local ClippingAttachment = require "spine-lua.attachments.ClippingAttachment" local AttachmentLoader = {} function AttachmentLoader.new () @@ -62,6 +63,10 @@ function AttachmentLoader.new () function self:newPointAttachment(skin, name) return PointAttachment.new(name) end + + function self:newClippingAttachment(skin, name) + return ClippingAttachment.new(name) + end return self end diff --git a/spine-lua/SkeletonClipping.lua b/spine-lua/SkeletonClipping.lua new file mode 100644 index 000000000..c74931c3d --- /dev/null +++ b/spine-lua/SkeletonClipping.lua @@ -0,0 +1,56 @@ +------------------------------------------------------------------------------- +-- Spine Runtimes Software License v2.5 +-- +-- Copyright (c) 2013-2016, Esoteric Software +-- All rights reserved. +-- +-- You are granted a perpetual, non-exclusive, non-sublicensable, and +-- non-transferable license to use, install, execute, and perform the Spine +-- Runtimes software and derivative works solely for personal or internal +-- use. Without the written permission of Esoteric Software (see Section 2 of +-- the Spine Software License Agreement), you may not (a) modify, translate, +-- adapt, or develop new applications using the Spine Runtimes or otherwise +-- create derivative works or improvements of the Spine Runtimes or (b) remove, +-- delete, alter, or obscure any trademarks or any copyright, trademark, patent, +-- or other intellectual property or proprietary rights notices on or in the +-- Software, including any copy thereof. Redistributions in binary or source +-- form must include this license and terms. +-- +-- THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR +-- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +-- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +-- EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF +-- USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +-- IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +-- POSSIBILITY OF SUCH DAMAGE. +------------------------------------------------------------------------------- + +local utils = require "spine-lua.utils" + +local setmetatable = setmetatable +local math_min = math.min +local math_max = math.max +local ipairs = ipairs +local table_insert = table.insert +local table_remove = table.remove + +local SkeletonClipping = {} +SkeletonClipping.__index = SkeletonClipping + +function SkeletonClipping.new () + local self = { + convexPolygons = {}, + convexPolygonsIndices = {}, + indicesArray = {}, + isConcaveArray = {}, + triangles = {} + } + setmetatable(self, SkeletonClipping) + + return self +end + +return Triangulator diff --git a/spine-lua/SkeletonJson.lua b/spine-lua/SkeletonJson.lua index d1a9f4274..7c06d6d62 100644 --- a/spine-lua/SkeletonJson.lua +++ b/spine-lua/SkeletonJson.lua @@ -242,7 +242,7 @@ function SkeletonJson.new (attachmentLoader) for slotName,slotMap in pairs(skinMap) do local slotIndex = skeletonData.slotNameIndices[slotName] for attachmentName,attachmentMap in pairs(slotMap) do - local attachment = readAttachment(attachmentMap, skin, slotIndex, attachmentName) + local attachment = readAttachment(attachmentMap, skin, slotIndex, attachmentName, skeletonData) if attachment then skin:addAttachment(slotIndex, attachmentName, attachment) end @@ -286,7 +286,7 @@ function SkeletonJson.new (attachmentLoader) return skeletonData end - readAttachment = function (map, skin, slotIndex, name) + readAttachment = function (map, skin, slotIndex, name, skeletonData) local scale = self.scale name = getValue(map, "name", name) @@ -407,6 +407,26 @@ function SkeletonJson.new (attachmentLoader) end return point + elseif type == AttachmentType.clipping then + local clip = attachmentLoader:newClippingAttachment(skin, name) + if not clip then return nil end + + local _end = getValue(map, "end", nil) + if _end then + local slot = skeletonData:findSlot(_end) + if not slot then error("Clipping end slot not found: " + _end) end + clip.endSlot = slot + end + + readVertices(map, clip, map.vertexCount * 2) + local color = map.color + if color then + clip.color:set(tonumber(color:sub(1, 2), 16) / 255, + tonumber(color:sub(3, 4), 16) / 255, + tonumber(color:sub(5, 6), 16) / 255, + tonumber(color:sub(7, 8), 16) / 255) + end + return clip end error("Unknown attachment type: " .. type .. " (" .. name .. ")") diff --git a/spine-lua/attachments/AttachmentType.lua b/spine-lua/attachments/AttachmentType.lua index b0a95b7e4..6be2eef63 100644 --- a/spine-lua/attachments/AttachmentType.lua +++ b/spine-lua/attachments/AttachmentType.lua @@ -34,6 +34,7 @@ local AttachmentType = { mesh = 2, linkedmesh = 3, path = 4, - point = 5 + point = 5, + clipping = 6 } return AttachmentType diff --git a/spine-lua/attachments/ClippingAttachment.lua b/spine-lua/attachments/ClippingAttachment.lua new file mode 100644 index 000000000..4271a7a7a --- /dev/null +++ b/spine-lua/attachments/ClippingAttachment.lua @@ -0,0 +1,48 @@ +------------------------------------------------------------------------------- +-- Spine Runtimes Software License v2.5 +-- +-- Copyright (c) 2013-2016, Esoteric Software +-- All rights reserved. +-- +-- You are granted a perpetual, non-exclusive, non-sublicensable, and +-- non-transferable license to use, install, execute, and perform the Spine +-- Runtimes software and derivative works solely for personal or internal +-- use. Without the written permission of Esoteric Software (see Section 2 of +-- the Spine Software License Agreement), you may not (a) modify, translate, +-- adapt, or develop new applications using the Spine Runtimes or otherwise +-- create derivative works or improvements of the Spine Runtimes or (b) remove, +-- delete, alter, or obscure any trademarks or any copyright, trademark, patent, +-- or other intellectual property or proprietary rights notices on or in the +-- Software, including any copy thereof. Redistributions in binary or source +-- form must include this license and terms. +-- +-- THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR +-- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +-- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +-- EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF +-- USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +-- IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +-- POSSIBILITY OF SUCH DAMAGE. +------------------------------------------------------------------------------- + +local AttachmentType = require "spine-lua.attachments.AttachmentType" +local VertexAttachment = require "spine-lua.attachments.VertexAttachment" +local Color = require "spine-lua.Color" + +local ClippingAttachment = {} +ClippingAttachment.__index = ClippingAttachment +setmetatable(ClippingAttachment, { __index = VertexAttachment }) + +function ClippingAttachment.new (name) + if not name then error("name cannot be nil", 2) end + + local self = VertexAttachment.new(name, AttachmentType.clipping) + self.color = Color.newWith(0.2275, 0.2275, 0.8078, 1) + self.endSlot = nil + setmetatable(self, ClippingAttachment) + return self +end +return ClippingAttachment