Skip to content

Commit

Permalink
Fixed constraint copy constructors references the wrong bones.
Browse files Browse the repository at this point in the history
ref #2511
  • Loading branch information
NathanSweet committed Apr 29, 2024
1 parent c65f73e commit cb48737
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 35 deletions.
Expand Up @@ -54,25 +54,24 @@ public IkConstraint (IkConstraintData data, Skeleton skeleton) {
if (data == null) throw new IllegalArgumentException("data cannot be null.");
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
this.data = data;
mix = data.mix;
softness = data.softness;
bendDirection = data.bendDirection;
compress = data.compress;
stretch = data.stretch;

bones = new Array(data.bones.size);
for (BoneData boneData : data.bones)
bones.add(skeleton.bones.get(boneData.index));

target = skeleton.bones.get(data.target.index);

mix = data.mix;
softness = data.softness;
bendDirection = data.bendDirection;
compress = data.compress;
stretch = data.stretch;
}

/** Copy constructor. */
public IkConstraint (IkConstraint constraint) {
if (constraint == null) throw new IllegalArgumentException("constraint cannot be null.");
data = constraint.data;
bones = new Array(constraint.bones);
target = constraint.target;
public IkConstraint (IkConstraint constraint, Skeleton skeleton) {
this(constraint.data, skeleton);

mix = constraint.mix;
softness = constraint.softness;
bendDirection = constraint.bendDirection;
Expand Down
Expand Up @@ -72,6 +72,7 @@ public PathConstraint (PathConstraintData data, Skeleton skeleton) {
bones.add(skeleton.bones.get(boneData.index));

target = skeleton.slots.get(data.target.index);

position = data.position;
spacing = data.spacing;
mixRotate = data.mixRotate;
Expand All @@ -80,11 +81,9 @@ public PathConstraint (PathConstraintData data, Skeleton skeleton) {
}

/** Copy constructor. */
public PathConstraint (PathConstraint constraint) {
if (constraint == null) throw new IllegalArgumentException("constraint cannot be null.");
data = constraint.data;
bones = new Array(constraint.bones);
target = constraint.target;
public PathConstraint (PathConstraint constraint, Skeleton skeleton) {
this(constraint.data, skeleton);

position = constraint.position;
spacing = constraint.spacing;
mixRotate = constraint.mixRotate;
Expand Down
Expand Up @@ -58,7 +58,9 @@ public PhysicsConstraint (PhysicsConstraintData data, Skeleton skeleton) {
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
this.data = data;
this.skeleton = skeleton;

bone = skeleton.bones.get(data.bone.index);

inertia = data.inertia;
strength = data.strength;
damping = data.damping;
Expand All @@ -69,11 +71,9 @@ public PhysicsConstraint (PhysicsConstraintData data, Skeleton skeleton) {
}

/** Copy constructor. */
public PhysicsConstraint (PhysicsConstraint constraint) {
if (constraint == null) throw new IllegalArgumentException("constraint cannot be null.");
data = constraint.data;
skeleton = constraint.skeleton;
bone = constraint.bone;
public PhysicsConstraint (PhysicsConstraint constraint, Skeleton skeleton) {
this(constraint.data, skeleton);

inertia = constraint.inertia;
strength = constraint.strength;
damping = constraint.damping;
Expand Down
Expand Up @@ -139,19 +139,19 @@ public Skeleton (Skeleton skeleton) {

ikConstraints = new Array(skeleton.ikConstraints.size);
for (IkConstraint ikConstraint : skeleton.ikConstraints)
ikConstraints.add(new IkConstraint(ikConstraint));
ikConstraints.add(new IkConstraint(ikConstraint, skeleton));

transformConstraints = new Array(skeleton.transformConstraints.size);
for (TransformConstraint transformConstraint : skeleton.transformConstraints)
transformConstraints.add(new TransformConstraint(transformConstraint));
transformConstraints.add(new TransformConstraint(transformConstraint, skeleton));

pathConstraints = new Array(skeleton.pathConstraints.size);
for (PathConstraint pathConstraint : skeleton.pathConstraints)
pathConstraints.add(new PathConstraint(pathConstraint));
pathConstraints.add(new PathConstraint(pathConstraint, skeleton));

physicsConstraints = new Array(skeleton.physicsConstraints.size);
for (PhysicsConstraint physicsConstraint : skeleton.physicsConstraints)
physicsConstraints.add(new PhysicsConstraint(physicsConstraint));
physicsConstraints.add(new PhysicsConstraint(physicsConstraint, skeleton));

skin = skeleton.skin;
color = new Color(skeleton.color);
Expand Down
Expand Up @@ -53,26 +53,25 @@ public TransformConstraint (TransformConstraintData data, Skeleton skeleton) {
if (data == null) throw new IllegalArgumentException("data cannot be null.");
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
this.data = data;
mixRotate = data.mixRotate;
mixX = data.mixX;
mixY = data.mixY;
mixScaleX = data.mixScaleX;
mixScaleY = data.mixScaleY;
mixShearY = data.mixShearY;

bones = new Array(data.bones.size);
for (BoneData boneData : data.bones)
bones.add(skeleton.bones.get(boneData.index));

target = skeleton.bones.get(data.target.index);

mixRotate = data.mixRotate;
mixX = data.mixX;
mixY = data.mixY;
mixScaleX = data.mixScaleX;
mixScaleY = data.mixScaleY;
mixShearY = data.mixShearY;
}

/** Copy constructor. */
public TransformConstraint (TransformConstraint constraint) {
if (constraint == null) throw new IllegalArgumentException("constraint cannot be null.");
data = constraint.data;
bones = new Array(constraint.bones);
target = constraint.target;
public TransformConstraint (TransformConstraint constraint, Skeleton skeleton) {
this(constraint.data, skeleton);

mixRotate = constraint.mixRotate;
mixX = constraint.mixX;
mixY = constraint.mixY;
Expand Down

0 comments on commit cb48737

Please sign in to comment.