[unity] Fix tangents not being solved.

This commit is contained in:
pharan 2018-03-24 06:19:41 +08:00
parent f5c2571c44
commit e46a04a130
4 changed files with 53 additions and 42 deletions

View File

@ -317,6 +317,7 @@ namespace Spine.Unity {
meshRenderer.sharedMaterials = rendererBuffers.GetUpdatedSharedMaterialsArray();
}
meshGenerator.FillLateVertexData(currentMesh);
// STEP 4. The UnityEngine.Mesh is ready. Set it as the MeshFilter's mesh. Store the instructions used for that mesh. ===========
meshFilter.sharedMesh = currentMesh;

View File

@ -50,13 +50,13 @@ namespace Spine.Unity {
}
}
/// <summary>Instructions for how to generate a mesh or submesh out of a range of slots in a given skeleton.</summary>
/// <summary>Instructions for how to generate a mesh or submesh: "Render this skeleton's slots: start slot, up to but not including endSlot, using this material."</summary>
public struct SubmeshInstruction {
public Skeleton skeleton;
public int startSlot;
public int endSlot;
public Material material;
public bool forceSeparate;
public int preActiveClippingSlotSource;
@ -448,9 +448,9 @@ namespace Spine.Unity {
meshBoundsThickness = 0f;
}
submeshes.Count = 1;
submeshes.Items[0].Clear(false);
submeshIndex = 0;
submeshes.Count = 1;
//submeshes.Items[0].Clear(false);
}
public void AddSubmesh (SubmeshInstruction instruction, bool updateTriangles = true) {
@ -1021,8 +1021,17 @@ namespace Spine.Unity {
mesh.uv2 = this.uv2.Items;
mesh.uv3 = this.uv3.Items;
}
}
}
public void FillLateVertexData (Mesh mesh) {
if (settings.calculateTangents) {
int vertexCount = this.vertexBuffer.Count;
var sbi = submeshes.Items;
int submeshCount = submeshes.Count;
var vbi = vertexBuffer.Items;
var ubi = uvBuffer.Items;
MeshGenerator.SolveTangents2DEnsureSize(ref this.tangents, ref this.tempTanBuffer, vertexCount);
for (int i = 0; i < submeshCount; i++) {
var submesh = sbi[i].Items;
@ -1033,7 +1042,6 @@ namespace Spine.Unity {
mesh.tangents = this.tangents;
}
}
}
public void FillTriangles (Mesh mesh) {
int submeshCount = submeshes.Count;

View File

@ -287,6 +287,7 @@ namespace Spine.Unity {
var mesh = smartMesh.mesh;
meshGenerator.FillVertexData(mesh);
if (updateTriangles) meshGenerator.FillTrianglesSingle(mesh);
meshGenerator.FillLateVertexData(mesh);
canvasRenderer.SetMesh(mesh);
smartMesh.instructionUsed.Set(currentInstructions);

View File

@ -117,6 +117,7 @@ namespace Spine.Unity.Modules {
meshRenderer.sharedMaterials = buffers.GetUpdatedSharedMaterialsArray();
}
}
meshGenerator.FillLateVertexData(mesh);
meshFilter.sharedMesh = mesh;
smartMesh.instructionUsed.Set(currentInstructions);