mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
[libgdx] Load physics constraints from JSON.
This commit is contained in:
parent
3541d005a7
commit
c30e5828d1
@ -154,7 +154,6 @@ public class PhysicsConstraint implements Updatable {
|
||||
xVelocity *= d;
|
||||
}
|
||||
if (y) {
|
||||
System.out.println(massInverse);
|
||||
yVelocity += (g - yOffset * e) * m;
|
||||
yOffset += yVelocity * step;
|
||||
yVelocity *= d;
|
||||
|
||||
@ -316,7 +316,7 @@ public class SkeletonBinary extends SkeletonLoader {
|
||||
data.rotate = (flags & 8) != 0;
|
||||
data.scaleX = (flags & 16) != 0;
|
||||
data.shearX = (flags & 32) != 0;
|
||||
data.step = input.readFloat();
|
||||
data.step = 1f / input.readByte();
|
||||
data.inertia = input.readFloat();
|
||||
data.strength = input.readFloat();
|
||||
data.damping = input.readFloat();
|
||||
|
||||
@ -56,6 +56,13 @@ import com.esotericsoftware.spine.Animation.IkConstraintTimeline;
|
||||
import com.esotericsoftware.spine.Animation.PathConstraintMixTimeline;
|
||||
import com.esotericsoftware.spine.Animation.PathConstraintPositionTimeline;
|
||||
import com.esotericsoftware.spine.Animation.PathConstraintSpacingTimeline;
|
||||
import com.esotericsoftware.spine.Animation.PhysicsConstraintDampingTimeline;
|
||||
import com.esotericsoftware.spine.Animation.PhysicsConstraintGravityTimeline;
|
||||
import com.esotericsoftware.spine.Animation.PhysicsConstraintInertiaTimeline;
|
||||
import com.esotericsoftware.spine.Animation.PhysicsConstraintMassTimeline;
|
||||
import com.esotericsoftware.spine.Animation.PhysicsConstraintMixTimeline;
|
||||
import com.esotericsoftware.spine.Animation.PhysicsConstraintStrengthTimeline;
|
||||
import com.esotericsoftware.spine.Animation.PhysicsConstraintWindTimeline;
|
||||
import com.esotericsoftware.spine.Animation.RGB2Timeline;
|
||||
import com.esotericsoftware.spine.Animation.RGBA2Timeline;
|
||||
import com.esotericsoftware.spine.Animation.RGBATimeline;
|
||||
@ -280,6 +287,33 @@ public class SkeletonJson extends SkeletonLoader {
|
||||
skeletonData.pathConstraints.add(data);
|
||||
}
|
||||
|
||||
// Physics constraints.
|
||||
for (JsonValue constraintMap = root.getChild("physics"); constraintMap != null; constraintMap = constraintMap.next) {
|
||||
PhysicsConstraintData data = new PhysicsConstraintData(constraintMap.getString("name"));
|
||||
data.order = constraintMap.getInt("order", 0);
|
||||
data.skinRequired = constraintMap.getBoolean("skin", false);
|
||||
|
||||
String boneName = constraintMap.getString("bone");
|
||||
data.bone = skeletonData.findBone(boneName);
|
||||
if (data.bone == null) throw new SerializationException("Physics bone not found: " + boneName);
|
||||
|
||||
data.x = constraintMap.getBoolean("x", false);
|
||||
data.y = constraintMap.getBoolean("y", false);
|
||||
data.rotate = constraintMap.getBoolean("rotate", false);
|
||||
data.scaleX = constraintMap.getBoolean("scaleX", false);
|
||||
data.shearX = constraintMap.getBoolean("shearX", false);
|
||||
data.step = 1f / constraintMap.getInt("fps", 60);
|
||||
data.inertia = constraintMap.getFloat("inertia", 1);
|
||||
data.strength = constraintMap.getFloat("strength", 100);
|
||||
data.damping = constraintMap.getFloat("damping", 1);
|
||||
data.massInverse = 1 / constraintMap.getFloat("mass", 1);
|
||||
data.wind = constraintMap.getFloat("wind", 0);
|
||||
data.gravity = constraintMap.getFloat("getFloat", 0);
|
||||
data.mix = constraintMap.getFloat("mix", 1);
|
||||
|
||||
skeletonData.physicsConstraints.add(data);
|
||||
}
|
||||
|
||||
// Skins.
|
||||
for (JsonValue skinMap = root.getChild("skins"); skinMap != null; skinMap = skinMap.next) {
|
||||
Skin skin = new Skin(skinMap.getString("name"));
|
||||
@ -881,7 +915,37 @@ public class SkeletonJson extends SkeletonLoader {
|
||||
}
|
||||
}
|
||||
|
||||
// BOZO - Physics timelines.
|
||||
// Physics constraint timelines.
|
||||
for (JsonValue constraintMap = map.getChild("physics"); constraintMap != null; constraintMap = constraintMap.next) {
|
||||
PhysicsConstraintData constraint = skeletonData.findPhysicsConstraint(constraintMap.name);
|
||||
if (constraint == null) throw new SerializationException("Physics constraint not found: " + constraintMap.name);
|
||||
int index = skeletonData.physicsConstraints.indexOf(constraint, true);
|
||||
for (JsonValue timelineMap = constraintMap.child; timelineMap != null; timelineMap = timelineMap.next) {
|
||||
JsonValue keyMap = timelineMap.child;
|
||||
if (keyMap == null) continue;
|
||||
|
||||
int frames = timelineMap.size;
|
||||
String timelineName = timelineMap.name;
|
||||
CurveTimeline1 timeline;
|
||||
if (timelineName.equals("inertia"))
|
||||
timeline = new PhysicsConstraintInertiaTimeline(frames, frames, index);
|
||||
else if (timelineName.equals("strength"))
|
||||
timeline = new PhysicsConstraintStrengthTimeline(frames, frames, index);
|
||||
else if (timelineName.equals("damping"))
|
||||
timeline = new PhysicsConstraintDampingTimeline(frames, frames, index);
|
||||
else if (timelineName.equals("mass"))
|
||||
timeline = new PhysicsConstraintMassTimeline(frames, frames, index);
|
||||
else if (timelineName.equals("wind"))
|
||||
timeline = new PhysicsConstraintWindTimeline(frames, frames, index);
|
||||
else if (timelineName.equals("gravity"))
|
||||
timeline = new PhysicsConstraintGravityTimeline(frames, frames, index);
|
||||
else if (timelineName.equals("mix")) //
|
||||
timeline = new PhysicsConstraintMixTimeline(frames, frames, index);
|
||||
else
|
||||
continue;
|
||||
timelines.add(readTimeline(keyMap, timeline, 0, 1));
|
||||
}
|
||||
}
|
||||
|
||||
// Attachment timelines.
|
||||
for (JsonValue attachmentsMap = map.getChild("attachments"); attachmentsMap != null; attachmentsMap = attachmentsMap.next) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user