mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-15 03:21:35 +08:00
[as3][starling] Added clipping. Worked before moving stuff around in FDT. Seems like convex decomposer is now bugged?
This commit is contained in:
parent
bd16d0fde8
commit
971e203b9e
Binary file not shown.
@ -1,13 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<exclude>
|
||||
<resource>frameworks/libs/air/aircore.swc</resource>
|
||||
<resource>frameworks/libs/air/airglobal.swc</resource>
|
||||
<resource>frameworks/libs/air/applicationupdater.swc</resource>
|
||||
<resource>frameworks/libs/air/applicationupdater_ui.swc</resource>
|
||||
<resource>frameworks/libs/air/servicemonitor.swc</resource>
|
||||
<resource>frameworks/libs/authoringsupport.swc</resource>
|
||||
<resource>frameworks/libs/core.swc</resource>
|
||||
<resource>frameworks/libs/osmf.swc</resource>
|
||||
<resource>frameworks/libs/textLayout.swc</resource>
|
||||
</exclude>
|
||||
<exclude />
|
||||
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/spine/ConvexDecomposer.as=UTF-8
|
||||
encoding//src/spine/SkeletonClipping.as=UTF-8
|
||||
encoding//src/spine/SkeletonJson.as=UTF-8
|
||||
encoding//src/spine/animation/TwoColorTimeline.as=UTF-8
|
||||
encoding//src/spine/attachments/ClippingAttachment.as=UTF-8
|
||||
encoding//src/spine/attachments/PointAttachment.as=UTF-8
|
||||
encoding/<project>=UTF-8
|
||||
|
||||
266
spine-as3/spine-as3/src/spine/ConvexDecomposer.as
Normal file
266
spine-as3/spine-as3/src/spine/ConvexDecomposer.as
Normal file
@ -0,0 +1,266 @@
|
||||
/******************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
package spine {
|
||||
public class ConvexDecomposer {
|
||||
private var convexPolygons : Vector.<Vector.<Number>> = new Vector.<Vector.<Number>>();
|
||||
private var convexPolygonsIndices : Vector.<Vector.<int>> = new Vector.<Vector.<int>>();
|
||||
private var indicesArray : Vector.<int> = new Vector.<int>();
|
||||
private var isConcaveArray : Vector.<Boolean> = new Vector.<Boolean>();
|
||||
private var triangles : Vector.<int> = new Vector.<int>();
|
||||
private var polygonPool : Pool = new Pool(function() : Vector.<Number> {
|
||||
return new Vector.<Number>();
|
||||
});
|
||||
private var polygonIndicesPool : Pool = new Pool(function() : Vector.<int> {
|
||||
return new Vector.<int>();
|
||||
});
|
||||
|
||||
public function decompose(input : Vector.<Number>) : Vector.<Vector.<Number>> {
|
||||
var vertices : Vector.<Number> = input;
|
||||
var vertexCount : int = input.length >> 1;
|
||||
var i : int, n : int;
|
||||
|
||||
var indices : Vector.<int> = this.indicesArray;
|
||||
indices.length = 0;
|
||||
for (i = 0; i < vertexCount; i++)
|
||||
indices[i] = i;
|
||||
|
||||
var isConcaveArray : Vector.<Boolean> = this.isConcaveArray;
|
||||
isConcaveArray.length = 0;
|
||||
for (i = 0, n = vertexCount; i < n; ++i)
|
||||
isConcaveArray[i] = isConcave(i, vertexCount, vertices, indices);
|
||||
|
||||
var triangles : Vector.<int> = this.triangles;
|
||||
triangles.length = 0;
|
||||
|
||||
while (vertexCount > 3) {
|
||||
// Find ear tip.
|
||||
var previous : int = vertexCount - 1, next : int = 1;
|
||||
i = 0;
|
||||
while (true) {
|
||||
outer:
|
||||
if (!isConcaveArray[i]) {
|
||||
var p1 : int = indices[previous] << 1, p2 : int = indices[i] << 1, p3 : int = indices[next] << 1;
|
||||
var p1x : Number = vertices[p1], p1y : Number = vertices[p1 + 1];
|
||||
var p2x : Number = vertices[p2], p2y : Number = vertices[p2 + 1];
|
||||
var p3x : Number = vertices[p3], p3y : Number = vertices[p3 + 1];
|
||||
for (var ii : int = (next + 1) % vertexCount; ii != previous; ii = (ii + 1) % vertexCount) {
|
||||
if (!isConcaveArray[ii]) continue;
|
||||
var v : int = indices[ii] << 1;
|
||||
var vx : int = vertices[v], vy : int = vertices[v + 1];
|
||||
if (positiveArea(p3x, p3y, p1x, p1y, vx, vy)) {
|
||||
if (positiveArea(p1x, p1y, p2x, p2y, vx, vy)) {
|
||||
if (positiveArea(p2x, p2y, p3x, p3y, vx, vy)) break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (next == 0) {
|
||||
do {
|
||||
if (!isConcaveArray[i]) break;
|
||||
i--;
|
||||
} while (i > 0);
|
||||
break;
|
||||
}
|
||||
|
||||
previous = i;
|
||||
i = next;
|
||||
next = (next + 1) % vertexCount;
|
||||
}
|
||||
|
||||
// Cut ear tip.
|
||||
triangles.push(indices[(vertexCount + i - 1) % vertexCount]);
|
||||
triangles.push(indices[i]);
|
||||
triangles.push(indices[(i + 1) % vertexCount]);
|
||||
indices.splice(i, 1);
|
||||
isConcaveArray.splice(i, 1);
|
||||
vertexCount--;
|
||||
|
||||
var previousIndex : int = (vertexCount + i - 1) % vertexCount;
|
||||
var nextIndex : int = i == vertexCount ? 0 : i;
|
||||
isConcaveArray[previousIndex] = isConcave(previousIndex, vertexCount, vertices, indices);
|
||||
isConcaveArray[nextIndex] = isConcave(nextIndex, vertexCount, vertices, indices);
|
||||
}
|
||||
|
||||
if (vertexCount == 3) {
|
||||
triangles.push(indices[2]);
|
||||
triangles.push(indices[0]);
|
||||
triangles.push(indices[1]);
|
||||
}
|
||||
|
||||
var convexPolygons : Vector.<Vector.<Number>> = this.convexPolygons;
|
||||
for (i = 0, n = convexPolygons.length; i < n; i++) {
|
||||
this.polygonPool.free(convexPolygons[i]);
|
||||
}
|
||||
convexPolygons.length = 0;
|
||||
|
||||
var convexPolygonsIndices : Vector.<Vector.<int>> = this.convexPolygonsIndices;
|
||||
for (i = 0, n = convexPolygonsIndices.length; i < n; i++) {
|
||||
this.polygonIndicesPool.free(convexPolygonsIndices[i]);
|
||||
}
|
||||
convexPolygonsIndices.length = 0;
|
||||
|
||||
var polygonIndices : Vector.<int> = Vector.<int>(this.polygonIndicesPool.obtain());
|
||||
polygonIndices.length = 0;
|
||||
|
||||
var polygon : Vector.<Number> = Vector.<Number>(this.polygonPool.obtain());
|
||||
polygon.length = 0;
|
||||
|
||||
// Merge subsequent triangles if they form a triangle fan.
|
||||
var fanBaseIndex : int = -1, lastWinding : int = 0;
|
||||
var x1 : Number, y1 : Number, x2 : Number, y2 : Number, x3 : Number, y3 : Number;
|
||||
var winding1 : int, winding2 : int, o : int;
|
||||
for (i = 0, n = triangles.length; i < n; i += 3) {
|
||||
var t1 : int = triangles[i] << 1, t2 : int = triangles[i + 1] << 1, t3 : int = triangles[i + 2] << 1;
|
||||
x1 = vertices[t1];
|
||||
y1 = vertices[t1 + 1];
|
||||
x2 = vertices[t2];
|
||||
y2 = vertices[t2 + 1];
|
||||
x3 = vertices[t3];
|
||||
y3 = vertices[t3 + 1];
|
||||
|
||||
// If the base of the last triangle is the same as this triangle, check if they form a convex polygon (triangle fan).
|
||||
var merged : Boolean = false;
|
||||
if (fanBaseIndex == t1) {
|
||||
o = polygon.length - 4;
|
||||
winding1 = ConvexDecomposer.winding(polygon[o], polygon[o + 1], polygon[o + 2], polygon[o + 3], x3, y3);
|
||||
winding2 = ConvexDecomposer.winding(x3, y3, polygon[0], polygon[1], polygon[2], polygon[3]);
|
||||
if (winding1 == lastWinding && winding2 == lastWinding) {
|
||||
polygon.push(x3);
|
||||
polygon.push(y3);
|
||||
polygonIndices.push(t3);
|
||||
merged = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise make this triangle the new base.
|
||||
if (!merged) {
|
||||
if (polygon.length > 0) {
|
||||
convexPolygons.push(polygon);
|
||||
convexPolygonsIndices.push(polygonIndices);
|
||||
}
|
||||
polygon = Vector.<Number>(this.polygonPool.obtain());
|
||||
polygon.length = 0;
|
||||
polygon.push(x1);
|
||||
polygon.push(y1);
|
||||
polygon.push(x2);
|
||||
polygon.push(y2);
|
||||
polygon.push(x3);
|
||||
polygon.push(y3);
|
||||
polygonIndices = Vector.<int>(this.polygonIndicesPool.obtain());
|
||||
polygonIndices.length = 0;
|
||||
polygonIndices.push(t1);
|
||||
polygonIndices.push(t2);
|
||||
polygonIndices.push(t3);
|
||||
lastWinding = ConvexDecomposer.winding(x1, y1, x2, y2, x3, y3);
|
||||
fanBaseIndex = t1;
|
||||
}
|
||||
}
|
||||
|
||||
if (polygon.length > 0) {
|
||||
convexPolygons.push(polygon);
|
||||
convexPolygonsIndices.push(polygonIndices);
|
||||
}
|
||||
|
||||
// Go through the list of polygons and try to merge the remaining triangles with the found triangle fans.
|
||||
for (i = 0, n = convexPolygons.length; i < n; i++) {
|
||||
polygonIndices = convexPolygonsIndices[i];
|
||||
if (polygonIndices.length == 0) continue;
|
||||
var firstIndex : int = polygonIndices[0];
|
||||
var lastIndex : int = polygonIndices[polygonIndices.length - 1];
|
||||
|
||||
polygon = convexPolygons[i];
|
||||
o = polygon.length - 4;
|
||||
var prevPrevX : Number = polygon[o], prevPrevY : Number = polygon[o + 1];
|
||||
var prevX : Number = polygon[o + 2], prevY : Number = polygon[o + 3];
|
||||
var firstX : Number = polygon[0], firstY : Number = polygon[1];
|
||||
var secondX : Number = polygon[2], secondY : Number = polygon[3];
|
||||
var currWinding : int = ConvexDecomposer.winding(prevPrevX, prevPrevY, prevX, prevY, firstX, firstY);
|
||||
|
||||
for (ii = 0; ii < n; ii++) {
|
||||
if (ii == i) continue;
|
||||
var otherIndices : Vector.<int>= convexPolygonsIndices[ii];
|
||||
if (otherIndices.length != 3) continue;
|
||||
var otherFirstIndex : int = otherIndices[0];
|
||||
var otherSecondIndex : int = otherIndices[1];
|
||||
var otherLastIndex : int = otherIndices[2];
|
||||
|
||||
var otherPoly : Vector.<Number>= convexPolygons[ii];
|
||||
x3 = otherPoly[otherPoly.length - 2];
|
||||
y3 = otherPoly[otherPoly.length - 1];
|
||||
|
||||
if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex) continue;
|
||||
winding1 = ConvexDecomposer.winding(prevPrevX, prevPrevY, prevX, prevY, x3, y3);
|
||||
winding2 = ConvexDecomposer.winding(x3, y3, firstX, firstY, secondX, secondY);
|
||||
if (winding1 == currWinding && winding2 == currWinding) {
|
||||
otherPoly.length = 0;
|
||||
otherIndices.length = 0;
|
||||
polygon.push(x3);
|
||||
polygon.push(y3);
|
||||
polygonIndices.push(otherLastIndex);
|
||||
prevPrevX = prevX;
|
||||
prevPrevY = prevY;
|
||||
prevX = x3;
|
||||
prevY = y3;
|
||||
ii = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove empty polygons that resulted from the merge step above.
|
||||
for (i = convexPolygons.length - 1; i >= 0; i--) {
|
||||
polygon = convexPolygons[i];
|
||||
if (polygon.length == 0) {
|
||||
convexPolygons.splice(i, 1);
|
||||
this.polygonPool.free(polygon);
|
||||
}
|
||||
}
|
||||
|
||||
return convexPolygons;
|
||||
}
|
||||
|
||||
private static function isConcave(index : Number, vertexCount : Number, vertices : Vector.<Number>, indices : Vector.<int>) : Boolean {
|
||||
var previous : int = indices[(vertexCount + index - 1) % vertexCount] << 1;
|
||||
var current : int = indices[index] << 1;
|
||||
var next : int = indices[(index + 1) % vertexCount] << 1;
|
||||
return !positiveArea(vertices[previous], vertices[previous + 1], vertices[current], vertices[current + 1], vertices[next], vertices[next + 1]);
|
||||
}
|
||||
|
||||
private static function positiveArea(p1x : Number, p1y : Number, p2x : Number, p2y : Number, p3x : Number, p3y : Number) : Boolean {
|
||||
return p1x * (p3y - p2y) + p2x * (p1y - p3y) + p3x * (p2y - p1y) >= 0;
|
||||
}
|
||||
|
||||
private static function winding(p1x : Number, p1y : Number, p2x : Number, p2y : Number, p3x : Number, p3y : Number) : int {
|
||||
var px : Number = p2x - p1x, py : Number = p2y - p1y;
|
||||
return p3x * py - p3y * px + px * p1y - p1x * py >= 0 ? 1 : -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
297
spine-as3/spine-as3/src/spine/SkeletonClipping.as
Normal file
297
spine-as3/spine-as3/src/spine/SkeletonClipping.as
Normal file
@ -0,0 +1,297 @@
|
||||
/******************************************************************************
|
||||
* 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,
|
||||
* devare, 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.
|
||||
*****************************************************************************/
|
||||
|
||||
package spine {
|
||||
import spine.attachments.ClippingAttachment;
|
||||
|
||||
public class SkeletonClipping {
|
||||
private var decomposer : ConvexDecomposer = new ConvexDecomposer();
|
||||
private var clippingPolygon : Vector.<Number> = new Vector.<Number>();
|
||||
private var clipOutput : Vector.<Number> = new Vector.<Number>();
|
||||
public var clippedVertices : Vector.<Number> = new Vector.<Number>();
|
||||
public var clippedUvs : Vector.<Number> = new Vector.<Number>();
|
||||
public var clippedTriangles : Vector.<uint> = new Vector.<uint>();
|
||||
private var scratch : Vector.<Number> = new Vector.<Number>();
|
||||
|
||||
private var clipAttachment: ClippingAttachment;
|
||||
private var clippingPolygons: Vector.<Vector.<Number>>;
|
||||
|
||||
public function clipStart (slot: Slot, clip: ClippingAttachment) : void {
|
||||
if (this.clipAttachment != null) return;
|
||||
this.clipAttachment = clip;
|
||||
|
||||
var i : int, n : int = clip.worldVerticesLength;
|
||||
var vertices : Vector.<Number> = this.clippingPolygon;
|
||||
vertices.length = n;
|
||||
clip.computeWorldVertices(slot, 0, n, vertices, 0, 2);
|
||||
var clippingPolygon : Vector.<Number> = this.clippingPolygon;
|
||||
SkeletonClipping.makeClockwise(clippingPolygon);
|
||||
var clippingPolygons : Vector.<Vector.<Number>> = this.clippingPolygons = this.decomposer.decompose(clippingPolygon);
|
||||
for (i = 0, n = clippingPolygons.length; i < n; i++) {
|
||||
var polygon : Vector.<Number> = clippingPolygons[i];
|
||||
SkeletonClipping.makeClockwise(polygon);
|
||||
polygon.push(polygon[0]);
|
||||
polygon.push(polygon[1]);
|
||||
}
|
||||
}
|
||||
|
||||
public function clipEndWithSlot (slot: Slot) : void {
|
||||
if (this.clipAttachment != null && this.clipAttachment.endSlot == slot.data) this.clipEnd();
|
||||
}
|
||||
|
||||
public function clipEnd () : void {
|
||||
if (this.clipAttachment == null) return;
|
||||
this.clipAttachment = null;
|
||||
this.clippingPolygons = null;
|
||||
this.clippedVertices.length = 0;
|
||||
this.clippedTriangles.length = 0;
|
||||
this.clippingPolygon.length = 0;
|
||||
}
|
||||
|
||||
public function isClipping (): Boolean {
|
||||
return this.clipAttachment != null;
|
||||
}
|
||||
|
||||
public function clipTriangles (vertices: Vector.<Number>, triangles: Vector.<uint>, trianglesLength: Number, uvs: Vector.<Number>) : void {
|
||||
|
||||
var clipOutput : Vector.<Number> = this.clipOutput, clippedVertices : Vector.<Number> = this.clippedVertices, clippedUvs : Vector.<Number> = this.clippedUvs;
|
||||
var clippedTriangles : Vector.<uint> = this.clippedTriangles;
|
||||
var polygons : Vector.<Vector.<Number>> = this.clippingPolygons;
|
||||
var polygonsCount : int = this.clippingPolygons.length;
|
||||
|
||||
var index : int = 0;
|
||||
clippedVertices.length = 0;
|
||||
clippedUvs.length = 0;
|
||||
clippedTriangles.length = 0;
|
||||
outer:
|
||||
for (var i : int = 0; i < trianglesLength; i += 3) {
|
||||
var vertexOffset : int = triangles[i] << 1;
|
||||
var x1 : Number = vertices[vertexOffset], y1 : Number = vertices[vertexOffset + 1];
|
||||
var u1 : Number = uvs[vertexOffset], v1 : Number = uvs[vertexOffset + 1];
|
||||
|
||||
vertexOffset = triangles[i + 1] << 1;
|
||||
var x2 : Number = vertices[vertexOffset], y2 : Number = vertices[vertexOffset + 1];
|
||||
var u2 : Number = uvs[vertexOffset], v2 : Number = uvs[vertexOffset + 1];
|
||||
|
||||
vertexOffset = triangles[i + 2] << 1;
|
||||
var x3 : Number = vertices[vertexOffset], y3 : Number = vertices[vertexOffset + 1];
|
||||
var u3 : Number = uvs[vertexOffset], v3 : Number = uvs[vertexOffset + 1];
|
||||
|
||||
for (var p : int = 0; p < polygonsCount; p++) {
|
||||
var s : int = clippedVertices.length;
|
||||
var clippedVerticesItems : Vector.<Number>;
|
||||
var clippedUvsItems : Vector.<Number>;
|
||||
var clippedTrianglesItems : Vector.<uint>;
|
||||
if (this.clip(x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) {
|
||||
var clipOutputLength : int = clipOutput.length;
|
||||
if (clipOutputLength == 0) continue;
|
||||
var d0 : Number = y2 - y3, d1 : Number = x3 - x2, d2 : Number = x1 - x3, d4 : Number = y3 - y1;
|
||||
var d : Number = 1 / (d0 * d2 + d1 * (y1 - y3));
|
||||
|
||||
var clipOutputCount : int = clipOutputLength >> 1;
|
||||
var clipOutputItems : Vector.<Number> = this.clipOutput;
|
||||
clippedVerticesItems = clippedVertices;
|
||||
clippedVerticesItems.length = s + clipOutputLength;
|
||||
clippedUvsItems = clippedUvs;
|
||||
clippedUvsItems.length = s + clipOutputLength;
|
||||
|
||||
var ii : int;
|
||||
for (ii = 0; ii < clipOutputLength; ii += 2) {
|
||||
var x : Number = clipOutputItems[ii], y : Number = clipOutputItems[ii + 1];
|
||||
clippedVerticesItems[s] = x;
|
||||
clippedVerticesItems[s + 1] = y;
|
||||
var c0 : Number = x - x3, c1 : Number = y - y3;
|
||||
var a : Number = (d0 * c0 + d1 * c1) * d;
|
||||
var b : Number = (d4 * c0 + d2 * c1) * d;
|
||||
var c : Number = 1 - a - b;
|
||||
clippedUvsItems[s] = u1 * a + u2 * b + u3 * c;
|
||||
clippedUvsItems[s + 1] = v1 * a + v2 * b + v3 * c;
|
||||
s += 2;
|
||||
}
|
||||
|
||||
s = clippedTriangles.length;
|
||||
clippedTrianglesItems = clippedTriangles;
|
||||
clippedTrianglesItems.length = s + 3 * (clipOutputCount - 2);
|
||||
clipOutputCount--;
|
||||
for (ii = 1; ii < clipOutputCount; ii++) {
|
||||
clippedTrianglesItems[s] = index;
|
||||
clippedTrianglesItems[s + 1] = (index + ii);
|
||||
clippedTrianglesItems[s + 2] = (index + ii + 1);
|
||||
s += 3;
|
||||
}
|
||||
index += clipOutputCount + 1;
|
||||
|
||||
} else {
|
||||
clippedVerticesItems = clippedVertices;
|
||||
clippedVerticesItems.length = s + 3 * 2;
|
||||
clippedVerticesItems[s] = x1;
|
||||
clippedVerticesItems[s + 1] = y1;
|
||||
clippedVerticesItems[s + 2] = x2;
|
||||
clippedVerticesItems[s + 3] = y2;
|
||||
clippedVerticesItems[s + 4] = x3;
|
||||
clippedVerticesItems[s + 5] = y3;
|
||||
|
||||
clippedUvsItems = clippedUvs;
|
||||
clippedUvsItems.length = s + 3 * 2;
|
||||
clippedUvsItems[s] = u1;
|
||||
clippedUvsItems[s + 1] = v1;
|
||||
clippedUvsItems[s + 2] = u2;
|
||||
clippedUvsItems[s + 3] = v2;
|
||||
clippedUvsItems[s + 4] = u3;
|
||||
clippedUvsItems[s + 5] = v3;
|
||||
|
||||
s = clippedTriangles.length;
|
||||
clippedTrianglesItems = clippedTriangles;
|
||||
clippedTrianglesItems.length = s + 3;
|
||||
clippedTrianglesItems[s] = index;
|
||||
clippedTrianglesItems[s + 1] = (index + 1);
|
||||
clippedTrianglesItems[s + 2] = (index + 2);
|
||||
index += 3;
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Clips the input triangle against the convex, clockwise clipping area. If the triangle lies entirely within the clipping
|
||||
* area, false is returned. The clipping area must duplicate the first vertex at the end of the vertices list. */
|
||||
public function clip (x1: Number, y1: Number, x2: Number, y2: Number, x3: Number, y3: Number, clippingArea: Vector.<Number>, output: Vector.<Number>) : Boolean {
|
||||
var originalOutput : Vector.<Number> = output;
|
||||
var clipped : Boolean = false;
|
||||
|
||||
// Avoid copy at the end.
|
||||
var input: Vector.<Number> = null;
|
||||
if (clippingArea.length % 4 >= 2) {
|
||||
input = output;
|
||||
output = this.scratch;
|
||||
} else
|
||||
input = this.scratch;
|
||||
|
||||
input.length = 0;
|
||||
input.push(x1);
|
||||
input.push(y1);
|
||||
input.push(x2);
|
||||
input.push(y2);
|
||||
input.push(x3);
|
||||
input.push(y3);
|
||||
input.push(x1);
|
||||
input.push(y1);
|
||||
output.length = 0;
|
||||
|
||||
var clippingVertices : Vector.<Number> = clippingArea;
|
||||
var clippingVerticesLast : int = clippingArea.length - 4;
|
||||
var c0 : Number, c2 : Number, ua : Number;
|
||||
var i : int, n : int;
|
||||
for (i = 0;; i += 2) {
|
||||
var edgeX : Number = clippingVertices[i], edgeY : Number = clippingVertices[i + 1];
|
||||
var edgeX2 : Number = clippingVertices[i + 2], edgeY2 : Number = clippingVertices[i + 3];
|
||||
var deltaX : Number = edgeX - edgeX2, deltaY : Number = edgeY - edgeY2;
|
||||
|
||||
var inputVertices : Vector.<Number> = input;
|
||||
var inputVerticesLength : int = input.length - 2, outputStart : int = output.length;
|
||||
for (var ii : int = 0; ii < inputVerticesLength; ii += 2) {
|
||||
var inputX : Number = inputVertices[ii], inputY : Number = inputVertices[ii + 1];
|
||||
var inputX2 : Number = inputVertices[ii + 2], inputY2 : Number = inputVertices[ii + 3];
|
||||
var side2 : Boolean = deltaX * (inputY2 - edgeY2) - deltaY * (inputX2 - edgeX2) > 0;
|
||||
if (deltaX * (inputY - edgeY2) - deltaY * (inputX - edgeX2) > 0) {
|
||||
if (side2) { // v1 inside, v2 inside
|
||||
output.push(inputX2);
|
||||
output.push(inputY2);
|
||||
continue;
|
||||
}
|
||||
// v1 inside, v2 outside
|
||||
c0 = inputY2 - inputY; c2 = inputX2 - inputX;
|
||||
ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / (c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY));
|
||||
output.push(edgeX + (edgeX2 - edgeX) * ua);
|
||||
output.push(edgeY + (edgeY2 - edgeY) * ua);
|
||||
} else if (side2) { // v1 outside, v2 inside
|
||||
c0 = inputY2 - inputY, c2 = inputX2 - inputX;
|
||||
ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / (c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY));
|
||||
output.push(edgeX + (edgeX2 - edgeX) * ua);
|
||||
output.push(edgeY + (edgeY2 - edgeY) * ua);
|
||||
output.push(inputX2);
|
||||
output.push(inputY2);
|
||||
}
|
||||
clipped = true;
|
||||
}
|
||||
|
||||
if (outputStart == output.length) { // All edges outside.
|
||||
originalOutput.length = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
output.push(output[0]);
|
||||
output.push(output[1]);
|
||||
|
||||
if (i == clippingVerticesLast) break;
|
||||
var temp : Vector.<Number> = output;
|
||||
output = input;
|
||||
output.length = 0;
|
||||
input = temp;
|
||||
}
|
||||
|
||||
if (originalOutput != output) {
|
||||
originalOutput.length = 0;
|
||||
for (i = 0, n = output.length - 2; i < n; i++)
|
||||
originalOutput[i] = output[i];
|
||||
} else
|
||||
originalOutput.length = originalOutput.length - 2;
|
||||
|
||||
return clipped;
|
||||
}
|
||||
|
||||
public static function makeClockwise (polygon: Vector.<Number>) : void {
|
||||
var vertices : Vector.<Number> = polygon;
|
||||
var verticeslength : int = polygon.length;
|
||||
|
||||
var area : Number = vertices[verticeslength - 2] * vertices[1] - vertices[0] * vertices[verticeslength - 1];
|
||||
var p1x : Number = 0, p1y : Number = 0, p2x : Number = 0, p2y : Number = 0;
|
||||
var i : int, n : int;
|
||||
for (i = 0, n = verticeslength - 3; i < n; i += 2) {
|
||||
p1x = vertices[i];
|
||||
p1y = vertices[i + 1];
|
||||
p2x = vertices[i + 2];
|
||||
p2y = vertices[i + 3];
|
||||
area += p1x * p2y - p2x * p1y;
|
||||
}
|
||||
if (area < 0) return;
|
||||
|
||||
var lastX : int;
|
||||
for (i = 0, lastX = verticeslength - 2, n = verticeslength >> 1; i < n; i += 2) {
|
||||
var x : Number = vertices[i], y : Number = vertices[i + 1];
|
||||
var other : int = lastX - i;
|
||||
vertices[i] = vertices[other];
|
||||
vertices[i + 1] = vertices[other + 1];
|
||||
vertices[other] = x;
|
||||
vertices[other + 1] = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -29,6 +29,7 @@
|
||||
*****************************************************************************/
|
||||
|
||||
package spine {
|
||||
import spine.attachments.ClippingAttachment;
|
||||
import spine.animation.TwoColorTimeline;
|
||||
import spine.attachments.PointAttachment;
|
||||
import spine.animation.PathConstraintMixTimeline;
|
||||
@ -231,7 +232,7 @@ package spine {
|
||||
var slotIndex : int = skeletonData.findSlotIndex(slotName);
|
||||
var slotEntry : Object = skinMap[slotName];
|
||||
for (var attachmentName : String in slotEntry) {
|
||||
var attachment : Attachment = readAttachment(slotEntry[attachmentName], skin, slotIndex, attachmentName);
|
||||
var attachment : Attachment = readAttachment(slotEntry[attachmentName], skin, slotIndex, attachmentName, skeletonData);
|
||||
if (attachment != null)
|
||||
skin.addAttachment(slotIndex, attachmentName, attachment);
|
||||
}
|
||||
@ -274,7 +275,7 @@ package spine {
|
||||
return skeletonData;
|
||||
}
|
||||
|
||||
private function readAttachment(map : Object, skin : Skin, slotIndex : int, name : String) : Attachment {
|
||||
private function readAttachment(map : Object, skin : Skin, slotIndex : int, name : String, skeletonData: SkeletonData) : Attachment {
|
||||
name = map["name"] || name;
|
||||
|
||||
var typeName : String = map["type"] || "region";
|
||||
@ -353,6 +354,23 @@ package spine {
|
||||
point.color.setFrom(toColor(color, 0), toColor(color, 1), toColor(color, 2), toColor(color, 3));
|
||||
}
|
||||
return point;
|
||||
case AttachmentType.clipping:
|
||||
var clip : ClippingAttachment = attachmentLoader.newClippingAttachment(skin, name);
|
||||
if (!clip) return null;
|
||||
var end : String = map["end"];
|
||||
if (end != null) {
|
||||
var slot : SlotData = skeletonData.findSlot(end);
|
||||
if (slot == null) throw new Error("Clipping end slot not found: " + end);
|
||||
clip.endSlot = slot;
|
||||
}
|
||||
|
||||
vertexCount = int(map["vertexCount"]);
|
||||
readVertices(map, clip, vertexCount << 1);
|
||||
color = map["color"];
|
||||
if (color) {
|
||||
clip.color.setFrom(toColor(color, 0), toColor(color, 1), toColor(color, 2), toColor(color, 3));
|
||||
}
|
||||
return clip;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@ -93,6 +93,10 @@ package spine.attachments {
|
||||
public function newPointAttachment(skin : Skin, name : String) : PointAttachment {
|
||||
return new PointAttachment(name);
|
||||
}
|
||||
|
||||
public function newClippingAttachment(skin : Skin, name : String) : ClippingAttachment {
|
||||
return new ClippingAttachment(name);
|
||||
}
|
||||
|
||||
static public function nextPOT(value : int) : int {
|
||||
value--;
|
||||
|
||||
@ -46,5 +46,8 @@ package spine.attachments {
|
||||
|
||||
/** @return May be null to not load an attachment */
|
||||
function newPointAttachment(skin : Skin, name : String) : PointAttachment;
|
||||
|
||||
/** @return May be null to not load an attachment */
|
||||
function newClippingAttachment(skin : Skin, name : String) : ClippingAttachment;
|
||||
}
|
||||
}
|
||||
@ -37,6 +37,7 @@ package spine.attachments {
|
||||
public static const linkedmesh : AttachmentType = new AttachmentType(3, "linkedmesh");
|
||||
public static const path : AttachmentType = new AttachmentType(4, "path");
|
||||
public static const point : AttachmentType = new AttachmentType(5, "point");
|
||||
public static const clipping : AttachmentType = new AttachmentType(6, "clipping");
|
||||
public var ordinal : int;
|
||||
public var name : String;
|
||||
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
/******************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
package spine.attachments {
|
||||
import spine.Color;
|
||||
import spine.SlotData;
|
||||
|
||||
public class ClippingAttachment extends VertexAttachment {
|
||||
public var endSlot : SlotData;
|
||||
public var color : Color = new Color(0.2275, 0.2275, 0.2275, 1);
|
||||
|
||||
public function ClippingAttachment(name : String) {
|
||||
super(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -33,14 +33,14 @@ package spine.attachments {
|
||||
import spine.Bone;
|
||||
|
||||
public dynamic class RegionAttachment extends Attachment {
|
||||
public const X1 : int = 0;
|
||||
public const Y1 : int = 1;
|
||||
public const X2 : int = 2;
|
||||
public const Y2 : int = 3;
|
||||
public const X3 : int = 4;
|
||||
public const Y3 : int = 5;
|
||||
public const X4 : int = 6;
|
||||
public const Y4 : int = 7;
|
||||
public const BLX : int = 0;
|
||||
public const BLY : int = 1;
|
||||
public const ULX : int = 2;
|
||||
public const ULY : int = 3;
|
||||
public const URX : int = 4;
|
||||
public const URY : int = 5;
|
||||
public const BRX : int = 6;
|
||||
public const BRY : int = 7;
|
||||
public var x : Number;
|
||||
public var y : Number;
|
||||
public var scaleX : Number = 1;
|
||||
@ -57,7 +57,7 @@ package spine.attachments {
|
||||
public var regionHeight : Number;
|
||||
public var regionOriginalWidth : Number; // Unrotated, unstripped size.
|
||||
public var regionOriginalHeight : Number;
|
||||
public var offset : Vector.<Number> = new Vector.<Number>();
|
||||
private var offset : Vector.<Number> = new Vector.<Number>();
|
||||
public var uvs : Vector.<Number> = new Vector.<Number>();
|
||||
|
||||
public function RegionAttachment(name : String) {
|
||||
@ -84,36 +84,36 @@ package spine.attachments {
|
||||
var localX2Sin : Number = localX2 * sin;
|
||||
var localY2Cos : Number = localY2 * cos + y;
|
||||
var localY2Sin : Number = localY2 * sin;
|
||||
offset[X1] = localXCos - localYSin;
|
||||
offset[Y1] = localYCos + localXSin;
|
||||
offset[X2] = localXCos - localY2Sin;
|
||||
offset[Y2] = localY2Cos + localXSin;
|
||||
offset[X3] = localX2Cos - localY2Sin;
|
||||
offset[Y3] = localY2Cos + localX2Sin;
|
||||
offset[X4] = localX2Cos - localYSin;
|
||||
offset[Y4] = localYCos + localX2Sin;
|
||||
offset[BLX] = localXCos - localYSin;
|
||||
offset[BLY] = localYCos + localXSin;
|
||||
offset[ULX] = localXCos - localY2Sin;
|
||||
offset[ULY] = localY2Cos + localXSin;
|
||||
offset[URX] = localX2Cos - localY2Sin;
|
||||
offset[URY] = localY2Cos + localX2Sin;
|
||||
offset[BRX] = localX2Cos - localYSin;
|
||||
offset[BRY] = localYCos + localX2Sin;
|
||||
}
|
||||
|
||||
public function setUVs(u : Number, v : Number, u2 : Number, v2 : Number, rotate : Boolean) : void {
|
||||
var uvs : Vector.<Number> = this.uvs;
|
||||
if (rotate) {
|
||||
uvs[X2] = u;
|
||||
uvs[Y2] = v2;
|
||||
uvs[X3] = u;
|
||||
uvs[Y3] = v;
|
||||
uvs[X4] = u2;
|
||||
uvs[Y4] = v;
|
||||
uvs[X1] = u2;
|
||||
uvs[Y1] = v2;
|
||||
uvs[4] = u;
|
||||
uvs[5] = v2;
|
||||
uvs[6] = u;
|
||||
uvs[7] = v;
|
||||
uvs[0] = u2;
|
||||
uvs[1] = v;
|
||||
uvs[2] = u2;
|
||||
uvs[3] = v2;
|
||||
} else {
|
||||
uvs[X1] = u;
|
||||
uvs[Y1] = v2;
|
||||
uvs[X2] = u;
|
||||
uvs[Y2] = v;
|
||||
uvs[X3] = u2;
|
||||
uvs[Y3] = v;
|
||||
uvs[X4] = u2;
|
||||
uvs[Y4] = v2;
|
||||
uvs[2] = u;
|
||||
uvs[3] = v2;
|
||||
uvs[4] = u;
|
||||
uvs[5] = v;
|
||||
uvs[6] = u2;
|
||||
uvs[7] = v;
|
||||
uvs[0] = u2;
|
||||
uvs[1] = v2;
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,26 +123,26 @@ package spine.attachments {
|
||||
var a : Number = bone.a, b : Number = bone.b, c : Number = bone.c, d : Number = bone.d;
|
||||
var offsetX : Number = 0, offsetY : Number = 0;
|
||||
|
||||
offsetX = vertexOffset[X1];
|
||||
offsetY = vertexOffset[Y1];
|
||||
offsetX = vertexOffset[BRX];
|
||||
offsetY = vertexOffset[BRY];
|
||||
worldVertices[offset] = offsetX * a + offsetY * b + x; // br
|
||||
worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
|
||||
offset += stride;
|
||||
|
||||
offsetX = vertexOffset[X2];
|
||||
offsetY = vertexOffset[Y2];
|
||||
|
||||
offsetX = vertexOffset[BLX];
|
||||
offsetY = vertexOffset[BLY];
|
||||
worldVertices[offset] = offsetX * a + offsetY * b + x; // bl
|
||||
worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
|
||||
offset += stride;
|
||||
|
||||
offsetX = vertexOffset[X3];
|
||||
offsetY = vertexOffset[Y3];
|
||||
|
||||
offsetX = vertexOffset[ULX];
|
||||
offsetY = vertexOffset[ULY];
|
||||
worldVertices[offset] = offsetX * a + offsetY * b + x; // ul
|
||||
worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
|
||||
offset += stride;
|
||||
|
||||
offsetX = vertexOffset[X4];
|
||||
offsetY = vertexOffset[Y4];
|
||||
|
||||
offsetX = vertexOffset[URX];
|
||||
offsetY = vertexOffset[URY];
|
||||
worldVertices[offset] = offsetX * a + offsetY * b + x; // ur
|
||||
worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -1,279 +1,251 @@
|
||||
|
||||
raptor.png
|
||||
size: 1024,1024
|
||||
size: 2048,2048
|
||||
format: RGBA8888
|
||||
filter: Linear,Linear
|
||||
repeat: none
|
||||
back_arm
|
||||
rotate: true
|
||||
xy: 140, 191
|
||||
size: 46, 29
|
||||
orig: 46, 29
|
||||
rotate: false
|
||||
xy: 1888, 1638
|
||||
size: 91, 57
|
||||
orig: 91, 57
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
back_bracer
|
||||
rotate: true
|
||||
xy: 167, 317
|
||||
size: 39, 28
|
||||
orig: 39, 28
|
||||
rotate: false
|
||||
xy: 1888, 1581
|
||||
size: 77, 55
|
||||
orig: 77, 55
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
back_hand
|
||||
rotate: false
|
||||
xy: 167, 358
|
||||
size: 36, 34
|
||||
orig: 36, 34
|
||||
xy: 1954, 1764
|
||||
size: 72, 68
|
||||
orig: 72, 68
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
back_knee
|
||||
rotate: false
|
||||
xy: 299, 478
|
||||
size: 49, 67
|
||||
orig: 49, 67
|
||||
xy: 275, 438
|
||||
size: 97, 134
|
||||
orig: 97, 134
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
back_thigh
|
||||
rotate: true
|
||||
xy: 167, 437
|
||||
size: 39, 24
|
||||
orig: 39, 24
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
eyes_closed
|
||||
rotate: true
|
||||
xy: 2, 2
|
||||
size: 47, 45
|
||||
orig: 47, 45
|
||||
rotate: false
|
||||
xy: 1778, 1518
|
||||
size: 78, 47
|
||||
orig: 78, 47
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
eyes_open
|
||||
rotate: true
|
||||
xy: 49, 2
|
||||
size: 47, 45
|
||||
orig: 47, 45
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
eyes_surprised
|
||||
rotate: true
|
||||
xy: 96, 2
|
||||
size: 47, 45
|
||||
orig: 47, 45
|
||||
rotate: false
|
||||
xy: 275, 347
|
||||
size: 93, 89
|
||||
orig: 93, 89
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
front_arm
|
||||
rotate: false
|
||||
xy: 419, 544
|
||||
size: 48, 30
|
||||
orig: 48, 30
|
||||
xy: 830, 1089
|
||||
size: 96, 60
|
||||
orig: 96, 60
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
front_bracer
|
||||
rotate: false
|
||||
xy: 880, 695
|
||||
size: 41, 29
|
||||
orig: 41, 29
|
||||
xy: 1888, 1697
|
||||
size: 81, 58
|
||||
orig: 81, 58
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
front_hand
|
||||
rotate: true
|
||||
xy: 167, 394
|
||||
size: 41, 38
|
||||
orig: 41, 38
|
||||
rotate: false
|
||||
xy: 1870, 1757
|
||||
size: 82, 75
|
||||
orig: 82, 75
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
front_open_hand
|
||||
rotate: false
|
||||
xy: 880, 726
|
||||
size: 43, 44
|
||||
orig: 43, 44
|
||||
xy: 192, 15
|
||||
size: 86, 87
|
||||
orig: 86, 87
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
front_thigh
|
||||
rotate: false
|
||||
xy: 360, 545
|
||||
size: 57, 29
|
||||
orig: 57, 29
|
||||
xy: 714, 1091
|
||||
size: 114, 58
|
||||
orig: 114, 58
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
gun
|
||||
rotate: false
|
||||
xy: 785, 774
|
||||
size: 107, 103
|
||||
orig: 107, 103
|
||||
xy: 1563, 1543
|
||||
size: 213, 206
|
||||
orig: 213, 206
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
gun_nohand
|
||||
rotate: false
|
||||
xy: 614, 703
|
||||
size: 105, 102
|
||||
orig: 105, 102
|
||||
xy: 1223, 1403
|
||||
size: 210, 203
|
||||
orig: 210, 203
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
head
|
||||
rotate: false
|
||||
xy: 2, 137
|
||||
size: 136, 149
|
||||
orig: 136, 149
|
||||
xy: 2, 274
|
||||
size: 271, 298
|
||||
orig: 271, 298
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
lower_leg
|
||||
rotate: true
|
||||
xy: 780, 699
|
||||
size: 73, 98
|
||||
orig: 73, 98
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
mouth_grind
|
||||
rotate: false
|
||||
xy: 469, 544
|
||||
size: 47, 30
|
||||
orig: 47, 30
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
mouth_oooo
|
||||
rotate: true
|
||||
xy: 894, 772
|
||||
size: 105, 30
|
||||
orig: 105, 30
|
||||
xy: 551, 893
|
||||
size: 146, 195
|
||||
orig: 146, 195
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
mouth_smile
|
||||
rotate: true
|
||||
xy: 140, 239
|
||||
size: 47, 30
|
||||
orig: 47, 30
|
||||
rotate: false
|
||||
xy: 928, 1090
|
||||
size: 93, 59
|
||||
orig: 93, 59
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
neck
|
||||
rotate: true
|
||||
xy: 538, 577
|
||||
size: 18, 21
|
||||
orig: 18, 21
|
||||
rotate: false
|
||||
xy: 330, 908
|
||||
size: 36, 41
|
||||
orig: 36, 41
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_arm_back
|
||||
rotate: false
|
||||
xy: 940, 936
|
||||
size: 82, 86
|
||||
orig: 82, 86
|
||||
xy: 386, 916
|
||||
size: 163, 172
|
||||
orig: 163, 172
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_body
|
||||
rotate: false
|
||||
xy: 2, 737
|
||||
size: 610, 285
|
||||
orig: 610, 285
|
||||
xy: 2, 1467
|
||||
size: 1219, 570
|
||||
orig: 1219, 570
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_front_arm
|
||||
rotate: true
|
||||
xy: 195, 464
|
||||
size: 81, 102
|
||||
orig: 81, 102
|
||||
rotate: false
|
||||
xy: 1870, 1834
|
||||
size: 162, 203
|
||||
orig: 162, 203
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_front_leg
|
||||
rotate: false
|
||||
xy: 2, 478
|
||||
size: 191, 257
|
||||
orig: 191, 257
|
||||
xy: 2, 951
|
||||
size: 382, 514
|
||||
orig: 382, 514
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_hindleg_back
|
||||
rotate: false
|
||||
xy: 614, 807
|
||||
size: 169, 215
|
||||
orig: 169, 215
|
||||
xy: 1223, 1608
|
||||
size: 338, 429
|
||||
orig: 338, 429
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_horn
|
||||
rotate: false
|
||||
xy: 360, 655
|
||||
size: 182, 80
|
||||
orig: 182, 80
|
||||
xy: 714, 1306
|
||||
size: 363, 159
|
||||
orig: 363, 159
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_horn_back
|
||||
rotate: false
|
||||
xy: 360, 576
|
||||
size: 176, 77
|
||||
orig: 176, 77
|
||||
xy: 714, 1151
|
||||
size: 351, 153
|
||||
orig: 351, 153
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_jaw
|
||||
rotate: false
|
||||
xy: 785, 879
|
||||
size: 153, 143
|
||||
orig: 153, 143
|
||||
xy: 1563, 1751
|
||||
size: 305, 286
|
||||
orig: 305, 286
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_saddle_noshadow
|
||||
rotate: false
|
||||
xy: 2, 288
|
||||
size: 163, 188
|
||||
orig: 163, 188
|
||||
xy: 2, 574
|
||||
size: 326, 375
|
||||
orig: 326, 375
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_saddle_strap_front
|
||||
rotate: false
|
||||
xy: 721, 710
|
||||
size: 57, 95
|
||||
orig: 57, 95
|
||||
xy: 1435, 1417
|
||||
size: 114, 189
|
||||
orig: 114, 189
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_saddle_strap_rear
|
||||
rotate: true
|
||||
xy: 940, 880
|
||||
size: 54, 74
|
||||
orig: 54, 74
|
||||
rotate: false
|
||||
xy: 1079, 1317
|
||||
size: 108, 148
|
||||
orig: 108, 148
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_saddle_w_shadow
|
||||
rotate: false
|
||||
xy: 195, 547
|
||||
size: 163, 188
|
||||
orig: 163, 188
|
||||
xy: 386, 1090
|
||||
size: 326, 375
|
||||
orig: 326, 375
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
raptor_tongue
|
||||
rotate: true
|
||||
xy: 544, 649
|
||||
size: 86, 64
|
||||
orig: 86, 64
|
||||
rotate: false
|
||||
xy: 1551, 1413
|
||||
size: 171, 128
|
||||
orig: 171, 128
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
stirrup_back
|
||||
rotate: true
|
||||
xy: 140, 145
|
||||
size: 44, 35
|
||||
orig: 44, 35
|
||||
rotate: false
|
||||
xy: 275, 276
|
||||
size: 87, 69
|
||||
orig: 87, 69
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
stirrup_front
|
||||
rotate: false
|
||||
xy: 538, 597
|
||||
size: 45, 50
|
||||
orig: 45, 50
|
||||
xy: 2, 2
|
||||
size: 89, 100
|
||||
orig: 89, 100
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
stirrup_strap
|
||||
rotate: false
|
||||
xy: 350, 497
|
||||
size: 49, 46
|
||||
orig: 49, 46
|
||||
xy: 93, 11
|
||||
size: 97, 91
|
||||
orig: 97, 91
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
torso
|
||||
rotate: true
|
||||
xy: 610, 647
|
||||
size: 54, 91
|
||||
orig: 54, 91
|
||||
rotate: false
|
||||
xy: 1778, 1567
|
||||
size: 108, 182
|
||||
orig: 108, 182
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
visor
|
||||
rotate: false
|
||||
xy: 2, 51
|
||||
size: 131, 84
|
||||
orig: 131, 84
|
||||
xy: 2, 104
|
||||
size: 261, 168
|
||||
orig: 261, 168
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"skeleton": { "hash": "WOArBZLexLEX/Tow3AuM8ddszEE", "spine": "3.6.14-beta", "width": 1223.73, "height": 1055.62, "images": "./images/" },
|
||||
"skeleton": { "hash": "T+jP778edtEIrEMb7QvVNAgiHUo", "spine": "3.6.14-beta", "width": 1223.73, "height": 1056.91, "images": "./images/" },
|
||||
"bones": [
|
||||
{ "name": "root" },
|
||||
{ "name": "hip", "parent": "root", "rotation": 3.16, "x": -136.79, "y": 415.48, "color": "fbff00ff" },
|
||||
@ -199,6 +199,7 @@
|
||||
{ "name": "tongue3", "parent": "tongue2", "length": 43.65, "rotation": 12.86, "x": 44.27, "y": -0.21, "color": "fff200ff" }
|
||||
],
|
||||
"slots": [
|
||||
{ "name": "clip", "bone": "root", "attachment": "clip" },
|
||||
{ "name": "back_hand", "bone": "back_hand", "attachment": "back_hand" },
|
||||
{ "name": "back_arm", "bone": "back_arm", "attachment": "back_arm" },
|
||||
{ "name": "back_bracer", "bone": "back_bracer", "attachment": "back_bracer" },
|
||||
@ -310,6 +311,15 @@
|
||||
"back_thigh": {
|
||||
"back_thigh": { "x": 37.85, "y": -4.37, "rotation": 19.25, "width": 78, "height": 47 }
|
||||
},
|
||||
"clip": {
|
||||
"clip": {
|
||||
"type": "clipping",
|
||||
"end": "clip",
|
||||
"vertexCount": 25,
|
||||
"vertices": [ -31.42, 352.85, -182.02, 382.27, -214.91, 562.3, -8.92, 647.12, 183.22, 555.37, 254.19, 375.35, 261.12, 153.78, 3.2, 13.57, -270.3, -36.63, -408.78, 48.19, -349.93, 280.14, -228.76, 133.01, -59.12, 94.93, 107.06, 160.71, 202.26, 349.38, 122.64, 487.86, -41.81, 557.1, -142.21, 489.6, -57.39, 422.09, 49.94, 432.47, 133.02, 370.16, 94.94, 271.49, 43.01, 186.67, -138.74, 174.55, -230.49, 273.22 ],
|
||||
"color": "ce3a3aff"
|
||||
}
|
||||
},
|
||||
"eyes_open": {
|
||||
"eyes_open": { "x": 93.24, "y": -25.45, "rotation": -70.58, "width": 93, "height": 89 }
|
||||
},
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 495 KiB After Width: | Height: | Size: 1.7 MiB |
@ -38,7 +38,7 @@ package spine.examples {
|
||||
private var _starling : Starling;
|
||||
|
||||
public function Main() {
|
||||
_starling = new Starling(SpineboyExample, stage);
|
||||
_starling = new Starling(RaptorExample, stage);
|
||||
_starling.enableErrorChecking = true;
|
||||
_starling.showStats = true;
|
||||
_starling.skipUnchangedFrames = false;
|
||||
|
||||
@ -65,13 +65,16 @@ package spine.examples {
|
||||
json.scale = 0.5;
|
||||
var skeletonData : SkeletonData = json.readSkeletonData(new RaptorJson());
|
||||
|
||||
this.x = 400;
|
||||
this.y = 560;
|
||||
|
||||
skeleton = new SkeletonAnimation(skeletonData);
|
||||
skeleton.x = 400;
|
||||
skeleton.y = 560;
|
||||
// skeleton.x = 400;
|
||||
// skeleton.y = 560;
|
||||
skeleton.state.setAnimationByName(0, "walk", true);
|
||||
|
||||
addChild(skeleton);
|
||||
Starling.juggler.add(skeleton);
|
||||
// Starling.juggler.add(skeleton);
|
||||
|
||||
addEventListener(TouchEvent.TOUCH, onClick);
|
||||
}
|
||||
|
||||
Binary file not shown.
@ -27,8 +27,39 @@
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
/******************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
package spine.starling {
|
||||
import spine.attachments.ClippingAttachment;
|
||||
import spine.SkeletonClipping;
|
||||
import spine.Bone;
|
||||
import spine.Skeleton;
|
||||
import spine.SkeletonData;
|
||||
@ -60,6 +91,8 @@ package spine.starling {
|
||||
public var batchable : Boolean = true;
|
||||
private var _smoothing : String = "bilinear";
|
||||
private static var _twoColorStyle : TwoColorMeshStyle;
|
||||
private static var clipper: SkeletonClipping = new SkeletonClipping();
|
||||
private static var QUAD_INDICES : Vector.<uint> = new <uint>[0, 1, 2, 2, 3, 0];
|
||||
|
||||
public function SkeletonSprite(skeletonData : SkeletonData) {
|
||||
Bone.yDown = true;
|
||||
@ -71,13 +104,13 @@ package spine.starling {
|
||||
}
|
||||
|
||||
override public function render(painter : Painter) : void {
|
||||
var clipper: SkeletonClipping = SkeletonSprite.clipper;
|
||||
painter.state.alpha *= skeleton.color.a;
|
||||
var originalBlendMode : String = painter.state.blendMode;
|
||||
var r : Number = skeleton.color.r * 255;
|
||||
var g : Number = skeleton.color.g * 255;
|
||||
var b : Number = skeleton.color.b * 255;
|
||||
var drawOrder : Vector.<Slot> = skeleton.drawOrder;
|
||||
var worldVertices : Vector.<Number> = _tempVertices;
|
||||
var drawOrder : Vector.<Slot> = skeleton.drawOrder;
|
||||
var ii : int, iii : int;
|
||||
var attachmentColor: spine.Color;
|
||||
var rgb : uint, a : Number;
|
||||
@ -88,6 +121,7 @@ package spine.starling {
|
||||
var uvs : Vector.<Number>;
|
||||
|
||||
for (var i : int = 0, n : int = drawOrder.length; i < n; ++i) {
|
||||
var worldVertices : Vector.<Number> = _tempVertices;
|
||||
var slot : Slot = drawOrder[i];
|
||||
if (slot.attachment is RegionAttachment) {
|
||||
var region : RegionAttachment = slot.attachment as RegionAttachment;
|
||||
@ -97,20 +131,20 @@ package spine.starling {
|
||||
region.computeWorldVertices(slot.bone, worldVertices, 0, 2);
|
||||
|
||||
mesh = region.rendererObject as SkeletonMesh;
|
||||
indices = QUAD_INDICES;
|
||||
if (mesh == null) {
|
||||
if (region.rendererObject is Image)
|
||||
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);
|
||||
|
||||
region.rendererObject = mesh = new SkeletonMesh(Image(AtlasRegion(region.rendererObject).rendererObject).texture);
|
||||
|
||||
indexData = mesh.getIndexData();
|
||||
indices = new <uint>[0, 1, 2, 2, 3, 0];
|
||||
for (ii = 0; ii < indices.length; ii++)
|
||||
indexData.setIndex(ii, indices[ii]);
|
||||
indexData.numIndices = 6;
|
||||
indexData.numIndices = indices.length;
|
||||
indexData.trim();
|
||||
}
|
||||
|
||||
indexData = mesh.getIndexData();
|
||||
attachmentColor = region.color;
|
||||
uvs = region.uvs;
|
||||
} else if (slot.attachment is MeshAttachment) {
|
||||
@ -121,6 +155,7 @@ package spine.starling {
|
||||
meshAttachment.computeWorldVertices(slot, 0, meshAttachment.worldVerticesLength, worldVertices, 0, 2);
|
||||
|
||||
mesh = meshAttachment.rendererObject as SkeletonMesh;
|
||||
indices = meshAttachment.triangles;
|
||||
if (mesh == null) {
|
||||
if (meshAttachment.rendererObject is Image)
|
||||
meshAttachment.rendererObject = mesh = new SkeletonMesh(Image(meshAttachment.rendererObject).texture);
|
||||
@ -129,17 +164,20 @@ package spine.starling {
|
||||
mesh.setStyle(_twoColorStyle);
|
||||
|
||||
indexData = mesh.getIndexData();
|
||||
indices = meshAttachment.triangles;
|
||||
indicesLength = meshAttachment.triangles.length;
|
||||
for (ii = 0; ii < indicesLength; ii++) {
|
||||
indexData.setIndex(ii, indices[ii]);
|
||||
}
|
||||
indexData.numIndices = indicesLength;
|
||||
indexData.trim();
|
||||
}
|
||||
|
||||
}
|
||||
indexData = mesh.getIndexData();
|
||||
attachmentColor = meshAttachment.color;
|
||||
uvs = meshAttachment.uvs;
|
||||
} else if (slot.attachment is ClippingAttachment) {
|
||||
var clip : ClippingAttachment = ClippingAttachment(slot.attachment);
|
||||
clipper.clipStart(slot, clip);
|
||||
continue;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
@ -149,6 +187,22 @@ package spine.starling {
|
||||
if (slot.darkColor == null) dark = Color.rgb(0, 0, 0);
|
||||
else dark = Color.rgb(slot.darkColor.r * 255, slot.darkColor.g * 255, slot.darkColor.b * 255);
|
||||
|
||||
if (clipper.isClipping()) {
|
||||
clipper.clipTriangles(worldVertices, indices, indices.length, uvs);
|
||||
|
||||
verticesCount = clipper.clippedVertices.length >> 1;
|
||||
worldVertices = clipper.clippedVertices;
|
||||
uvs = clipper.clippedUvs;
|
||||
|
||||
indices = clipper.clippedTriangles;
|
||||
indicesLength = indices.length;
|
||||
for (ii = 0; ii < indicesLength; ii++) {
|
||||
indexData.setIndex(ii, indices[ii]);
|
||||
}
|
||||
indexData.numIndices = indicesLength;
|
||||
indexData.trim();
|
||||
}
|
||||
|
||||
// Mesh doesn't retain the style, can't find the reason why
|
||||
mesh.setStyle(_twoColorStyle);
|
||||
vertexData = mesh.getVertexData();
|
||||
@ -161,8 +215,11 @@ package spine.starling {
|
||||
vertexData.numVertices = verticesCount;
|
||||
painter.state.blendMode = blendModes[slot.data.blendMode.ordinal];
|
||||
painter.batchMesh(mesh);
|
||||
|
||||
clipper.clipEndWithSlot(slot);
|
||||
}
|
||||
painter.state.blendMode = originalBlendMode;
|
||||
clipper.clipEnd();
|
||||
}
|
||||
|
||||
override public function hitTest(localPoint : Point) : DisplayObject {
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
*****************************************************************************/
|
||||
|
||||
package spine.starling {
|
||||
import spine.attachments.ClippingAttachment;
|
||||
import spine.attachments.PointAttachment;
|
||||
import spine.attachments.PathAttachment;
|
||||
|
||||
@ -129,5 +130,9 @@ package spine.starling {
|
||||
public function newPointAttachment(skin : Skin, name : String) : PointAttachment {
|
||||
return new PointAttachment(name);
|
||||
}
|
||||
|
||||
public function newClippingAttachment(skin : Skin, name : String) : ClippingAttachment {
|
||||
return new ClippingAttachment(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user