[haxe] 4.3 porting WIP - TC constants.

This commit is contained in:
Davide Tantillo 2025-06-12 15:36:37 +02:00
parent 3eb587c988
commit e210e20524
4 changed files with 49 additions and 42 deletions

View File

@ -307,12 +307,12 @@ class SkeletonBinary {
froms[ii] = from;
}
flags = input.readByte();
if ((flags & 1) != 0) data.offsets[0] = input.readFloat();
if ((flags & 2) != 0) data.offsets[1] = input.readFloat() * scale;
if ((flags & 4) != 0) data.offsets[2] = input.readFloat() * scale;
if ((flags & 8) != 0) data.offsets[3] = input.readFloat();
if ((flags & 16) != 0) data.offsets[4] = input.readFloat();
if ((flags & 32) != 0) data.offsets[5] = input.readFloat();
if ((flags & 1) != 0) data.offsets[TransformConstraintData.ROTATION] = input.readFloat();
if ((flags & 2) != 0) data.offsets[TransformConstraintData.X] = input.readFloat() * scale;
if ((flags & 4) != 0) data.offsets[TransformConstraintData.Y] = input.readFloat() * scale;
if ((flags & 8) != 0) data.offsets[TransformConstraintData.SCALEX] = input.readFloat();
if ((flags & 16) != 0) data.offsets[TransformConstraintData.SCALEY] = input.readFloat();
if ((flags & 32) != 0) data.offsets[TransformConstraintData.SHEARY] = input.readFloat();
flags = input.readByte();
var setup = data.setup;
if ((flags & 1) != 0) setup.mixRotate = input.readFloat();

View File

@ -262,12 +262,12 @@ class SkeletonJson {
if (from.to.length > 0) data.properties.push(from);
}
data.offsets[0] = getFloat(constraintMap, "rotation", 0);
data.offsets[1] = getFloat(constraintMap, "x", 0) * scale;
data.offsets[2] = getFloat(constraintMap, "y", 0) * scale;
data.offsets[3] = getFloat(constraintMap, "scaleX", 0);
data.offsets[4] = getFloat(constraintMap, "scaleY", 0);
data.offsets[5] = getFloat(constraintMap, "shearY", 0);
data.offsets[TransformConstraintData.ROTATION] = getFloat(constraintMap, "rotation", 0);
data.offsets[TransformConstraintData.X] = getFloat(constraintMap, "x", 0) * scale;
data.offsets[TransformConstraintData.Y] = getFloat(constraintMap, "y", 0) * scale;
data.offsets[TransformConstraintData.SCALEX] = getFloat(constraintMap, "scaleX", 0);
data.offsets[TransformConstraintData.SCALEY] = getFloat(constraintMap, "scaleY", 0);
data.offsets[TransformConstraintData.SHEARY] = getFloat(constraintMap, "shearY", 0);
var setup = data.setup;
if (rotate) setup.mixRotate = getFloat(constraintMap, "mixRotate", 1);

View File

@ -36,6 +36,13 @@ package spine;
* @see https://esotericsoftware.com/spine-transform-constraints Transform constraints in the Spine User Guide
*/
class TransformConstraintData extends ConstraintData<TransformConstraint, TransformConstraintPose> {
public static inline final ROTATION = 0;
public static inline final X = 1;
public static inline final Y = 2;
public static inline final SCALEX = 3;
public static inline final SCALEY = 4;
public static inline final SHEARY = 5;
/** The bones that will be modified by this transform constraint. */
public final bones:Array<BoneData> = new Array<BoneData>();
@ -90,61 +97,61 @@ class TransformConstraintData extends ConstraintData<TransformConstraint, Transf
/** An offset added to the constrained bone rotation. */
public function getOffsetRotation ():Float {
return offsets[0];
return offsets[TransformConstraintData.ROTATION];
}
public function setOffsetRotation (offsetRotation:Float):Float {
offsets[0] = offsetRotation;
offsets[TransformConstraintData.ROTATION] = offsetRotation;
return offsetRotation;
}
/** An offset added to the constrained bone X translation. */
public function getOffsetX ():Float {
return offsets[1];
return offsets[TransformConstraintData.X];
}
public function setOffsetX (offsetX:Float):Float {
offsets[1] = offsetX;
offsets[TransformConstraintData.X] = offsetX;
return offsetX;
}
/** An offset added to the constrained bone Y translation. */
public function getOffsetY ():Float {
return offsets[2];
return offsets[TransformConstraintData.Y];
}
public function setOffsetY (offsetY:Float):Float {
offsets[2] = offsetY;
offsets[TransformConstraintData.Y] = offsetY;
return offsetY;
}
/** An offset added to the constrained bone scaleX. */
public function getOffsetScaleX ():Float {
return offsets[3];
return offsets[TransformConstraintData.SCALEX];
}
public function setOffsetScaleX (offsetScaleX:Float):Float {
offsets[3] = offsetScaleX;
offsets[TransformConstraintData.SCALEX] = offsetScaleX;
return offsetScaleX;
}
/** An offset added to the constrained bone scaleY. */
public function getOffsetScaleY ():Float {
return offsets[4];
return offsets[TransformConstraintData.SCALEY];
}
public function setOffsetScaleY (offsetScaleY:Float):Float {
offsets[4] = offsetScaleY;
offsets[TransformConstraintData.SCALEY] = offsetScaleY;
return offsetScaleY;
}
/** An offset added to the constrained bone shearY. */
public function getOffsetShearY ():Float {
return offsets[5];
return offsets[TransformConstraintData.SHEARY];
}
public function setOffsetShearY (offsetShearY:Float):Float {
offsets[5] = offsetShearY;
offsets[TransformConstraintData.SHEARY] = offsetShearY;
return offsetShearY;
}
@ -188,9 +195,9 @@ abstract class ToProperty {
class FromRotate extends FromProperty {
public function value (source:BonePose, local:Bool, offsets:Array<Float>):Float {
if (local) return source.rotation + offsets[0];
if (local) return source.rotation + offsets[TransformConstraintData.ROTATION];
var value = Math.atan2(source.c, source.a) * MathUtils.radDeg
+ (source.a * source.d - source.b * source.c > 0 ? offsets[0] : -offsets[0]);
+ (source.a * source.d - source.b * source.c > 0 ? offsets[TransformConstraintData.ROTATION] : -offsets[TransformConstraintData.ROTATION]);
if (value < 0) value += 360;
return value;
}
@ -225,7 +232,7 @@ class ToRotate extends ToProperty {
class FromX extends FromProperty {
public function value (source:BonePose, local:Bool, offsets:Array<Float>):Float {
return local ? source.x + offsets[1] : offsets[1] * source.a + offsets[2] * source.b + source.worldX;
return local ? source.x + offsets[TransformConstraintData.X] : offsets[TransformConstraintData.X] * source.a + offsets[TransformConstraintData.Y] * source.b + source.worldX;
}
}
@ -247,7 +254,7 @@ class ToX extends ToProperty {
class FromY extends FromProperty {
public function value (source:BonePose, local:Bool, offsets:Array<Float>):Float {
return local ? source.y + offsets[2] : offsets[1] * source.c + offsets[2] * source.d + source.worldY;
return local ? source.y + offsets[TransformConstraintData.Y] : offsets[TransformConstraintData.X] * source.c + offsets[TransformConstraintData.Y] * source.d + source.worldY;
}
}
@ -269,7 +276,7 @@ class ToY extends ToProperty {
class FromScaleX extends FromProperty {
public function value (source:BonePose, local:Bool, offsets:Array<Float>):Float {
return (local ? source.scaleX : Math.sqrt(source.a * source.a + source.c * source.c)) + offsets[3];
return (local ? source.scaleX : Math.sqrt(source.a * source.a + source.c * source.c)) + offsets[TransformConstraintData.SCALEX];
}
}
@ -300,7 +307,7 @@ class ToScaleX extends ToProperty {
class FromScaleY extends FromProperty {
public function value (source:BonePose, local:Bool, offsets:Array<Float>):Float {
return (local ? source.scaleY : Math.sqrt(source.b * source.b + source.d * source.d)) + offsets[4];
return (local ? source.scaleY : Math.sqrt(source.b * source.b + source.d * source.d)) + offsets[TransformConstraintData.SCALEY];
}
}
@ -331,7 +338,7 @@ class ToScaleY extends ToProperty {
class FromShearY extends FromProperty {
public function value (source:BonePose, local:Bool, offsets:Array<Float>):Float {
return (local ? source.shearY : (Math.atan2(source.d, source.b) - Math.atan2(source.c, source.a)) * MathUtils.radDeg - 90) + offsets[5];
return (local ? source.shearY : (Math.atan2(source.d, source.b) - Math.atan2(source.c, source.a)) * MathUtils.radDeg - 90) + offsets[TransformConstraintData.SHEARY];
}
}

View File

@ -68,7 +68,7 @@ class RegionAttachment extends Attachment implements HasTextureRegion {
/** For each of the 4 vertices, a pair of x,y values that is the local position of the vertex.
*
* See RegionAttachment.updateRegion(). */
private var offsets:Array<Float> = new Array<Float>();
private var offset:Array<Float> = new Array<Float>();
public var uvs:Array<Float> = new Array<Float>();
@ -116,14 +116,14 @@ class RegionAttachment extends Attachment implements HasTextureRegion {
var localY2Cos = localY2 * cos + y;
var localY2Sin = localY2 * sin;
offsets[0] = localXCos - localYSin;
offsets[1] = localYCos + localXSin;
offsets[2] = localXCos - localY2Sin;
offsets[3] = localY2Cos + localXSin;
offsets[4] = localX2Cos - localY2Sin;
offsets[5] = localY2Cos + localX2Sin;
offsets[6] = localX2Cos - localYSin;
offsets[7] = localYCos + localX2Sin;
offset[0] = localXCos - localYSin;
offset[1] = localYCos + localXSin;
offset[2] = localXCos - localY2Sin;
offset[3] = localY2Cos + localXSin;
offset[4] = localX2Cos - localY2Sin;
offset[5] = localY2Cos + localX2Sin;
offset[6] = localX2Cos - localYSin;
offset[7] = localYCos + localX2Sin;
if (region.degrees == 90) {
uvs[0] = region.u2;
@ -156,7 +156,7 @@ class RegionAttachment extends Attachment implements HasTextureRegion {
public function computeWorldVertices(slot:Slot, worldVertices:Array<Float>, offset:Int, stride:Int):Void {
if (sequence != null) sequence.apply(slot.applied, this);
var vertexOffset = this.offsets;
var vertexOffset = this.offset;
var bone = slot.bone.applied;
var x = bone.worldX, y = bone.worldY;
var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
@ -198,7 +198,7 @@ class RegionAttachment extends Attachment implements HasTextureRegion {
copy.width = width;
copy.height = height;
copy.uvs = uvs.copy();
copy.offsets = offsets.copy();
copy.offset = offset.copy();
copy.color.setFromColor(color);
copy.sequence = sequence != null ? sequence.copy() : null;
return copy;