Fixed constraint copy constructors references the wrong bones.

ref #2511
This commit is contained in:
Nathan Sweet 2024-04-29 12:23:22 -04:00
parent c65f73e873
commit cb4873702d
5 changed files with 32 additions and 35 deletions

View File

@ -54,25 +54,24 @@ public class IkConstraint implements Updatable {
if (data == null) throw new IllegalArgumentException("data cannot be null."); if (data == null) throw new IllegalArgumentException("data cannot be null.");
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null."); if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
this.data = data; this.data = data;
mix = data.mix;
softness = data.softness;
bendDirection = data.bendDirection;
compress = data.compress;
stretch = data.stretch;
bones = new Array(data.bones.size); bones = new Array(data.bones.size);
for (BoneData boneData : data.bones) for (BoneData boneData : data.bones)
bones.add(skeleton.bones.get(boneData.index)); bones.add(skeleton.bones.get(boneData.index));
target = skeleton.bones.get(data.target.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. */ /** Copy constructor. */
public IkConstraint (IkConstraint constraint) { public IkConstraint (IkConstraint constraint, Skeleton skeleton) {
if (constraint == null) throw new IllegalArgumentException("constraint cannot be null."); this(constraint.data, skeleton);
data = constraint.data;
bones = new Array(constraint.bones);
target = constraint.target;
mix = constraint.mix; mix = constraint.mix;
softness = constraint.softness; softness = constraint.softness;
bendDirection = constraint.bendDirection; bendDirection = constraint.bendDirection;

View File

@ -72,6 +72,7 @@ public class PathConstraint implements Updatable {
bones.add(skeleton.bones.get(boneData.index)); bones.add(skeleton.bones.get(boneData.index));
target = skeleton.slots.get(data.target.index); target = skeleton.slots.get(data.target.index);
position = data.position; position = data.position;
spacing = data.spacing; spacing = data.spacing;
mixRotate = data.mixRotate; mixRotate = data.mixRotate;
@ -80,11 +81,9 @@ public class PathConstraint implements Updatable {
} }
/** Copy constructor. */ /** Copy constructor. */
public PathConstraint (PathConstraint constraint) { public PathConstraint (PathConstraint constraint, Skeleton skeleton) {
if (constraint == null) throw new IllegalArgumentException("constraint cannot be null."); this(constraint.data, skeleton);
data = constraint.data;
bones = new Array(constraint.bones);
target = constraint.target;
position = constraint.position; position = constraint.position;
spacing = constraint.spacing; spacing = constraint.spacing;
mixRotate = constraint.mixRotate; mixRotate = constraint.mixRotate;

View File

@ -58,7 +58,9 @@ public class PhysicsConstraint implements Updatable {
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null."); if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
this.data = data; this.data = data;
this.skeleton = skeleton; this.skeleton = skeleton;
bone = skeleton.bones.get(data.bone.index); bone = skeleton.bones.get(data.bone.index);
inertia = data.inertia; inertia = data.inertia;
strength = data.strength; strength = data.strength;
damping = data.damping; damping = data.damping;
@ -69,11 +71,9 @@ public class PhysicsConstraint implements Updatable {
} }
/** Copy constructor. */ /** Copy constructor. */
public PhysicsConstraint (PhysicsConstraint constraint) { public PhysicsConstraint (PhysicsConstraint constraint, Skeleton skeleton) {
if (constraint == null) throw new IllegalArgumentException("constraint cannot be null."); this(constraint.data, skeleton);
data = constraint.data;
skeleton = constraint.skeleton;
bone = constraint.bone;
inertia = constraint.inertia; inertia = constraint.inertia;
strength = constraint.strength; strength = constraint.strength;
damping = constraint.damping; damping = constraint.damping;

View File

@ -139,19 +139,19 @@ public class Skeleton {
ikConstraints = new Array(skeleton.ikConstraints.size); ikConstraints = new Array(skeleton.ikConstraints.size);
for (IkConstraint ikConstraint : skeleton.ikConstraints) for (IkConstraint ikConstraint : skeleton.ikConstraints)
ikConstraints.add(new IkConstraint(ikConstraint)); ikConstraints.add(new IkConstraint(ikConstraint, skeleton));
transformConstraints = new Array(skeleton.transformConstraints.size); transformConstraints = new Array(skeleton.transformConstraints.size);
for (TransformConstraint transformConstraint : skeleton.transformConstraints) for (TransformConstraint transformConstraint : skeleton.transformConstraints)
transformConstraints.add(new TransformConstraint(transformConstraint)); transformConstraints.add(new TransformConstraint(transformConstraint, skeleton));
pathConstraints = new Array(skeleton.pathConstraints.size); pathConstraints = new Array(skeleton.pathConstraints.size);
for (PathConstraint pathConstraint : skeleton.pathConstraints) for (PathConstraint pathConstraint : skeleton.pathConstraints)
pathConstraints.add(new PathConstraint(pathConstraint)); pathConstraints.add(new PathConstraint(pathConstraint, skeleton));
physicsConstraints = new Array(skeleton.physicsConstraints.size); physicsConstraints = new Array(skeleton.physicsConstraints.size);
for (PhysicsConstraint physicsConstraint : skeleton.physicsConstraints) for (PhysicsConstraint physicsConstraint : skeleton.physicsConstraints)
physicsConstraints.add(new PhysicsConstraint(physicsConstraint)); physicsConstraints.add(new PhysicsConstraint(physicsConstraint, skeleton));
skin = skeleton.skin; skin = skeleton.skin;
color = new Color(skeleton.color); color = new Color(skeleton.color);

View File

@ -53,26 +53,25 @@ public class TransformConstraint implements Updatable {
if (data == null) throw new IllegalArgumentException("data cannot be null."); if (data == null) throw new IllegalArgumentException("data cannot be null.");
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null."); if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
this.data = data; 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); bones = new Array(data.bones.size);
for (BoneData boneData : data.bones) for (BoneData boneData : data.bones)
bones.add(skeleton.bones.get(boneData.index)); bones.add(skeleton.bones.get(boneData.index));
target = skeleton.bones.get(data.target.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. */ /** Copy constructor. */
public TransformConstraint (TransformConstraint constraint) { public TransformConstraint (TransformConstraint constraint, Skeleton skeleton) {
if (constraint == null) throw new IllegalArgumentException("constraint cannot be null."); this(constraint.data, skeleton);
data = constraint.data;
bones = new Array(constraint.bones);
target = constraint.target;
mixRotate = constraint.mixRotate; mixRotate = constraint.mixRotate;
mixX = constraint.mixX; mixX = constraint.mixX;
mixY = constraint.mixY; mixY = constraint.mixY;