SkinnedMeshAttachment renamed to WeightedMeshAttachment.

This commit is contained in:
NathanSweet 2016-02-14 22:48:38 +01:00
parent 5835337bed
commit bb187daa10
15 changed files with 49 additions and 43 deletions

View File

@ -39,11 +39,11 @@ import com.esotericsoftware.spine.attachments.AttachmentLoader;
import com.esotericsoftware.spine.attachments.BoundingBoxAttachment;
import com.esotericsoftware.spine.attachments.MeshAttachment;
import com.esotericsoftware.spine.attachments.RegionAttachment;
import com.esotericsoftware.spine.attachments.SkinnedMeshAttachment;
import com.esotericsoftware.spine.attachments.WeightedMeshAttachment;
public class AnimationStateTest {
final SkeletonJson json = new SkeletonJson(new AttachmentLoader() {
public SkinnedMeshAttachment newSkinnedMeshAttachment (Skin skin, String name, String path) {
public WeightedMeshAttachment newWeightedMeshAttachment (Skin skin, String name, String path) {
return null;
}

View File

@ -36,13 +36,13 @@ import com.esotericsoftware.spine.attachments.AttachmentLoader;
import com.esotericsoftware.spine.attachments.BoundingBoxAttachment;
import com.esotericsoftware.spine.attachments.MeshAttachment;
import com.esotericsoftware.spine.attachments.RegionAttachment;
import com.esotericsoftware.spine.attachments.SkinnedMeshAttachment;
import com.esotericsoftware.spine.attachments.WeightedMeshAttachment;
public class BonePlotting {
static public void main (String[] args) throws Exception {
// This example shows how to load skeleton data and plot a bone transform for each animation.
SkeletonJson json = new SkeletonJson(new AttachmentLoader() {
public SkinnedMeshAttachment newSkinnedMeshAttachment (Skin skin, String name, String path) {
public WeightedMeshAttachment newWeightedMeshAttachment (Skin skin, String name, String path) {
return null;
}

View File

@ -300,12 +300,20 @@ public class Bone implements Updatable {
return worldY;
}
public float getWorldSignX () {
return worldSignX;
}
public float getWorldSignY () {
return worldSignY;
}
public float getWorldRotationX () {
return (float)Math.atan2(c, a) * MathUtils.radDeg;
return MathUtils.atan2(c, a) * MathUtils.radDeg;
}
public float getWorldRotationY () {
return (float)Math.atan2(d, b) * MathUtils.radDeg;
return MathUtils.atan2(d, b) * MathUtils.radDeg;
}
public float getWorldScaleX () {
@ -316,14 +324,6 @@ public class Bone implements Updatable {
return (float)Math.sqrt(c * c + d * d) * worldSignY;
}
public float getWorldSignX () {
return worldSignX;
}
public float getWorldSignY () {
return worldSignY;
}
public Matrix3 getWorldTransform (Matrix3 worldTransform) {
if (worldTransform == null) throw new IllegalArgumentException("worldTransform cannot be null.");
float[] val = worldTransform.val;

View File

@ -116,7 +116,7 @@ public class IkConstraint implements Updatable {
}
public String toString () {
return data.name + " CONSTRAINT";
return data.name;
}
/** Adjusts the bone rotation so the tip is as close to the target position as possible. The target is specified in the world
@ -134,7 +134,7 @@ public class IkConstraint implements Updatable {
/** Adjusts the parent and child bone rotations so the tip of the child is as close to the target position as possible. The
* target is specified in the world coordinate system.
* @param child Any descendant bone of the parent. */
* @param child A direct descendant of the parent bone. */
static public void apply (Bone parent, Bone child, float targetX, float targetY, int bendDir, float alpha) {
if (alpha == 0) return;
float px = parent.x, py = parent.y, psx = parent.scaleX, psy = parent.scaleY, csx = child.scaleX, cy = child.y;

View File

@ -37,7 +37,7 @@ import com.badlogic.gdx.utils.Array;
import com.esotericsoftware.spine.attachments.Attachment;
import com.esotericsoftware.spine.attachments.MeshAttachment;
import com.esotericsoftware.spine.attachments.RegionAttachment;
import com.esotericsoftware.spine.attachments.SkinnedMeshAttachment;
import com.esotericsoftware.spine.attachments.WeightedMeshAttachment;
public class Skeleton {
final SkeletonData data;
@ -380,8 +380,8 @@ public class Skeleton {
} else if (attachment instanceof MeshAttachment) {
vertices = ((MeshAttachment)attachment).updateWorldVertices(slot, true);
} else if (attachment instanceof SkinnedMeshAttachment) {
vertices = ((SkinnedMeshAttachment)attachment).updateWorldVertices(slot, true);
} else if (attachment instanceof WeightedMeshAttachment) {
vertices = ((WeightedMeshAttachment)attachment).updateWorldVertices(slot, true);
}
if (vertices != null) {
for (int ii = 0, nn = vertices.length; ii < nn; ii += 5) {

View File

@ -59,7 +59,7 @@ import com.esotericsoftware.spine.attachments.AttachmentType;
import com.esotericsoftware.spine.attachments.BoundingBoxAttachment;
import com.esotericsoftware.spine.attachments.MeshAttachment;
import com.esotericsoftware.spine.attachments.RegionAttachment;
import com.esotericsoftware.spine.attachments.SkinnedMeshAttachment;
import com.esotericsoftware.spine.attachments.WeightedMeshAttachment;
public class SkeletonBinary {
static public final int TIMELINE_SCALE = 0;
@ -280,10 +280,10 @@ public class SkeletonBinary {
}
return mesh;
}
case skinnedmesh: {
case weightedmesh: {
String path = input.readString();
if (path == null) path = name;
SkinnedMeshAttachment mesh = attachmentLoader.newSkinnedMeshAttachment(skin, name, path);
WeightedMeshAttachment mesh = attachmentLoader.newWeightedMeshAttachment(skin, name, path);
if (mesh == null) return null;
mesh.setPath(path);
float[] uvs = readFloatArray(input, 1);
@ -462,7 +462,7 @@ public class SkeletonBinary {
if (attachment instanceof MeshAttachment)
vertexCount = ((MeshAttachment)attachment).getVertices().length;
else
vertexCount = ((SkinnedMeshAttachment)attachment).getWeights().length / 3 * 2;
vertexCount = ((WeightedMeshAttachment)attachment).getWeights().length / 3 * 2;
int end = input.readInt(true);
if (end == 0) {

View File

@ -58,7 +58,7 @@ import com.esotericsoftware.spine.attachments.AttachmentType;
import com.esotericsoftware.spine.attachments.BoundingBoxAttachment;
import com.esotericsoftware.spine.attachments.MeshAttachment;
import com.esotericsoftware.spine.attachments.RegionAttachment;
import com.esotericsoftware.spine.attachments.SkinnedMeshAttachment;
import com.esotericsoftware.spine.attachments.WeightedMeshAttachment;
public class SkeletonJson {
private final AttachmentLoader attachmentLoader;
@ -223,7 +223,9 @@ public class SkeletonJson {
name = map.getString("name", name);
String path = map.getString("path", name);
switch (AttachmentType.valueOf(map.getString("type", AttachmentType.region.name()))) {
String type = map.getString("type", AttachmentType.region.name());
if (type.equals("skinnedmesh")) type = "weightedmesh";
switch (AttachmentType.valueOf(type)) {
case region: {
RegionAttachment region = attachmentLoader.newRegionAttachment(skin, name, path);
if (region == null) return null;
@ -276,8 +278,8 @@ public class SkeletonJson {
mesh.setHeight(map.getFloat("height", 0) * scale);
return mesh;
}
case skinnedmesh: {
SkinnedMeshAttachment mesh = attachmentLoader.newSkinnedMeshAttachment(skin, name, path);
case weightedmesh: {
WeightedMeshAttachment mesh = attachmentLoader.newWeightedMeshAttachment(skin, name, path);
if (mesh == null) return null;
mesh.setPath(path);
float[] uvs = map.require("uvs").asFloatArray();
@ -443,7 +445,7 @@ public class SkeletonJson {
if (attachment instanceof MeshAttachment)
vertexCount = ((MeshAttachment)attachment).getVertices().length;
else
vertexCount = ((SkinnedMeshAttachment)attachment).getWeights().length / 3 * 2;
vertexCount = ((WeightedMeshAttachment)attachment).getWeights().length / 3 * 2;
int frameIndex = 0;
for (JsonValue valueMap = meshMap.child; valueMap != null; valueMap = valueMap.next) {

View File

@ -38,7 +38,7 @@ import com.esotericsoftware.spine.attachments.Attachment;
import com.esotericsoftware.spine.attachments.MeshAttachment;
import com.esotericsoftware.spine.attachments.RegionAttachment;
import com.esotericsoftware.spine.attachments.SkeletonAttachment;
import com.esotericsoftware.spine.attachments.SkinnedMeshAttachment;
import com.esotericsoftware.spine.attachments.WeightedMeshAttachment;
public class SkeletonMeshRenderer extends SkeletonRenderer<PolygonSpriteBatch> {
static private final short[] quadTriangles = {0, 1, 2, 2, 3, 0};
@ -67,8 +67,8 @@ public class SkeletonMeshRenderer extends SkeletonRenderer<PolygonSpriteBatch> {
triangles = mesh.getTriangles();
texture = mesh.getRegion().getTexture();
} else if (attachment instanceof SkinnedMeshAttachment) {
SkinnedMeshAttachment mesh = (SkinnedMeshAttachment)attachment;
} else if (attachment instanceof WeightedMeshAttachment) {
WeightedMeshAttachment mesh = (WeightedMeshAttachment)attachment;
vertices = mesh.updateWorldVertices(slot, premultipliedAlpha);
triangles = mesh.getTriangles();
texture = mesh.getRegion().getTexture();

View File

@ -37,7 +37,7 @@ import com.esotericsoftware.spine.attachments.Attachment;
import com.esotericsoftware.spine.attachments.MeshAttachment;
import com.esotericsoftware.spine.attachments.RegionAttachment;
import com.esotericsoftware.spine.attachments.SkeletonAttachment;
import com.esotericsoftware.spine.attachments.SkinnedMeshAttachment;
import com.esotericsoftware.spine.attachments.WeightedMeshAttachment;
public class SkeletonRenderer<T extends Batch> {
boolean premultipliedAlpha;
@ -64,7 +64,7 @@ public class SkeletonRenderer<T extends Batch> {
}
batch.draw(regionAttachment.getRegion().getTexture(), vertices, 0, 20);
} else if (attachment instanceof MeshAttachment || attachment instanceof SkinnedMeshAttachment) {
} else if (attachment instanceof MeshAttachment || attachment instanceof WeightedMeshAttachment) {
throw new RuntimeException("SkeletonMeshRenderer is required to render meshes.");
} else if (attachment instanceof SkeletonAttachment) {

View File

@ -34,7 +34,7 @@ package com.esotericsoftware.spine;
import com.esotericsoftware.spine.attachments.Attachment;
import com.esotericsoftware.spine.attachments.MeshAttachment;
import com.esotericsoftware.spine.attachments.RegionAttachment;
import com.esotericsoftware.spine.attachments.SkinnedMeshAttachment;
import com.esotericsoftware.spine.attachments.WeightedMeshAttachment;
import static com.badlogic.gdx.graphics.g2d.Batch.*;
@ -128,8 +128,8 @@ public class SkeletonRendererDebug {
vertices = mesh.getWorldVertices();
triangles = mesh.getTriangles();
hullLength = mesh.getHullLength();
} else if (attachment instanceof SkinnedMeshAttachment) {
SkinnedMeshAttachment mesh = (SkinnedMeshAttachment)attachment;
} else if (attachment instanceof WeightedMeshAttachment) {
WeightedMeshAttachment mesh = (WeightedMeshAttachment)attachment;
mesh.updateWorldVertices(slot, false);
vertices = mesh.getWorldVertices();
triangles = mesh.getTriangles();

View File

@ -12,6 +12,8 @@ public class TransformConstraint implements Updatable {
public TransformConstraint (TransformConstraintData data, Skeleton skeleton) {
this.data = data;
translateMix = data.translateMix;
x = data.x;
y = data.y;
if (skeleton != null) {
bone = skeleton.findBone(data.bone.name);
@ -22,9 +24,11 @@ public class TransformConstraint implements Updatable {
/** Copy constructor. */
public TransformConstraint (TransformConstraint constraint, Skeleton skeleton) {
data = constraint.data;
translateMix = data.translateMix;
bone = skeleton.bones.get(constraint.bone.skeleton.bones.indexOf(constraint.bone, true));
target = skeleton.bones.get(constraint.target.skeleton.bones.indexOf(constraint.target, true));
translateMix = constraint.translateMix;
x = constraint.x;
y = constraint.y;
}
public void apply () {

View File

@ -61,11 +61,11 @@ public class AtlasAttachmentLoader implements AttachmentLoader {
return attachment;
}
public SkinnedMeshAttachment newSkinnedMeshAttachment (Skin skin, String name, String path) {
public WeightedMeshAttachment newWeightedMeshAttachment (Skin skin, String name, String path) {
AtlasRegion region = atlas.findRegion(path);
if (region == null)
throw new RuntimeException("Region not found in atlas: " + path + " (skinned mesh attachment: " + name + ")");
SkinnedMeshAttachment attachment = new SkinnedMeshAttachment(name);
WeightedMeshAttachment attachment = new WeightedMeshAttachment(name);
attachment.setRegion(region);
return attachment;
}

View File

@ -41,7 +41,7 @@ public interface AttachmentLoader {
public MeshAttachment newMeshAttachment (Skin skin, String name, String path);
/** @return May be null to not load any attachment. */
public SkinnedMeshAttachment newSkinnedMeshAttachment (Skin skin, String name, String path);
public WeightedMeshAttachment newWeightedMeshAttachment (Skin skin, String name, String path);
/** @return May be null to not load any attachment. */
public BoundingBoxAttachment newBoundingBoxAttachment (Skin skin, String name);

View File

@ -32,7 +32,7 @@
package com.esotericsoftware.spine.attachments;
public enum AttachmentType {
region, boundingbox, mesh, skinnedmesh;
region, boundingbox, mesh, weightedmesh;
static public AttachmentType[] values = values();
}

View File

@ -42,7 +42,7 @@ import com.badlogic.gdx.utils.FloatArray;
import com.badlogic.gdx.utils.NumberUtils;
/** Attachment that displays a texture region. */
public class SkinnedMeshAttachment extends Attachment {
public class WeightedMeshAttachment extends Attachment {
private TextureRegion region;
private String path;
private int[] bones;
@ -56,7 +56,7 @@ public class SkinnedMeshAttachment extends Attachment {
private int[] edges;
private float width, height;
public SkinnedMeshAttachment (String name) {
public WeightedMeshAttachment (String name) {
super(name);
}