mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-05 02:06:53 +08:00
[libgdx] Physics debug rendering for Skeleton Viewer.
This commit is contained in:
parent
95487552dc
commit
23729f8eee
@ -38,6 +38,8 @@ import com.badlogic.gdx.math.Vector2;
|
|||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.FloatArray;
|
import com.badlogic.gdx.utils.FloatArray;
|
||||||
|
|
||||||
|
import com.esotericsoftware.spine.PhysicsConstraintData.Node;
|
||||||
|
import com.esotericsoftware.spine.PhysicsConstraintData.Spring;
|
||||||
import com.esotericsoftware.spine.attachments.Attachment;
|
import com.esotericsoftware.spine.attachments.Attachment;
|
||||||
import com.esotericsoftware.spine.attachments.BoundingBoxAttachment;
|
import com.esotericsoftware.spine.attachments.BoundingBoxAttachment;
|
||||||
import com.esotericsoftware.spine.attachments.ClippingAttachment;
|
import com.esotericsoftware.spine.attachments.ClippingAttachment;
|
||||||
@ -55,7 +57,7 @@ public class SkeletonRendererDebug {
|
|||||||
|
|
||||||
private final ShapeRenderer shapes;
|
private final ShapeRenderer shapes;
|
||||||
private boolean drawBones = true, drawRegionAttachments = true, drawBoundingBoxes = true, drawPoints = true;
|
private boolean drawBones = true, drawRegionAttachments = true, drawBoundingBoxes = true, drawPoints = true;
|
||||||
private boolean drawMeshHull = true, drawMeshTriangles = true, drawPaths = true, drawClipping = true;
|
private boolean drawMeshHull = true, drawMeshTriangles = true, drawPaths = true, drawClipping = true, drawPhysics = true;
|
||||||
private final SkeletonBounds bounds = new SkeletonBounds();
|
private final SkeletonBounds bounds = new SkeletonBounds();
|
||||||
private final FloatArray vertices = new FloatArray(32);
|
private final FloatArray vertices = new FloatArray(32);
|
||||||
private float scale = 1;
|
private float scale = 1;
|
||||||
@ -236,6 +238,22 @@ public class SkeletonRendererDebug {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (drawPhysics) {
|
||||||
|
Array<PhysicsConstraint> physicsConstraints = skeleton.physicsConstraints;
|
||||||
|
for (int i = 0, n = physicsConstraints.size; i < n; i++) {
|
||||||
|
PhysicsConstraint constraint = physicsConstraints.get(i);
|
||||||
|
if (constraint.mix <= 0) continue;
|
||||||
|
for (Spring spring : constraint.springs) {
|
||||||
|
shapes.setColor(Color.GOLDENROD);
|
||||||
|
shapes.line(spring.node1.x, spring.node1.y, spring.node2.x, spring.node2.y);
|
||||||
|
}
|
||||||
|
for (Node node : constraint.nodes) {
|
||||||
|
shapes.setColor(Color.GREEN);
|
||||||
|
shapes.circle(node.x, node.y, 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
shapes.end();
|
shapes.end();
|
||||||
shapes.begin(ShapeType.Filled);
|
shapes.begin(ShapeType.Filled);
|
||||||
|
|
||||||
@ -277,31 +295,35 @@ public class SkeletonRendererDebug {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setRegionAttachments (boolean regionAttachments) {
|
public void setRegionAttachments (boolean regionAttachments) {
|
||||||
this.drawRegionAttachments = regionAttachments;
|
drawRegionAttachments = regionAttachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBoundingBoxes (boolean boundingBoxes) {
|
public void setBoundingBoxes (boolean boundingBoxes) {
|
||||||
this.drawBoundingBoxes = boundingBoxes;
|
drawBoundingBoxes = boundingBoxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMeshHull (boolean meshHull) {
|
public void setMeshHull (boolean meshHull) {
|
||||||
this.drawMeshHull = meshHull;
|
drawMeshHull = meshHull;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMeshTriangles (boolean meshTriangles) {
|
public void setMeshTriangles (boolean meshTriangles) {
|
||||||
this.drawMeshTriangles = meshTriangles;
|
drawMeshTriangles = meshTriangles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPaths (boolean paths) {
|
public void setPaths (boolean paths) {
|
||||||
this.drawPaths = paths;
|
drawPaths = paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPoints (boolean points) {
|
public void setPoints (boolean points) {
|
||||||
this.drawPoints = points;
|
drawPoints = points;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setClipping (boolean clipping) {
|
public void setClipping (boolean clipping) {
|
||||||
this.drawClipping = clipping;
|
drawClipping = clipping;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPhysics (boolean physics) {
|
||||||
|
drawPhysics = physics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPremultipliedAlpha (boolean premultipliedAlpha) {
|
public void setPremultipliedAlpha (boolean premultipliedAlpha) {
|
||||||
|
|||||||
@ -283,6 +283,7 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
debugRenderer.setPaths(ui.debugPathsCheckbox.isChecked());
|
debugRenderer.setPaths(ui.debugPathsCheckbox.isChecked());
|
||||||
debugRenderer.setPoints(ui.debugPointsCheckbox.isChecked());
|
debugRenderer.setPoints(ui.debugPointsCheckbox.isChecked());
|
||||||
debugRenderer.setClipping(ui.debugClippingCheckbox.isChecked());
|
debugRenderer.setClipping(ui.debugClippingCheckbox.isChecked());
|
||||||
|
debugRenderer.setClipping(ui.debugPhysicsCheckbox.isChecked());
|
||||||
debugRenderer.draw(skeleton);
|
debugRenderer.draw(skeleton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -112,6 +112,7 @@ class SkeletonViewerUI {
|
|||||||
CheckBox debugPathsCheckbox = new CheckBox("Paths", skin);
|
CheckBox debugPathsCheckbox = new CheckBox("Paths", skin);
|
||||||
CheckBox debugPointsCheckbox = new CheckBox("Points", skin);
|
CheckBox debugPointsCheckbox = new CheckBox("Points", skin);
|
||||||
CheckBox debugClippingCheckbox = new CheckBox("Clipping", skin);
|
CheckBox debugClippingCheckbox = new CheckBox("Clipping", skin);
|
||||||
|
CheckBox debugPhysicsCheckbox = new CheckBox("Physics", skin);
|
||||||
|
|
||||||
CheckBox pmaCheckbox = new CheckBox("Premultiplied", skin);
|
CheckBox pmaCheckbox = new CheckBox("Premultiplied", skin);
|
||||||
|
|
||||||
@ -257,7 +258,7 @@ class SkeletonViewerUI {
|
|||||||
root.add();
|
root.add();
|
||||||
root.add(table(debugPathsCheckbox, debugPointsCheckbox, debugClippingCheckbox)).row();
|
root.add(table(debugPathsCheckbox, debugPointsCheckbox, debugClippingCheckbox)).row();
|
||||||
root.add();
|
root.add();
|
||||||
root.add(table(debugMeshHullCheckbox, debugMeshTrianglesCheckbox)).row();
|
root.add(table(debugMeshHullCheckbox, debugMeshTrianglesCheckbox, debugPhysicsCheckbox)).row();
|
||||||
root.add("Atlas alpha:");
|
root.add("Atlas alpha:");
|
||||||
{
|
{
|
||||||
Table table = table();
|
Table table = table();
|
||||||
@ -626,6 +627,7 @@ class SkeletonViewerUI {
|
|||||||
debugPathsCheckbox.addListener(savePrefsListener);
|
debugPathsCheckbox.addListener(savePrefsListener);
|
||||||
debugPointsCheckbox.addListener(savePrefsListener);
|
debugPointsCheckbox.addListener(savePrefsListener);
|
||||||
debugClippingCheckbox.addListener(savePrefsListener);
|
debugClippingCheckbox.addListener(savePrefsListener);
|
||||||
|
debugPhysicsCheckbox.addListener(savePrefsListener);
|
||||||
pmaCheckbox.addListener(savePrefsListener);
|
pmaCheckbox.addListener(savePrefsListener);
|
||||||
linearCheckbox.addListener(savePrefsListener);
|
linearCheckbox.addListener(savePrefsListener);
|
||||||
bonesSetupPoseButton.addListener(savePrefsListener);
|
bonesSetupPoseButton.addListener(savePrefsListener);
|
||||||
@ -698,6 +700,7 @@ class SkeletonViewerUI {
|
|||||||
prefs.putBoolean("debugPaths", debugPathsCheckbox.isChecked());
|
prefs.putBoolean("debugPaths", debugPathsCheckbox.isChecked());
|
||||||
prefs.putBoolean("debugPoints", debugPointsCheckbox.isChecked());
|
prefs.putBoolean("debugPoints", debugPointsCheckbox.isChecked());
|
||||||
prefs.putBoolean("debugClipping", debugClippingCheckbox.isChecked());
|
prefs.putBoolean("debugClipping", debugClippingCheckbox.isChecked());
|
||||||
|
prefs.putBoolean("debugPhysics", debugPhysicsCheckbox.isChecked());
|
||||||
prefs.putBoolean("premultiplied", pmaCheckbox.isChecked());
|
prefs.putBoolean("premultiplied", pmaCheckbox.isChecked());
|
||||||
prefs.putBoolean("linear", linearCheckbox.isChecked());
|
prefs.putBoolean("linear", linearCheckbox.isChecked());
|
||||||
if (bonesSetupPoseButton.isChecked())
|
if (bonesSetupPoseButton.isChecked())
|
||||||
@ -740,6 +743,7 @@ class SkeletonViewerUI {
|
|||||||
debugPathsCheckbox.setChecked(prefs.getBoolean("debugPaths", true));
|
debugPathsCheckbox.setChecked(prefs.getBoolean("debugPaths", true));
|
||||||
debugPointsCheckbox.setChecked(prefs.getBoolean("debugPoints", true));
|
debugPointsCheckbox.setChecked(prefs.getBoolean("debugPoints", true));
|
||||||
debugClippingCheckbox.setChecked(prefs.getBoolean("debugClipping", true));
|
debugClippingCheckbox.setChecked(prefs.getBoolean("debugClipping", true));
|
||||||
|
debugPhysicsCheckbox.setChecked(prefs.getBoolean("debugPhysics", true));
|
||||||
pmaCheckbox.setChecked(prefs.getBoolean("premultiplied", true));
|
pmaCheckbox.setChecked(prefs.getBoolean("premultiplied", true));
|
||||||
linearCheckbox.setChecked(prefs.getBoolean("linear", true));
|
linearCheckbox.setChecked(prefs.getBoolean("linear", true));
|
||||||
String setupPose = prefs.getString("setupPose", "");
|
String setupPose = prefs.getString("setupPose", "");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user