Permalink
Browse files

[ts][threejs] Added VertexEffect to SkeletonMesh

  • Loading branch information...
badlogic committed Jun 21, 2017
1 parent b685e49 commit 8d4a14b2003e088056fe3738062372fffd39b18b
@@ -1699,6 +1699,10 @@ declare module spine.threejs {
}
declare module spine.threejs {
class SkeletonMesh extends THREE.Mesh {
tempPos: Vector2;
tempUv: Vector2;
tempLight: Color;
tempDark: Color;
skeleton: Skeleton;
state: AnimationState;
zOffset: number;

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1238,6 +1238,10 @@ declare module spine.threejs {
}
declare module spine.threejs {
class SkeletonMesh extends THREE.Mesh {
tempPos: Vector2;
tempUv: Vector2;
tempLight: Color;
tempDark: Color;
skeleton: Skeleton;
state: AnimationState;
zOffset: number;

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -30,7 +30,10 @@
module spine.threejs {
export class SkeletonMesh extends THREE.Mesh {
tempPos: Vector2 = new Vector2();
tempUv: Vector2 = new Vector2();
tempLight = new Color();
tempDark = new Color();
skeleton: Skeleton;
state: AnimationState;
zOffset: number = 0.1;
@@ -71,6 +74,11 @@ module spine.threejs {
}
private updateGeometry() {
let tempPos = this.tempPos;
let tempUv = this.tempUv;
let tempLight = this.tempLight;
let tempDark = this.tempDark;
let geometry = <THREE.BufferGeometry>this.geometry;
var numVertices = 0;
var verticesLength = 0;
@@ -148,16 +156,58 @@ module spine.threejs {
clipper.clipTriangles(vertices, numFloats, triangles, triangles.length, uvs, color, null, false);
let clippedVertices = clipper.clippedVertices;
let clippedTriangles = clipper.clippedTriangles;
if (this.vertexEffect != null) {
let vertexEffect = this.vertexEffect;
let verts = clippedVertices;
for (let v = 0, n = clippedVertices.length; v < n; v += vertexSize) {
tempPos.x = verts[v];
tempPos.y = verts[v + 1];
tempLight.setFromColor(color);
tempDark.set(0, 0, 0, 0);
tempUv.x = verts[v + 6];
tempUv.y = verts[v + 7];
vertexEffect.transform(tempPos, tempUv, tempLight, tempDark);
verts[v] = tempPos.x;
verts[v + 1] = tempPos.y;
verts[v + 2] = tempLight.r;
verts[v + 3] = tempLight.g;
verts[v + 4] = tempLight.b;
verts[v + 5] = tempLight.a;
verts[v + 6] = tempUv.x;
verts[v + 7] = tempUv.y;
}
}
batcher.batch(clippedVertices, clippedVertices.length, clippedTriangles, clippedTriangles.length, z);
} else {
let verts = vertices;
for (let v = 2, u = 0, n = numFloats; v < n; v += vertexSize, u += 2) {
verts[v] = color.r;
verts[v + 1] = color.g;
verts[v + 2] = color.b;
verts[v + 3] = color.a;
verts[v + 4] = uvs[u];
verts[v + 5] = uvs[u + 1];
if (this.vertexEffect != null) {
let vertexEffect = this.vertexEffect;
for (let v = 0, u = 0, n = numFloats; v < n; v += vertexSize, u += 2) {
tempPos.x = verts[v];
tempPos.y = verts[v + 1];
tempLight.setFromColor(color);
tempDark.set(0, 0, 0, 0);
tempUv.x = uvs[u];
tempUv.y = uvs[u + 1];
vertexEffect.transform(tempPos, tempUv, tempLight, tempDark);
verts[v] = tempPos.x;
verts[v + 1] = tempPos.y;
verts[v + 2] = tempLight.r;
verts[v + 3] = tempLight.g;
verts[v + 4] = tempLight.b;
verts[v + 5] = tempLight.a;
verts[v + 6] = tempUv.x;
verts[v + 7] = tempUv.y;
}
} else {
for (let v = 2, u = 0, n = numFloats; v < n; v += vertexSize, u += 2) {
verts[v] = color.r;
verts[v + 1] = color.g;
verts[v + 2] = color.b;
verts[v + 3] = color.a;
verts[v + 4] = uvs[u];
verts[v + 5] = uvs[u + 1];
}
}
batcher.batch(vertices, numFloats, triangles, triangles.length, z);
}

0 comments on commit 8d4a14b

Please sign in to comment.