public MeshAndMaterials GenerateMesh(ExposedList <SubmeshInstruction> instructions, int startSubmesh, int endSubmesh) { SubmeshInstruction[] items = instructions.Items; this.currentInstructions.Clear(false); for (int i = startSubmesh; i < endSubmesh; i++) { this.currentInstructions.Add(items[i]); } SmartMesh next = this.doubleBufferedSmartMesh.GetNext(); Mesh mesh = next.mesh; int count = this.currentInstructions.Count; SubmeshInstruction[] items2 = this.currentInstructions.Items; int num = 0; for (int j = 0; j < count; j++) { items2[j].firstVertexIndex = num; num += items2[j].vertexCount; } bool flag = ArraysMeshGenerator.EnsureSize(num, ref this.meshVertices, ref this.meshUVs, ref this.meshColors32); bool flag2 = ArraysMeshGenerator.EnsureTriangleBuffersSize(this.submeshBuffers, count, items2); float zspacing = this.ZSpacing; Vector3 boundsMin; Vector3 boundsMax; if (num <= 0) { boundsMin = new Vector3(0f, 0f, 0f); boundsMax = new Vector3(0f, 0f, 0f); } else { boundsMin.x = 2.14748365E+09f; boundsMin.y = 2.14748365E+09f; boundsMax.x = -2.14748365E+09f; boundsMax.y = -2.14748365E+09f; int endSlot = items2[count - 1].endSlot; if (zspacing > 0f) { boundsMin.z = 0f; boundsMax.z = zspacing * (float)endSlot; } else { boundsMin.z = zspacing * (float)endSlot; boundsMax.z = 0f; } } ExposedList <Attachment> exposedList = this.attachmentBuffer; exposedList.Clear(false); int num2 = 0; for (int k = 0; k < count; k++) { SubmeshInstruction submeshInstruction = items2[k]; int startSlot = submeshInstruction.startSlot; int endSlot2 = submeshInstruction.endSlot; Skeleton skeleton = submeshInstruction.skeleton; Slot[] items3 = skeleton.DrawOrder.Items; for (int l = startSlot; l < endSlot2; l++) { Attachment attachment = items3[l].attachment; if (attachment != null) { exposedList.Add(attachment); } } ArraysMeshGenerator.FillVerts(skeleton, startSlot, endSlot2, zspacing, base.PremultiplyVertexColors, this.meshVertices, this.meshUVs, this.meshColors32, ref num2, ref this.attachmentVertexBuffer, ref boundsMin, ref boundsMax, true); } bool flag3 = flag || flag2 || next.StructureDoesntMatch(exposedList, this.currentInstructions); for (int m = 0; m < count; m++) { SubmeshInstruction submeshInstruction2 = items2[m]; if (flag3) { SubmeshTriangleBuffer submeshTriangleBuffer = this.submeshBuffers.Items[m]; bool isLastSubmesh = m == count - 1; ArraysMeshGenerator.FillTriangles(ref submeshTriangleBuffer.triangles, submeshInstruction2.skeleton, submeshInstruction2.triangleCount, submeshInstruction2.firstVertexIndex, submeshInstruction2.startSlot, submeshInstruction2.endSlot, isLastSubmesh); submeshTriangleBuffer.triangleCount = submeshInstruction2.triangleCount; submeshTriangleBuffer.firstVertex = submeshInstruction2.firstVertexIndex; } } if (flag3) { mesh.Clear(); this.sharedMaterials = this.currentInstructions.GetUpdatedMaterialArray(this.sharedMaterials); } next.Set(this.meshVertices, this.meshUVs, this.meshColors32, exposedList, this.currentInstructions); mesh.bounds = ArraysMeshGenerator.ToBounds(boundsMin, boundsMax); if (flag3) { mesh.subMeshCount = count; for (int n = 0; n < count; n++) { mesh.SetTriangles(this.submeshBuffers.Items[n].triangles, n); } base.TryAddNormalsTo(mesh, num); } if (this.addTangents) { ArraysMeshGenerator.SolveTangents2DEnsureSize(ref this.meshTangents, ref this.tempTanBuffer, num); int num3 = 0; int num4 = count; while (num3 < num4) { SubmeshTriangleBuffer submeshTriangleBuffer2 = this.submeshBuffers.Items[num3]; ArraysMeshGenerator.SolveTangents2DTriangles(this.tempTanBuffer, submeshTriangleBuffer2.triangles, submeshTriangleBuffer2.triangleCount, this.meshVertices, this.meshUVs, num); num3++; } ArraysMeshGenerator.SolveTangents2DBuffer(this.meshTangents, this.tempTanBuffer, num); } return(new MeshAndMaterials(next.mesh, this.sharedMaterials)); }
public MeshAndMaterials GenerateMesh(SubmeshedMeshInstruction meshInstructions) { SmartMesh next = this.doubleBufferedSmartMesh.GetNext(); Mesh mesh = next.mesh; int count = meshInstructions.submeshInstructions.Count; ExposedList <SubmeshInstruction> submeshInstructions = meshInstructions.submeshInstructions; int vertexCount = meshInstructions.vertexCount; bool flag = ArraysMeshGenerator.EnsureTriangleBuffersSize(this.submeshBuffers, count, submeshInstructions.Items); bool flag2 = ArraysMeshGenerator.EnsureSize(vertexCount, ref this.meshVertices, ref this.meshUVs, ref this.meshColors32); Vector3[] meshVertices = this.meshVertices; float zspacing = this.ZSpacing; int count2 = meshInstructions.attachmentList.Count; Vector3 boundsMin; Vector3 boundsMax; if (count2 <= 0) { boundsMin = new Vector3(0f, 0f, 0f); boundsMax = new Vector3(0f, 0f, 0f); } else { boundsMin.x = 2.14748365E+09f; boundsMin.y = 2.14748365E+09f; boundsMax.x = -2.14748365E+09f; boundsMax.y = -2.14748365E+09f; if (zspacing > 0f) { boundsMin.z = 0f; boundsMax.z = zspacing * (float)(count2 - 1); } else { boundsMin.z = zspacing * (float)(count2 - 1); boundsMax.z = 0f; } } bool flag3 = flag2 || flag || next.StructureDoesntMatch(meshInstructions); int num = 0; for (int i = 0; i < count; i++) { SubmeshInstruction submeshInstruction = submeshInstructions.Items[i]; int startSlot = submeshInstruction.startSlot; int endSlot = submeshInstruction.endSlot; Skeleton skeleton = submeshInstruction.skeleton; ArraysMeshGenerator.FillVerts(skeleton, startSlot, endSlot, zspacing, base.PremultiplyVertexColors, meshVertices, this.meshUVs, this.meshColors32, ref num, ref this.attachmentVertexBuffer, ref boundsMin, ref boundsMax, true); if (flag3) { SubmeshTriangleBuffer submeshTriangleBuffer = this.submeshBuffers.Items[i]; bool isLastSubmesh = i == count - 1; ArraysMeshGenerator.FillTriangles(ref submeshTriangleBuffer.triangles, skeleton, submeshInstruction.triangleCount, submeshInstruction.firstVertexIndex, startSlot, endSlot, isLastSubmesh); submeshTriangleBuffer.triangleCount = submeshInstruction.triangleCount; submeshTriangleBuffer.firstVertex = submeshInstruction.firstVertexIndex; } } if (flag3) { mesh.Clear(); this.sharedMaterials = meshInstructions.GetUpdatedMaterialArray(this.sharedMaterials); } next.Set(this.meshVertices, this.meshUVs, this.meshColors32, meshInstructions); mesh.bounds = ArraysMeshGenerator.ToBounds(boundsMin, boundsMax); if (flag3) { mesh.subMeshCount = count; for (int j = 0; j < count; j++) { mesh.SetTriangles(this.submeshBuffers.Items[j].triangles, j); } base.TryAddNormalsTo(mesh, vertexCount); } if (this.addTangents) { ArraysMeshGenerator.SolveTangents2DEnsureSize(ref this.meshTangents, ref this.tempTanBuffer, vertexCount); int k = 0; int num2 = count; while (k < num2) { SubmeshTriangleBuffer submeshTriangleBuffer2 = this.submeshBuffers.Items[k]; ArraysMeshGenerator.SolveTangents2DTriangles(this.tempTanBuffer, submeshTriangleBuffer2.triangles, submeshTriangleBuffer2.triangleCount, this.meshVertices, this.meshUVs, vertexCount); k++; } ArraysMeshGenerator.SolveTangents2DBuffer(this.meshTangents, this.tempTanBuffer, vertexCount); } return(new MeshAndMaterials(next.mesh, this.sharedMaterials)); }