mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
[as3] Separated triangulation and convex decomposition
This commit is contained in:
parent
f757b39fb1
commit
73dce74fcc
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
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/Triangulator.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
|
||||
|
||||
@ -32,7 +32,7 @@ package spine {
|
||||
import spine.attachments.ClippingAttachment;
|
||||
|
||||
public class SkeletonClipping {
|
||||
private var decomposer : ConvexDecomposer = new ConvexDecomposer();
|
||||
private var triangulator : Triangulator = new Triangulator();
|
||||
private var clippingPolygon : Vector.<Number> = new Vector.<Number>();
|
||||
private var clipOutput : Vector.<Number> = new Vector.<Number>();
|
||||
public var clippedVertices : Vector.<Number> = new Vector.<Number>();
|
||||
@ -46,8 +46,8 @@ package spine {
|
||||
public function SkeletonClipping () {
|
||||
}
|
||||
|
||||
public function clipStart (slot: Slot, clip: ClippingAttachment) : void {
|
||||
if (this.clipAttachment != null) return;
|
||||
public function clipStart (slot: Slot, clip: ClippingAttachment) : int {
|
||||
if (this.clipAttachment != null) return 0;
|
||||
this.clipAttachment = clip;
|
||||
|
||||
var i : int, n : int = clip.worldVerticesLength;
|
||||
@ -56,13 +56,15 @@ package spine {
|
||||
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);
|
||||
var clippingPolygons : Vector.<Vector.<Number>> = this.clippingPolygons = this.triangulator.decompose(clippingPolygon, triangulator.triangulate(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]);
|
||||
}
|
||||
|
||||
return clippingPolygons.length;
|
||||
}
|
||||
|
||||
public function clipEndWithSlot (slot: Slot) : void {
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
package spine {
|
||||
public class ConvexDecomposer {
|
||||
public class Triangulator {
|
||||
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>();
|
||||
@ -41,12 +41,12 @@ package spine {
|
||||
return new Vector.<int>();
|
||||
});
|
||||
|
||||
public function ConvexDecomposer () {
|
||||
public function Triangulator () {
|
||||
}
|
||||
|
||||
public function decompose(input : Vector.<Number>) : Vector.<Vector.<Number>> {
|
||||
var vertices : Vector.<Number> = input;
|
||||
var vertexCount : int = input.length >> 1;
|
||||
|
||||
public function triangulate(verticesArray : Vector.<Number>) : Vector.<int> {
|
||||
var vertices : Vector.<Number> = verticesArray;
|
||||
var vertexCount : int = verticesArray.length >> 1;
|
||||
var i : int, n : int;
|
||||
|
||||
var indices : Vector.<int> = this.indicesArray;
|
||||
@ -118,8 +118,14 @@ package spine {
|
||||
triangles.push(indices[0]);
|
||||
triangles.push(indices[1]);
|
||||
}
|
||||
|
||||
return triangles;
|
||||
}
|
||||
|
||||
public function decompose(verticesArray : Vector.<Number>, triangles : Vector.<int>) : Vector.<Vector.<Number>> {
|
||||
var vertices : Vector.<Number> = verticesArray;
|
||||
var convexPolygons : Vector.<Vector.<Number>> = this.convexPolygons;
|
||||
var i : int, n : int;
|
||||
for (i = 0, n = convexPolygons.length; i < n; i++) {
|
||||
this.polygonPool.free(convexPolygons[i]);
|
||||
}
|
||||
@ -154,8 +160,8 @@ package spine {
|
||||
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]);
|
||||
winding1 = Triangulator.winding(polygon[o], polygon[o + 1], polygon[o + 2], polygon[o + 3], x3, y3);
|
||||
winding2 = Triangulator.winding(x3, y3, polygon[0], polygon[1], polygon[2], polygon[3]);
|
||||
if (winding1 == lastWinding && winding2 == lastWinding) {
|
||||
polygon.push(x3);
|
||||
polygon.push(y3);
|
||||
@ -183,7 +189,7 @@ package spine {
|
||||
polygonIndices.push(t1);
|
||||
polygonIndices.push(t2);
|
||||
polygonIndices.push(t3);
|
||||
lastWinding = ConvexDecomposer.winding(x1, y1, x2, y2, x3, y3);
|
||||
lastWinding = Triangulator.winding(x1, y1, x2, y2, x3, y3);
|
||||
fanBaseIndex = t1;
|
||||
}
|
||||
}
|
||||
@ -206,9 +212,9 @@ package spine {
|
||||
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);
|
||||
var currWinding : int = Triangulator.winding(prevPrevX, prevPrevY, prevX, prevY, firstX, firstY);
|
||||
|
||||
for (ii = 0; ii < n; ii++) {
|
||||
for (var ii : int = 0; ii < n; ii++) {
|
||||
if (ii == i) continue;
|
||||
var otherIndices : Vector.<int>= convexPolygonsIndices[ii];
|
||||
if (otherIndices.length != 3) continue;
|
||||
@ -221,8 +227,8 @@ package spine {
|
||||
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);
|
||||
winding1 = Triangulator.winding(prevPrevX, prevPrevY, prevX, prevY, x3, y3);
|
||||
winding2 = Triangulator.winding(x3, y3, firstX, firstY, secondX, secondY);
|
||||
if (winding1 == currWinding && winding2 == currWinding) {
|
||||
otherPoly.length = 0;
|
||||
otherIndices.length = 0;
|
||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user