mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Moved Skeleton refernce from Slot to Bone.
This commit is contained in:
parent
e18de6cbe6
commit
2cfb6ad980
@ -90,10 +90,9 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ComputeWorldVertices (float x, float y, Slot slot, float[] worldVertices) {
|
public void ComputeWorldVertices (Slot slot, float[] worldVertices) {
|
||||||
Bone bone = slot.bone;
|
Bone bone = slot.bone;
|
||||||
x += bone.worldX;
|
float x = bone.skeleton.x + bone.worldX, y = bone.skeleton.y + bone.worldY;
|
||||||
y += bone.worldY;
|
|
||||||
float m00 = bone.m00, m01 = bone.m01, m10 = bone.m10, m11 = bone.m11;
|
float m00 = bone.m00, m01 = bone.m01, m10 = bone.m10, m11 = bone.m11;
|
||||||
float[] vertices = this.vertices;
|
float[] vertices = this.vertices;
|
||||||
int verticesCount = vertices.Length;
|
int verticesCount = vertices.Length;
|
||||||
|
|||||||
@ -134,9 +134,8 @@ namespace Spine {
|
|||||||
offset[Y4] = localYCos + localX2Sin;
|
offset[Y4] = localYCos + localX2Sin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ComputeWorldVertices (float x, float y, Bone bone, float[] worldVertices) {
|
public void ComputeWorldVertices (Bone bone, float[] worldVertices) {
|
||||||
x += bone.worldX;
|
float x = bone.skeleton.x + bone.worldX, y = bone.skeleton.y + bone.worldY;
|
||||||
y += bone.worldY;
|
|
||||||
float m00 = bone.m00, m01 = bone.m01, m10 = bone.m10, m11 = bone.m11;
|
float m00 = bone.m00, m01 = bone.m01, m10 = bone.m10, m11 = bone.m11;
|
||||||
float[] offset = this.offset;
|
float[] offset = this.offset;
|
||||||
worldVertices[X1] = offset[X1] * m00 + offset[Y1] * m01 + x;
|
worldVertices[X1] = offset[X1] * m00 + offset[Y1] * m01 + x;
|
||||||
|
|||||||
@ -93,8 +93,10 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ComputeWorldVertices (float x, float y, Slot slot, float[] worldVertices) {
|
public void ComputeWorldVertices (Slot slot, float[] worldVertices) {
|
||||||
List<Bone> skeletonBones = slot.skeleton.bones;
|
Skeleton skeleton = slot.bone.skeleton;
|
||||||
|
List<Bone> skeletonBones = skeleton.bones;
|
||||||
|
float x = skeleton.x, y = skeleton.y;
|
||||||
float[] weights = this.weights;
|
float[] weights = this.weights;
|
||||||
int[] bones = this.bones;
|
int[] bones = this.bones;
|
||||||
if (slot.attachmentVerticesCount == 0) {
|
if (slot.attachmentVerticesCount == 0) {
|
||||||
|
|||||||
@ -35,13 +35,14 @@ namespace Spine {
|
|||||||
static public bool yDown;
|
static public bool yDown;
|
||||||
|
|
||||||
internal BoneData data;
|
internal BoneData data;
|
||||||
|
internal Skeleton skeleton;
|
||||||
internal Bone parent;
|
internal Bone parent;
|
||||||
internal float x, y, rotation, rotationIK, scaleX, scaleY;
|
internal float x, y, rotation, rotationIK, scaleX, scaleY;
|
||||||
internal float m00, m01, m10, m11;
|
internal float m00, m01, m10, m11;
|
||||||
internal float worldX, worldY, worldRotation, worldScaleX, worldScaleY;
|
internal float worldX, worldY, worldRotation, worldScaleX, worldScaleY;
|
||||||
internal bool flipX, flipY;
|
|
||||||
|
|
||||||
public BoneData Data { get { return data; } }
|
public BoneData Data { get { return data; } }
|
||||||
|
public Skeleton Skeleton { get { return skeleton; } }
|
||||||
public Bone Parent { get { return parent; } }
|
public Bone Parent { get { return parent; } }
|
||||||
public float X { get { return x; } set { x = value; } }
|
public float X { get { return x; } set { x = value; } }
|
||||||
public float Y { get { return y; } set { y = value; } }
|
public float Y { get { return y; } set { y = value; } }
|
||||||
@ -63,9 +64,11 @@ namespace Spine {
|
|||||||
public float WorldScaleY { get { return worldScaleY; } }
|
public float WorldScaleY { get { return worldScaleY; } }
|
||||||
|
|
||||||
/// <param name="parent">May be null.</param>
|
/// <param name="parent">May be null.</param>
|
||||||
public Bone (BoneData data, Bone parent) {
|
public Bone (BoneData data, Skeleton skeleton, Bone parent) {
|
||||||
if (data == null) throw new ArgumentNullException("data cannot be null.");
|
if (data == null) throw new ArgumentNullException("data cannot be null.");
|
||||||
|
if (skeleton == null) throw new ArgumentNullException("skeleton cannot be null.");
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
this.skeleton = skeleton;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
SetToSetupPose();
|
SetToSetupPose();
|
||||||
}
|
}
|
||||||
@ -73,6 +76,7 @@ namespace Spine {
|
|||||||
/// <summary>Computes the world SRT using the parent bone and the local SRT.</summary>
|
/// <summary>Computes the world SRT using the parent bone and the local SRT.</summary>
|
||||||
public void UpdateWorldTransform () {
|
public void UpdateWorldTransform () {
|
||||||
Bone parent = this.parent;
|
Bone parent = this.parent;
|
||||||
|
Skeleton skeleton = this.skeleton;
|
||||||
float x = this.x, y = this.y;
|
float x = this.x, y = this.y;
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
worldX = x * parent.m00 + y * parent.m01 + parent.worldX;
|
worldX = x * parent.m00 + y * parent.m01 + parent.worldX;
|
||||||
@ -86,8 +90,8 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
worldRotation = data.inheritRotation ? parent.worldRotation + rotationIK : rotationIK;
|
worldRotation = data.inheritRotation ? parent.worldRotation + rotationIK : rotationIK;
|
||||||
} else {
|
} else {
|
||||||
worldX = flipX ? -x : x;
|
worldX = skeleton.flipX ? -x : x;
|
||||||
worldY = flipY != yDown ? -y : y;
|
worldY = skeleton.flipY != yDown ? -y : y;
|
||||||
worldScaleX = scaleX;
|
worldScaleX = scaleX;
|
||||||
worldScaleY = scaleY;
|
worldScaleY = scaleY;
|
||||||
worldRotation = rotationIK;
|
worldRotation = rotationIK;
|
||||||
@ -95,14 +99,14 @@ namespace Spine {
|
|||||||
float radians = worldRotation * (float)Math.PI / 180;
|
float radians = worldRotation * (float)Math.PI / 180;
|
||||||
float cos = (float)Math.Cos(radians);
|
float cos = (float)Math.Cos(radians);
|
||||||
float sin = (float)Math.Sin(radians);
|
float sin = (float)Math.Sin(radians);
|
||||||
if (flipX) {
|
if (skeleton.flipX) {
|
||||||
m00 = -cos * worldScaleX;
|
m00 = -cos * worldScaleX;
|
||||||
m01 = sin * worldScaleY;
|
m01 = sin * worldScaleY;
|
||||||
} else {
|
} else {
|
||||||
m00 = cos * worldScaleX;
|
m00 = cos * worldScaleX;
|
||||||
m01 = -sin * worldScaleY;
|
m01 = -sin * worldScaleY;
|
||||||
}
|
}
|
||||||
if (flipY != yDown) {
|
if (skeleton.flipY != yDown) {
|
||||||
m10 = -sin * worldScaleX;
|
m10 = -sin * worldScaleX;
|
||||||
m11 = -cos * worldScaleY;
|
m11 = -cos * worldScaleY;
|
||||||
} else {
|
} else {
|
||||||
@ -124,7 +128,8 @@ namespace Spine {
|
|||||||
public void worldToLocal (float worldX, float worldY, out float localX, out float localY) {
|
public void worldToLocal (float worldX, float worldY, out float localX, out float localY) {
|
||||||
float dx = worldX - this.worldX, dy = worldY - this.worldY;
|
float dx = worldX - this.worldX, dy = worldY - this.worldY;
|
||||||
float m00 = this.m00, m10 = this.m10, m01 = this.m01, m11 = this.m11;
|
float m00 = this.m00, m10 = this.m10, m01 = this.m01, m11 = this.m11;
|
||||||
if (flipX != (flipY != yDown)) {
|
Skeleton skeleton = this.skeleton;
|
||||||
|
if (skeleton.flipX != (skeleton.flipY != yDown)) {
|
||||||
m00 *= -1;
|
m00 *= -1;
|
||||||
m11 *= -1;
|
m11 *= -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,11 +53,9 @@ namespace Spine {
|
|||||||
bendDirection = data.bendDirection;
|
bendDirection = data.bendDirection;
|
||||||
|
|
||||||
bones = new List<Bone>(data.bones.Count);
|
bones = new List<Bone>(data.bones.Count);
|
||||||
if (skeleton != null) {
|
foreach (BoneData boneData in data.bones)
|
||||||
foreach (BoneData boneData in data.bones)
|
bones.Add(skeleton.FindBone(boneData.name));
|
||||||
bones.Add(skeleton.FindBone(boneData.name));
|
target = skeleton.FindBone(data.target.name);
|
||||||
target = skeleton.FindBone(data.target.name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void apply () {
|
public void apply () {
|
||||||
|
|||||||
@ -38,7 +38,7 @@ namespace Spine {
|
|||||||
internal List<Slot> slots;
|
internal List<Slot> slots;
|
||||||
internal List<Slot> drawOrder;
|
internal List<Slot> drawOrder;
|
||||||
internal List<IkConstraint> ikConstraints = new List<IkConstraint>();
|
internal List<IkConstraint> ikConstraints = new List<IkConstraint>();
|
||||||
private List<List<Bone>> updateBonesCache = new List<List<Bone>>();
|
private List<List<Bone>> bonesCache = new List<List<Bone>>();
|
||||||
internal Skin skin;
|
internal Skin skin;
|
||||||
internal float r = 1, g = 1, b = 1, a = 1;
|
internal float r = 1, g = 1, b = 1, a = 1;
|
||||||
internal float time;
|
internal float time;
|
||||||
@ -58,28 +58,8 @@ namespace Spine {
|
|||||||
public float Time { get { return time; } set { time = value; } }
|
public float Time { get { return time; } set { time = value; } }
|
||||||
public float X { get { return x; } set { x = value; } }
|
public float X { get { return x; } set { x = value; } }
|
||||||
public float Y { get { return y; } set { y = value; } }
|
public float Y { get { return y; } set { y = value; } }
|
||||||
|
public bool FlipX { get { return flipX; } set { flipX = value; } }
|
||||||
public bool FlipX {
|
public bool FlipY { get { return flipY; } set { flipY = value; } }
|
||||||
get { return flipX; }
|
|
||||||
set {
|
|
||||||
if (flipX == value) return;
|
|
||||||
flipX = value;
|
|
||||||
List<Bone> bones = this.bones;
|
|
||||||
for (int i = 0, n = bones.Count; i < n; i++)
|
|
||||||
bones[i].flipX = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool FlipY {
|
|
||||||
get { return flipY; }
|
|
||||||
set {
|
|
||||||
if (flipY == value) return;
|
|
||||||
flipY = value;
|
|
||||||
List<Bone> bones = this.bones;
|
|
||||||
for (int i = 0, n = bones.Count; i < n; i++)
|
|
||||||
bones[i].flipY = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Bone RootBone {
|
public Bone RootBone {
|
||||||
get {
|
get {
|
||||||
@ -94,14 +74,14 @@ namespace Spine {
|
|||||||
bones = new List<Bone>(data.bones.Count);
|
bones = new List<Bone>(data.bones.Count);
|
||||||
foreach (BoneData boneData in data.bones) {
|
foreach (BoneData boneData in data.bones) {
|
||||||
Bone parent = boneData.parent == null ? null : bones[data.bones.IndexOf(boneData.parent)];
|
Bone parent = boneData.parent == null ? null : bones[data.bones.IndexOf(boneData.parent)];
|
||||||
bones.Add(new Bone(boneData, parent));
|
bones.Add(new Bone(boneData, this, parent));
|
||||||
}
|
}
|
||||||
|
|
||||||
slots = new List<Slot>(data.slots.Count);
|
slots = new List<Slot>(data.slots.Count);
|
||||||
drawOrder = new List<Slot>(data.slots.Count);
|
drawOrder = new List<Slot>(data.slots.Count);
|
||||||
foreach (SlotData slotData in data.slots) {
|
foreach (SlotData slotData in data.slots) {
|
||||||
Bone bone = bones[data.bones.IndexOf(slotData.boneData)];
|
Bone bone = bones[data.bones.IndexOf(slotData.boneData)];
|
||||||
Slot slot = new Slot(slotData, this, bone);
|
Slot slot = new Slot(slotData, bone);
|
||||||
slots.Add(slot);
|
slots.Add(slot);
|
||||||
drawOrder.Add(slot);
|
drawOrder.Add(slot);
|
||||||
}
|
}
|
||||||
@ -116,18 +96,18 @@ namespace Spine {
|
|||||||
/// <summary>Caches information about bones and IK constraints. Must be called if bones or IK constraints are added or
|
/// <summary>Caches information about bones and IK constraints. Must be called if bones or IK constraints are added or
|
||||||
/// removed.</summary>
|
/// removed.</summary>
|
||||||
public void UpdateCache () {
|
public void UpdateCache () {
|
||||||
List<List<Bone>> updateBonesCache = this.updateBonesCache;
|
List<List<Bone>> bonesCache = this.bonesCache;
|
||||||
List<IkConstraint> ikConstraints = this.ikConstraints;
|
List<IkConstraint> ikConstraints = this.ikConstraints;
|
||||||
int ikConstraintsCount = ikConstraints.Count;
|
int ikConstraintsCount = ikConstraints.Count;
|
||||||
|
|
||||||
int arrayCount = ikConstraintsCount + 1;
|
int arrayCount = ikConstraintsCount + 1;
|
||||||
if (updateBonesCache.Count > arrayCount) updateBonesCache.RemoveRange(arrayCount, updateBonesCache.Count - arrayCount);
|
if (bonesCache.Count > arrayCount) bonesCache.RemoveRange(arrayCount, bonesCache.Count - arrayCount);
|
||||||
for (int i = 0, n = updateBonesCache.Count; i < n; i++)
|
for (int i = 0, n = bonesCache.Count; i < n; i++)
|
||||||
updateBonesCache[i].Clear();
|
bonesCache[i].Clear();
|
||||||
while (updateBonesCache.Count < arrayCount)
|
while (bonesCache.Count < arrayCount)
|
||||||
updateBonesCache.Add(new List<Bone>());
|
bonesCache.Add(new List<Bone>());
|
||||||
|
|
||||||
List<Bone> nonIkBones = updateBonesCache[0];
|
List<Bone> nonIkBones = bonesCache[0];
|
||||||
|
|
||||||
for (int i = 0, n = bones.Count; i < n; i++) {
|
for (int i = 0, n = bones.Count; i < n; i++) {
|
||||||
Bone bone = bones[i];
|
Bone bone = bones[i];
|
||||||
@ -139,8 +119,8 @@ namespace Spine {
|
|||||||
Bone child = ikConstraint.bones[ikConstraint.bones.Count - 1];
|
Bone child = ikConstraint.bones[ikConstraint.bones.Count - 1];
|
||||||
while (true) {
|
while (true) {
|
||||||
if (current == child) {
|
if (current == child) {
|
||||||
updateBonesCache[ii].Add(bone);
|
bonesCache[ii].Add(bone);
|
||||||
updateBonesCache[ii + 1].Add(bone);
|
bonesCache[ii + 1].Add(bone);
|
||||||
goto outer;
|
goto outer;
|
||||||
}
|
}
|
||||||
if (child == parent) break;
|
if (child == parent) break;
|
||||||
@ -161,11 +141,11 @@ namespace Spine {
|
|||||||
Bone bone = bones[ii];
|
Bone bone = bones[ii];
|
||||||
bone.rotationIK = bone.rotation;
|
bone.rotationIK = bone.rotation;
|
||||||
}
|
}
|
||||||
List<List<Bone>> updateBonesCache = this.updateBonesCache;
|
List<List<Bone>> bonesCache = this.bonesCache;
|
||||||
List<IkConstraint> ikConstraints = this.ikConstraints;
|
List<IkConstraint> ikConstraints = this.ikConstraints;
|
||||||
int i = 0, last = updateBonesCache.Count - 1;
|
int i = 0, last = bonesCache.Count - 1;
|
||||||
while (true) {
|
while (true) {
|
||||||
List<Bone> updateBones = updateBonesCache[i];
|
List<Bone> updateBones = bonesCache[i];
|
||||||
for (int ii = 0, nn = updateBones.Count; ii < nn; ii++)
|
for (int ii = 0, nn = updateBones.Count; ii < nn; ii++)
|
||||||
updateBones[ii].UpdateWorldTransform();
|
updateBones[ii].UpdateWorldTransform();
|
||||||
if (i == last) break;
|
if (i == last) break;
|
||||||
|
|||||||
@ -91,14 +91,14 @@ namespace Spine {
|
|||||||
if (root == null) throw new Exception("Invalid JSON.");
|
if (root == null) throw new Exception("Invalid JSON.");
|
||||||
|
|
||||||
// Skeleton.
|
// Skeleton.
|
||||||
var skeletonMap = (Dictionary<String, Object>)root["skeleton"];
|
if (root.ContainsKey("skeleton")) {
|
||||||
if (skeletonMap != null) {
|
var skeletonMap = (Dictionary<String, Object>)root["skeleton"];
|
||||||
skeletonData.version = (String)skeletonMap["spine"];
|
skeletonData.version = (String)skeletonMap["spine"];
|
||||||
skeletonData.hash = (String)skeletonMap["hash"];
|
skeletonData.hash = (String)skeletonMap["hash"];
|
||||||
skeletonData.width = GetFloat(skeletonMap, "width", 0);
|
skeletonData.width = GetFloat(skeletonMap, "width", 0);
|
||||||
skeletonData.height = GetFloat(skeletonMap, "width", 1);
|
skeletonData.height = GetFloat(skeletonMap, "width", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bones.
|
// Bones.
|
||||||
foreach (Dictionary<String, Object> boneMap in (List<Object>)root["bones"]) {
|
foreach (Dictionary<String, Object> boneMap in (List<Object>)root["bones"]) {
|
||||||
BoneData parent = null;
|
BoneData parent = null;
|
||||||
@ -120,23 +120,25 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IK constraints.
|
// IK constraints.
|
||||||
foreach (Dictionary<String, Object> ikMap in (List<Object>)root["ik"]) {
|
if (root.ContainsKey("ik")) {
|
||||||
IkConstraintData ikConstraintData = new IkConstraintData((String)ikMap["name"]);
|
foreach (Dictionary<String, Object> ikMap in (List<Object>)root["ik"]) {
|
||||||
|
IkConstraintData ikConstraintData = new IkConstraintData((String)ikMap["name"]);
|
||||||
|
|
||||||
foreach (String boneName in (List<Object>)ikMap["bones"]) {
|
foreach (String boneName in (List<Object>)ikMap["bones"]) {
|
||||||
BoneData bone = skeletonData.FindBone(boneName);
|
BoneData bone = skeletonData.FindBone(boneName);
|
||||||
if (bone == null) throw new Exception("IK bone not found: " + boneName);
|
if (bone == null) throw new Exception("IK bone not found: " + boneName);
|
||||||
ikConstraintData.bones.Add(bone);
|
ikConstraintData.bones.Add(bone);
|
||||||
|
}
|
||||||
|
|
||||||
|
String targetName = (String)ikMap["target"];
|
||||||
|
ikConstraintData.target = skeletonData.FindBone(targetName);
|
||||||
|
if (ikConstraintData.target == null) throw new Exception("Target bone not found: " + targetName);
|
||||||
|
|
||||||
|
ikConstraintData.bendDirection = GetBoolean(ikMap, "bendPositive", true) ? 1 : -1;
|
||||||
|
ikConstraintData.mix = GetFloat(ikMap, "mix", 1);
|
||||||
|
|
||||||
|
skeletonData.ikConstraints.Add(ikConstraintData);
|
||||||
}
|
}
|
||||||
|
|
||||||
String targetName = (String)ikMap["target"];
|
|
||||||
ikConstraintData.target = skeletonData.FindBone(targetName);
|
|
||||||
if (ikConstraintData.target == null) throw new Exception("Target bone not found: " + targetName);
|
|
||||||
|
|
||||||
ikConstraintData.bendDirection = GetBoolean(ikMap, "bendPositive", true) ? 1 : -1;
|
|
||||||
ikConstraintData.mix = GetFloat(ikMap, "mix", 1);
|
|
||||||
|
|
||||||
skeletonData.ikConstraints.Add(ikConstraintData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slots.
|
// Slots.
|
||||||
|
|||||||
@ -34,7 +34,6 @@ namespace Spine {
|
|||||||
public class Slot {
|
public class Slot {
|
||||||
internal SlotData data;
|
internal SlotData data;
|
||||||
internal Bone bone;
|
internal Bone bone;
|
||||||
internal Skeleton skeleton;
|
|
||||||
internal float r, g, b, a;
|
internal float r, g, b, a;
|
||||||
internal Attachment attachment;
|
internal Attachment attachment;
|
||||||
internal float attachmentTime;
|
internal float attachmentTime;
|
||||||
@ -43,7 +42,7 @@ namespace Spine {
|
|||||||
|
|
||||||
public SlotData Data { get { return data; } }
|
public SlotData Data { get { return data; } }
|
||||||
public Bone Bone { get { return bone; } }
|
public Bone Bone { get { return bone; } }
|
||||||
public Skeleton Skeleton { get { return skeleton; } }
|
public Skeleton Skeleton { get { return bone.skeleton; } }
|
||||||
public float R { get { return r; } set { r = value; } }
|
public float R { get { return r; } set { r = value; } }
|
||||||
public float G { get { return g; } set { g = value; } }
|
public float G { get { return g; } set { g = value; } }
|
||||||
public float B { get { return b; } set { b = value; } }
|
public float B { get { return b; } set { b = value; } }
|
||||||
@ -56,29 +55,27 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
attachment = value;
|
attachment = value;
|
||||||
attachmentTime = skeleton.time;
|
attachmentTime = bone.skeleton.time;
|
||||||
attachmentVerticesCount = 0;
|
attachmentVerticesCount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public float AttachmentTime {
|
public float AttachmentTime {
|
||||||
get {
|
get {
|
||||||
return skeleton.time - attachmentTime;
|
return bone.skeleton.time - attachmentTime;
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
attachmentTime = skeleton.time - value;
|
attachmentTime = bone.skeleton.time - value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public float[] AttachmentVertices { get { return attachmentVertices; } set { attachmentVertices = value; } }
|
public float[] AttachmentVertices { get { return attachmentVertices; } set { attachmentVertices = value; } }
|
||||||
public int AttachmentVerticesCount { get { return attachmentVerticesCount; } set { attachmentVerticesCount = value; } }
|
public int AttachmentVerticesCount { get { return attachmentVerticesCount; } set { attachmentVerticesCount = value; } }
|
||||||
|
|
||||||
public Slot (SlotData data, Skeleton skeleton, Bone bone) {
|
public Slot (SlotData data, Bone bone) {
|
||||||
if (data == null) throw new ArgumentNullException("data cannot be null.");
|
if (data == null) throw new ArgumentNullException("data cannot be null.");
|
||||||
if (skeleton == null) throw new ArgumentNullException("skeleton cannot be null.");
|
|
||||||
if (bone == null) throw new ArgumentNullException("bone cannot be null.");
|
if (bone == null) throw new ArgumentNullException("bone cannot be null.");
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.skeleton = skeleton;
|
|
||||||
this.bone = bone;
|
this.bone = bone;
|
||||||
SetToSetupPose();
|
SetToSetupPose();
|
||||||
}
|
}
|
||||||
@ -88,11 +85,11 @@ namespace Spine {
|
|||||||
g = data.g;
|
g = data.g;
|
||||||
b = data.b;
|
b = data.b;
|
||||||
a = data.a;
|
a = data.a;
|
||||||
Attachment = data.attachmentName == null ? null : skeleton.GetAttachment(slotIndex, data.attachmentName);
|
Attachment = data.attachmentName == null ? null : bone.skeleton.GetAttachment(slotIndex, data.attachmentName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetToSetupPose () {
|
public void SetToSetupPose () {
|
||||||
SetToSetupPose(skeleton.data.slots.IndexOf(data));
|
SetToSetupPose(bone.skeleton.data.slots.IndexOf(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
override public String ToString () {
|
override public String ToString () {
|
||||||
|
|||||||
@ -190,14 +190,14 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
Color32[] colors = this.colors;
|
Color32[] colors = this.colors;
|
||||||
int vertexIndex = 0;
|
int vertexIndex = 0;
|
||||||
Color32 color = new Color32();
|
Color32 color = new Color32();
|
||||||
float x = skeleton.x, y = skeleton.y, zSpacing = this.zSpacing;
|
float zSpacing = this.zSpacing;
|
||||||
float a = skeleton.a * 255, r = skeleton.r, g = skeleton.g, b = skeleton.b;
|
float a = skeleton.a * 255, r = skeleton.r, g = skeleton.g, b = skeleton.b;
|
||||||
for (int i = 0; i < drawOrderCount; i++) {
|
for (int i = 0; i < drawOrderCount; i++) {
|
||||||
Slot slot = drawOrder[i];
|
Slot slot = drawOrder[i];
|
||||||
Attachment attachment = slot.attachment;
|
Attachment attachment = slot.attachment;
|
||||||
if (attachment is RegionAttachment) {
|
if (attachment is RegionAttachment) {
|
||||||
RegionAttachment regionAttachment = (RegionAttachment)attachment;
|
RegionAttachment regionAttachment = (RegionAttachment)attachment;
|
||||||
regionAttachment.ComputeWorldVertices(x, y, slot.bone, tempVertices);
|
regionAttachment.ComputeWorldVertices(slot.bone, tempVertices);
|
||||||
|
|
||||||
float z = i * zSpacing;
|
float z = i * zSpacing;
|
||||||
vertices[vertexIndex] = new Vector3(tempVertices[RegionAttachment.X1], tempVertices[RegionAttachment.Y1], z);
|
vertices[vertexIndex] = new Vector3(tempVertices[RegionAttachment.X1], tempVertices[RegionAttachment.Y1], z);
|
||||||
@ -228,7 +228,7 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
MeshAttachment meshAttachment = (MeshAttachment)attachment;
|
MeshAttachment meshAttachment = (MeshAttachment)attachment;
|
||||||
int meshVertexCount = meshAttachment.vertices.Length;
|
int meshVertexCount = meshAttachment.vertices.Length;
|
||||||
if (tempVertices.Length < meshVertexCount) tempVertices = new float[meshVertexCount];
|
if (tempVertices.Length < meshVertexCount) tempVertices = new float[meshVertexCount];
|
||||||
meshAttachment.ComputeWorldVertices(x, y, slot, tempVertices);
|
meshAttachment.ComputeWorldVertices(slot, tempVertices);
|
||||||
|
|
||||||
color.a = (byte)(a * slot.a * meshAttachment.a);
|
color.a = (byte)(a * slot.a * meshAttachment.a);
|
||||||
color.r = (byte)(r * slot.r * meshAttachment.r * color.a);
|
color.r = (byte)(r * slot.r * meshAttachment.r * color.a);
|
||||||
@ -247,7 +247,7 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
SkinnedMeshAttachment meshAttachment = (SkinnedMeshAttachment)attachment;
|
SkinnedMeshAttachment meshAttachment = (SkinnedMeshAttachment)attachment;
|
||||||
int meshVertexCount = meshAttachment.uvs.Length;
|
int meshVertexCount = meshAttachment.uvs.Length;
|
||||||
if (tempVertices.Length < meshVertexCount) tempVertices = new float[meshVertexCount];
|
if (tempVertices.Length < meshVertexCount) tempVertices = new float[meshVertexCount];
|
||||||
meshAttachment.ComputeWorldVertices(x, y, slot, tempVertices);
|
meshAttachment.ComputeWorldVertices(slot, tempVertices);
|
||||||
|
|
||||||
color.a = (byte)(a * slot.a * meshAttachment.a);
|
color.a = (byte)(a * slot.a * meshAttachment.a);
|
||||||
color.r = (byte)(r * slot.r * meshAttachment.r * color.a);
|
color.r = (byte)(r * slot.r * meshAttachment.r * color.a);
|
||||||
|
|||||||
@ -193,14 +193,14 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
Color32[] colors = this.colors;
|
Color32[] colors = this.colors;
|
||||||
int vertexIndex = 0;
|
int vertexIndex = 0;
|
||||||
Color32 color = new Color32();
|
Color32 color = new Color32();
|
||||||
float x = skeleton.x, y = skeleton.y, zSpacing = this.zSpacing;
|
float zSpacing = this.zSpacing;
|
||||||
float a = skeleton.a * 255, r = skeleton.r, g = skeleton.g, b = skeleton.b;
|
float a = skeleton.a * 255, r = skeleton.r, g = skeleton.g, b = skeleton.b;
|
||||||
for (int i = 0; i < drawOrderCount; i++) {
|
for (int i = 0; i < drawOrderCount; i++) {
|
||||||
Slot slot = drawOrder[i];
|
Slot slot = drawOrder[i];
|
||||||
Attachment attachment = slot.attachment;
|
Attachment attachment = slot.attachment;
|
||||||
if (attachment is RegionAttachment) {
|
if (attachment is RegionAttachment) {
|
||||||
RegionAttachment regionAttachment = (RegionAttachment)attachment;
|
RegionAttachment regionAttachment = (RegionAttachment)attachment;
|
||||||
regionAttachment.ComputeWorldVertices(x, y, slot.bone, tempVertices);
|
regionAttachment.ComputeWorldVertices(slot.bone, tempVertices);
|
||||||
|
|
||||||
float z = i * zSpacing;
|
float z = i * zSpacing;
|
||||||
vertices[vertexIndex] = new Vector3(tempVertices[RegionAttachment.X1], tempVertices[RegionAttachment.Y1], z);
|
vertices[vertexIndex] = new Vector3(tempVertices[RegionAttachment.X1], tempVertices[RegionAttachment.Y1], z);
|
||||||
@ -231,7 +231,7 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
MeshAttachment meshAttachment = (MeshAttachment)attachment;
|
MeshAttachment meshAttachment = (MeshAttachment)attachment;
|
||||||
int meshVertexCount = meshAttachment.vertices.Length;
|
int meshVertexCount = meshAttachment.vertices.Length;
|
||||||
if (tempVertices.Length < meshVertexCount) tempVertices = new float[meshVertexCount];
|
if (tempVertices.Length < meshVertexCount) tempVertices = new float[meshVertexCount];
|
||||||
meshAttachment.ComputeWorldVertices(x, y, slot, tempVertices);
|
meshAttachment.ComputeWorldVertices(slot, tempVertices);
|
||||||
|
|
||||||
color.a = (byte)(a * slot.a * meshAttachment.a);
|
color.a = (byte)(a * slot.a * meshAttachment.a);
|
||||||
color.r = (byte)(r * slot.r * meshAttachment.r * color.a);
|
color.r = (byte)(r * slot.r * meshAttachment.r * color.a);
|
||||||
@ -250,7 +250,7 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
SkinnedMeshAttachment meshAttachment = (SkinnedMeshAttachment)attachment;
|
SkinnedMeshAttachment meshAttachment = (SkinnedMeshAttachment)attachment;
|
||||||
int meshVertexCount = meshAttachment.uvs.Length;
|
int meshVertexCount = meshAttachment.uvs.Length;
|
||||||
if (tempVertices.Length < meshVertexCount) tempVertices = new float[meshVertexCount];
|
if (tempVertices.Length < meshVertexCount) tempVertices = new float[meshVertexCount];
|
||||||
meshAttachment.ComputeWorldVertices(x, y, slot, tempVertices);
|
meshAttachment.ComputeWorldVertices(slot, tempVertices);
|
||||||
|
|
||||||
color.a = (byte)(a * slot.a * meshAttachment.a);
|
color.a = (byte)(a * slot.a * meshAttachment.a);
|
||||||
color.r = (byte)(r * slot.r * meshAttachment.r * color.a);
|
color.r = (byte)(r * slot.r * meshAttachment.r * color.a);
|
||||||
|
|||||||
@ -90,7 +90,6 @@ namespace Spine {
|
|||||||
public void Draw (Skeleton skeleton) {
|
public void Draw (Skeleton skeleton) {
|
||||||
float[] vertices = this.vertices;
|
float[] vertices = this.vertices;
|
||||||
List<Slot> drawOrder = skeleton.DrawOrder;
|
List<Slot> drawOrder = skeleton.DrawOrder;
|
||||||
float x = skeleton.X, y = skeleton.Y;
|
|
||||||
float skeletonR = skeleton.R, skeletonG = skeleton.G, skeletonB = skeleton.B, skeletonA = skeleton.A;
|
float skeletonR = skeleton.R, skeletonG = skeleton.G, skeletonB = skeleton.B, skeletonA = skeleton.A;
|
||||||
for (int i = 0, n = drawOrder.Count; i < n; i++) {
|
for (int i = 0, n = drawOrder.Count; i < n; i++) {
|
||||||
Slot slot = drawOrder[i];
|
Slot slot = drawOrder[i];
|
||||||
@ -128,7 +127,7 @@ namespace Spine {
|
|||||||
itemVertices[BR].Color = color;
|
itemVertices[BR].Color = color;
|
||||||
itemVertices[TR].Color = color;
|
itemVertices[TR].Color = color;
|
||||||
|
|
||||||
regionAttachment.ComputeWorldVertices(x, y, slot.Bone, vertices);
|
regionAttachment.ComputeWorldVertices(slot.Bone, vertices);
|
||||||
itemVertices[TL].Position.X = vertices[RegionAttachment.X1];
|
itemVertices[TL].Position.X = vertices[RegionAttachment.X1];
|
||||||
itemVertices[TL].Position.Y = vertices[RegionAttachment.Y1];
|
itemVertices[TL].Position.Y = vertices[RegionAttachment.Y1];
|
||||||
itemVertices[TL].Position.Z = 0;
|
itemVertices[TL].Position.Z = 0;
|
||||||
@ -155,7 +154,7 @@ namespace Spine {
|
|||||||
MeshAttachment mesh = (MeshAttachment)attachment;
|
MeshAttachment mesh = (MeshAttachment)attachment;
|
||||||
int vertexCount = mesh.Vertices.Length;
|
int vertexCount = mesh.Vertices.Length;
|
||||||
if (vertices.Length < vertexCount) vertices = new float[vertexCount];
|
if (vertices.Length < vertexCount) vertices = new float[vertexCount];
|
||||||
mesh.ComputeWorldVertices(x, y, slot, vertices);
|
mesh.ComputeWorldVertices(slot, vertices);
|
||||||
|
|
||||||
int[] triangles = mesh.Triangles;
|
int[] triangles = mesh.Triangles;
|
||||||
MeshItem item = batcher.NextItem(vertexCount, triangles.Length);
|
MeshItem item = batcher.NextItem(vertexCount, triangles.Length);
|
||||||
@ -192,7 +191,7 @@ namespace Spine {
|
|||||||
SkinnedMeshAttachment mesh = (SkinnedMeshAttachment)attachment;
|
SkinnedMeshAttachment mesh = (SkinnedMeshAttachment)attachment;
|
||||||
int vertexCount = mesh.UVs.Length;
|
int vertexCount = mesh.UVs.Length;
|
||||||
if (vertices.Length < vertexCount) vertices = new float[vertexCount];
|
if (vertices.Length < vertexCount) vertices = new float[vertexCount];
|
||||||
mesh.ComputeWorldVertices(x, y, slot, vertices);
|
mesh.ComputeWorldVertices(slot, vertices);
|
||||||
|
|
||||||
int[] triangles = mesh.Triangles;
|
int[] triangles = mesh.Triangles;
|
||||||
MeshItem item = batcher.NextItem(vertexCount, triangles.Length);
|
MeshItem item = batcher.NextItem(vertexCount, triangles.Length);
|
||||||
|
|||||||
@ -83,7 +83,6 @@ namespace Spine {
|
|||||||
|
|
||||||
public void Draw (Skeleton skeleton) {
|
public void Draw (Skeleton skeleton) {
|
||||||
List<Slot> drawOrder = skeleton.DrawOrder;
|
List<Slot> drawOrder = skeleton.DrawOrder;
|
||||||
float x = skeleton.X, y = skeleton.Y;
|
|
||||||
float skeletonR = skeleton.R, skeletonG = skeleton.G, skeletonB = skeleton.B, skeletonA = skeleton.A;
|
float skeletonR = skeleton.R, skeletonG = skeleton.G, skeletonB = skeleton.B, skeletonA = skeleton.A;
|
||||||
for (int i = 0, n = drawOrder.Count; i < n; i++) {
|
for (int i = 0, n = drawOrder.Count; i < n; i++) {
|
||||||
Slot slot = drawOrder[i];
|
Slot slot = drawOrder[i];
|
||||||
@ -112,7 +111,7 @@ namespace Spine {
|
|||||||
item.vertexTR.Color = color;
|
item.vertexTR.Color = color;
|
||||||
|
|
||||||
float[] vertices = this.vertices;
|
float[] vertices = this.vertices;
|
||||||
regionAttachment.ComputeWorldVertices(x, y, slot.Bone, vertices);
|
regionAttachment.ComputeWorldVertices(slot.Bone, vertices);
|
||||||
item.vertexTL.Position.X = vertices[RegionAttachment.X1];
|
item.vertexTL.Position.X = vertices[RegionAttachment.X1];
|
||||||
item.vertexTL.Position.Y = vertices[RegionAttachment.Y1];
|
item.vertexTL.Position.Y = vertices[RegionAttachment.Y1];
|
||||||
item.vertexTL.Position.Z = 0;
|
item.vertexTL.Position.Z = 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user