mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
Organization.
This commit is contained in:
parent
99cb5cae09
commit
1671d6bd9f
@ -258,7 +258,7 @@ public class SkeletonBinary {
|
||||
weights.add(input.readFloat());
|
||||
}
|
||||
}
|
||||
mesh.setMesh(bones.toArray(), weights.toArray(), uvs, triangles);
|
||||
mesh.setMesh(bones.toArray(), weights.toArray(), triangles, uvs);
|
||||
|
||||
Color.rgba8888ToColor(mesh.getColor(), input.readInt());
|
||||
if (nonessential) {
|
||||
|
||||
@ -239,7 +239,7 @@ public class SkeletonJson {
|
||||
i += 4;
|
||||
}
|
||||
}
|
||||
mesh.setMesh(bones.toArray(), weights.toArray(), uvs, triangles);
|
||||
mesh.setMesh(bones.toArray(), weights.toArray(), triangles, uvs);
|
||||
|
||||
if (map.has("hull")) mesh.setHullLength(map.require("hull").asInt() * 2);
|
||||
if (map.has("edges")) mesh.setEdges(map.require("edges").asIntArray());
|
||||
|
||||
@ -43,7 +43,7 @@ import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
public class SkeletonRenderer {
|
||||
static private final short[] quadTriangle = {0, 1, 2, 2, 3, 0};
|
||||
static private final short[] quadTriangles = {0, 1, 2, 2, 3, 0};
|
||||
|
||||
private boolean premultipliedAlpha;
|
||||
|
||||
@ -65,7 +65,7 @@ public class SkeletonRenderer {
|
||||
RegionAttachment region = (RegionAttachment)attachment;
|
||||
region.updateWorldVertices(slot, premultipliedAlpha);
|
||||
vertices = region.getWorldVertices();
|
||||
triangles = quadTriangle;
|
||||
triangles = quadTriangles;
|
||||
texture = region.getRegion().getTexture();
|
||||
|
||||
if (slot.data.getAdditiveBlending() != additive) {
|
||||
|
||||
@ -50,9 +50,9 @@ public class MeshAttachment extends Attachment {
|
||||
private final Color color = new Color(1, 1, 1, 1);
|
||||
|
||||
// Nonessential.
|
||||
private int hullLength;
|
||||
private int[] edges;
|
||||
private float width, height;
|
||||
private int hullLength;
|
||||
|
||||
public MeshAttachment (String name) {
|
||||
super(name);
|
||||
@ -68,6 +68,36 @@ public class MeshAttachment extends Attachment {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void setMesh (float[] vertices, short[] triangles, float[] uvs) {
|
||||
this.vertices = vertices;
|
||||
this.triangles = triangles;
|
||||
|
||||
int worldVerticesLength = vertices.length / 2 * 5;
|
||||
if (worldVertices == null || worldVertices.length != worldVerticesLength) worldVertices = new float[worldVerticesLength];
|
||||
|
||||
float u, v, width, height;
|
||||
if (region == null) {
|
||||
u = v = 0;
|
||||
width = height = 1;
|
||||
} else {
|
||||
u = region.getU();
|
||||
v = region.getV();
|
||||
width = region.getU2() - u;
|
||||
height = region.getV2() - v;
|
||||
}
|
||||
if (region instanceof AtlasRegion && ((AtlasRegion)region).rotate) {
|
||||
for (int i = 0, w = 3, n = vertices.length; i < n; i += 2, w += 5) {
|
||||
worldVertices[w] = u + uvs[i + 1] * width;
|
||||
worldVertices[w + 1] = v + height - uvs[i] * height;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0, w = 3, n = vertices.length; i < n; i += 2, w += 5) {
|
||||
worldVertices[w] = u + uvs[i] * width;
|
||||
worldVertices[w + 1] = v + uvs[i + 1] * height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateWorldVertices (Slot slot, boolean premultipliedAlpha) {
|
||||
Skeleton skeleton = slot.getSkeleton();
|
||||
Color skeletonColor = skeleton.getColor();
|
||||
@ -152,34 +182,4 @@ public class MeshAttachment extends Attachment {
|
||||
public void setHeight (float height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public void setMesh (float[] vertices, short[] triangles, float[] uvs) {
|
||||
this.vertices = vertices;
|
||||
this.triangles = triangles;
|
||||
|
||||
int worldVerticesLength = vertices.length / 2 * 5;
|
||||
if (worldVertices == null || worldVertices.length != worldVerticesLength) worldVertices = new float[worldVerticesLength];
|
||||
|
||||
float u, v, w, h;
|
||||
if (region == null) {
|
||||
u = v = 0;
|
||||
w = h = 1;
|
||||
} else {
|
||||
u = region.getU();
|
||||
v = region.getV();
|
||||
w = region.getU2() - u;
|
||||
h = region.getV2() - v;
|
||||
}
|
||||
if (region instanceof AtlasRegion && ((AtlasRegion)region).rotate) {
|
||||
for (int i = 0, ii = 3, n = vertices.length; i < n; i += 2, ii += 5) {
|
||||
worldVertices[ii] = u + uvs[i + 1] * w;
|
||||
worldVertices[ii + 1] = v + h - uvs[i] * h;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0, ii = 3, n = vertices.length; i < n; i += 2, ii += 5) {
|
||||
worldVertices[ii] = u + uvs[i] * w;
|
||||
worldVertices[ii + 1] = v + uvs[i + 1] * h;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,6 +69,44 @@ public class SkinnedMeshAttachment extends Attachment {
|
||||
return region;
|
||||
}
|
||||
|
||||
/** @param bones For each vertex, the number of bones affecting the vertex followed by that many bone indices. Ie: count,
|
||||
* boneIndex, ...
|
||||
* @param weights For each bone affecting the vertex, the vertex position in the bone's coordinate system and the weight for
|
||||
* the bone's influence. Ie: x, y, weight, ...
|
||||
* @param uvs For each vertex, a texure coordinate pair. Ie: u, v, ...
|
||||
* @param triangles Vertex number triplets which describe the mesh's triangulation. */
|
||||
public void setMesh (int[] bones, float[] weights, short[] triangles, float[] uvs) {
|
||||
this.bones = bones;
|
||||
this.weights = weights;
|
||||
this.triangles = triangles;
|
||||
|
||||
int uvsLength = uvs.length;
|
||||
int worldVerticesLength = uvsLength / 2 * 5;
|
||||
if (worldVertices == null || worldVertices.length != worldVerticesLength) worldVertices = new float[worldVerticesLength];
|
||||
|
||||
float u, v, w, h;
|
||||
if (region == null) {
|
||||
u = v = 0;
|
||||
w = h = 1;
|
||||
} else {
|
||||
u = region.getU();
|
||||
v = region.getV();
|
||||
w = region.getU2() - u;
|
||||
h = region.getV2() - v;
|
||||
}
|
||||
if (region instanceof AtlasRegion && ((AtlasRegion)region).rotate) {
|
||||
for (int i = 0, ii = 3; i < uvsLength; i += 2, ii += 5) {
|
||||
worldVertices[ii] = u + uvs[i + 1] * w;
|
||||
worldVertices[ii + 1] = v + h - uvs[i] * h;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0, ii = 3; i < uvsLength; i += 2, ii += 5) {
|
||||
worldVertices[ii] = u + uvs[i] * w;
|
||||
worldVertices[ii + 1] = v + uvs[i + 1] * h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateWorldVertices (Slot slot, boolean premultipliedAlpha) {
|
||||
Skeleton skeleton = slot.getSkeleton();
|
||||
Color skeletonColor = skeleton.getColor();
|
||||
@ -180,42 +218,4 @@ public class SkinnedMeshAttachment extends Attachment {
|
||||
public void setHeight (float height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/** @param bones For each vertex, the number of bones affecting the vertex followed by that many bone indices. Ie: count,
|
||||
* boneIndex, ...
|
||||
* @param weights For each bone affecting the vertex, the vertex position in the bone's coordinate system and the weight for
|
||||
* the bone's influence. Ie: x, y, weight, ...
|
||||
* @param uvs For each vertex, a texure coordinate pair. Ie: u, v, ...
|
||||
* @param triangles Vertex number triplets which describe the mesh's triangulation. */
|
||||
public void setMesh (int[] bones, float[] weights, float[] uvs, short[] triangles) {
|
||||
this.bones = bones;
|
||||
this.weights = weights;
|
||||
this.triangles = triangles;
|
||||
|
||||
int uvsLength = uvs.length;
|
||||
int worldVerticesLength = uvsLength / 2 * 5;
|
||||
if (worldVertices == null || worldVertices.length != worldVerticesLength) worldVertices = new float[worldVerticesLength];
|
||||
|
||||
float u, v, w, h;
|
||||
if (region == null) {
|
||||
u = v = 0;
|
||||
w = h = 1;
|
||||
} else {
|
||||
u = region.getU();
|
||||
v = region.getV();
|
||||
w = region.getU2() - u;
|
||||
h = region.getV2() - v;
|
||||
}
|
||||
if (region instanceof AtlasRegion && ((AtlasRegion)region).rotate) {
|
||||
for (int i = 0, ii = 3; i < uvsLength; i += 2, ii += 5) {
|
||||
worldVertices[ii] = u + uvs[i + 1] * w;
|
||||
worldVertices[ii + 1] = v + h - uvs[i] * h;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0, ii = 3; i < uvsLength; i += 2, ii += 5) {
|
||||
worldVertices[ii] = u + uvs[i] * w;
|
||||
worldVertices[ii + 1] = v + uvs[i + 1] * h;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user