mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-06 02:36:56 +08:00
[libgdx] Transform constraint relative->additive and mix applies on "to" side.
This commit is contained in:
parent
7a366cd6f5
commit
764eafa212
@ -285,7 +285,7 @@ public class SkeletonBinary extends SkeletonLoader {
|
|||||||
data.skinRequired = (flags & 1) != 0;
|
data.skinRequired = (flags & 1) != 0;
|
||||||
data.localSource = (flags & 2) != 0;
|
data.localSource = (flags & 2) != 0;
|
||||||
data.localTarget = (flags & 4) != 0;
|
data.localTarget = (flags & 4) != 0;
|
||||||
data.relative = (flags & 8) != 0;
|
data.additive = (flags & 8) != 0;
|
||||||
data.clamp = (flags & 16) != 0;
|
data.clamp = (flags & 16) != 0;
|
||||||
Object[] froms = data.properties.setSize(nn = flags >> 5);
|
Object[] froms = data.properties.setSize(nn = flags >> 5);
|
||||||
for (int ii = 0, tn; ii < nn; ii++) {
|
for (int ii = 0, tn; ii < nn; ii++) {
|
||||||
|
|||||||
@ -258,7 +258,7 @@ public class SkeletonJson extends SkeletonLoader {
|
|||||||
|
|
||||||
data.localSource = constraintMap.getBoolean("localSource", false);
|
data.localSource = constraintMap.getBoolean("localSource", false);
|
||||||
data.localTarget = constraintMap.getBoolean("localTarget", false);
|
data.localTarget = constraintMap.getBoolean("localTarget", false);
|
||||||
data.relative = constraintMap.getBoolean("relative", false);
|
data.additive = constraintMap.getBoolean("additive", false);
|
||||||
data.clamp = constraintMap.getBoolean("clamp", false);
|
data.clamp = constraintMap.getBoolean("clamp", false);
|
||||||
|
|
||||||
for (JsonValue fromEntry = constraintMap.getChild("properties"); fromEntry != null; fromEntry = fromEntry.next) {
|
for (JsonValue fromEntry = constraintMap.getChild("properties"); fromEntry != null; fromEntry = fromEntry.next) {
|
||||||
|
|||||||
@ -97,7 +97,7 @@ public class TransformConstraint implements Updatable {
|
|||||||
if (mixRotate == 0 && mixX == 0 && mixY == 0 && mixScaleX == 0 && mixScaleY == 0 && mixShearY == 0) return;
|
if (mixRotate == 0 && mixX == 0 && mixY == 0 && mixScaleX == 0 && mixScaleY == 0 && mixShearY == 0) return;
|
||||||
|
|
||||||
TransformConstraintData data = this.data;
|
TransformConstraintData data = this.data;
|
||||||
boolean localFrom = data.localSource, localTarget = data.localTarget, relative = data.relative, clamp = data.clamp;
|
boolean localFrom = data.localSource, localTarget = data.localTarget, additive = data.additive, clamp = data.clamp;
|
||||||
Bone source = this.source;
|
Bone source = this.source;
|
||||||
Object[] fromItems = data.properties.items;
|
Object[] fromItems = data.properties.items;
|
||||||
int fn = data.properties.size;
|
int fn = data.properties.size;
|
||||||
@ -106,11 +106,11 @@ public class TransformConstraint implements Updatable {
|
|||||||
var bone = (Bone)bones[i];
|
var bone = (Bone)bones[i];
|
||||||
for (int f = 0; f < fn; f++) {
|
for (int f = 0; f < fn; f++) {
|
||||||
var from = (FromProperty)fromItems[f];
|
var from = (FromProperty)fromItems[f];
|
||||||
if (from.mix(this) != 0) {
|
float value = from.value(data, source, localFrom) - from.offset;
|
||||||
float value = from.value(data, source, localFrom) - from.offset;
|
Object[] toItems = from.to.items;
|
||||||
Object[] toItems = from.to.items;
|
for (int t = 0, tn = from.to.size; t < tn; t++) {
|
||||||
for (int t = 0, tn = from.to.size; t < tn; t++) {
|
var to = (ToProperty)toItems[t];
|
||||||
var to = (ToProperty)toItems[t];
|
if (to.mix(this) != 0) {
|
||||||
float clamped = to.offset + value * to.scale;
|
float clamped = to.offset + value * to.scale;
|
||||||
if (clamp) {
|
if (clamp) {
|
||||||
if (to.offset < to.max)
|
if (to.offset < to.max)
|
||||||
@ -118,7 +118,7 @@ public class TransformConstraint implements Updatable {
|
|||||||
else
|
else
|
||||||
clamped = clamp(clamped, to.max, to.offset);
|
clamped = clamp(clamped, to.max, to.offset);
|
||||||
}
|
}
|
||||||
to.apply(data, bone, clamped, localTarget, relative);
|
to.apply(data, bone, clamped, localTarget, additive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,7 +40,7 @@ public class TransformConstraintData extends ConstraintData {
|
|||||||
final Array<BoneData> bones = new Array();
|
final Array<BoneData> bones = new Array();
|
||||||
BoneData source;
|
BoneData source;
|
||||||
float offsetX, offsetY, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY;
|
float offsetX, offsetY, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY;
|
||||||
boolean localSource, localTarget, relative, clamp;
|
boolean localSource, localTarget, additive, clamp;
|
||||||
final Array<FromProperty> properties = new Array();
|
final Array<FromProperty> properties = new Array();
|
||||||
|
|
||||||
public TransformConstraintData (String name) {
|
public TransformConstraintData (String name) {
|
||||||
@ -158,12 +158,12 @@ public class TransformConstraintData extends ConstraintData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Adds the source bone transform to the constrained bones instead of setting it absolutely. */
|
/** Adds the source bone transform to the constrained bones instead of setting it absolutely. */
|
||||||
public boolean getRelative () {
|
public boolean getAdditive () {
|
||||||
return relative;
|
return additive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRelative (boolean relative) {
|
public void setAdditive (boolean additive) {
|
||||||
this.relative = relative;
|
this.additive = additive;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prevents constrained bones from exceeding the ranged defined by {@link ToProperty#offset} and {@link ToProperty#max}. */
|
/** Prevents constrained bones from exceeding the ranged defined by {@link ToProperty#offset} and {@link ToProperty#max}. */
|
||||||
@ -183,9 +183,6 @@ public class TransformConstraintData extends ConstraintData {
|
|||||||
/** Constrained properties. */
|
/** Constrained properties. */
|
||||||
public final Array<ToProperty> to = new Array();
|
public final Array<ToProperty> to = new Array();
|
||||||
|
|
||||||
/** Reads the mix for this property from the specified constraint. */
|
|
||||||
abstract public float mix (TransformConstraint constraint);
|
|
||||||
|
|
||||||
/** Reads this property from the specified bone. */
|
/** Reads this property from the specified bone. */
|
||||||
abstract public float value (TransformConstraintData data, Bone source, boolean local);
|
abstract public float value (TransformConstraintData data, Bone source, boolean local);
|
||||||
}
|
}
|
||||||
@ -201,29 +198,32 @@ public class TransformConstraintData extends ConstraintData {
|
|||||||
/** The scale of the {@link FromProperty} value in relation to this property. */
|
/** The scale of the {@link FromProperty} value in relation to this property. */
|
||||||
public float scale;
|
public float scale;
|
||||||
|
|
||||||
|
/** Reads the mix for this property from the specified constraint. */
|
||||||
|
abstract public float mix (TransformConstraint constraint);
|
||||||
|
|
||||||
/** Applies the value to this property. */
|
/** Applies the value to this property. */
|
||||||
abstract public void apply (TransformConstraintData data, Bone bone, float value, boolean local, boolean relative);
|
abstract public void apply (TransformConstraintData data, Bone bone, float value, boolean local, boolean additive);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class FromRotate extends FromProperty {
|
static public class FromRotate extends FromProperty {
|
||||||
public float mix (TransformConstraint constraint) {
|
|
||||||
return constraint.mixRotate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float value (TransformConstraintData data, Bone source, boolean local) {
|
public float value (TransformConstraintData data, Bone source, boolean local) {
|
||||||
return local ? source.arotation : atan2(source.c, source.a) * radDeg;
|
return local ? source.arotation : atan2(source.c, source.a) * radDeg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class ToRotate extends ToProperty {
|
static public class ToRotate extends ToProperty {
|
||||||
public void apply (TransformConstraintData data, Bone bone, float value, boolean local, boolean relative) {
|
public float mix (TransformConstraint constraint) {
|
||||||
|
return constraint.mixRotate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void apply (TransformConstraintData data, Bone bone, float value, boolean local, boolean additive) {
|
||||||
if (local) {
|
if (local) {
|
||||||
if (!relative) value -= bone.arotation;
|
if (!additive) value -= bone.arotation;
|
||||||
bone.arotation += value * data.mixRotate;
|
bone.arotation += value * data.mixRotate;
|
||||||
} else {
|
} else {
|
||||||
float a = bone.a, b = bone.b, c = bone.c, d = bone.d;
|
float a = bone.a, b = bone.b, c = bone.c, d = bone.d;
|
||||||
value *= degRad;
|
value *= degRad;
|
||||||
if (!relative) value -= atan2(c, a);
|
if (!additive) value -= atan2(c, a);
|
||||||
if (value > PI)
|
if (value > PI)
|
||||||
value -= PI2;
|
value -= PI2;
|
||||||
else if (value < -PI) //
|
else if (value < -PI) //
|
||||||
@ -239,69 +239,69 @@ public class TransformConstraintData extends ConstraintData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public class FromX extends FromProperty {
|
static public class FromX extends FromProperty {
|
||||||
public float mix (TransformConstraint constraint) {
|
|
||||||
return constraint.mixX;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float value (TransformConstraintData data, Bone source, boolean local) {
|
public float value (TransformConstraintData data, Bone source, boolean local) {
|
||||||
return local ? source.ax + data.offsetX : data.offsetX * source.a + data.offsetY * source.b + source.worldX;
|
return local ? source.ax + data.offsetX : data.offsetX * source.a + data.offsetY * source.b + source.worldX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class ToX extends ToProperty {
|
static public class ToX extends ToProperty {
|
||||||
public void apply (TransformConstraintData data, Bone bone, float value, boolean local, boolean relative) {
|
public float mix (TransformConstraint constraint) {
|
||||||
|
return constraint.mixX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void apply (TransformConstraintData data, Bone bone, float value, boolean local, boolean additive) {
|
||||||
if (local) {
|
if (local) {
|
||||||
if (!relative) value -= bone.ax;
|
if (!additive) value -= bone.ax;
|
||||||
bone.ax += value * data.mixX;
|
bone.ax += value * data.mixX;
|
||||||
} else {
|
} else {
|
||||||
if (!relative) value -= bone.worldX;
|
if (!additive) value -= bone.worldX;
|
||||||
bone.worldX += value * data.mixX;
|
bone.worldX += value * data.mixX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class FromY extends FromProperty {
|
static public class FromY extends FromProperty {
|
||||||
public float mix (TransformConstraint constraint) {
|
|
||||||
return constraint.mixY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float value (TransformConstraintData data, Bone source, boolean local) {
|
public float value (TransformConstraintData data, Bone source, boolean local) {
|
||||||
return local ? source.ay + data.offsetY : data.offsetX * source.c + data.offsetY * source.d + source.worldY;
|
return local ? source.ay + data.offsetY : data.offsetX * source.c + data.offsetY * source.d + source.worldY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class ToY extends ToProperty {
|
static public class ToY extends ToProperty {
|
||||||
public void apply (TransformConstraintData data, Bone bone, float value, boolean local, boolean relative) {
|
public float mix (TransformConstraint constraint) {
|
||||||
|
return constraint.mixY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void apply (TransformConstraintData data, Bone bone, float value, boolean local, boolean additive) {
|
||||||
if (local) {
|
if (local) {
|
||||||
if (!relative) value -= bone.ay;
|
if (!additive) value -= bone.ay;
|
||||||
bone.ay += value * data.mixY;
|
bone.ay += value * data.mixY;
|
||||||
} else {
|
} else {
|
||||||
if (!relative) value -= bone.worldY;
|
if (!additive) value -= bone.worldY;
|
||||||
bone.worldY += value * data.mixY;
|
bone.worldY += value * data.mixY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class FromScaleX extends FromProperty {
|
static public class FromScaleX extends FromProperty {
|
||||||
public float mix (TransformConstraint constraint) {
|
|
||||||
return constraint.mixScaleX;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float value (TransformConstraintData data, Bone source, boolean local) {
|
public float value (TransformConstraintData data, Bone source, boolean local) {
|
||||||
return local ? source.ascaleX : (float)Math.sqrt(source.a * source.a + source.c * source.c);
|
return local ? source.ascaleX : (float)Math.sqrt(source.a * source.a + source.c * source.c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class ToScaleX extends ToProperty {
|
static public class ToScaleX extends ToProperty {
|
||||||
public void apply (TransformConstraintData data, Bone bone, float value, boolean local, boolean relative) {
|
public float mix (TransformConstraint constraint) {
|
||||||
|
return constraint.mixScaleX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void apply (TransformConstraintData data, Bone bone, float value, boolean local, boolean additive) {
|
||||||
if (local) {
|
if (local) {
|
||||||
if (relative)
|
if (additive)
|
||||||
bone.ascaleX *= 1 + ((value - 1) * data.mixScaleX);
|
bone.ascaleX *= 1 + ((value - 1) * data.mixScaleX);
|
||||||
else if (bone.ascaleX != 0) //
|
else if (bone.ascaleX != 0) //
|
||||||
bone.ascaleX = 1 + (value / bone.ascaleX - 1) * data.mixScaleX;
|
bone.ascaleX = 1 + (value / bone.ascaleX - 1) * data.mixScaleX;
|
||||||
} else {
|
} else {
|
||||||
float s;
|
float s;
|
||||||
if (relative)
|
if (additive)
|
||||||
s = 1 + (value - 1) * data.mixScaleX;
|
s = 1 + (value - 1) * data.mixScaleX;
|
||||||
else {
|
else {
|
||||||
s = (float)Math.sqrt(bone.a * bone.a + bone.c * bone.c);
|
s = (float)Math.sqrt(bone.a * bone.a + bone.c * bone.c);
|
||||||
@ -314,25 +314,25 @@ public class TransformConstraintData extends ConstraintData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public class FromScaleY extends FromProperty {
|
static public class FromScaleY extends FromProperty {
|
||||||
public float mix (TransformConstraint constraint) {
|
|
||||||
return constraint.mixScaleY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float value (TransformConstraintData data, Bone source, boolean local) {
|
public float value (TransformConstraintData data, Bone source, boolean local) {
|
||||||
return local ? source.ascaleY : (float)Math.sqrt(source.b * source.b + source.d * source.d);
|
return local ? source.ascaleY : (float)Math.sqrt(source.b * source.b + source.d * source.d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class ToScaleY extends ToProperty {
|
static public class ToScaleY extends ToProperty {
|
||||||
public void apply (TransformConstraintData data, Bone bone, float value, boolean local, boolean relative) {
|
public float mix (TransformConstraint constraint) {
|
||||||
|
return constraint.mixScaleY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void apply (TransformConstraintData data, Bone bone, float value, boolean local, boolean additive) {
|
||||||
if (local) {
|
if (local) {
|
||||||
if (relative)
|
if (additive)
|
||||||
bone.ascaleY *= 1 + ((value - 1) * data.mixScaleY);
|
bone.ascaleY *= 1 + ((value - 1) * data.mixScaleY);
|
||||||
else if (bone.ascaleY != 0) //
|
else if (bone.ascaleY != 0) //
|
||||||
bone.ascaleY = 1 + (value / bone.ascaleY - 1) * data.mixScaleY;
|
bone.ascaleY = 1 + (value / bone.ascaleY - 1) * data.mixScaleY;
|
||||||
} else {
|
} else {
|
||||||
float s;
|
float s;
|
||||||
if (relative)
|
if (additive)
|
||||||
s = 1 + (value - 1) * data.mixScaleY;
|
s = 1 + (value - 1) * data.mixScaleY;
|
||||||
else {
|
else {
|
||||||
s = (float)Math.sqrt(bone.b * bone.b + bone.d * bone.d);
|
s = (float)Math.sqrt(bone.b * bone.b + bone.d * bone.d);
|
||||||
@ -345,24 +345,24 @@ public class TransformConstraintData extends ConstraintData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public class FromShearY extends FromProperty {
|
static public class FromShearY extends FromProperty {
|
||||||
public float mix (TransformConstraint constraint) {
|
|
||||||
return constraint.mixShearY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float value (TransformConstraintData data, Bone source, boolean local) {
|
public float value (TransformConstraintData data, Bone source, boolean local) {
|
||||||
return local ? source.ashearY : (atan2(source.d, source.b) - atan2(source.c, source.a)) * radDeg - 90;
|
return local ? source.ashearY : (atan2(source.d, source.b) - atan2(source.c, source.a)) * radDeg - 90;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class ToShearY extends ToProperty {
|
static public class ToShearY extends ToProperty {
|
||||||
public void apply (TransformConstraintData data, Bone bone, float value, boolean local, boolean relative) {
|
public float mix (TransformConstraint constraint) {
|
||||||
|
return constraint.mixShearY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void apply (TransformConstraintData data, Bone bone, float value, boolean local, boolean additive) {
|
||||||
if (local) {
|
if (local) {
|
||||||
if (!relative) value -= bone.ashearY;
|
if (!additive) value -= bone.ashearY;
|
||||||
bone.ashearY += value * data.mixShearY;
|
bone.ashearY += value * data.mixShearY;
|
||||||
} else {
|
} else {
|
||||||
float b = bone.b, d = bone.d, by = atan2(d, b);
|
float b = bone.b, d = bone.d, by = atan2(d, b);
|
||||||
value = (value + 90) * degRad;
|
value = (value + 90) * degRad;
|
||||||
if (relative)
|
if (additive)
|
||||||
value -= PI / 2;
|
value -= PI / 2;
|
||||||
else {
|
else {
|
||||||
value -= by - atan2(bone.c, bone.a);
|
value -= by - atan2(bone.c, bone.a);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user