mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
Minor clean up.
This commit is contained in:
parent
ba5e4073c3
commit
7823833bb4
@ -70,6 +70,7 @@
|
|||||||
<Compile Include="src\Attachments\AttachmentLoader.cs" />
|
<Compile Include="src\Attachments\AttachmentLoader.cs" />
|
||||||
<Compile Include="src\Attachments\AttachmentType.cs" />
|
<Compile Include="src\Attachments\AttachmentType.cs" />
|
||||||
<Compile Include="src\Attachments\BoundingBoxAttachment.cs" />
|
<Compile Include="src\Attachments\BoundingBoxAttachment.cs" />
|
||||||
|
<Compile Include="src\Attachments\IFfdAttachment.cs" />
|
||||||
<Compile Include="src\Attachments\MeshAttachment.cs" />
|
<Compile Include="src\Attachments\MeshAttachment.cs" />
|
||||||
<Compile Include="src\Attachments\RegionAttachment.cs" />
|
<Compile Include="src\Attachments\RegionAttachment.cs" />
|
||||||
<Compile Include="src\Attachments\WeightedMeshAttachment.cs" />
|
<Compile Include="src\Attachments\WeightedMeshAttachment.cs" />
|
||||||
|
|||||||
@ -548,7 +548,7 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FFDTimeline : CurveTimeline {
|
public class FfdTimeline : CurveTimeline {
|
||||||
internal int slotIndex;
|
internal int slotIndex;
|
||||||
internal float[] frames;
|
internal float[] frames;
|
||||||
private float[][] frameVertices;
|
private float[][] frameVertices;
|
||||||
@ -559,7 +559,7 @@ namespace Spine {
|
|||||||
public float[][] Vertices { get { return frameVertices; } set { frameVertices = value; } }
|
public float[][] Vertices { get { return frameVertices; } set { frameVertices = value; } }
|
||||||
public Attachment Attachment { get { return attachment; } set { attachment = value; } }
|
public Attachment Attachment { get { return attachment; } set { attachment = value; } }
|
||||||
|
|
||||||
public FFDTimeline (int frameCount)
|
public FfdTimeline (int frameCount)
|
||||||
: base(frameCount) {
|
: base(frameCount) {
|
||||||
frames = new float[frameCount];
|
frames = new float[frameCount];
|
||||||
frameVertices = new float[frameCount][];
|
frameVertices = new float[frameCount][];
|
||||||
@ -573,7 +573,7 @@ namespace Spine {
|
|||||||
|
|
||||||
override public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList<Event> firedEvents, float alpha) {
|
override public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList<Event> firedEvents, float alpha) {
|
||||||
Slot slot = skeleton.slots.Items[slotIndex];
|
Slot slot = skeleton.slots.Items[slotIndex];
|
||||||
IFfdAttachment ffdAttachment = slot.attachment as IFfdAttachment; // == null if not FfdAttachment.
|
IFfdAttachment ffdAttachment = slot.attachment as IFfdAttachment;
|
||||||
if (ffdAttachment == null || !ffdAttachment.ApplyFFD(attachment)) return;
|
if (ffdAttachment == null || !ffdAttachment.ApplyFFD(attachment)) return;
|
||||||
|
|
||||||
float[] frames = this.frames;
|
float[] frames = this.frames;
|
||||||
|
|||||||
@ -1,4 +1,35 @@
|
|||||||
namespace Spine {
|
/******************************************************************************
|
||||||
|
* 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.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
namespace Spine {
|
||||||
public interface IFfdAttachment {
|
public interface IFfdAttachment {
|
||||||
bool ApplyFFD (Attachment sourceAttachment);
|
bool ApplyFFD (Attachment sourceAttachment);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -99,18 +99,18 @@ namespace Spine {
|
|||||||
static public void Apply (Bone parent, Bone child, float targetX, float targetY, int bendDir, float alpha) {
|
static public void Apply (Bone parent, Bone child, float targetX, float targetY, int bendDir, float alpha) {
|
||||||
if (alpha == 0) return;
|
if (alpha == 0) return;
|
||||||
float px = parent.x, py = parent.y, psx = parent.scaleX, psy = parent.scaleY;
|
float px = parent.x, py = parent.y, psx = parent.scaleX, psy = parent.scaleY;
|
||||||
int offset1, offset2, sign2;
|
int os1, os2, s2;
|
||||||
if (psx < 0) {
|
if (psx < 0) {
|
||||||
psx = -psx;
|
psx = -psx;
|
||||||
offset1 = 180;
|
os1 = 180;
|
||||||
sign2 = -1;
|
s2 = -1;
|
||||||
} else {
|
} else {
|
||||||
offset1 = 0;
|
os1 = 0;
|
||||||
sign2 = 1;
|
s2 = 1;
|
||||||
}
|
}
|
||||||
if (psy < 0) {
|
if (psy < 0) {
|
||||||
psy = -psy;
|
psy = -psy;
|
||||||
sign2 = -sign2;
|
s2 = -s2;
|
||||||
}
|
}
|
||||||
float cx = child.x, cy = child.y, csx = child.scaleX;
|
float cx = child.x, cy = child.y, csx = child.scaleX;
|
||||||
bool u = Math.Abs(psx - psy) <= 0.0001f;
|
bool u = Math.Abs(psx - psy) <= 0.0001f;
|
||||||
@ -121,9 +121,9 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
if (csx < 0) {
|
if (csx < 0) {
|
||||||
csx = -csx;
|
csx = -csx;
|
||||||
offset2 = 180;
|
os2 = 180;
|
||||||
} else
|
} else
|
||||||
offset2 = 0;
|
os2 = 0;
|
||||||
Bone pp = parent.parent;
|
Bone pp = parent.parent;
|
||||||
float tx, ty, dx, dy;
|
float tx, ty, dx, dy;
|
||||||
if (pp == null) {
|
if (pp == null) {
|
||||||
@ -208,9 +208,9 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
outer:
|
outer:
|
||||||
float oo = MathUtils.Atan2(cy, cx) * sign2;
|
float os = MathUtils.Atan2(cy, cx) * s2;
|
||||||
a1 = (a1 - oo) * MathUtils.radDeg + offset1;
|
a1 = (a1 - os) * MathUtils.radDeg + os1;
|
||||||
a2 = (a2 + oo) * MathUtils.radDeg * sign2 + offset2;
|
a2 = (a2 + os) * MathUtils.radDeg * s2 + os2;
|
||||||
if (a1 > 180) a1 -= 360;
|
if (a1 > 180) a1 -= 360;
|
||||||
else if (a1 < -180) a1 += 360;
|
else if (a1 < -180) a1 += 360;
|
||||||
if (a2 > 180) a2 -= 360;
|
if (a2 > 180) a2 -= 360;
|
||||||
|
|||||||
@ -50,11 +50,10 @@ namespace Spine {
|
|||||||
public const int CURVE_STEPPED = 1;
|
public const int CURVE_STEPPED = 1;
|
||||||
public const int CURVE_BEZIER = 2;
|
public const int CURVE_BEZIER = 2;
|
||||||
|
|
||||||
private AttachmentLoader attachmentLoader;
|
|
||||||
public float Scale { get; set; }
|
public float Scale { get; set; }
|
||||||
private byte[] bytes = new byte[32];
|
|
||||||
private byte[] buffer = new byte[4];
|
|
||||||
|
|
||||||
|
private AttachmentLoader attachmentLoader;
|
||||||
|
private byte[] buffer = new byte[32];
|
||||||
private List<SkeletonJson.LinkedMesh> linkedMeshes = new List<SkeletonJson.LinkedMesh>();
|
private List<SkeletonJson.LinkedMesh> linkedMeshes = new List<SkeletonJson.LinkedMesh>();
|
||||||
|
|
||||||
public SkeletonBinary (params Atlas[] atlasArray)
|
public SkeletonBinary (params Atlas[] atlasArray)
|
||||||
@ -358,7 +357,7 @@ namespace Spine {
|
|||||||
for (int i = 0; i < vertexCount; i++) {
|
for (int i = 0; i < vertexCount; i++) {
|
||||||
int boneCount = (int)ReadFloat(input);
|
int boneCount = (int)ReadFloat(input);
|
||||||
bones.Add(boneCount);
|
bones.Add(boneCount);
|
||||||
for (int ii = 0; i < boneCount; ii++) {
|
for (int ii = 0; ii < boneCount; ii++) {
|
||||||
bones.Add((int)ReadFloat(input));
|
bones.Add((int)ReadFloat(input));
|
||||||
weights.Add(ReadFloat(input) * scale);
|
weights.Add(ReadFloat(input) * scale);
|
||||||
weights.Add(ReadFloat(input) * scale);
|
weights.Add(ReadFloat(input) * scale);
|
||||||
@ -554,7 +553,7 @@ namespace Spine {
|
|||||||
for (int iii = 0, nnn = ReadVarint(input, true); iii < nnn; iii++) {
|
for (int iii = 0, nnn = ReadVarint(input, true); iii < nnn; iii++) {
|
||||||
Attachment attachment = skin.GetAttachment(slotIndex, ReadString(input));
|
Attachment attachment = skin.GetAttachment(slotIndex, ReadString(input));
|
||||||
int frameCount = ReadVarint(input, true);
|
int frameCount = ReadVarint(input, true);
|
||||||
FFDTimeline timeline = new FFDTimeline(frameCount);
|
FfdTimeline timeline = new FfdTimeline(frameCount);
|
||||||
timeline.slotIndex = slotIndex;
|
timeline.slotIndex = slotIndex;
|
||||||
timeline.attachment = attachment;
|
timeline.attachment = attachment;
|
||||||
for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) {
|
for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) {
|
||||||
@ -698,9 +697,7 @@ namespace Spine {
|
|||||||
if ((b & 0x80) != 0) {
|
if ((b & 0x80) != 0) {
|
||||||
b = input.ReadByte();
|
b = input.ReadByte();
|
||||||
result |= (b & 0x7F) << 21;
|
result |= (b & 0x7F) << 21;
|
||||||
if ((b & 0x80) != 0) {
|
if ((b & 0x80) != 0) result |= (input.ReadByte() & 0x7F) << 28;
|
||||||
result |= (input.ReadByte() & 0x7F) << 28;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -716,20 +713,18 @@ namespace Spine {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
byteCount--;
|
byteCount--;
|
||||||
byte[] bytes = this.bytes;
|
byte[] buffer = this.buffer;
|
||||||
if (bytes.Length < byteCount) bytes = new byte[byteCount];
|
if (buffer.Length < byteCount) buffer = new byte[byteCount];
|
||||||
ReadFully(input, bytes, 0, byteCount);
|
ReadFully(input, buffer, 0, byteCount);
|
||||||
return System.Text.Encoding.UTF8.GetString(bytes, 0, byteCount);
|
return System.Text.Encoding.UTF8.GetString(buffer, 0, byteCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ReadFully (Stream input, byte[] b, int off, int len) {
|
private static void ReadFully (Stream input, byte[] buffer, int offset, int length) {
|
||||||
while (len > 0) {
|
while (length > 0) {
|
||||||
int count = input.Read(b, off, len);
|
int count = input.Read(buffer, offset, length);
|
||||||
if (count <= 0) {
|
if (count <= 0) throw new EndOfStreamException();
|
||||||
throw new EndOfStreamException();
|
offset += count;
|
||||||
}
|
length -= count;
|
||||||
off += count;
|
|
||||||
len -= count;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,8 +44,9 @@ using Windows.Storage;
|
|||||||
|
|
||||||
namespace Spine {
|
namespace Spine {
|
||||||
public class SkeletonJson {
|
public class SkeletonJson {
|
||||||
private AttachmentLoader attachmentLoader;
|
|
||||||
public float Scale { get; set; }
|
public float Scale { get; set; }
|
||||||
|
|
||||||
|
private AttachmentLoader attachmentLoader;
|
||||||
private List<LinkedMesh> linkedMeshes = new List<LinkedMesh>();
|
private List<LinkedMesh> linkedMeshes = new List<LinkedMesh>();
|
||||||
|
|
||||||
public SkeletonJson (params Atlas[] atlasArray)
|
public SkeletonJson (params Atlas[] atlasArray)
|
||||||
@ -365,12 +366,11 @@ namespace Spine {
|
|||||||
for (int i = 0, n = vertices.Length; i < n;) {
|
for (int i = 0, n = vertices.Length; i < n;) {
|
||||||
int boneCount = (int)vertices[i++];
|
int boneCount = (int)vertices[i++];
|
||||||
bones.Add(boneCount);
|
bones.Add(boneCount);
|
||||||
for (int nn = i + boneCount * 4; i < nn;) {
|
for (int nn = i + boneCount * 4; i < nn; i += 4) {
|
||||||
bones.Add((int)vertices[i]);
|
bones.Add((int)vertices[i]);
|
||||||
weights.Add(vertices[i + 1] * scale);
|
weights.Add(vertices[i + 1] * scale);
|
||||||
weights.Add(vertices[i + 2] * scale);
|
weights.Add(vertices[i + 2] * scale);
|
||||||
weights.Add(vertices[i + 3]);
|
weights.Add(vertices[i + 3]);
|
||||||
i += 4;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mesh.bones = bones.ToArray();
|
mesh.bones = bones.ToArray();
|
||||||
@ -576,7 +576,7 @@ namespace Spine {
|
|||||||
int slotIndex = skeletonData.FindSlotIndex(slotMap.Key);
|
int slotIndex = skeletonData.FindSlotIndex(slotMap.Key);
|
||||||
foreach (KeyValuePair<String, Object> meshMap in (Dictionary<String, Object>)slotMap.Value) {
|
foreach (KeyValuePair<String, Object> meshMap in (Dictionary<String, Object>)slotMap.Value) {
|
||||||
var values = (List<Object>)meshMap.Value;
|
var values = (List<Object>)meshMap.Value;
|
||||||
var timeline = new FFDTimeline(values.Count);
|
var timeline = new FfdTimeline(values.Count);
|
||||||
Attachment attachment = skin.GetAttachment(slotIndex, meshMap.Key);
|
Attachment attachment = skin.GetAttachment(slotIndex, meshMap.Key);
|
||||||
if (attachment == null) throw new Exception("FFD attachment not found: " + meshMap.Key);
|
if (attachment == null) throw new Exception("FFD attachment not found: " + meshMap.Key);
|
||||||
timeline.slotIndex = slotIndex;
|
timeline.slotIndex = slotIndex;
|
||||||
|
|||||||
@ -138,18 +138,18 @@ public class IkConstraint implements Updatable {
|
|||||||
static public void apply (Bone parent, Bone child, float targetX, float targetY, int bendDir, float alpha) {
|
static public void apply (Bone parent, Bone child, float targetX, float targetY, int bendDir, float alpha) {
|
||||||
if (alpha == 0) return;
|
if (alpha == 0) return;
|
||||||
float px = parent.x, py = parent.y, psx = parent.scaleX, psy = parent.scaleY;
|
float px = parent.x, py = parent.y, psx = parent.scaleX, psy = parent.scaleY;
|
||||||
int offset1, offset2, sign2;
|
int os1, os2, s2;
|
||||||
if (psx < 0) {
|
if (psx < 0) {
|
||||||
psx = -psx;
|
psx = -psx;
|
||||||
offset1 = 180;
|
os1 = 180;
|
||||||
sign2 = -1;
|
s2 = -1;
|
||||||
} else {
|
} else {
|
||||||
offset1 = 0;
|
os1 = 0;
|
||||||
sign2 = 1;
|
s2 = 1;
|
||||||
}
|
}
|
||||||
if (psy < 0) {
|
if (psy < 0) {
|
||||||
psy = -psy;
|
psy = -psy;
|
||||||
sign2 = -sign2;
|
s2 = -s2;
|
||||||
}
|
}
|
||||||
float cx = child.x, cy = child.y, csx = child.appliedScaleX;
|
float cx = child.x, cy = child.y, csx = child.appliedScaleX;
|
||||||
boolean u = Math.abs(psx - psy) <= 0.0001f;
|
boolean u = Math.abs(psx - psy) <= 0.0001f;
|
||||||
@ -160,9 +160,9 @@ public class IkConstraint implements Updatable {
|
|||||||
}
|
}
|
||||||
if (csx < 0) {
|
if (csx < 0) {
|
||||||
csx = -csx;
|
csx = -csx;
|
||||||
offset2 = 180;
|
os2 = 180;
|
||||||
} else
|
} else
|
||||||
offset2 = 0;
|
os2 = 0;
|
||||||
Bone pp = parent.parent;
|
Bone pp = parent.parent;
|
||||||
float tx, ty, dx, dy;
|
float tx, ty, dx, dy;
|
||||||
if (pp == null) {
|
if (pp == null) {
|
||||||
@ -248,9 +248,9 @@ public class IkConstraint implements Updatable {
|
|||||||
a2 = maxAngle * bendDir;
|
a2 = maxAngle * bendDir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float o = atan2(cy, cx) * sign2;
|
float o = atan2(cy, cx) * s2;
|
||||||
a1 = (a1 - o) * radDeg + offset1;
|
a1 = (a1 - o) * radDeg + os1;
|
||||||
a2 = (a2 + o) * radDeg * sign2 + offset2;
|
a2 = (a2 + o) * radDeg * s2 + os2;
|
||||||
if (a1 > 180)
|
if (a1 > 180)
|
||||||
a1 -= 360;
|
a1 -= 360;
|
||||||
else if (a1 < -180) a1 += 360;
|
else if (a1 < -180) a1 += 360;
|
||||||
|
|||||||
@ -376,7 +376,7 @@ public class SkeletonBinary {
|
|||||||
for (int i = 0; i < vertexCount; i++) {
|
for (int i = 0; i < vertexCount; i++) {
|
||||||
int boneCount = (int)input.readFloat();
|
int boneCount = (int)input.readFloat();
|
||||||
bones.add(boneCount);
|
bones.add(boneCount);
|
||||||
for (int ii = 0, nn = boneCount; ii < nn; ii++) {
|
for (int ii = 0; ii < boneCount; ii++) {
|
||||||
bones.add((int)input.readFloat());
|
bones.add((int)input.readFloat());
|
||||||
weights.add(input.readFloat() * scale);
|
weights.add(input.readFloat() * scale);
|
||||||
weights.add(input.readFloat() * scale);
|
weights.add(input.readFloat() * scale);
|
||||||
|
|||||||
@ -328,12 +328,11 @@ public class SkeletonJson {
|
|||||||
for (int i = 0, n = vertices.length; i < n;) {
|
for (int i = 0, n = vertices.length; i < n;) {
|
||||||
int boneCount = (int)vertices[i++];
|
int boneCount = (int)vertices[i++];
|
||||||
bones.add(boneCount);
|
bones.add(boneCount);
|
||||||
for (int nn = i + boneCount * 4; i < nn;) {
|
for (int nn = i + boneCount * 4; i < nn; i += 4) {
|
||||||
bones.add((int)vertices[i]);
|
bones.add((int)vertices[i]);
|
||||||
weights.add(vertices[i + 1] * scale);
|
weights.add(vertices[i + 1] * scale);
|
||||||
weights.add(vertices[i + 2] * scale);
|
weights.add(vertices[i + 2] * scale);
|
||||||
weights.add(vertices[i + 3]);
|
weights.add(vertices[i + 3]);
|
||||||
i += 4;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mesh.setBones(bones.toArray());
|
mesh.setBones(bones.toArray());
|
||||||
|
|||||||
Binary file not shown.
@ -125,7 +125,7 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
skeleton.X = 400;
|
skeleton.X = 400;
|
||||||
skeleton.Y = 690;
|
skeleton.Y = 580;
|
||||||
skeleton.UpdateWorldTransform();
|
skeleton.UpdateWorldTransform();
|
||||||
|
|
||||||
headSlot = skeleton.FindSlot("head");
|
headSlot = skeleton.FindSlot("head");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user