mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-06 10:46:53 +08:00
[ts] 4.3 porting WIP - latest updates.
This commit is contained in:
parent
317aa13c87
commit
e723893c0c
@ -334,6 +334,7 @@ export class SkeletonBinary {
|
|||||||
default: continue;
|
default: continue;
|
||||||
};
|
};
|
||||||
data.property.offset = offset;
|
data.property.offset = offset;
|
||||||
|
data.offset = input.readFloat();
|
||||||
data.scale = input.readFloat();
|
data.scale = input.readFloat();
|
||||||
}
|
}
|
||||||
constraints.push(data);
|
constraints.push(data);
|
||||||
|
|||||||
@ -343,7 +343,9 @@ export class SkeletonJson {
|
|||||||
if (!data.bone) throw new Error("Slider bone not found: " + boneName);
|
if (!data.bone) throw new Error("Slider bone not found: " + boneName);
|
||||||
const property = constraintMap.property;
|
const property = constraintMap.property;
|
||||||
data.property = this.fromProperty(property);
|
data.property = this.fromProperty(property);
|
||||||
data.property.offset = getValue(constraintMap, "offset", 0) * this.propertyScale(property, scale);
|
const propertyScale = this.propertyScale(property, scale);
|
||||||
|
data.property.offset = getValue(constraintMap, "from", 0) * propertyScale;
|
||||||
|
data.offset = getValue(constraintMap, "to", 0);
|
||||||
data.scale = getValue(constraintMap, "scale", 1);
|
data.scale = getValue(constraintMap, "scale", 1);
|
||||||
data.local = getValue(constraintMap, "local", false);
|
data.local = getValue(constraintMap, "local", false);
|
||||||
}
|
}
|
||||||
@ -919,12 +921,10 @@ export class SkeletonJson {
|
|||||||
skeletonData.constraints.indexOf(constraint));
|
skeletonData.constraints.indexOf(constraint));
|
||||||
|
|
||||||
let time = getValue(keyMap, "time", 0);
|
let time = getValue(keyMap, "time", 0);
|
||||||
let mixRotate = getValue(keyMap, "mixRotate", 0);
|
let mixRotate = getValue(keyMap, "mixRotate", 1);
|
||||||
let mixX = getValue(keyMap, "mixX", 0);
|
let mixX = getValue(keyMap, "mixX", 1), mixY = getValue(keyMap, "mixY", mixX);
|
||||||
let mixY = getValue(keyMap, "mixY", mixX);
|
let mixScaleX = getValue(keyMap, "mixScaleX", 1), mixScaleY = getValue(keyMap, "mixScaleY", 1);
|
||||||
let mixScaleX = getValue(keyMap, "mixScaleX", 0);
|
let mixShearY = getValue(keyMap, "mixShearY", 1);
|
||||||
let mixScaleY = getValue(keyMap, "mixScaleY", mixScaleX);
|
|
||||||
let mixShearY = getValue(keyMap, "mixShearY", 0);
|
|
||||||
|
|
||||||
for (let frame = 0, bezier = 0; ; frame++) {
|
for (let frame = 0, bezier = 0; ; frame++) {
|
||||||
timeline.setFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY);
|
timeline.setFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY);
|
||||||
@ -936,10 +936,8 @@ export class SkeletonJson {
|
|||||||
|
|
||||||
let time2 = getValue(nextMap, "time", 0);
|
let time2 = getValue(nextMap, "time", 0);
|
||||||
let mixRotate2 = getValue(nextMap, "mixRotate", 1);
|
let mixRotate2 = getValue(nextMap, "mixRotate", 1);
|
||||||
let mixX2 = getValue(nextMap, "mixX", 1);
|
let mixX2 = getValue(nextMap, "mixX", 1), mixY2 = getValue(nextMap, "mixY", mixX2);
|
||||||
let mixY2 = getValue(nextMap, "mixY", mixX2);
|
let mixScaleX2 = getValue(nextMap, "mixScaleX", 1), mixScaleY2 = getValue(nextMap, "mixScaleY", 1);
|
||||||
let mixScaleX2 = getValue(nextMap, "mixScaleX", 1);
|
|
||||||
let mixScaleY2 = getValue(nextMap, "mixScaleY", mixScaleX2);
|
|
||||||
let mixShearY2 = getValue(nextMap, "mixShearY", 1);
|
let mixShearY2 = getValue(nextMap, "mixShearY", 1);
|
||||||
let curve = keyMap.curve;
|
let curve = keyMap.curve;
|
||||||
if (curve) {
|
if (curve) {
|
||||||
|
|||||||
@ -64,7 +64,8 @@ export class Slider extends Constraint<Slider, SliderData, SliderPose> {
|
|||||||
if (bone !== null) {
|
if (bone !== null) {
|
||||||
if (!bone.active) return;
|
if (!bone.active) return;
|
||||||
if (data.local) bone.applied.validateLocalTransform(skeleton);
|
if (data.local) bone.applied.validateLocalTransform(skeleton);
|
||||||
p.time = (data.property.value(bone.applied, data.local, Slider.offsets) - data.property.offset) * data.scale;
|
p.time = data.offset
|
||||||
|
+ (data.property.value(skeleton, bone.applied, data.local, Slider.offsets) - data.property.offset) * data.scale;
|
||||||
if (data.loop)
|
if (data.loop)
|
||||||
p.time = animation.duration + (p.time % animation.duration);
|
p.time = animation.duration + (p.time % animation.duration);
|
||||||
else
|
else
|
||||||
|
|||||||
@ -45,6 +45,7 @@ export class SliderData extends ConstraintData<Slider, SliderPose> {
|
|||||||
bone: BoneData | null = null;
|
bone: BoneData | null = null;
|
||||||
property!: FromProperty;
|
property!: FromProperty;
|
||||||
scale = 0;
|
scale = 0;
|
||||||
|
offset = 0;
|
||||||
local = false;
|
local = false;
|
||||||
|
|
||||||
constructor (name: string) {
|
constructor (name: string) {
|
||||||
|
|||||||
@ -88,7 +88,7 @@ export class TransformConstraint extends Constraint<TransformConstraint, Transfo
|
|||||||
bone.modifyWorld(update);
|
bone.modifyWorld(update);
|
||||||
for (let f = 0; f < fn; f++) {
|
for (let f = 0; f < fn; f++) {
|
||||||
const from = fromItems[f];
|
const from = fromItems[f];
|
||||||
const value = from.value(source, localSource, offsets) - from.offset;
|
const value = from.value(skeleton, source, localSource, offsets) - from.offset;
|
||||||
const toItems = from.to;
|
const toItems = from.to;
|
||||||
for (let t = 0, tn = from.to.length; t < tn; t++) {
|
for (let t = 0, tn = from.to.length; t < tn; t++) {
|
||||||
const to = toItems[t];
|
const to = toItems[t];
|
||||||
|
|||||||
@ -153,7 +153,7 @@ export abstract class FromProperty {
|
|||||||
readonly to: Array<ToProperty> = [];
|
readonly to: Array<ToProperty> = [];
|
||||||
|
|
||||||
/** Reads this property from the specified bone. */
|
/** Reads this property from the specified bone. */
|
||||||
abstract value (source: BonePose, local: boolean, offsets: Array<number>): number;
|
abstract value (skeleton: Skeleton, source: BonePose, local: boolean, offsets: Array<number>): number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Constrained property for a {@link TransformConstraint}. */
|
/** Constrained property for a {@link TransformConstraint}. */
|
||||||
@ -175,9 +175,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 (skeleton: Skeleton, source: BonePose, local: boolean, offsets: Array<number>): number {
|
||||||
if (local) return source.rotation + offsets[TransformConstraintData.ROTATION];
|
if (local) return source.rotation + offsets[TransformConstraintData.ROTATION];
|
||||||
let value = Math.atan2(source.c, source.a) * MathUtils.radDeg
|
let value = Math.atan2(source.c / skeleton.scaleY, source.a / skeleton.scaleX) * MathUtils.radDeg
|
||||||
+ (source.a * source.d - source.b * source.c > 0 ? offsets[TransformConstraintData.ROTATION] : -offsets[TransformConstraintData.ROTATION]);
|
+ (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;
|
||||||
@ -212,8 +212,10 @@ 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 (skeleton: Skeleton, source: BonePose, local: boolean, offsets: Array<number>): number {
|
||||||
return local ? source.x + offsets[TransformConstraintData.X] : offsets[TransformConstraintData.X] * source.a + offsets[TransformConstraintData.Y] * source.b + source.worldX;
|
return local
|
||||||
|
? source.x + offsets[TransformConstraintData.X]
|
||||||
|
: (offsets[TransformConstraintData.X] * source.a + offsets[TransformConstraintData.Y] * source.b + source.worldX) / skeleton.scaleX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,8 +236,10 @@ 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 (skeleton: Skeleton, source: BonePose, local: boolean, offsets: Array<number>): number {
|
||||||
return local ? source.y + offsets[TransformConstraintData.Y] : offsets[TransformConstraintData.X] * source.c + offsets[TransformConstraintData.Y] * source.d + source.worldY;
|
return local
|
||||||
|
? source.y + offsets[TransformConstraintData.Y]
|
||||||
|
: (offsets[TransformConstraintData.X] * source.c + offsets[TransformConstraintData.Y] * source.d + source.worldY) / skeleton.scaleY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,8 +260,10 @@ 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 (skeleton: Skeleton, source: BonePose, local: boolean, offsets: Array<number>): number {
|
||||||
return local ? source.scaleX : Math.sqrt(source.a * source.a + source.c * source.c) + offsets[TransformConstraintData.SCALEX];
|
if (local) return source.scaleX + offsets[TransformConstraintData.SCALEX];
|
||||||
|
const a = source.a / skeleton.scaleX, c = source.c / skeleton.scaleY;
|
||||||
|
return Math.sqrt(a * a + c * c) + offsets[TransformConstraintData.SCALEX];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,8 +293,10 @@ 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 (skeleton: Skeleton, source: BonePose, local: boolean, offsets: Array<number>): number {
|
||||||
return local ? source.scaleY : Math.sqrt(source.b * source.b + source.d * source.d) + offsets[TransformConstraintData.SCALEY];
|
if (local) return source.scaleY + offsets[TransformConstraintData.SCALEY];
|
||||||
|
const b = source.b / skeleton.scaleX, d = source.d / skeleton.scaleY;
|
||||||
|
return Math.sqrt(b * b + d * d) + offsets[TransformConstraintData.SCALEY];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,8 +326,11 @@ 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 (skeleton: Skeleton, 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[TransformConstraintData.SHEARY];
|
if (local) return source.shearY + offsets[TransformConstraintData.SHEARY];
|
||||||
|
const sx = 1 / skeleton.scaleX, sy = 1 / skeleton.scaleY;
|
||||||
|
return (Math.atan2(source.d * sy, source.b * sx) - Math.atan2(source.c * sy, source.a * sx))
|
||||||
|
* MathUtils.radDeg - 90 + offsets[TransformConstraintData.SHEARY];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user