mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-12 10:08:44 +08:00
Spring constraint -> physics constraint.
This commit is contained in:
parent
02a85972de
commit
0c269a07d6
@ -31,11 +31,11 @@ package com.esotericsoftware.spine;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
/** Stores the current pose for a spring constraint. A spring constraint applies physics to bones.
|
||||
/** Stores the current pose for a physics constraint. A physics constraint applies physics to bones.
|
||||
* <p>
|
||||
* See <a href="http://esotericsoftware.com/spine-spring-constraints">Spring constraints</a> in the Spine User Guide. */
|
||||
public class SpringConstraint implements Updatable {
|
||||
final SpringConstraintData data;
|
||||
* See <a href="http://esotericsoftware.com/spine-physics-constraints">Physics constraints</a> in the Spine User Guide. */
|
||||
public class PhysicsConstraint implements Updatable {
|
||||
final PhysicsConstraintData data;
|
||||
final Array<Bone> bones;
|
||||
// BOZO! - stiffness -> strength. stiffness, damping, rope, stretch -> move to spring.
|
||||
float mix, friction, gravity, wind, stiffness, damping;
|
||||
@ -43,7 +43,7 @@ public class SpringConstraint implements Updatable {
|
||||
|
||||
boolean active;
|
||||
|
||||
public SpringConstraint (SpringConstraintData data, Skeleton skeleton) {
|
||||
public PhysicsConstraint (PhysicsConstraintData 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;
|
||||
@ -62,7 +62,7 @@ public class SpringConstraint implements Updatable {
|
||||
}
|
||||
|
||||
/** Copy constructor. */
|
||||
public SpringConstraint (SpringConstraint constraint, Skeleton skeleton) {
|
||||
public PhysicsConstraint (PhysicsConstraint constraint, Skeleton skeleton) {
|
||||
if (constraint == null) throw new IllegalArgumentException("constraint cannot be null.");
|
||||
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
|
||||
data = constraint.data;
|
||||
@ -84,7 +84,7 @@ public class SpringConstraint implements Updatable {
|
||||
|
||||
}
|
||||
|
||||
/** The bones that will be modified by this spring constraint. */
|
||||
/** The bones that will be modified by this physics constraint. */
|
||||
public Array<Bone> getBones () {
|
||||
return bones;
|
||||
}
|
||||
@ -158,8 +158,8 @@ public class SpringConstraint implements Updatable {
|
||||
return active;
|
||||
}
|
||||
|
||||
/** The spring constraint's setup pose data. */
|
||||
public SpringConstraintData getData () {
|
||||
/** The physics constraint's setup pose data. */
|
||||
public PhysicsConstraintData getData () {
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -31,19 +31,19 @@ package com.esotericsoftware.spine;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
/** Stores the setup pose for a {@link SpringConstraint}.
|
||||
/** Stores the setup pose for a {@link PhysicsConstraint}.
|
||||
* <p>
|
||||
* See <a href="http://esotericsoftware.com/spine-spring-constraints">Spring constraints</a> in the Spine User Guide. */
|
||||
public class SpringConstraintData extends ConstraintData {
|
||||
* See <a href="http://esotericsoftware.com/spine-physics-constraints">Physics constraints</a> in the Spine User Guide. */
|
||||
public class PhysicsConstraintData extends ConstraintData {
|
||||
final Array<BoneData> bones = new Array();
|
||||
float mix, friction, gravity, wind, stiffness, damping;
|
||||
boolean rope, stretch;
|
||||
|
||||
public SpringConstraintData (String name) {
|
||||
public PhysicsConstraintData (String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/** The bones that are constrained by this spring constraint. */
|
||||
/** The bones that are constrained by this physics constraint. */
|
||||
public Array<BoneData> getBones () {
|
||||
return bones;
|
||||
}
|
||||
@ -55,7 +55,7 @@ public class Skeleton {
|
||||
final Array<IkConstraint> ikConstraints;
|
||||
final Array<TransformConstraint> transformConstraints;
|
||||
final Array<PathConstraint> pathConstraints;
|
||||
final Array<SpringConstraint> springConstraints;
|
||||
final Array<PhysicsConstraint> physicsConstraints;
|
||||
final Array<Updatable> updateCache = new Array();
|
||||
@Null Skin skin;
|
||||
final Color color;
|
||||
@ -101,9 +101,9 @@ public class Skeleton {
|
||||
for (PathConstraintData pathConstraintData : data.pathConstraints)
|
||||
pathConstraints.add(new PathConstraint(pathConstraintData, this));
|
||||
|
||||
springConstraints = new Array(data.springConstraints.size);
|
||||
for (SpringConstraintData springConstraintData : data.springConstraints)
|
||||
springConstraints.add(new SpringConstraint(springConstraintData, this));
|
||||
physicsConstraints = new Array(data.physicsConstraints.size);
|
||||
for (PhysicsConstraintData physicsConstraintData : data.physicsConstraints)
|
||||
physicsConstraints.add(new PhysicsConstraint(physicsConstraintData, this));
|
||||
|
||||
color = new Color(1, 1, 1, 1);
|
||||
|
||||
@ -150,9 +150,9 @@ public class Skeleton {
|
||||
for (PathConstraint pathConstraint : skeleton.pathConstraints)
|
||||
pathConstraints.add(new PathConstraint(pathConstraint, this));
|
||||
|
||||
springConstraints = new Array(skeleton.springConstraints.size);
|
||||
for (SpringConstraint springConstraint : skeleton.springConstraints)
|
||||
springConstraints.add(new SpringConstraint(springConstraint, this));
|
||||
physicsConstraints = new Array(skeleton.physicsConstraints.size);
|
||||
for (PhysicsConstraint physicsConstraint : skeleton.physicsConstraints)
|
||||
physicsConstraints.add(new PhysicsConstraint(physicsConstraint, this));
|
||||
|
||||
skin = skeleton.skin;
|
||||
color = new Color(skeleton.color);
|
||||
@ -188,10 +188,10 @@ public class Skeleton {
|
||||
}
|
||||
|
||||
int ikCount = ikConstraints.size, transformCount = transformConstraints.size, pathCount = pathConstraints.size,
|
||||
springCount = springConstraints.size;
|
||||
physicsCount = physicsConstraints.size;
|
||||
Object[] ikConstraints = this.ikConstraints.items, transformConstraints = this.transformConstraints.items,
|
||||
pathConstraints = this.pathConstraints.items, springConstraints = this.springConstraints.items;
|
||||
int constraintCount = ikCount + transformCount + pathCount + springCount;
|
||||
pathConstraints = this.pathConstraints.items, physicsConstraints = this.physicsConstraints.items;
|
||||
int constraintCount = ikCount + transformCount + pathCount + physicsCount;
|
||||
outer:
|
||||
for (int i = 0; i < constraintCount; i++) {
|
||||
for (int ii = 0; ii < ikCount; ii++) {
|
||||
@ -215,10 +215,10 @@ public class Skeleton {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
for (int ii = 0; ii < springCount; ii++) {
|
||||
SpringConstraint constraint = (SpringConstraint)springConstraints[ii];
|
||||
for (int ii = 0; ii < physicsCount; ii++) {
|
||||
PhysicsConstraint constraint = (PhysicsConstraint)physicsConstraints[ii];
|
||||
if (constraint.data.order == i) {
|
||||
sortSpringConstraint(constraint);
|
||||
sortPhysicsConstraint(constraint);
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
@ -333,7 +333,7 @@ public class Skeleton {
|
||||
}
|
||||
}
|
||||
|
||||
private void sortSpringConstraint (SpringConstraint constraint) {
|
||||
private void sortPhysicsConstraint (PhysicsConstraint constraint) {
|
||||
constraint.active = !constraint.data.skinRequired || (skin != null && skin.constraints.contains(constraint.data, true));
|
||||
if (!constraint.active) return;
|
||||
|
||||
@ -467,10 +467,10 @@ public class Skeleton {
|
||||
constraint.mixY = data.mixY;
|
||||
}
|
||||
|
||||
Object[] springConstraints = this.springConstraints.items;
|
||||
for (int i = 0, n = this.springConstraints.size; i < n; i++) {
|
||||
SpringConstraint constraint = (SpringConstraint)springConstraints[i];
|
||||
SpringConstraintData data = constraint.data;
|
||||
Object[] physicsConstraints = this.physicsConstraints.items;
|
||||
for (int i = 0, n = this.physicsConstraints.size; i < n; i++) {
|
||||
PhysicsConstraint constraint = (PhysicsConstraint)physicsConstraints[i];
|
||||
PhysicsConstraintData data = constraint.data;
|
||||
constraint.mix = data.mix;
|
||||
constraint.friction = data.friction;
|
||||
constraint.gravity = data.gravity;
|
||||
@ -686,18 +686,18 @@ public class Skeleton {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** The skeleton's spring constraints. */
|
||||
public Array<SpringConstraint> getSpringConstraints () {
|
||||
return springConstraints;
|
||||
/** The skeleton's physics constraints. */
|
||||
public Array<PhysicsConstraint> getPhysicsConstraints () {
|
||||
return physicsConstraints;
|
||||
}
|
||||
|
||||
/** Finds a spring constraint by comparing each spring constraint's name. It is more efficient to cache the results of this
|
||||
/** Finds a physics constraint by comparing each physics constraint's name. It is more efficient to cache the results of this
|
||||
* method than to call it repeatedly. */
|
||||
public @Null SpringConstraint findSpringConstraint (String constraintName) {
|
||||
public @Null PhysicsConstraint findPhysicsConstraint (String constraintName) {
|
||||
if (constraintName == null) throw new IllegalArgumentException("constraintName cannot be null.");
|
||||
Object[] springConstraints = this.springConstraints.items;
|
||||
for (int i = 0, n = this.springConstraints.size; i < n; i++) {
|
||||
SpringConstraint constraint = (SpringConstraint)springConstraints[i];
|
||||
Object[] physicsConstraints = this.physicsConstraints.items;
|
||||
for (int i = 0, n = this.physicsConstraints.size; i < n; i++) {
|
||||
PhysicsConstraint constraint = (PhysicsConstraint)physicsConstraints[i];
|
||||
if (constraint.data.name.equals(constraintName)) return constraint;
|
||||
}
|
||||
return null;
|
||||
|
||||
@ -47,7 +47,7 @@ public class SkeletonData {
|
||||
final Array<IkConstraintData> ikConstraints = new Array();
|
||||
final Array<TransformConstraintData> transformConstraints = new Array();
|
||||
final Array<PathConstraintData> pathConstraints = new Array();
|
||||
final Array<SpringConstraintData> springConstraints = new Array();
|
||||
final Array<PhysicsConstraintData> physicsConstraints = new Array();
|
||||
float x, y, width, height;
|
||||
@Null String version, hash;
|
||||
|
||||
@ -216,20 +216,20 @@ public class SkeletonData {
|
||||
return null;
|
||||
}
|
||||
|
||||
// --- Spring constraints
|
||||
// --- Physics constraints
|
||||
|
||||
/** The skeleton's spring constraints. */
|
||||
public Array<SpringConstraintData> getSpringConstraints () {
|
||||
return springConstraints;
|
||||
/** The skeleton's physics constraints. */
|
||||
public Array<PhysicsConstraintData> getPhysicsConstraints () {
|
||||
return physicsConstraints;
|
||||
}
|
||||
|
||||
/** Finds a spring constraint by comparing each spring constraint's name. It is more efficient to cache the results of this
|
||||
/** Finds a physics constraint by comparing each physics constraint's name. It is more efficient to cache the results of this
|
||||
* method than to call it multiple times. */
|
||||
public @Null SpringConstraintData findSpringConstraint (String constraintName) {
|
||||
public @Null PhysicsConstraintData findPhysicsConstraint (String constraintName) {
|
||||
if (constraintName == null) throw new IllegalArgumentException("constraintName cannot be null.");
|
||||
Object[] springConstraints = this.springConstraints.items;
|
||||
for (int i = 0, n = this.springConstraints.size; i < n; i++) {
|
||||
SpringConstraintData constraint = (SpringConstraintData)springConstraints[i];
|
||||
Object[] physicsConstraints = this.physicsConstraints.items;
|
||||
for (int i = 0, n = this.physicsConstraints.size; i < n; i++) {
|
||||
PhysicsConstraintData constraint = (PhysicsConstraintData)physicsConstraints[i];
|
||||
if (constraint.name.equals(constraintName)) return constraint;
|
||||
}
|
||||
return null;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user