mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[ts] 4.3 porting WIP - TC constants.
This commit is contained in:
parent
951233c856
commit
3eb587c988
@ -235,12 +235,12 @@ export class SkeletonBinary {
|
|||||||
data.properties[ii] = from;
|
data.properties[ii] = from;
|
||||||
}
|
}
|
||||||
flags = input.readByte();
|
flags = input.readByte();
|
||||||
if ((flags & 1) != 0) data.offsets[0] = input.readFloat();
|
if ((flags & 1) != 0) data.offsets[TransformConstraintData.ROTATION] = input.readFloat();
|
||||||
if ((flags & 2) != 0) data.offsets[1] = input.readFloat() * scale;
|
if ((flags & 2) != 0) data.offsets[TransformConstraintData.X] = input.readFloat() * scale;
|
||||||
if ((flags & 4) != 0) data.offsets[2] = input.readFloat() * scale;
|
if ((flags & 4) != 0) data.offsets[TransformConstraintData.Y] = input.readFloat() * scale;
|
||||||
if ((flags & 8) != 0) data.offsets[3] = input.readFloat();
|
if ((flags & 8) != 0) data.offsets[TransformConstraintData.SCALEX] = input.readFloat();
|
||||||
if ((flags & 16) != 0) data.offsets[4] = input.readFloat();
|
if ((flags & 16) != 0) data.offsets[TransformConstraintData.SCALEY] = input.readFloat();
|
||||||
if ((flags & 32) != 0) data.offsets[5] = input.readFloat();
|
if ((flags & 32) != 0) data.offsets[TransformConstraintData.SHEARY] = input.readFloat();
|
||||||
flags = input.readByte();
|
flags = input.readByte();
|
||||||
const setup = data.setup;
|
const setup = data.setup;
|
||||||
if ((flags & 1) != 0) setup.mixRotate = input.readFloat();
|
if ((flags & 1) != 0) setup.mixRotate = input.readFloat();
|
||||||
|
|||||||
@ -243,12 +243,12 @@ export class SkeletonJson {
|
|||||||
if (from.to.length > 0) data.properties.push(from);
|
if (from.to.length > 0) data.properties.push(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.offsets[0] = getValue(constraintMap, "rotation", 0);
|
data.offsets[TransformConstraintData.ROTATION] = getValue(constraintMap, "rotation", 0);
|
||||||
data.offsets[1] = getValue(constraintMap, "x", 0) * scale;
|
data.offsets[TransformConstraintData.X] = getValue(constraintMap, "x", 0) * scale;
|
||||||
data.offsets[2] = getValue(constraintMap, "y", 0) * scale;
|
data.offsets[TransformConstraintData.Y] = getValue(constraintMap, "y", 0) * scale;
|
||||||
data.offsets[3] = getValue(constraintMap, "scaleX", 0);
|
data.offsets[TransformConstraintData.SCALEX] = getValue(constraintMap, "scaleX", 0);
|
||||||
data.offsets[4] = getValue(constraintMap, "scaleY", 0);
|
data.offsets[TransformConstraintData.SCALEY] = getValue(constraintMap, "scaleY", 0);
|
||||||
data.offsets[5] = getValue(constraintMap, "shearY", 0);
|
data.offsets[TransformConstraintData.SHEARY] = getValue(constraintMap, "shearY", 0);
|
||||||
|
|
||||||
const setup = data.setup;
|
const setup = data.setup;
|
||||||
if (rotate) setup.mixRotate = getValue(constraintMap, "mixRotate", 1);
|
if (rotate) setup.mixRotate = getValue(constraintMap, "mixRotate", 1);
|
||||||
|
|||||||
@ -39,6 +39,13 @@ import { BonePose } from "./BonePose.js";
|
|||||||
*
|
*
|
||||||
* See [Transform constraints](http://esotericsoftware.com/spine-transform-constraints) in the Spine User Guide. */
|
* See [Transform constraints](http://esotericsoftware.com/spine-transform-constraints) in the Spine User Guide. */
|
||||||
export class TransformConstraintData extends ConstraintData<TransformConstraint, TransformConstraintPose> {
|
export class TransformConstraintData extends ConstraintData<TransformConstraint, TransformConstraintPose> {
|
||||||
|
public static readonly ROTATION = 0;
|
||||||
|
public static readonly X = 1;
|
||||||
|
public static readonly Y = 2;
|
||||||
|
public static readonly SCALEX = 3;
|
||||||
|
public static readonly SCALEY = 4;
|
||||||
|
public static readonly SHEARY = 5;
|
||||||
|
|
||||||
/** The bones that will be modified by this transform constraint. */
|
/** The bones that will be modified by this transform constraint. */
|
||||||
bones = new Array<BoneData>();
|
bones = new Array<BoneData>();
|
||||||
|
|
||||||
@ -83,56 +90,56 @@ export class TransformConstraintData extends ConstraintData<TransformConstraint,
|
|||||||
|
|
||||||
/** An offset added to the constrained bone rotation. */
|
/** An offset added to the constrained bone rotation. */
|
||||||
getOffsetRotation () {
|
getOffsetRotation () {
|
||||||
return this.offsets[0];
|
return this.offsets[TransformConstraintData.ROTATION];
|
||||||
}
|
}
|
||||||
|
|
||||||
setOffsetRotation (offsetRotation: number) {
|
setOffsetRotation (offsetRotation: number) {
|
||||||
this.offsets[0] = offsetRotation;
|
this.offsets[TransformConstraintData.ROTATION] = offsetRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An offset added to the constrained bone X translation. */
|
/** An offset added to the constrained bone X translation. */
|
||||||
getOffsetX () {
|
getOffsetX () {
|
||||||
return this.offsets[1];
|
return this.offsets[TransformConstraintData.X];
|
||||||
}
|
}
|
||||||
|
|
||||||
setOffsetX (offsetX: number) {
|
setOffsetX (offsetX: number) {
|
||||||
this.offsets[1] = offsetX;
|
this.offsets[TransformConstraintData.X] = offsetX;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An offset added to the constrained bone Y translation. */
|
/** An offset added to the constrained bone Y translation. */
|
||||||
getOffsetY () {
|
getOffsetY () {
|
||||||
return this.offsets[2];
|
return this.offsets[TransformConstraintData.Y];
|
||||||
}
|
}
|
||||||
|
|
||||||
setOffsetY (offsetY: number) {
|
setOffsetY (offsetY: number) {
|
||||||
this.offsets[2] = offsetY;
|
this.offsets[TransformConstraintData.Y] = offsetY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An offset added to the constrained bone scaleX. */
|
/** An offset added to the constrained bone scaleX. */
|
||||||
getOffsetScaleX () {
|
getOffsetScaleX () {
|
||||||
return this.offsets[3];
|
return this.offsets[TransformConstraintData.SCALEX];
|
||||||
}
|
}
|
||||||
|
|
||||||
setOffsetScaleX (offsetScaleX: number) {
|
setOffsetScaleX (offsetScaleX: number) {
|
||||||
this.offsets[3] = offsetScaleX;
|
this.offsets[TransformConstraintData.SCALEX] = offsetScaleX;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An offset added to the constrained bone scaleY. */
|
/** An offset added to the constrained bone scaleY. */
|
||||||
getOffsetScaleY () {
|
getOffsetScaleY () {
|
||||||
return this.offsets[4];
|
return this.offsets[TransformConstraintData.SCALEY];
|
||||||
}
|
}
|
||||||
|
|
||||||
setOffsetScaleY (offsetScaleY: number) {
|
setOffsetScaleY (offsetScaleY: number) {
|
||||||
this.offsets[4] = offsetScaleY;
|
this.offsets[TransformConstraintData.SCALEY] = offsetScaleY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An offset added to the constrained bone shearY. */
|
/** An offset added to the constrained bone shearY. */
|
||||||
getOffsetShearY () {
|
getOffsetShearY () {
|
||||||
return this.offsets[5];
|
return this.offsets[TransformConstraintData.SHEARY];
|
||||||
}
|
}
|
||||||
|
|
||||||
setOffsetShearY (offsetShearY: number) {
|
setOffsetShearY (offsetShearY: number) {
|
||||||
this.offsets[5] = offsetShearY;
|
this.offsets[TransformConstraintData.SHEARY] = offsetShearY;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -169,9 +176,9 @@ export abstract class ToProperty {
|
|||||||
|
|
||||||
export class FromRotate extends FromProperty {
|
export class FromRotate extends FromProperty {
|
||||||
value (source: BonePose, local: boolean, offsets: Array<number>): number {
|
value (source: BonePose, local: boolean, offsets: Array<number>): number {
|
||||||
if (local) return source.rotation + offsets[0];
|
if (local) return source.rotation + offsets[TransformConstraintData.ROTATION];
|
||||||
let value = Math.atan2(source.c, source.a) * MathUtils.radDeg
|
let 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;
|
if (value < 0) value += 360;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -206,7 +213,7 @@ export class ToRotate extends ToProperty {
|
|||||||
|
|
||||||
export class FromX extends FromProperty {
|
export class FromX extends FromProperty {
|
||||||
value (source: BonePose, local: boolean, offsets: Array<number>): number {
|
value (source: BonePose, local: boolean, offsets: Array<number>): number {
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +235,7 @@ export class ToX extends ToProperty {
|
|||||||
|
|
||||||
export class FromY extends FromProperty {
|
export class FromY extends FromProperty {
|
||||||
value (source: BonePose, local: boolean, offsets: Array<number>): number {
|
value (source: BonePose, local: boolean, offsets: Array<number>): number {
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +257,7 @@ export class ToY extends ToProperty {
|
|||||||
|
|
||||||
export class FromScaleX extends FromProperty {
|
export class FromScaleX extends FromProperty {
|
||||||
value (source: BonePose, local: boolean, offsets: Array<number>): number {
|
value (source: BonePose, local: boolean, offsets: Array<number>): number {
|
||||||
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,7 +288,7 @@ export class ToScaleX extends ToProperty {
|
|||||||
|
|
||||||
export class FromScaleY extends FromProperty {
|
export class FromScaleY extends FromProperty {
|
||||||
value (source: BonePose, local: boolean, offsets: Array<number>): number {
|
value (source: BonePose, local: boolean, offsets: Array<number>): number {
|
||||||
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +319,7 @@ export class ToScaleY extends ToProperty {
|
|||||||
|
|
||||||
export class FromShearY extends FromProperty {
|
export class FromShearY extends FromProperty {
|
||||||
value (source: BonePose, local: boolean, offsets: Array<number>): number {
|
value (source: BonePose, local: boolean, offsets: Array<number>): number {
|
||||||
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user