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