增加ScaleX和ScaleY

This commit is contained in:
ww-rm
2025-04-22 23:54:20 +08:00
parent 794de783db
commit 5b1c177f58
3 changed files with 40 additions and 71 deletions

View File

@@ -33,7 +33,7 @@ using System.Collections.Generic;
namespace SpineRuntime21 {
public class Bone{
static public bool yDown;
static readonly public bool yDown = false;
internal BoneData data;
internal Skeleton skeleton;
@@ -84,7 +84,8 @@ namespace SpineRuntime21 {
/// <summary>Computes the world SRT using the parent bone and the local SRT.</summary>
public void UpdateWorldTransform () {
Bone parent = this.parent;
float sx = skeleton.scaleX, sy = skeleton.scaleY;
Bone parent = this.parent;
float x = this.x, y = this.y;
if (parent != null) {
worldX = x * parent.m00 + y * parent.m01 + parent.worldX;
@@ -100,34 +101,22 @@ namespace SpineRuntime21 {
worldFlipX = parent.worldFlipX != flipX;
worldFlipY = parent.worldFlipY != flipY;
} else {
Skeleton skeleton = this.skeleton;
bool skeletonFlipX = skeleton.flipX, skeletonFlipY = skeleton.flipY;
worldX = skeletonFlipX ? -x : x;
worldY = skeletonFlipY != yDown ? -y : y;
worldX = x * sx;
worldY = y * sy;
worldScaleX = scaleX;
worldScaleY = scaleY;
worldRotation = rotationIK;
worldFlipX = skeletonFlipX != flipX;
worldFlipY = skeletonFlipY != flipY;
worldFlipX = (sx < 0) != flipX;
worldFlipY = (sy < 0) != flipY;
}
float radians = worldRotation * (float)Math.PI / 180;
float cos = (float)Math.Cos(radians);
float sin = (float)Math.Sin(radians);
if (worldFlipX) {
m00 = -cos * worldScaleX;
m01 = sin * worldScaleY;
} else {
m00 = cos * worldScaleX;
m01 = -sin * worldScaleY;
}
if (worldFlipY != yDown) {
m10 = -sin * worldScaleX;
m11 = -cos * worldScaleY;
} else {
m10 = sin * worldScaleX;
m11 = cos * worldScaleY;
}
}
m00 = cos * worldScaleX * sx;
m01 = -sin * worldScaleY * sx;
m10 = sin * worldScaleX * sy;
m11 = cos * worldScaleY * sy;
}
public void SetToSetupPose () {
BoneData data = this.data;

View File

@@ -42,8 +42,8 @@ namespace SpineRuntime21 {
internal Skin skin;
internal float r = 1, g = 1, b = 1, a = 1;
internal float time;
internal bool flipX, flipY;
internal float x, y;
internal float scaleX = 1, scaleY = 1;
internal float x, y;
public SkeletonData Data { get { return data; } }
public List<Bone> Bones { get { return bones; } }
@@ -58,10 +58,16 @@ namespace SpineRuntime21 {
public float Time { get { return time; } set { time = value; } }
public float X { get { return x; } set { x = value; } }
public float Y { get { return y; } set { y = value; } }
public bool FlipX { get { return flipX; } set { flipX = value; } }
public bool FlipY { get { return flipY; } set { flipY = value; } }
public float ScaleX { get { return scaleX; } set { scaleX = value; } }
public float ScaleY { get { return scaleY; } set { scaleY = value; } }
public Bone RootBone {
[Obsolete("Use ScaleX instead. FlipX is when ScaleX is negative.")]
public bool FlipX { get { return scaleX < 0; } set { scaleX = value ? -1f : 1f; } }
[Obsolete("Use ScaleY instead. FlipY is when ScaleY is negative.")]
public bool FlipY { get { return scaleY < 0; } set { scaleY = value ? -1f : 1f; } }
public Bone RootBone {
get {
return bones.Count == 0 ? null : bones[0];
}