public void SetWithSubset(ExposedList <SubmeshInstruction> instructions, int startSubmesh, int endSubmesh) { int num = 0; ExposedList <SubmeshInstruction> submeshInstructions = this.submeshInstructions; submeshInstructions.Clear(false); int newSize = endSubmesh - startSubmesh; submeshInstructions.Resize(newSize); SubmeshInstruction[] items = submeshInstructions.Items; SubmeshInstruction[] instructionArray2 = instructions.Items; for (int i = 0; i < newSize; i++) { SubmeshInstruction instruction = instructionArray2[startSubmesh + i]; items[i] = instruction; this.hasActiveClipping |= instruction.hasClipping; items[i].rawFirstVertexIndex = num; num += instruction.rawVertexCount; } this.rawVertexCount = num; int startSlot = instructionArray2[startSubmesh].startSlot; int endSlot = instructionArray2[endSubmesh - 1].endSlot; this.attachments.Clear(false); int num6 = endSlot - startSlot; this.attachments.Resize(num6); Attachment[] attachmentArray = this.attachments.Items; Slot[] slotArray = instructionArray2[0].skeleton.drawOrder.Items; for (int j = 0; j < num6; j++) { attachmentArray[j] = slotArray[startSlot + j].attachment; } }
public static bool GeometryNotEqual(SkeletonRendererInstruction a, SkeletonRendererInstruction b) { if (a.hasActiveClipping || b.hasActiveClipping) { return(true); } if (a.rawVertexCount != b.rawVertexCount) { return(true); } if (a.immutableTriangles != b.immutableTriangles) { return(true); } int count = b.attachments.Count; if (a.attachments.Count != count) { return(true); } int num2 = a.submeshInstructions.Count; int num3 = b.submeshInstructions.Count; if (num2 != num3) { return(true); } SubmeshInstruction[] items = a.submeshInstructions.Items; SubmeshInstruction[] instructionArray2 = b.submeshInstructions.Items; Attachment[] attachmentArray = a.attachments.Items; Attachment[] attachmentArray2 = b.attachments.Items; for (int i = 0; i < count; i++) { if (!object.ReferenceEquals(attachmentArray[i], attachmentArray2[i])) { return(true); } } for (int j = 0; j < num3; j++) { SubmeshInstruction instruction = items[j]; SubmeshInstruction instruction2 = instructionArray2[j]; if (((instruction.rawVertexCount != instruction2.rawVertexCount) || (instruction.startSlot != instruction2.startSlot)) || (((instruction.endSlot != instruction2.endSlot) || (instruction.rawTriangleCount != instruction2.rawTriangleCount)) || (instruction.rawFirstVertexIndex != instruction2.rawFirstVertexIndex))) { return(true); } } return(false); }
private static bool CheckIfMustUpdateMeshStructure(SmartMesh.Instruction a, SmartMesh.Instruction b) { if (a.vertexCount != b.vertexCount) { return(true); } if (a.immutableTriangles != b.immutableTriangles) { return(true); } int count = b.attachments.Count; if (a.attachments.Count != count) { return(true); } Attachment[] items = a.attachments.Items; Attachment[] items2 = b.attachments.Items; for (int i = 0; i < count; i++) { if (items[i] != items2[i]) { return(true); } } int count2 = a.submeshInstructions.Count; int count3 = b.submeshInstructions.Count; if (count2 != count3) { return(true); } SubmeshInstruction[] items3 = a.submeshInstructions.Items; SubmeshInstruction[] items4 = b.submeshInstructions.Items; for (int j = 0; j < count3; j++) { SubmeshInstruction submeshInstruction = items3[j]; SubmeshInstruction submeshInstruction2 = items4[j]; if (submeshInstruction.vertexCount != submeshInstruction2.vertexCount || submeshInstruction.startSlot != submeshInstruction2.startSlot || submeshInstruction.endSlot != submeshInstruction2.endSlot || submeshInstruction.triangleCount != submeshInstruction2.triangleCount || submeshInstruction.firstVertexIndex != submeshInstruction2.firstVertexIndex) { return(true); } } return(false); }
public virtual void LateUpdate() { if (!valid || (!meshRenderer.enabled && this.generateMeshOverride == null)) { return; } ExposedList <Slot> drawOrder = skeleton.drawOrder; Slot[] items = drawOrder.Items; int count = drawOrder.Count; bool flag = renderMeshes; SmartMesh.Instruction instruction = currentInstructions; ExposedList <Attachment> attachments = instruction.attachments; attachments.Clear(clearArray: false); attachments.GrowIfNeeded(count); attachments.Count = count; Attachment[] items2 = instruction.attachments.Items; ExposedList <SubmeshInstruction> submeshInstructions = instruction.submeshInstructions; submeshInstructions.Clear(clearArray: false); bool flag2 = customSlotMaterials.Count > 0; int num = 0; int num2 = 0; int num3 = 0; int firstVertexIndex = 0; int startSlot = 0; Material material = null; for (int i = 0; i < count; i++) { Slot slot = items[i]; Attachment attachment = items2[i] = slot.attachment; RegionAttachment regionAttachment = attachment as RegionAttachment; object rendererObject; int num4; int num5; if (regionAttachment != null) { rendererObject = regionAttachment.RendererObject; num4 = 4; num5 = 6; } else { if (!flag) { continue; } MeshAttachment meshAttachment = attachment as MeshAttachment; if (meshAttachment == null) { continue; } rendererObject = meshAttachment.RendererObject; num4 = meshAttachment.worldVerticesLength >> 1; num5 = meshAttachment.triangles.Length; } Material value; if (flag2) { if (!customSlotMaterials.TryGetValue(slot, out value)) { value = (Material)((AtlasRegion)rendererObject).page.rendererObject; } } else { value = (Material)((AtlasRegion)rendererObject).page.rendererObject; } bool flag3 = separatorSlots.Count > 0 && separatorSlots.Contains(slot); if (num > 0 && (material.GetInstanceID() != value.GetInstanceID() || flag3)) { submeshInstructions.Add(new SubmeshInstruction { skeleton = skeleton, material = material, startSlot = startSlot, endSlot = i, triangleCount = num3, firstVertexIndex = firstVertexIndex, vertexCount = num2, forceSeparate = flag3 }); num3 = 0; num2 = 0; firstVertexIndex = num; startSlot = i; } material = value; num3 += num5; num += num4; num2 += num4; } if (num2 != 0) { submeshInstructions.Add(new SubmeshInstruction { skeleton = skeleton, material = material, startSlot = startSlot, endSlot = count, triangleCount = num3, firstVertexIndex = firstVertexIndex, vertexCount = num2, forceSeparate = false }); } instruction.vertexCount = num; instruction.immutableTriangles = immutableTriangles; if (customMaterialOverride.Count > 0) { SubmeshInstruction[] items3 = submeshInstructions.Items; for (int j = 0; j < submeshInstructions.Count; j++) { Material material2 = items3[j].material; Material value2; if (customMaterialOverride.TryGetValue(material2, out value2)) { items3[j].material = value2; } } } if (this.generateMeshOverride != null) { this.generateMeshOverride(instruction); if (disableRenderingOnOverride) { return; } } if (ArraysMeshGenerator.EnsureSize(num, ref vertices, ref uvs, ref colors) && calculateNormals) { Vector3[] array = normals = new Vector3[num]; Vector3 vector = new Vector3(0f, 0f, -1f); for (int k = 0; k < num; k++) { array[k] = vector; } } Vector3 boundsMin = default(Vector3); Vector3 boundsMax = default(Vector3); 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; if (zSpacing > 0f) { boundsMin.z = 0f; boundsMax.z = zSpacing * (float)(count - 1); } else { boundsMin.z = zSpacing * (float)(count - 1); boundsMax.z = 0f; } } int vertexIndex = 0; ArraysMeshGenerator.FillVerts(skeleton, 0, count, zSpacing, pmaVertexColors, vertices, uvs, colors, ref vertexIndex, ref tempVertices, ref boundsMin, ref boundsMax, flag); SmartMesh next = doubleBufferedMesh.GetNext(); Mesh mesh = next.mesh; mesh.vertices = vertices; mesh.colors32 = colors; mesh.uv = uvs; mesh.bounds = ArraysMeshGenerator.ToBounds(boundsMin, boundsMax); SmartMesh.Instruction instructionUsed = next.instructionUsed; if (calculateNormals && instructionUsed.vertexCount < num) { mesh.normals = normals; } bool flag4 = CheckIfMustUpdateMeshStructure(instruction, instructionUsed); int count2 = submeshInstructions.Count; if (flag4) { ExposedList <Material> exposedList = submeshMaterials; exposedList.Clear(clearArray: false); int count3 = submeshes.Count; if (submeshes.Capacity < count2) { submeshes.Capacity = count2; } for (int l = count3; l < count2; l++) { submeshes.Items[l] = new ArraysMeshGenerator.SubmeshTriangleBuffer(submeshInstructions.Items[l].triangleCount); } submeshes.Count = count2; bool flag5 = !instruction.immutableTriangles; int m = 0; int num6 = count2 - 1; for (; m < count2; m++) { SubmeshInstruction submeshInstruction = submeshInstructions.Items[m]; if (flag5 || m >= count3) { ArraysMeshGenerator.SubmeshTriangleBuffer submeshTriangleBuffer = submeshes.Items[m]; int triangleCount = submeshInstruction.triangleCount; if (flag) { ArraysMeshGenerator.FillTriangles(ref submeshTriangleBuffer.triangles, skeleton, triangleCount, submeshInstruction.firstVertexIndex, submeshInstruction.startSlot, submeshInstruction.endSlot, m == num6); submeshTriangleBuffer.triangleCount = triangleCount; } else { ArraysMeshGenerator.FillTrianglesQuads(ref submeshTriangleBuffer.triangles, ref submeshTriangleBuffer.triangleCount, ref submeshTriangleBuffer.firstVertex, submeshInstruction.firstVertexIndex, triangleCount, m == num6); } } exposedList.Add(submeshInstruction.material); } mesh.subMeshCount = count2; for (int n = 0; n < count2; n++) { mesh.SetTriangles(submeshes.Items[n].triangles, n); } } if (calculateTangents) { ArraysMeshGenerator.SolveTangents2DEnsureSize(ref tangents, ref tempTanBuffer, vertices.Length); for (int num7 = 0; num7 < count2; num7++) { ArraysMeshGenerator.SubmeshTriangleBuffer submeshTriangleBuffer2 = submeshes.Items[num7]; ArraysMeshGenerator.SolveTangents2DTriangles(tempTanBuffer, submeshTriangleBuffer2.triangles, submeshTriangleBuffer2.triangleCount, vertices, uvs, num); } ArraysMeshGenerator.SolveTangents2DBuffer(tangents, tempTanBuffer, num); mesh.tangents = tangents; } Material[] array2 = sharedMaterials; bool flag6 = flag4 || array2.Length != count2; if (!flag6) { SubmeshInstruction[] items4 = submeshInstructions.Items; int num8 = 0; for (int num9 = array2.Length; num8 < num9; num8++) { if (array2[num8].GetInstanceID() != items4[num8].material.GetInstanceID()) { flag6 = true; break; } } } if (flag6) { if (submeshMaterials.Count == sharedMaterials.Length) { submeshMaterials.CopyTo(sharedMaterials); } else { sharedMaterials = submeshMaterials.ToArray(); } meshRenderer.sharedMaterials = sharedMaterials; } meshFilter.sharedMesh = mesh; next.instructionUsed.Set(instruction); }
public void BuildMeshWithArrays(SkeletonRendererInstruction instruction, bool updateTriangles) { Settings settings = this.settings; int rawVertexCount = instruction.rawVertexCount; if (rawVertexCount > vertexBuffer.Items.Length) { Array.Resize(ref vertexBuffer.Items, rawVertexCount); Array.Resize(ref uvBuffer.Items, rawVertexCount); Array.Resize(ref colorBuffer.Items, rawVertexCount); } vertexBuffer.Count = (uvBuffer.Count = (colorBuffer.Count = rawVertexCount)); Color32 color = default(Color32); int num = 0; float[] array = tempVerts; Vector3 v = meshBoundsMin; Vector3 v2 = meshBoundsMax; Vector3[] items = vertexBuffer.Items; Vector2[] items2 = uvBuffer.Items; Color32[] items3 = colorBuffer.Items; int num2 = 0; int i = 0; Vector2 vector = default(Vector2); Vector2 vector2 = default(Vector2); for (int count = instruction.submeshInstructions.Count; i < count; i++) { SubmeshInstruction submeshInstruction = instruction.submeshInstructions.Items[i]; Skeleton skeleton = submeshInstruction.skeleton; Slot[] items4 = skeleton.drawOrder.Items; float num3 = skeleton.a * 255f; float r = skeleton.r; float g = skeleton.g; float b = skeleton.b; int endSlot = submeshInstruction.endSlot; int startSlot = submeshInstruction.startSlot; num2 = endSlot; if (settings.tintBlack) { int num4 = num; vector.y = 1f; if (uv2 == null) { uv2 = new ExposedList <Vector2>(); uv3 = new ExposedList <Vector2>(); } if (rawVertexCount > uv2.Items.Length) { Array.Resize(ref uv2.Items, rawVertexCount); Array.Resize(ref uv3.Items, rawVertexCount); } uv2.Count = (uv3.Count = rawVertexCount); Vector2[] items5 = uv2.Items; Vector2[] items6 = uv3.Items; for (int j = startSlot; j < endSlot; j++) { Slot slot = items4[j]; Attachment attachment = slot.attachment; vector2.x = slot.r2; vector2.y = slot.g2; vector.x = slot.b2; RegionAttachment regionAttachment = attachment as RegionAttachment; if (regionAttachment != null) { items5[num4] = vector2; items5[num4 + 1] = vector2; items5[num4 + 2] = vector2; items5[num4 + 3] = vector2; items6[num4] = vector; items6[num4 + 1] = vector; items6[num4 + 2] = vector; items6[num4 + 3] = vector; num4 += 4; continue; } MeshAttachment meshAttachment = attachment as MeshAttachment; if (meshAttachment != null) { int worldVerticesLength = meshAttachment.worldVerticesLength; for (int k = 0; k < worldVerticesLength; k += 2) { items5[num4] = vector2; items6[num4] = vector; num4++; } } } } for (int l = startSlot; l < endSlot; l++) { Slot slot2 = items4[l]; Attachment attachment2 = slot2.attachment; float z = (float)l * settings.zSpacing; RegionAttachment regionAttachment2 = attachment2 as RegionAttachment; if (regionAttachment2 != null) { regionAttachment2.ComputeWorldVertices(slot2.bone, array, 0); float num5 = array[0]; float num6 = array[1]; float num7 = array[2]; float num8 = array[3]; float num9 = array[4]; float num10 = array[5]; float num11 = array[6]; float num12 = array[7]; items[num].x = num5; items[num].y = num6; items[num].z = z; items[num + 1].x = num11; items[num + 1].y = num12; items[num + 1].z = z; items[num + 2].x = num7; items[num + 2].y = num8; items[num + 2].z = z; items[num + 3].x = num9; items[num + 3].y = num10; items[num + 3].z = z; if (settings.pmaVertexColors) { color.a = (byte)(num3 * slot2.a * regionAttachment2.a); color.r = (byte)(r * slot2.r * regionAttachment2.r * (float)(int)color.a); color.g = (byte)(g * slot2.g * regionAttachment2.g * (float)(int)color.a); color.b = (byte)(b * slot2.b * regionAttachment2.b * (float)(int)color.a); if (slot2.data.blendMode == BlendMode.Additive) { color.a = 0; } } else { color.a = (byte)(num3 * slot2.a * regionAttachment2.a); color.r = (byte)(r * slot2.r * regionAttachment2.r * 255f); color.g = (byte)(g * slot2.g * regionAttachment2.g * 255f); color.b = (byte)(b * slot2.b * regionAttachment2.b * 255f); } items3[num] = color; items3[num + 1] = color; items3[num + 2] = color; items3[num + 3] = color; float[] uvs = regionAttachment2.uvs; items2[num].x = uvs[0]; items2[num].y = uvs[1]; items2[num + 1].x = uvs[6]; items2[num + 1].y = uvs[7]; items2[num + 2].x = uvs[2]; items2[num + 2].y = uvs[3]; items2[num + 3].x = uvs[4]; items2[num + 3].y = uvs[5]; if (num5 < v.x) { v.x = num5; } if (num5 > v2.x) { v2.x = num5; } if (num7 < v.x) { v.x = num7; } else if (num7 > v2.x) { v2.x = num7; } if (num9 < v.x) { v.x = num9; } else if (num9 > v2.x) { v2.x = num9; } if (num11 < v.x) { v.x = num11; } else if (num11 > v2.x) { v2.x = num11; } if (num6 < v.y) { v.y = num6; } if (num6 > v2.y) { v2.y = num6; } if (num8 < v.y) { v.y = num8; } else if (num8 > v2.y) { v2.y = num8; } if (num10 < v.y) { v.y = num10; } else if (num10 > v2.y) { v2.y = num10; } if (num12 < v.y) { v.y = num12; } else if (num12 > v2.y) { v2.y = num12; } num += 4; continue; } MeshAttachment meshAttachment2 = attachment2 as MeshAttachment; if (meshAttachment2 == null) { continue; } int worldVerticesLength2 = meshAttachment2.worldVerticesLength; if (array.Length < worldVerticesLength2) { array = (tempVerts = new float[worldVerticesLength2]); } meshAttachment2.ComputeWorldVertices(slot2, array); if (settings.pmaVertexColors) { color.a = (byte)(num3 * slot2.a * meshAttachment2.a); color.r = (byte)(r * slot2.r * meshAttachment2.r * (float)(int)color.a); color.g = (byte)(g * slot2.g * meshAttachment2.g * (float)(int)color.a); color.b = (byte)(b * slot2.b * meshAttachment2.b * (float)(int)color.a); if (slot2.data.blendMode == BlendMode.Additive) { color.a = 0; } } else { color.a = (byte)(num3 * slot2.a * meshAttachment2.a); color.r = (byte)(r * slot2.r * meshAttachment2.r * 255f); color.g = (byte)(g * slot2.g * meshAttachment2.g * 255f); color.b = (byte)(b * slot2.b * meshAttachment2.b * 255f); } float[] uvs2 = meshAttachment2.uvs; if (num == 0) { float num13 = array[0]; float num14 = array[1]; if (num13 < v.x) { v.x = num13; } if (num13 > v2.x) { v2.x = num13; } if (num14 < v.y) { v.y = num14; } if (num14 > v2.y) { v2.y = num14; } } for (int m = 0; m < worldVerticesLength2; m += 2) { float num15 = array[m]; float num16 = array[m + 1]; items[num].x = num15; items[num].y = num16; items[num].z = z; items3[num] = color; items2[num].x = uvs2[m]; items2[num].y = uvs2[m + 1]; if (num15 < v.x) { v.x = num15; } else if (num15 > v2.x) { v2.x = num15; } if (num16 < v.y) { v.y = num16; } else if (num16 > v2.y) { v2.y = num16; } num++; } } } meshBoundsMin = v; meshBoundsMax = v2; meshBoundsThickness = (float)num2 * settings.zSpacing; if (!updateTriangles) { return; } int count2 = instruction.submeshInstructions.Count; if (submeshes.Count < count2) { submeshes.Resize(count2); int n = 0; for (int num17 = count2; n < num17; n++) { ExposedList <int> exposedList = submeshes.Items[n]; if (exposedList == null) { submeshes.Items[n] = new ExposedList <int>(); } else { exposedList.Clear(clearArray: false); } } } SubmeshInstruction[] items7 = instruction.submeshInstructions.Items; int num18 = 0; for (int num19 = 0; num19 < count2; num19++) { SubmeshInstruction submeshInstruction2 = items7[num19]; ExposedList <int> exposedList2 = submeshes.Items[num19]; int rawTriangleCount = submeshInstruction2.rawTriangleCount; if (rawTriangleCount > exposedList2.Items.Length) { Array.Resize(ref exposedList2.Items, rawTriangleCount); } else if (rawTriangleCount < exposedList2.Items.Length) { int[] items8 = exposedList2.Items; int num20 = rawTriangleCount; for (int num21 = items8.Length; num20 < num21; num20++) { items8[num20] = 0; } } exposedList2.Count = rawTriangleCount; int[] items9 = exposedList2.Items; int num22 = 0; Skeleton skeleton2 = submeshInstruction2.skeleton; Slot[] items10 = skeleton2.drawOrder.Items; int num23 = submeshInstruction2.startSlot; for (int endSlot2 = submeshInstruction2.endSlot; num23 < endSlot2; num23++) { Attachment attachment3 = items10[num23].attachment; if (attachment3 is RegionAttachment) { items9[num22] = num18; items9[num22 + 1] = num18 + 2; items9[num22 + 2] = num18 + 1; items9[num22 + 3] = num18 + 2; items9[num22 + 4] = num18 + 3; items9[num22 + 5] = num18 + 1; num22 += 6; num18 += 4; continue; } MeshAttachment meshAttachment3 = attachment3 as MeshAttachment; if (meshAttachment3 != null) { int[] triangles = meshAttachment3.triangles; int num24 = 0; int num25 = triangles.Length; while (num24 < num25) { items9[num22] = num18 + triangles[num24]; num24++; num22++; } num18 += meshAttachment3.worldVerticesLength >> 1; } } } }
public void AddSubmesh(SubmeshInstruction instruction, bool updateTriangles = true) { Settings settings = this.settings; if (submeshes.Count - 1 < submeshIndex) { submeshes.Resize(submeshIndex + 1); if (submeshes.Items[submeshIndex] == null) { submeshes.Items[submeshIndex] = new ExposedList <int>(); } } ExposedList <int> exposedList = submeshes.Items[submeshIndex]; exposedList.Clear(clearArray: false); Skeleton skeleton = instruction.skeleton; Slot[] items = skeleton.drawOrder.Items; Color32 color = default(Color32); float num = skeleton.a * 255f; float r = skeleton.r; float g = skeleton.g; float b = skeleton.b; Vector2 vector = meshBoundsMin; Vector2 vector2 = meshBoundsMax; float zSpacing = settings.zSpacing; bool pmaVertexColors = settings.pmaVertexColors; bool tintBlack = settings.tintBlack; bool flag = settings.useClipping && instruction.hasClipping; if (flag && instruction.preActiveClippingSlotSource >= 0) { Slot slot = items[instruction.preActiveClippingSlotSource]; clipper.ClipStart(slot, slot.attachment as ClippingAttachment); } for (int i = instruction.startSlot; i < instruction.endSlot; i++) { Slot slot2 = items[i]; Attachment attachment = slot2.attachment; float z = zSpacing * (float)i; float[] array = tempVerts; Color color2 = default(Color); RegionAttachment regionAttachment = attachment as RegionAttachment; float[] array2; int[] array3; int num2; int num3; if (regionAttachment != null) { regionAttachment.ComputeWorldVertices(slot2.bone, array, 0); array2 = regionAttachment.uvs; array3 = regionTriangles; color2.r = regionAttachment.r; color2.g = regionAttachment.g; color2.b = regionAttachment.b; color2.a = regionAttachment.a; num2 = 4; num3 = 6; } else { MeshAttachment meshAttachment = attachment as MeshAttachment; if (meshAttachment == null) { if (flag) { ClippingAttachment clippingAttachment = attachment as ClippingAttachment; if (clippingAttachment != null) { clipper.ClipStart(slot2, clippingAttachment); } } continue; } int worldVerticesLength = meshAttachment.worldVerticesLength; if (array.Length < worldVerticesLength) { array = (tempVerts = new float[worldVerticesLength]); } meshAttachment.ComputeWorldVertices(slot2, 0, worldVerticesLength, array, 0); array2 = meshAttachment.uvs; array3 = meshAttachment.triangles; color2.r = meshAttachment.r; color2.g = meshAttachment.g; color2.b = meshAttachment.b; color2.a = meshAttachment.a; num2 = worldVerticesLength >> 1; num3 = meshAttachment.triangles.Length; } if (pmaVertexColors) { color.a = (byte)(num * slot2.a * color2.a); color.r = (byte)(r * slot2.r * color2.r * (float)(int)color.a); color.g = (byte)(g * slot2.g * color2.g * (float)(int)color.a); color.b = (byte)(b * slot2.b * color2.b * (float)(int)color.a); if (slot2.data.blendMode == BlendMode.Additive) { color.a = 0; } } else { color.a = (byte)(num * slot2.a * color2.a); color.r = (byte)(r * slot2.r * color2.r * 255f); color.g = (byte)(g * slot2.g * color2.g * 255f); color.b = (byte)(b * slot2.b * color2.b * 255f); } if (flag && clipper.IsClipping()) { clipper.ClipTriangles(array, num2 << 1, array3, num3, array2); array = clipper.clippedVertices.Items; num2 = clipper.clippedVertices.Count >> 1; array3 = clipper.clippedTriangles.Items; num3 = clipper.clippedTriangles.Count; array2 = clipper.clippedUVs.Items; } if (num2 != 0 && num3 != 0) { if (tintBlack) { AddAttachmentTintBlack(slot2.r2, slot2.g2, slot2.b2, num2); } int count = vertexBuffer.Count; int num4 = count + num2; if (num4 > vertexBuffer.Items.Length) { Array.Resize(ref vertexBuffer.Items, num4); Array.Resize(ref uvBuffer.Items, num4); Array.Resize(ref colorBuffer.Items, num4); } vertexBuffer.Count = (uvBuffer.Count = (colorBuffer.Count = num4)); Vector3[] items2 = vertexBuffer.Items; Vector2[] items3 = uvBuffer.Items; Color32[] items4 = colorBuffer.Items; if (count == 0) { for (int j = 0; j < num2; j++) { int num5 = count + j; int num6 = j << 1; float num7 = array[num6]; float num8 = array[num6 + 1]; items2[num5].x = num7; items2[num5].y = num8; items2[num5].z = z; items3[num5].x = array2[num6]; items3[num5].y = array2[num6 + 1]; items4[num5] = color; if (num7 < vector.x) { vector.x = num7; } if (num7 > vector2.x) { vector2.x = num7; } if (num8 < vector.y) { vector.y = num8; } if (num8 > vector2.y) { vector2.y = num8; } } } else { for (int k = 0; k < num2; k++) { int num9 = count + k; int num10 = k << 1; float num11 = array[num10]; float num12 = array[num10 + 1]; items2[num9].x = num11; items2[num9].y = num12; items2[num9].z = z; items3[num9].x = array2[num10]; items3[num9].y = array2[num10 + 1]; items4[num9] = color; if (num11 < vector.x) { vector.x = num11; } else if (num11 > vector2.x) { vector2.x = num11; } if (num12 < vector.y) { vector.y = num12; } else if (num12 > vector2.y) { vector2.y = num12; } } } if (updateTriangles) { int count2 = exposedList.Count; int num13 = count2 + num3; if (num13 > exposedList.Items.Length) { Array.Resize(ref exposedList.Items, num13); } exposedList.Count = num13; int[] items5 = exposedList.Items; for (int l = 0; l < num3; l++) { items5[count2 + l] = array3[l] + count; } } } clipper.ClipEnd(slot2); } clipper.ClipEnd(); meshBoundsMin = vector; meshBoundsMax = vector2; meshBoundsThickness = (float)instruction.endSlot * zSpacing; int[] items6 = exposedList.Items; int m = exposedList.Count; for (int num14 = items6.Length; m < num14; m++) { items6[m] = 0; } submeshIndex++; }
public static void GenerateSkeletonRendererInstruction(SkeletonRendererInstruction instructionOutput, Skeleton skeleton, Dictionary <Slot, Material> customSlotMaterials, List <Slot> separatorSlots, bool generateMeshOverride, bool immutableTriangles = false) { ExposedList <Slot> drawOrder = skeleton.drawOrder; int count = drawOrder.Count; instructionOutput.Clear(); ExposedList <SubmeshInstruction> submeshInstructions = instructionOutput.submeshInstructions; instructionOutput.attachments.Resize(count); Attachment[] items = instructionOutput.attachments.Items; int num = 0; bool hasActiveClipping = false; SubmeshInstruction submeshInstruction = default(SubmeshInstruction); submeshInstruction.skeleton = skeleton; submeshInstruction.preActiveClippingSlotSource = -1; SubmeshInstruction submeshInstruction2 = submeshInstruction; bool flag = customSlotMaterials != null && customSlotMaterials.Count > 0; int num2 = (separatorSlots != null) ? separatorSlots.Count : 0; bool flag2 = num2 > 0; int num3 = -1; int preActiveClippingSlotSource = -1; SlotData slotData = null; int num4 = 0; Slot[] items2 = drawOrder.Items; for (int i = 0; i < count; i++) { Slot slot = items2[i]; Attachment attachment = items[i] = slot.attachment; int num5 = 0; int num6 = 0; object obj = null; bool flag3 = false; RegionAttachment regionAttachment = attachment as RegionAttachment; if (regionAttachment != null) { obj = regionAttachment.RendererObject; num5 = 4; num6 = 6; } else { MeshAttachment meshAttachment = attachment as MeshAttachment; if (meshAttachment != null) { obj = meshAttachment.RendererObject; num5 = meshAttachment.worldVerticesLength >> 1; num6 = meshAttachment.triangles.Length; } else { ClippingAttachment clippingAttachment = attachment as ClippingAttachment; if (clippingAttachment != null) { slotData = clippingAttachment.endSlot; num3 = i; submeshInstruction2.hasClipping = true; hasActiveClipping = true; } flag3 = true; } } if (slotData != null && slot.data == slotData) { slotData = null; num3 = -1; } if (flag2) { submeshInstruction2.forceSeparate = false; for (int j = 0; j < num2; j++) { if (object.ReferenceEquals(slot, separatorSlots[j])) { submeshInstruction2.forceSeparate = true; break; } } } if (flag3) { if (submeshInstruction2.forceSeparate && generateMeshOverride) { submeshInstruction2.endSlot = i; submeshInstruction2.preActiveClippingSlotSource = preActiveClippingSlotSource; submeshInstructions.Resize(num4 + 1); submeshInstructions.Items[num4] = submeshInstruction2; num4++; submeshInstruction2.startSlot = i; preActiveClippingSlotSource = num3; submeshInstruction2.rawTriangleCount = 0; submeshInstruction2.rawVertexCount = 0; submeshInstruction2.rawFirstVertexIndex = num; submeshInstruction2.hasClipping = (num3 >= 0); } continue; } Material value; if (flag) { if (!customSlotMaterials.TryGetValue(slot, out value)) { value = (Material)((AtlasRegion)obj).page.rendererObject; } } else { value = (Material)((AtlasRegion)obj).page.rendererObject; } if (submeshInstruction2.forceSeparate || (submeshInstruction2.rawVertexCount > 0 && !object.ReferenceEquals(submeshInstruction2.material, value))) { submeshInstruction2.endSlot = i; submeshInstruction2.preActiveClippingSlotSource = preActiveClippingSlotSource; submeshInstructions.Resize(num4 + 1); submeshInstructions.Items[num4] = submeshInstruction2; num4++; submeshInstruction2.startSlot = i; preActiveClippingSlotSource = num3; submeshInstruction2.rawTriangleCount = 0; submeshInstruction2.rawVertexCount = 0; submeshInstruction2.rawFirstVertexIndex = num; submeshInstruction2.hasClipping = (num3 >= 0); } submeshInstruction2.material = value; submeshInstruction2.rawTriangleCount += num6; submeshInstruction2.rawVertexCount += num5; submeshInstruction2.rawFirstVertexIndex = num; num += num5; } if (submeshInstruction2.rawVertexCount > 0) { submeshInstruction2.endSlot = count; submeshInstruction2.preActiveClippingSlotSource = preActiveClippingSlotSource; submeshInstruction2.forceSeparate = false; submeshInstructions.Resize(num4 + 1); submeshInstructions.Items[num4] = submeshInstruction2; } instructionOutput.hasActiveClipping = hasActiveClipping; instructionOutput.rawVertexCount = num; instructionOutput.immutableTriangles = immutableTriangles; }
public static void GenerateSingleSubmeshInstruction(SkeletonRendererInstruction instructionOutput, Skeleton skeleton, Material material) { ExposedList <Slot> drawOrder = skeleton.drawOrder; int count = drawOrder.Count; instructionOutput.Clear(); ExposedList <SubmeshInstruction> submeshInstructions = instructionOutput.submeshInstructions; submeshInstructions.Resize(1); instructionOutput.attachments.Resize(count); Attachment[] items = instructionOutput.attachments.Items; int num = 0; SubmeshInstruction submeshInstruction = default(SubmeshInstruction); submeshInstruction.skeleton = skeleton; submeshInstruction.preActiveClippingSlotSource = -1; submeshInstruction.startSlot = 0; submeshInstruction.rawFirstVertexIndex = 0; submeshInstruction.material = material; submeshInstruction.forceSeparate = false; submeshInstruction.endSlot = count; SubmeshInstruction submeshInstruction2 = submeshInstruction; bool hasActiveClipping = false; Slot[] items2 = drawOrder.Items; for (int i = 0; i < count; i++) { Slot slot = items2[i]; Attachment attachment = items[i] = slot.attachment; RegionAttachment regionAttachment = attachment as RegionAttachment; int num2; int num3; if (regionAttachment != null) { num2 = 4; num3 = 6; } else { MeshAttachment meshAttachment = attachment as MeshAttachment; if (meshAttachment != null) { num2 = meshAttachment.worldVerticesLength >> 1; num3 = meshAttachment.triangles.Length; } else { ClippingAttachment clippingAttachment = attachment as ClippingAttachment; if (clippingAttachment != null) { submeshInstruction2.hasClipping = true; hasActiveClipping = true; } num2 = 0; num3 = 0; } } submeshInstruction2.rawTriangleCount += num3; submeshInstruction2.rawVertexCount += num2; num += num2; } instructionOutput.hasActiveClipping = hasActiveClipping; instructionOutput.rawVertexCount = num; submeshInstructions.Items[0] = submeshInstruction2; }