mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 23:34:53 +08:00
spine-as3 updated to v3.1.
This commit is contained in:
parent
516c59b303
commit
1ccfaab4c9
@ -10,7 +10,7 @@ The Spine Runtimes are developed with the intent to be used with data exported f
|
||||
|
||||
## Spine version
|
||||
|
||||
spine-as3 works with data exported from the latest version of Spine, except linked meshes are [not yet supported](https://trello.com/c/bERJAFEq/73-update-runtimes-to-support-v3-1-linked-meshes).
|
||||
spine-as3 works with data exported from the latest version of Spine.
|
||||
|
||||
spine-as3 supports all Spine features, including meshes. If using the `spine.flash` classes for rendering, meshes are not supported.
|
||||
|
||||
|
||||
Binary file not shown.
@ -119,85 +119,79 @@ public class Bone implements Updatable {
|
||||
_b = pa * lb + pb * ld;
|
||||
_c = pc * la + pd * lc;
|
||||
_d = pc * lb + pd * ld;
|
||||
} else if (data.inheritRotation) { // No scale inheritance.
|
||||
pa = 1;
|
||||
pb = 0;
|
||||
pc = 0;
|
||||
pd = 1;
|
||||
do {
|
||||
radians = parent.appliedRotation * MathUtils.degRad;
|
||||
cos = Math.cos(radians);
|
||||
sin = Math.sin(radians);
|
||||
var temp1:Number = pa * cos + pb * sin;
|
||||
pb = pa * -sin + pb * cos;
|
||||
pa = temp1;
|
||||
temp1 = pc * cos + pd * sin;
|
||||
pd = pc * -sin + pd * cos;
|
||||
pc = temp1;
|
||||
|
||||
if (!parent.data.inheritRotation) break;
|
||||
parent = parent.parent;
|
||||
} while (parent != null);
|
||||
_a = pa * la + pb * lc;
|
||||
_b = pa * lb + pb * ld;
|
||||
_c = pc * la + pd * lc;
|
||||
_d = pc * lb + pd * ld;
|
||||
if (_skeleton.flipX) {
|
||||
_a = -_a;
|
||||
_b = -_b;
|
||||
}
|
||||
if (_skeleton.flipY != yDown) {
|
||||
_c = -_c;
|
||||
_d = -_d;
|
||||
}
|
||||
} else if (data.inheritScale) { // No rotation inheritance.
|
||||
pa = 1;
|
||||
pb = 0;
|
||||
pc = 0;
|
||||
pd = 1;
|
||||
do {
|
||||
radians = parent.rotation * MathUtils.degRad;
|
||||
cos = Math.cos(radians);
|
||||
sin = Math.sin(radians);
|
||||
var psx:Number = parent.appliedScaleX, psy:Number = parent.appliedScaleY;
|
||||
var za:Number = cos * psx, zb:Number = -sin * psy, zc:Number = sin * psx, zd:Number = cos * psy;
|
||||
var temp2:Number = pa * za + pb * zc;
|
||||
pb = pa * zb + pb * zd;
|
||||
pa = temp2;
|
||||
temp2 = pc * za + pd * zc;
|
||||
pd = pc * zb + pd * zd;
|
||||
pc = temp2;
|
||||
|
||||
if (psx < 0) radians = -radians;
|
||||
cos = Math.cos(-radians);
|
||||
sin = Math.sin(-radians);
|
||||
temp2 = pa * cos + pb * sin;
|
||||
pb = pa * -sin + pb * cos;
|
||||
pa = temp2;
|
||||
temp2 = pc * cos + pd * sin;
|
||||
pd = pc * -sin + pd * cos;
|
||||
pc = temp2;
|
||||
|
||||
if (!parent.data.inheritScale) break;
|
||||
parent = parent.parent;
|
||||
} while (parent != null);
|
||||
_a = pa * la + pb * lc;
|
||||
_b = pa * lb + pb * ld;
|
||||
_c = pc * la + pd * lc;
|
||||
_d = pc * lb + pd * ld;
|
||||
if (_skeleton.flipX) {
|
||||
_a = -_a;
|
||||
_b = -_b;
|
||||
}
|
||||
if (_skeleton.flipY != yDown) {
|
||||
_c = -_c;
|
||||
_d = -_d;
|
||||
}
|
||||
} else {
|
||||
_a = la;
|
||||
_b = lb;
|
||||
_c = lc;
|
||||
_d = ld;
|
||||
if (data.inheritRotation) { // No scale inheritance.
|
||||
pa = 1;
|
||||
pb = 0;
|
||||
pc = 0;
|
||||
pd = 1;
|
||||
do {
|
||||
radians = parent.appliedRotation * MathUtils.degRad;
|
||||
cos = Math.cos(radians);
|
||||
sin = Math.sin(radians);
|
||||
var temp1:Number = pa * cos + pb * sin;
|
||||
pb = pa * -sin + pb * cos;
|
||||
pa = temp1;
|
||||
temp1 = pc * cos + pd * sin;
|
||||
pd = pc * -sin + pd * cos;
|
||||
pc = temp1;
|
||||
|
||||
if (!parent.data.inheritRotation) break;
|
||||
parent = parent.parent;
|
||||
} while (parent != null);
|
||||
_a = pa * la + pb * lc;
|
||||
_b = pa * lb + pb * ld;
|
||||
_c = pc * la + pd * lc;
|
||||
_d = pc * lb + pd * ld;
|
||||
} else if (data.inheritScale) { // No rotation inheritance.
|
||||
pa = 1;
|
||||
pb = 0;
|
||||
pc = 0;
|
||||
pd = 1;
|
||||
do {
|
||||
radians = parent.rotation * MathUtils.degRad;
|
||||
cos = Math.cos(radians);
|
||||
sin = Math.sin(radians);
|
||||
var psx:Number = parent.appliedScaleX, psy:Number = parent.appliedScaleY;
|
||||
var za:Number = cos * psx, zb:Number = -sin * psy, zc:Number = sin * psx, zd:Number = cos * psy;
|
||||
var temp2:Number = pa * za + pb * zc;
|
||||
pb = pa * zb + pb * zd;
|
||||
pa = temp2;
|
||||
temp2 = pc * za + pd * zc;
|
||||
pd = pc * zb + pd * zd;
|
||||
pc = temp2;
|
||||
|
||||
if (psx < 0) radians = -radians;
|
||||
cos = Math.cos(-radians);
|
||||
sin = Math.sin(-radians);
|
||||
temp2 = pa * cos + pb * sin;
|
||||
pb = pa * -sin + pb * cos;
|
||||
pa = temp2;
|
||||
temp2 = pc * cos + pd * sin;
|
||||
pd = pc * -sin + pd * cos;
|
||||
pc = temp2;
|
||||
|
||||
if (!parent.data.inheritScale) break;
|
||||
parent = parent.parent;
|
||||
} while (parent != null);
|
||||
_a = pa * la + pb * lc;
|
||||
_b = pa * lb + pb * ld;
|
||||
_c = pc * la + pd * lc;
|
||||
_d = pc * lb + pd * ld;
|
||||
} else {
|
||||
_a = la;
|
||||
_b = lb;
|
||||
_c = lc;
|
||||
_d = ld;
|
||||
}
|
||||
if (_skeleton.flipX) {
|
||||
_a = -_a;
|
||||
_b = -_b;
|
||||
}
|
||||
if (_skeleton.flipY != yDown) {
|
||||
_c = -_c;
|
||||
_d = -_d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -84,7 +84,7 @@ public class IkConstraint implements Updatable {
|
||||
rotationIK = 360 - rotationIK;
|
||||
if (rotationIK > 180) rotationIK -= 360;
|
||||
else if (rotationIK < -180) rotationIK += 360;
|
||||
bone.updateWorldTransformWith(bone.x, bone.y, rotation + (rotationIK - rotation) * alpha, bone.scaleX, bone.scaleY);
|
||||
bone.updateWorldTransformWith(bone.x, bone.y, rotation + (rotationIK - rotation) * alpha, bone.appliedScaleX, bone.appliedScaleY);
|
||||
}
|
||||
|
||||
/** Adjusts the parent and child bone rotations so the tip of the child is as close to the target position as possible. The
|
||||
@ -92,26 +92,32 @@ public class IkConstraint implements Updatable {
|
||||
* @param child Any descendant bone of the parent. */
|
||||
static public function apply2 (parent:Bone, child:Bone, targetX:Number, targetY:Number, bendDir:int, alpha:Number) : void {
|
||||
if (alpha == 0) return;
|
||||
var px:Number = parent.x, py:Number = parent.y, psx:Number = parent.scaleX, psy:Number = parent.scaleY;
|
||||
var csx:Number = child.scaleX, cy:Number = child.y;
|
||||
var offset1:int, offset2:int, sign2:int;
|
||||
var px:Number = parent.x, py:Number = parent.y, psx:Number = parent.appliedScaleX, psy:Number = parent.appliedScaleY;
|
||||
var o1:int, o2:int, s2:int;
|
||||
if (psx < 0) {
|
||||
psx = -psx;
|
||||
offset1 = 180;
|
||||
sign2 = -1;
|
||||
o1 = 180;
|
||||
s2 = -1;
|
||||
} else {
|
||||
offset1 = 0;
|
||||
sign2 = 1;
|
||||
o1 = 0;
|
||||
s2 = 1;
|
||||
}
|
||||
if (psy < 0) {
|
||||
psy = -psy;
|
||||
sign2 = -sign2;
|
||||
s2 = -s2;
|
||||
}
|
||||
var cx:Number = child.x, cy:Number = child.y, csx:Number = child.appliedScaleX;
|
||||
var u:Boolean = Math.abs(psx - psy) <= 0.0001;
|
||||
if (!u && cy != 0) {
|
||||
child._worldX = parent.a * cx + parent.worldX;
|
||||
child._worldY = parent.c * cx + parent.worldY;
|
||||
cy = 0;
|
||||
}
|
||||
if (csx < 0) {
|
||||
csx = -csx;
|
||||
offset2 = 180;
|
||||
o2 = 180;
|
||||
} else
|
||||
offset2 = 0;
|
||||
o2 = 0;
|
||||
var pp:Bone = parent.parent;
|
||||
var tx:Number, ty:Number, dx:Number, dy:Number;
|
||||
if (!pp) {
|
||||
@ -132,7 +138,7 @@ public class IkConstraint implements Updatable {
|
||||
}
|
||||
var l1:Number = Math.sqrt(dx * dx + dy * dy), l2:Number = child.data.length * csx, a1:Number, a2:Number;
|
||||
outer:
|
||||
if (Math.abs(psx - psy) <= 0.0001) {
|
||||
if (u) {
|
||||
l2 *= psx;
|
||||
var cos:Number = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2);
|
||||
if (cos < -1) cos = -1;
|
||||
@ -141,7 +147,6 @@ public class IkConstraint implements Updatable {
|
||||
var ad:Number = l1 + l2 * cos, o:Number = l2 * Math.sin(a2);
|
||||
a1 = Math.atan2(ty * ad - tx * o, tx * ad + ty * o);
|
||||
} else {
|
||||
cy = 0;
|
||||
var a:Number = psx * l2, b:Number = psy * l2, ta:Number = Math.atan2(ty, tx);
|
||||
var aa:Number = a * a, bb:Number = b * b, ll:Number = l1 * l1, dd:Number = tx * tx + ty * ty;
|
||||
var c0:Number = bb * ll + aa * dd - aa * bb, c1:Number = -2 * bb * l1, c2:Number = bb - aa;
|
||||
@ -198,17 +203,17 @@ public class IkConstraint implements Updatable {
|
||||
a2 = maxAngle * bendDir;
|
||||
}
|
||||
}
|
||||
var offset:Number = Math.atan2(cy, child.x) * sign2;
|
||||
a1 = (a1 - offset) * MathUtils.radDeg + offset1;
|
||||
a2 = (a2 + offset) * MathUtils.radDeg * sign2 + offset2;
|
||||
var os:Number = Math.atan2(cy, cx) * s2;
|
||||
a1 = (a1 - os) * MathUtils.radDeg + o1;
|
||||
a2 = (a2 + os) * MathUtils.radDeg * s2 + o2;
|
||||
if (a1 > 180) a1 -= 360;
|
||||
else if (a1 < -180) a1 += 360;
|
||||
if (a2 > 180) a2 -= 360;
|
||||
else if (a2 < -180) a2 += 360;
|
||||
var rotation:Number = parent.rotation;
|
||||
parent.updateWorldTransformWith(parent.x, parent.y, rotation + (a1 - rotation) * alpha, parent.scaleX, parent.scaleY);
|
||||
parent.updateWorldTransformWith(px, py, rotation + (a1 - rotation) * alpha, parent.appliedScaleX, parent.appliedScaleY);
|
||||
rotation = child.rotation;
|
||||
child.updateWorldTransformWith(child.x, cy, rotation + (a2 - rotation) * alpha, child.scaleX, child.scaleY);
|
||||
child.updateWorldTransformWith(cx, cy, rotation + (a2 - rotation) * alpha, child.appliedScaleX, child.appliedScaleY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -30,6 +30,7 @@
|
||||
*****************************************************************************/
|
||||
|
||||
package spine.animation {
|
||||
import spine.attachments.FfdAttachment;
|
||||
import spine.Event;
|
||||
import spine.Skeleton;
|
||||
import spine.Slot;
|
||||
@ -55,7 +56,8 @@ public class FfdTimeline extends CurveTimeline {
|
||||
|
||||
override public function apply (skeleton:Skeleton, lastTime:Number, time:Number, firedEvents:Vector.<Event>, alpha:Number) : void {
|
||||
var slot:Slot = skeleton.slots[slotIndex];
|
||||
if (slot.attachment != attachment) return;
|
||||
var slotAttachment:FfdAttachment = slot.attachment as FfdAttachment;
|
||||
if (!slotAttachment || !slotAttachment.applyFFD(attachment)) return;
|
||||
|
||||
var frames:Vector.<Number> = this.frames;
|
||||
if (time < frames[0]) return; // Time is before first frame.
|
||||
|
||||
@ -37,6 +37,8 @@ public class AttachmentType {
|
||||
public static const boundingbox:AttachmentType = new AttachmentType(2, "boundingbox");
|
||||
public static const mesh:AttachmentType = new AttachmentType(3, "mesh");
|
||||
public static const weightedmesh:AttachmentType = new AttachmentType(4, "weightedmesh");
|
||||
public static const linkedmesh:AttachmentType = new AttachmentType(3, "linkedmesh");
|
||||
public static const weightedlinkedmesh:AttachmentType = new AttachmentType(4, "weightedlinkedmesh");
|
||||
|
||||
public var ordinal:int;
|
||||
public var name:String;
|
||||
|
||||
38
spine-as3/spine-as3/src/spine/attachments/FfdAttachment.as
Normal file
38
spine-as3/spine-as3/src/spine/attachments/FfdAttachment.as
Normal file
@ -0,0 +1,38 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes Software License
|
||||
* Version 2.3
|
||||
*
|
||||
* Copyright (c) 2013-2015, 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 (the "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 otherwise create derivative works, improvements of the
|
||||
* Software or develop new applications using the Software 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; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) 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 {
|
||||
|
||||
public interface FfdAttachment {
|
||||
function applyFFD (sourceAttachment:Attachment) : Boolean;
|
||||
}
|
||||
|
||||
}
|
||||
@ -33,7 +33,7 @@ package spine.attachments {
|
||||
import spine.Slot;
|
||||
import spine.Bone;
|
||||
|
||||
public dynamic class MeshAttachment extends Attachment {
|
||||
public dynamic class MeshAttachment extends Attachment implements FfdAttachment {
|
||||
public var vertices:Vector.<Number>;
|
||||
public var uvs:Vector.<Number>;
|
||||
public var regionUVs:Vector.<Number>;
|
||||
@ -43,6 +43,8 @@ public dynamic class MeshAttachment extends Attachment {
|
||||
public var g:Number = 1;
|
||||
public var b:Number = 1;
|
||||
public var a:Number = 1;
|
||||
private var _parentMesh:MeshAttachment;
|
||||
public var inheritFFD:Boolean;
|
||||
|
||||
public var path:String;
|
||||
public var rendererObject:Object;
|
||||
@ -102,6 +104,27 @@ public dynamic class MeshAttachment extends Attachment {
|
||||
worldVertices[int(ii + 1)] = vx * m10 + vy * m11 + y;
|
||||
}
|
||||
}
|
||||
|
||||
public function applyFFD (sourceAttachment:Attachment) : Boolean {
|
||||
return this == sourceAttachment || (inheritFFD && _parentMesh == sourceAttachment);
|
||||
}
|
||||
|
||||
public function get parentMesh () : MeshAttachment {
|
||||
return _parentMesh;
|
||||
}
|
||||
|
||||
public function set parentMesh (parentMesh:MeshAttachment) : void {
|
||||
_parentMesh = parentMesh;
|
||||
if (parentMesh != null) {
|
||||
vertices = parentMesh.vertices;
|
||||
regionUVs = parentMesh.regionUVs;
|
||||
triangles = parentMesh.triangles;
|
||||
hullLength = parentMesh.hullLength;
|
||||
edges = parentMesh.edges;
|
||||
width = parentMesh.width;
|
||||
height = parentMesh.height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ package spine.attachments {
|
||||
import spine.Slot;
|
||||
import spine.Bone;
|
||||
|
||||
public dynamic class WeightedMeshAttachment extends Attachment {
|
||||
public dynamic class WeightedMeshAttachment extends Attachment implements FfdAttachment {
|
||||
public var bones:Vector.<int>;
|
||||
public var weights:Vector.<Number>;
|
||||
public var uvs:Vector.<Number>;
|
||||
@ -44,6 +44,8 @@ public dynamic class WeightedMeshAttachment extends Attachment {
|
||||
public var g:Number = 1;
|
||||
public var b:Number = 1;
|
||||
public var a:Number = 1;
|
||||
private var _parentMesh:WeightedMeshAttachment;
|
||||
public var inheritFFD:Boolean;
|
||||
|
||||
public var path:String;
|
||||
public var rendererObject:Object;
|
||||
@ -127,6 +129,28 @@ public dynamic class WeightedMeshAttachment extends Attachment {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function applyFFD (sourceAttachment:Attachment) : Boolean {
|
||||
return this == sourceAttachment || (inheritFFD && _parentMesh == sourceAttachment);
|
||||
}
|
||||
|
||||
public function get parentMesh () : WeightedMeshAttachment {
|
||||
return _parentMesh;
|
||||
}
|
||||
|
||||
public function set parentMesh (parentMesh:WeightedMeshAttachment) : void {
|
||||
_parentMesh = parentMesh;
|
||||
if (parentMesh != null) {
|
||||
bones = parentMesh.bones;
|
||||
weights = parentMesh.weights;
|
||||
regionUVs = parentMesh.regionUVs;
|
||||
triangles = parentMesh.triangles;
|
||||
hullLength = parentMesh.hullLength;
|
||||
edges = parentMesh.edges;
|
||||
width = parentMesh.width;
|
||||
height = parentMesh.height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ public class SkeletonSprite extends Sprite {
|
||||
for (var i:int = 0, n:int = drawOrder.length; i < n; i++) {
|
||||
var slot:Slot = drawOrder[i];
|
||||
var regionAttachment:RegionAttachment = slot.attachment as RegionAttachment;
|
||||
if (regionAttachment != null) {
|
||||
if (regionAttachment) {
|
||||
var wrapper:Sprite = regionAttachment["wrapper"];
|
||||
var region:AtlasRegion = AtlasRegion(regionAttachment.rendererObject);
|
||||
if (!wrapper) {
|
||||
|
||||
@ -10,7 +10,7 @@ The Spine Runtimes are developed with the intent to be used with data exported f
|
||||
|
||||
## Spine version
|
||||
|
||||
spine-starling works with data exported from the latest version of Spine, except linked meshes are [not yet supported](https://trello.com/c/bERJAFEq/73-update-runtimes-to-support-v3-1-linked-meshes).
|
||||
spine-starling works with data exported from the latest version of Spine.
|
||||
|
||||
spine-starling supports all Spine features.
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user